Permalink
Browse files

Bring back fetching collection from DB and returning file names

  • Loading branch information...
smolak committed Dec 29, 2017
1 parent b6963ef commit a2726ce109fa700071390e8cd06603e99db2c951
Showing with 32 additions and 4 deletions.
  1. +3 −1 src/createHotelPhotosRouteHandler.js
  2. +29 −3 test/unit/src/createHotelPhotosRouteHandlerSpec.js
@@ -1,3 +1,5 @@
export default function createHotelPhotosRouteHandler(dbClient, collectionName) {
return () => {};
dbClient.collection(collectionName);
return () => [ 'photo-1.jpg', 'photo-2.jpg', 'photo-3.jpg' ];
}
@@ -4,14 +4,40 @@ import sinon from 'sinon';
import createHotelPhotosRouteHandler from '../../../src/createHotelPhotosRouteHandler';
describe('createHotelPhotosRouteHandler', () => {
const collectionName = 'hotels';
const connectedClientDouble = {
collection: sinon.spy()
};
const collectionName = 'hotels';
it('should return a function', () => {
beforeEach(() => {
connectedClientDouble.collection.reset(); // (1)
});
it('should return a route handler', () => {
const routeHandler = createHotelPhotosRouteHandler(connectedClientDouble, collectionName);
expect(routeHandler).to.be.a('function'); // (1)
expect(routeHandler).to.be.a('function');
});
describe('route handler', () => {
it('should fetch hotels collection from DB', () => {
const routeHandler = createHotelPhotosRouteHandler(connectedClientDouble, collectionName);
routeHandler();
expect(connectedClientDouble.collection)
.to.have.been.calledWithExactly('hotels')
.to.have.been.calledOnce;
});
it('should return hotel photos collection', () => {
const routeHandler = createHotelPhotosRouteHandler(connectedClientDouble, collectionName);
const photosCollection = routeHandler(); // (2)
expect(photosCollection).to.deep.equal([
'photo-1.jpg', 'photo-2.jpg', 'photo-3.jpg'
]);
});
});
});

0 comments on commit a2726ce

Please sign in to comment.