Created
September 24, 2013 12:05
-
-
Save logicware/6683751 to your computer and use it in GitHub Desktop.
Examples of tests created with mocha/should for a node.js server for an app based on xWiki.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Testing createBlogPost', function(){ | |
it('Should Create Blog Post and return code=2', function(done){ | |
request.post({url:baseURL + "/api/createBlogPost", json:true,body:JSON.stringify({blogPostName:blogPostName, blogPostTitle:blogPostTitle, blogPostContent:blogPostContent})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); // is already there, will return 1 | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing createBlogPost with existing post', function(){ | |
it('Should Not Create Blog Post if same exists and return code=1', function(done){ | |
request.post({url:baseURL + "/api/createBlogPost", json:true,body:JSON.stringify({blogPostName:blogPostName, blogPostTitle:blogPostTitle, blogPostContent:blogPostContent})}, | |
function(error,resp,body){ | |
body.code.should.equal(1); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing /getBlog', function(){ | |
it('Retrieve Blog Post and get code=200', function(done){ | |
request.post({url:baseURL + "/api/getBlog", json:true, body:JSON.stringify({blogPostName:blogPostName})}, | |
function(error,resp,body){ | |
//console.log(body); | |
body.code.should.equal(200); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing deleteBlogPost', function(){ | |
it('Should delete Blog Post and return code=2', function(done){ | |
request.post({url:baseURL + "/api/deleteBlog", json:true,body:JSON.stringify({blogPostName:blogPostName, blogPostTitle:blogPostTitle, blogPostContent:blogPostContent})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing deleteBlogPost', function(){ | |
it('Blog Post should not exist and return code=1', function(done){ | |
request.post({url:baseURL + "/api/deleteBlog", json:true,body:JSON.stringify({blogPostName:blogPostName, blogPostTitle:blogPostTitle, blogPostContent:blogPostContent})}, | |
function(error,resp,body){ | |
body.code.should.equal(1); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing createSpace', function(){ | |
it('Should Create Space and return code=2', function(done){ | |
request.post({url:baseURL + "/api/createSpace", json:true,body:JSON.stringify({creator:spaceCreator, spaceName:spaceName})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing Duplicate createSpace ', function(){ | |
it('Should NOT Create Duplicate Space and return code=1', function(done){ | |
request.post({url:baseURL + "/api/createSpace", json:true,body:JSON.stringify({creator:spaceCreator, spaceName:spaceName})}, | |
function(error,resp,body){ | |
body.code.should.equal(1); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing getSpacesByCreator', function(){ | |
it('Should Get Space and return code=2', function(done){ | |
request.post({url:baseURL + "/api/getSpacesByCreator", json:true,body:JSON.stringify({creator:spaceCreator, spaces:[spaceName] })}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing deleteSpace ', function(){ | |
it('Should Delete Space and return code=2', function(done){ | |
request.post({url:baseURL + "/api/deleteSpace", json:true,body:JSON.stringify({creator:spaceCreator, spaceName:spaceName, pageName:pageName})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing createPage', function(){ | |
it('Should Create Page and return code=2', function(done){ | |
request.post({url:baseURL + "/api/createPage", json:true,body:JSON.stringify({creator:spaceCreator, spaceName:spaceName, pageName:pageName2, pageTitle:pageTitle, pageContent:pageContent })}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing duplicate createPage', function(){ | |
it('Should NOT Create Page and return code=1', function(done){ | |
request.post({url:baseURL + "/api/createPage", json:true,body:JSON.stringify({creator:spaceCreator, spaceName:spaceName, pageName:pageName2, pageTitle:pageTitle, pageContent:pageContent })}, | |
function(error,resp,body){ | |
body.code.should.equal(1); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing deletePage', function(){ | |
it('Should Delete Page and return code=2', function(done){ | |
request.post({url:baseURL + "/api/deletePage", json:true,body:JSON.stringify({spaceName:spaceCreator + '_' + spaceName, pageName:pageName2 })}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing createTag', function(){ | |
it('Should Create Tag and return code=2', function(done){ | |
request.post({url:baseURL + "/api/createTag", json:true,body:JSON.stringify({creator: '', spaceName:'matloob', pageName:'NewPage1', tagName:'painful headache'})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing Attach Page', function(){ | |
it('Should Attach Page and return code=2', function(done){ | |
request.post({url:baseURL + "/api/attachPage", json:true,body:JSON.stringify({collectionType: 'tags', creator: '', spaceName:'matloob', pageName:'NewPage1', tagName:'boring'})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing create Relation', function(){ | |
it('Should Create Relation and return code=2', function(done){ | |
request.post({url:baseURL + "/api/createRelation", json:true,body:JSON.stringify({collectionType: 'relations', creator: '', spaceName:'matloob', pageName:'NewPage1', | |
relName:'Last step', spaceName2:'Main', pageName2:'MainPage'})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing Attach Attribute', function(){ | |
it('Should Attach Attribute and return code=2', function(done){ | |
request.post({url:baseURL + "/api/attachAttribute", json:true,body:JSON.stringify({collectionType: 'attributes', creator: '', spaceName:'matloob', pageName:'NewPage1', | |
attribName:'Cost', attribType:'number', attribValue: 10000})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); | |
describe('Testing Delete Attribute', function(){ | |
it('Should Delete Attribute and return code=2', function(done){ | |
request.post({url:baseURL + "/api/deleteAttribute", json:true,body:JSON.stringify({collectionType: 'attributes', creator: '', spaceName:'matloob', pageName:'NewPage1', | |
attribName:'Cost'})}, | |
function(error,resp,body){ | |
body.code.should.equal(2); | |
done(); | |
} | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment