Skip to content

Instantly share code, notes, and snippets.

@mickaelw
Last active August 18, 2020 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickaelw/16a596f4a2e6e2e9d84f81890e508cab to your computer and use it in GitHub Desktop.
Save mickaelw/16a596f4a2e6e2e9d84f81890e508cab to your computer and use it in GitHub Desktop.
describe('Integration | Controller | Book information', () => {
let app: Express
let fakeDependencies: Dependencies
beforeEach(() => {
fakeDependencies = {
bookInformation: sinon.stub()
}
app = express()
bookstoreRoutes(app, fakeDependencies)
})
it('GET /books/:id succès', done => {
fakeDependencies.bookInformation.resolves(new BookDetails('title', true))
supertest
.agent(app)
.get('/books/bookId')
.expect(200)
.then(res => {
expect(fakeDependencies.bookInformation).to.have.been.calledOnceWith('bookId')
expect(res.body).to.be.deep.equal({ title: 'title', is_available: true })
done()
})
})
it('GET /books/:id échec', done => {
fakeDependencies.bookInformation.rejects('Book not found')
supertest
.agent(app)
.get('/books/unknownBookId')
.expect(404)
.then(res => {
expect(res.body).to.be.equal('Book not found')
done()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment