-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new integration tests for notes API. In these tests we can test the whole API, check HTTP response codes and content.
- Loading branch information
1 parent
bc37f74
commit efc62e1
Showing
4 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,6 @@ console.log(config) | |
console.log(server) | ||
|
||
server.start() | ||
|
||
// Export the app for testing | ||
module.exports = app |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Import the dependencies for testing | ||
const chai = require('chai') | ||
const chaiHttp = require('chai-http') | ||
const mocha = require('mocha') | ||
const app = require('../../../index') | ||
|
||
const describe = mocha.describe | ||
const it = mocha.it | ||
const expect = chai.expect | ||
|
||
// Configure chai | ||
chai.use(chaiHttp) | ||
chai.should() | ||
|
||
var noteId | ||
let note = { | ||
'topic': 'test', | ||
'description': 'API Testing', | ||
'user': 'Tester', | ||
'session_id': 'test' | ||
} | ||
|
||
describe('Notes API', function () { | ||
describe('/POST notes', function () { | ||
it('Should insert a note', function () { | ||
return chai.request(app) | ||
.post('/notes') | ||
.send(note) | ||
.then((res) => { | ||
res.should.have.status(200) | ||
res.body.should.be.a('object') | ||
|
||
expect(res.body.topic).to.equal(note.topic) | ||
|
||
noteId = res.body.id | ||
}) | ||
}) | ||
}) | ||
|
||
describe('/GET notes from sessions', function () { | ||
it('Should get notes from session', function () { | ||
return chai.request(app) | ||
.get('/notes/test') | ||
.then((res) => { | ||
res.should.have.status(200) | ||
res.body.should.be.a('array') | ||
|
||
expect(res.body[0].description).to.equal(note.description) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('/PUT notes', function () { | ||
it('Should update a note', function () { | ||
var newDescription = 'updated note' | ||
note.description = newDescription | ||
return chai.request(app) | ||
.put('/notes/' + noteId) | ||
.send(note) | ||
.then((res) => { | ||
res.should.have.status(200) | ||
res.body.should.be.a('object') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('/DELETE note', function () { | ||
it('Should delete note', function () { | ||
return chai.request(app) | ||
.delete('/notes/' + noteId) | ||
.then((res) => { | ||
res.should.have.status(200) | ||
res.body.should.be.a('object') | ||
}) | ||
}) | ||
}) | ||
}) |