-
-
Save johnhamelink/3bc91203fb434a19e9e4 to your computer and use it in GitHub Desktop.
This file contains 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
var should = require('should'), | |
req = require('request'); | |
describe('Create a new research item',function(){ | |
var url = "http://localhost:3000/research/", | |
searchUrl = "http://localhost:3000/research/search", | |
params = { | |
name: 'test report', | |
type: 'comment', | |
idStaff: 1, | |
feedback: 'Great work!', | |
attachment: 'google.com/test.pdf', | |
attachmentMetaData: 'text/pdf', | |
email: 'This is a test email template', | |
status: 'published', | |
timeApproved: 123456, | |
approvedBy: 1, | |
isActive: 1 | |
}; | |
it("Request shouldn't be failing",function(done){ | |
req({ | |
url: url, | |
method: "post", | |
form: params | |
},function(error, response, body){ | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
done(); | |
}); | |
}); | |
it("Should Respond with valid JSON",function(){ | |
req({ | |
url: url, | |
method: "post", | |
form: params | |
},function(error, response, body){ | |
response.should.be.json; | |
done(); | |
}); | |
}); | |
it("Should show up on a search",function(){ | |
req({ | |
url: searchUrl, | |
method: "post", | |
form: params | |
},function(error, response, body){ | |
var json = JSON.parse(body); | |
json.should.be.a('object'); | |
json.should.not.be.a('array'); | |
done(); | |
}); | |
}); | |
}); | |
describe('list research items', function(){ | |
var url = 'http://localhost:3000/research'; | |
it("Request shouldn't be failing",function(done){ | |
req(url, function (error, response, body) { | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
done(); | |
}); | |
}); | |
it('Should respond with valid JSON', function(done){ | |
req(url, function (error, response, body) { | |
response.should.be.json; | |
done(); | |
}); | |
}); | |
it('Is not responding with an error',function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
json.should.not.include('Error'); | |
json.should.not.include('error'); | |
done(); | |
}); | |
}); | |
}); | |
describe('list research items, limited to 1 result',function(){ | |
var url = "http://localhost:3000/research?limit=1"; | |
it("Request should't be failing",function(done){ | |
req(url, function (error, response, body) { | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
done(); | |
}); | |
}); | |
it('Should respond with valid JSON',function(done){ | |
req(url, function (error, response, body) { | |
response.should.be.json; | |
done(); | |
}); | |
}); | |
it("Not responding with an error",function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
json.should.not.include('Error'); | |
json.should.not.include('error'); | |
done(); | |
}); | |
}); | |
it("Gives one result",function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
json.should.not.be.empty; | |
json.length.should.eql(1); | |
done(); | |
}); | |
}); | |
}); | |
describe('list research items, sorted by name',function(){ | |
var url = "http://localhost:3000/research?sort=[name|asc]"; | |
it("Request should't be failing",function(done){ | |
req(url, function (error, response, body) { | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
done(); | |
}); | |
}); | |
it('Should respond with valid JSON',function(done){ | |
req(url, function (error, response, body) { | |
response.should.be.json; | |
done(); | |
}); | |
}); | |
it("Not responding with an error",function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
json.should.not.include('Error'); | |
json.should.not.include('error'); | |
done(); | |
}); | |
}); | |
it("Sorts Results",function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
if(json.length > 1){ | |
var names = [json[0].name,json[1].name], | |
sortedNames = names.sort(); | |
names.should.eql(sortedNames); | |
} else { | |
throw new Error('Not enough rows exist in DB to test.'); | |
} | |
done(); | |
}); | |
}); | |
}); | |
describe('Distinct research item names',function(){ | |
var url = "http://localhost:3000/research?sort=[name|distinct]"; | |
it("Request should't be failing",function(done){ | |
req(url, function (error, response, body) { | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
done(); | |
}); | |
}); | |
it('Should respond with valid JSON',function(done){ | |
req(url, function (error, response, body) { | |
response.should.be.json; | |
done(); | |
}); | |
}); | |
it("Not responding with an error",function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
json.should.not.include('Error'); | |
json.should.not.include('error'); | |
done(); | |
}); | |
}); | |
it("Responding distinctly",function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
json.should.be.a('object'); | |
json.length.should.be.above(0); | |
done(); | |
}); | |
}); | |
}); | |
describe('Show individual research item',function(done){ | |
var url = "http://localhost:3000/research/4f1934eae60df10000000001"; | |
it("Request should't be failing",function(done){ | |
req(url, function (error, response, body) { | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
done(); | |
}); | |
}); | |
it('Should respond with valid JSON',function(done){ | |
req(url, function (error, response, body) { | |
response.should.be.json; | |
done(); | |
}); | |
}); | |
it("Not responding with an error",function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
if(json){ | |
json.should.not.have.property('Error'); | |
json.should.not.have.property('error'); | |
} else { | |
throw new Error("JSON didn't parse correctly or output was null"); | |
} | |
done(); | |
}); | |
}); | |
it("Gives one result",function(done){ | |
req(url, function (error, response, body) { | |
var json = JSON.parse(body); | |
if(json){ | |
json.should.be.a('object'); | |
json.should.not.be.a('array'); | |
} else { | |
throw new Error("JSON didn't parse correctly or output was null"); | |
} | |
done(); | |
}); | |
}); | |
}); | |
describe('Search for a research item',function(){ | |
var url = "http://localhost:3000/research/search", | |
params1 = { | |
name: "test report" | |
}, | |
params2 = { | |
idStaff: 1 | |
}, | |
params3 = { | |
name: "test report", | |
idStaff: 1 | |
}; | |
it("Should be able to search for a string ({ name: 'test report' })",function(done){ | |
req({ | |
url: url, | |
method: "post", | |
form: params1 | |
},function(error, response, body){ | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
response.should.be.json; | |
var json = JSON.parse(body); | |
json.should.be.a('object'); | |
json[0].should.have.property('name'); | |
done(); | |
}); | |
}); | |
it("Should be able to search for an integer ({ idStaff: 1 })",function(done){ | |
req({ | |
url: url, | |
method: "post", | |
form: params2 | |
},function(error, response, body){ | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
response.should.be.json; | |
var json = JSON.parse(body); | |
json.should.be.a('object'); | |
json[0].should.have.property('name'); | |
done(); | |
}); | |
}); | |
it("Should be able to search with multiple conditions ({ name: 'test report', idStaff: 1 })",function(done){ | |
req({ | |
url: url, | |
method: "post", | |
form: params3 | |
},function(error, response, body){ | |
if(error){ | |
error.should.equal(null); | |
} | |
response.statusCode.should.equal(200); | |
response.should.be.json; | |
var json = JSON.parse(body); | |
json.should.be.a('object'); | |
json[0].should.have.property('name'); | |
done(); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment