-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
40 lines (35 loc) · 1.01 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import proxyquire from 'proxyquire';
import sinon from 'sinon';
import test from 'ava';
const mockCompanyId = 'catahoula-inc-123';
const mockMealDetails = {
name: 'Pho Ga',
description: 'Pure deliciousness'
};
const mockMeals = [{
id: 'pho-ga'
}, {
id: 'cha-gio'
}];
const stubFetchMealById = sinon.stub()
.withArgs('pho-ga').resolves(mockMealDetails);
const stubFetchMeals = sinon.stub()
.withArgs(mockCompanyId).resolves(mockMeals);
const stubIsTodaysMeal = meal => {
return meal.id === 'pho-ga';
};
const zerocaterService = proxyquire
.noCallThru()
.load('.', {
'./fetch-meal-by-id': stubFetchMealById,
'./fetch-meals': stubFetchMeals,
'./is-todays-meal': stubIsTodaysMeal
});
test('it proxies calls to get all meals', async t => {
const result = await zerocaterService.all(mockCompanyId);
t.deepEqual(result, mockMeals);
});
test('it identifies and returns today\'s meal', async t => {
const result = await zerocaterService.today(mockCompanyId);
t.deepEqual(result, mockMealDetails);
});