-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
155 lines (130 loc) · 6.07 KB
/
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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict'
const tapeWithoutPromise = require('tape')
const addPromiseSupport = require('tape-promise').default
const tape = addPromiseSupport(tapeWithoutPromise)
const tests = require('.')
tape('fpti-tests.packageJson', async (t) => {
const validPackage1 = {
dependencies: {
'validate-fptf': '2.1.1'
}
}
const validPackage2 = {
devDependencies: {
'validate-fptf': '2.1.1'
}
}
const invalidPackage1 = {}
const invalidPackage2 = { dependencies: {
'validate-fptf': '0.0.0'
} }
await tests.packageJson(validPackage1).then(() => t.pass()).catch(() => t.fail())
await tests.packageJson(validPackage2).then(() => t.pass()).catch(() => t.fail())
await tests.packageJson(invalidPackage1).then(() => t.fail()).catch(() => t.pass())
await tests.packageJson(invalidPackage2).then(() => t.fail()).catch(() => t.pass())
t.end()
})
tape('fpti-tests.packageExports', (t) => {
const package1 = {
journeys: () => 1,
stations: {
all: () => 1,
nearby: () => 1
}
}
package1.journeys.features = {}
package1.stations.all.features = {}
package1.stations.nearby.features = {}
const package2 = {
journeys: () => 1,
stops: {
nearby: () => 1
},
regions: {
all: () => 1
},
otherMethod: () => 1
}
package2.journeys.features = {}
package2.regions.all.features = {}
package2.stops.nearby.features = {}
const package3 = {
journeys: () => 1,
stopovers: { features: {} }
}
package3.journeys.features = {}
const package4 = {
otherMethod: 1
}
const package5 = {
journeys: () => 1,
regions: {
search: () => 1
}
}
package5.journeys.features = {}
t.ok(tests.packageExports(package1, ['journeys', 'stations.all', 'stations.nearby']))
t.throws(() => tests.packageExports(package1, ['journeys', 'stations.nearby']))
t.throws(() => tests.packageExports(package1, ['journeys', 'stations.nearby', 'stations.all', 'stopovers']))
t.ok(tests.packageExports(package2, ['journeys', 'regions.all', 'stops.nearby']))
t.throws(() => tests.packageExports(package3, ['journeys', 'stopovers']))
t.throws(() => tests.packageExports(package3, ['journeys']))
t.throws(() => tests.packageExports(package4, ['stations.all']))
t.throws(() => tests.packageExports(package4, []))
t.throws(() => tests.packageExports(package5, ['journeys', 'regions.search']))
package5.regions.search.features = {}
t.ok(tests.packageExports(package5, ['journeys', 'regions.search']))
t.end()
})
tape('fpti-tests._features', (t) => {
const _allFeatures1 = {}
const _allFeatures2 = { otherOption: 'description' }
const _nearbyFeatures1 = { results: 'description' }
const _nearbyFeatures2 = { otherOption: 'description' }
const _nearbyFeatures3 = { results: 1 }
const _searchFeatures1 = { results: 'description' }
const _searchFeatures2 = { otherOption: 'description' }
const stopoversFeatures1 = { when: 'description', departureAfter: 'description', results: 'description', interval: 'description' }
const stopoversFeatures2 = { when: 'description', otherOption: 'description' }
const journeysFeatures1 = { when: 'description', departureAfter: 'description', results: 'description', interval: 'description', transfers: 'description' }
const journeysFeatures2 = { when: 'description', otherOption: 'description' }
t.ok(tests.stationsAllFeatures(_allFeatures1, []))
t.ok(tests.stationsAllFeatures(_allFeatures2, []))
t.ok(tests.stopsAllFeatures(_allFeatures1, []))
t.ok(tests.stopsAllFeatures(_allFeatures2, []))
t.ok(tests.regionsAllFeatures(_allFeatures1, []))
t.ok(tests.regionsAllFeatures(_allFeatures2, []))
t.ok(tests.stationsNearbyFeatures(_nearbyFeatures1, ['results']))
t.throws(() => tests.stationsNearbyFeatures(_nearbyFeatures1, ['results', 'distance']))
t.throws(() => tests.stationsNearbyFeatures(_nearbyFeatures2, ['results']))
t.throws(() => tests.stationsNearbyFeatures(_nearbyFeatures2, []))
t.throws(() => tests.stationsNearbyFeatures(_nearbyFeatures3, ['results']))
t.ok(tests.stopsNearbyFeatures(_nearbyFeatures1, ['results']))
t.throws(() => tests.stopsNearbyFeatures(_nearbyFeatures1, ['results', 'distance']))
t.throws(() => tests.stopsNearbyFeatures(_nearbyFeatures2, ['results']))
t.throws(() => tests.stopsNearbyFeatures(_nearbyFeatures2, []))
t.ok(tests.regionsNearbyFeatures(_nearbyFeatures1, ['results']))
t.throws(() => tests.regionsNearbyFeatures(_nearbyFeatures1, ['results', 'distance']))
t.throws(() => tests.regionsNearbyFeatures(_nearbyFeatures2, ['results']))
t.throws(() => tests.regionsNearbyFeatures(_nearbyFeatures2, []))
t.ok(tests.stationsSearchFeatures(_searchFeatures1, ['results']))
t.throws(() => tests.stationsSearchFeatures(_searchFeatures2, ['results']))
t.throws(() => tests.stationsSearchFeatures(_searchFeatures2, []))
t.ok(tests.stopsSearchFeatures(_searchFeatures1, ['results']))
t.throws(() => tests.stopsSearchFeatures(_searchFeatures2, ['results']))
t.throws(() => tests.stopsSearchFeatures(_searchFeatures2, []))
t.ok(tests.regionsSearchFeatures(_searchFeatures1, ['results']))
t.throws(() => tests.regionsSearchFeatures(_searchFeatures2, ['results']))
t.throws(() => tests.regionsSearchFeatures(_searchFeatures2, []))
t.ok(tests.stopoversFeatures(stopoversFeatures1, ['when', 'departureAfter', 'results', 'interval']))
t.throws(() => tests.stopoversFeatures(stopoversFeatures1, ['when', 'departureAfter', 'results']))
t.throws(() => tests.stopoversFeatures(stopoversFeatures1, ['when', 'departureAfter', 'results', 'interval', 'direction']))
t.throws(() => tests.stopoversFeatures(stopoversFeatures2, ['when', 'departureAfter', 'results', 'interval']))
t.throws(() => tests.stopoversFeatures(stopoversFeatures2, []))
t.ok(tests.journeysFeatures(journeysFeatures1, ['when', 'departureAfter', 'results', 'interval', 'transfers']))
t.throws(() => tests.journeysFeatures(journeysFeatures1, ['when', 'departureAfter', 'results', 'transfers']))
t.throws(() => tests.journeysFeatures(journeysFeatures1, ['when', 'departureAfter', 'results', 'interval', 'transfers', 'via']))
t.throws(() => tests.journeysFeatures(journeysFeatures2, ['when', 'departureAfter', 'results', 'interval', 'transfers']))
t.throws(() => tests.journeysFeatures(journeysFeatures2, []))
t.end()
})