Permalink
Browse files

Return file names in response body with response code 200

  • Loading branch information...
smolak committed Dec 29, 2017
1 parent a2726ce commit f00f6388e1f0f4f4c9c98f1260af20c4d80b403a
Showing with 20 additions and 6 deletions.
  1. +4 −1 src/createHotelPhotosRouteHandler.js
  2. +16 −5 test/unit/src/createHotelPhotosRouteHandlerSpec.js
@@ -1,5 +1,8 @@
export default function createHotelPhotosRouteHandler(dbClient, collectionName) {
dbClient.collection(collectionName);
return () => [ 'photo-1.jpg', 'photo-2.jpg', 'photo-3.jpg' ];
return (ctx) => {
ctx.response.status = 200;
ctx.response.body = [ 'photo-1.jpg', 'photo-2.jpg', 'photo-3.jpg' ];
};
}
@@ -9,9 +9,18 @@ describe('createHotelPhotosRouteHandler', () => {
const connectedClientDouble = {
collection: sinon.spy()
};
const ctxDouble = {
response: { // (1)
status: 0,
body: ''
}
};
beforeEach(() => {
connectedClientDouble.collection.reset(); // (1)
connectedClientDouble.collection.reset();
ctxDouble.response.status = 0; // (2)
ctxDouble.response.body = '';
});
it('should return a route handler', () => {
@@ -24,18 +33,20 @@ describe('createHotelPhotosRouteHandler', () => {
it('should fetch hotels collection from DB', () => {
const routeHandler = createHotelPhotosRouteHandler(connectedClientDouble, collectionName);
routeHandler();
routeHandler(ctxDouble);
expect(connectedClientDouble.collection)
.to.have.been.calledWithExactly('hotels')
.to.have.been.calledOnce;
});
it('should return hotel photos collection', () => {
it('should return hotel photos collection', () => { // (3)
const routeHandler = createHotelPhotosRouteHandler(connectedClientDouble, collectionName);
const photosCollection = routeHandler(); // (2)
expect(photosCollection).to.deep.equal([
routeHandler(ctxDouble); // (4)
expect(ctxDouble.response.status).to.equal(200);
expect(ctxDouble.response.body).to.deep.equal([
'photo-1.jpg', 'photo-2.jpg', 'photo-3.jpg'
]);
});

0 comments on commit f00f638

Please sign in to comment.