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