-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
85 lines (75 loc) · 3.36 KB
/
tests.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
80
81
82
83
84
85
const scriptToTest = process.argv[3] === 'solutions' ? './solutions' : './problems'
const assert = require('chai').assert
const {
Author,
getReadersOfBooks,
Equipment,
Service,
airportData,
Person,
Identifier
} = require(scriptToTest)
describe('Refactor a simple loop into a pipeline', () => {
it ('gets twitter handles for a given list of authors and company', () => {
const authors =
[ {name: 'Gary', twitterHandle: '@gary', company: 'Apple'}
, {name: 'Carla', twitterHandle: '@carla', company: 'Apple'}
, {name: 'Jessica', twitterHandle: '@jessica', company: 'Microsoft'}
].map(author =>
new Author(author.name, author.twitterHandle, author.company))
assert.deepEqual(Author.twitterHandles(authors, 'Apple'), [ '@gary', '@carla' ])
})
})
describe('Nested loop - reader of books', () => {
it ('gets readers of books on a given date', () => {
const result = getReadersOfBooks(['Gary', 'Carla'], ['Dracula'], Date.now())
assert.deepEqual([...result], [ 'Carla' ])
})
})
describe('Equipment Offerings', () => {
it ('marks possible equipment preferences', () => {
assert.deepEqual(Equipment.allOfferings(),
[{region: 'boston', supported: 'snow-blower', supplied: 'snow-blower', isPreferred: true, isMatch: true}
,{region: 'boston', supported: 'snow-blower', supplied: 'snow-shovel', isPreferred: false, isMatch: false}
,{region: 'miami', supported: 'snow-shovel', supplied: 'snow-blower', isPreferred: false, isMatch: false}
])
Service.markPreferredOferrings(Equipment)
assert.deepEqual(Equipment.allOfferings(),
[{region: 'boston', supported: 'snow-blower', supplied: 'snow-blower', isPreferred: true, isMatch: true}
,{region: 'boston', supported: 'snow-blower', supplied: 'snow-shovel', isPreferred: false, isMatch: false}
,{region: 'miami', supported: 'snow-shovel', supplied: 'snow-blower', isPreferred: true, isMatch: false}
])
})
})
describe('Group flight data', () => {
it ('groups flight data', () => {
assert.deepEqual(airportData(), { LAX: { meanDelay: 0.05, cancellationRate: 0.3333333333333333 } })
})
})
describe('Identifiers', () => {
it('doesnt check ids unless ids present', () => {
const person = new Person()
const note = person.checkValidIds()
assert.deepEqual(note, { errors: [ 'has no ids' ] })
})
it('notifies if duplicate schemes are present', () => {
const person = new Person([new Identifier('scheme1', 1), new Identifier('scheme2', 2), new Identifier('scheme2', 2)])
const note = person.checkValidIds()
assert.deepEqual(note, { errors: [ 'duplicate schemes: scheme2' ] })
})
it('skips void schemes', () => {
const person = new Person([new Identifier('scheme1', 1), new Identifier('scheme2', 2), new Identifier('scheme2', 2, true)])
const note = person.checkValidIds()
assert.deepEqual(note, { errors: [] })
})
it('notifies if required schemes are missing', () => {
const person = new Person([new Identifier('scheme1', 1), new Identifier('scheme2', 2), new Identifier('scheme3', 3)])
const note = person.checkValidIds(['scheme1', 'scheme4'])
assert.deepEqual(note, { errors: [ 'missing schemes: scheme4' ] })
})
it('doesnt notify if all required shemes are present', () => {
const person = new Person([new Identifier('scheme1', 1), new Identifier('scheme2', 2), new Identifier('scheme3', 3)])
const note = person.checkValidIds(['scheme1', 'scheme3'])
assert.deepEqual(note, { errors: [] })
})
})