-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcontroller.spec.js
79 lines (58 loc) · 1.82 KB
/
controller.spec.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import controller from './controller';
import trailData from '../trail-data';
describe('module-4ab/api/trails/controller', () => {
function aMockResponse() {
//... no changes
}
function getLastCallArgs(mockResponse) {
//... no changes
}
it('returns all trails with no criteria', () => {
//... no changes
});
it('filters by sport', () => {
//... no changes
});
it('filters by hills', () => {
//... no changes
});
// SOLUTION!
describe('filters by distance', () => {
it('returns trails within a mile when distance is less than 10', () => {
const mockResponse = aMockResponse();
const request = {
query: {
distance: 3,
},
};
controller.get(request, mockResponse);
const lastCallArgs = getLastCallArgs(mockResponse);
expect(lastCallArgs.length).toEqual(7);
expect(lastCallArgs.some(x => x.name === 'Scuppernong 5k')).toBe(true);
});
it('returns trails within 2 miles when distance is between 10 and 20', () => {
const mockResponse = aMockResponse();
const request = {
query: {
distance: 16,
},
};
controller.get(request, mockResponse);
const lastCallArgs = getLastCallArgs(mockResponse);
expect(lastCallArgs.length).toEqual(2);
expect(lastCallArgs.some(x => x.name === 'New Berlin Trail')).toBe(true);
});
it('returns trails within 3 miles when distance is more than 20', () => {
const mockResponse = aMockResponse();
const request = {
query: {
distance: 23,
},
};
controller.get(request, mockResponse);
const lastCallArgs = getLastCallArgs(mockResponse);
expect(lastCallArgs.length).toEqual(3);
expect(lastCallArgs.some(x => x.name === 'Devils Lake')).toBe(true);
});
});
});