Last active
August 18, 2020 10:13
-
-
Save mickaelw/16a596f4a2e6e2e9d84f81890e508cab 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
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