Skip to content

Commit 839358d

Browse files
authored
Merge pull request #879 from opentripplanner/unchanged-files-check-annotations
Address unchanged files with check annotations
2 parents f230ae9 + 0f05128 commit 839358d

File tree

3 files changed

+183
-158
lines changed

3 files changed

+183
-158
lines changed

__tests__/test-utils/index.js renamed to __tests__/test-utils/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Sun Aug 04 2019 19:34:56 GMT-0700
22
const DEFAULT_TEST_TIME = Date.UTC(2019, 7, 5, 2, 34, 56, 78)
33

4-
export function timeoutPromise (ms) {
5-
return new Promise((resolve, reject) => {
4+
export function timeoutPromise(ms: number): Promise<void> {
5+
return new Promise((resolve) => {
66
setTimeout(resolve, ms)
77
})
88
}
@@ -17,7 +17,7 @@ export function timeoutPromise (ms) {
1717
* https://stackoverflow.com/a/42787232/915811 (basically, moment.js uses
1818
* Date#now internally).
1919
*/
20-
export function setTestTime (time) {
20+
export function setTestTime(time: number): void {
2121
const date = new Date(time)
2222
// Log human-readable date to help out human testers.
2323
console.log(`Setting test time to ${date}`)
@@ -28,14 +28,15 @@ export function setTestTime (time) {
2828
* Sets the default mock test time for a variety of tests such that various
2929
* calculations and feed version statuses resolve to a certain state.
3030
*/
31-
export function setDefaultTestTime () {
31+
export function setDefaultTestTime(): void {
3232
setTestTime(DEFAULT_TEST_TIME)
3333
}
3434

3535
/**
3636
* Restore the standard functionality of Date library. This should be used in
3737
* the afterEach clause in test suites that require a mocked date.
3838
*/
39-
export function restoreDateNowBehavior () {
40-
Date.now.mockRestore && Date.now.mockRestore()
39+
export function restoreDateNowBehavior(): void {
40+
const now = Date.now as jest.Mock
41+
now.mockRestore && now.mockRestore()
4142
}

__tests__/util/itinerary.js

Lines changed: 0 additions & 152 deletions
This file was deleted.

__tests__/util/itinerary.ts

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/* globals describe, expect, it */
2+
3+
import {
4+
getItineraryDefaultMonitoredDays,
5+
itineraryCanBeMonitored
6+
} from '../../lib/util/itinerary'
7+
import { WEEKDAYS, WEEKEND_DAYS } from '../../lib/util/monitored-trip'
8+
9+
const walkLeg = {
10+
mode: 'WALK'
11+
}
12+
13+
describe('util > itinerary', () => {
14+
describe('itineraryCanBeMonitored', () => {
15+
const transitLeg = {
16+
mode: 'BUS',
17+
transitLeg: true
18+
}
19+
const rentalBikeLeg = {
20+
mode: 'BICYCLE_RENT',
21+
rentedBike: true
22+
}
23+
const rentalCarLeg = {
24+
mode: 'CAR_RENT',
25+
rentedCar: true
26+
}
27+
const rentalMicromobilityLeg = {
28+
mode: 'MICROMOBILITY_RENT',
29+
rentedVehicle: true
30+
}
31+
const rideHailLeg = {
32+
hailedCar: true,
33+
mode: 'CAR_HAIL'
34+
}
35+
36+
const testCases = [
37+
{
38+
expected: true,
39+
itinerary: {
40+
legs: [transitLeg, walkLeg]
41+
},
42+
title:
43+
'should be true for an itinerary with transit, no rentals/ride hail.'
44+
},
45+
{
46+
expected: false,
47+
itinerary: {
48+
legs: [walkLeg, rentalBikeLeg]
49+
},
50+
title: 'should be false for an itinerary without transit.'
51+
},
52+
{
53+
expected: false,
54+
itinerary: {
55+
legs: [walkLeg, transitLeg, rentalBikeLeg]
56+
},
57+
title: 'should be false for an itinerary with transit and rental bike.'
58+
},
59+
{
60+
expected: false,
61+
itinerary: {
62+
legs: [walkLeg, transitLeg, rentalCarLeg]
63+
},
64+
title: 'should be false for an itinerary with transit and rental car.'
65+
},
66+
{
67+
expected: false,
68+
itinerary: {
69+
legs: [walkLeg, transitLeg, rentalMicromobilityLeg]
70+
},
71+
title:
72+
'should be false for an itinerary with transit and rental micromobility.'
73+
},
74+
{
75+
expected: false,
76+
itinerary: {
77+
legs: [walkLeg, transitLeg, rideHailLeg]
78+
},
79+
title: 'should be false for an itinerary with transit and ride hail.'
80+
},
81+
{
82+
expected: false,
83+
itinerary: {},
84+
title: 'should be false for a blank itinerary.'
85+
},
86+
{
87+
expected: false,
88+
itinerary: null,
89+
title: 'should be false for a null itinerary.'
90+
}
91+
]
92+
93+
testCases.forEach(({ expected, itinerary, title }) => {
94+
it(`${title}`, () => {
95+
expect(itineraryCanBeMonitored(itinerary)).toBe(expected)
96+
})
97+
})
98+
})
99+
describe('getItineraryDefaultMonitoredDays', () => {
100+
const transitLegWeekday = {
101+
mode: 'BUS',
102+
serviceDate: '20210609', // Wednesday
103+
transitLeg: true
104+
}
105+
const transitLegSaturday = {
106+
mode: 'BUS',
107+
serviceDate: '20210612', // Saturday
108+
transitLeg: true
109+
}
110+
const transitLegSunday = {
111+
mode: 'BUS',
112+
serviceDate: '20210613', // Sunday
113+
transitLeg: true
114+
}
115+
116+
const testCases = [
117+
{
118+
expected: WEEKDAYS,
119+
itinerary: {
120+
legs: [walkLeg, transitLegWeekday]
121+
},
122+
title:
123+
"should be ['monday' thru 'friday'] for an itinerary starting on a weekday."
124+
},
125+
{
126+
expected: WEEKEND_DAYS,
127+
itinerary: {
128+
legs: [walkLeg, transitLegSaturday]
129+
},
130+
title:
131+
"should be ['saturday', 'sunday'] for an itinerary starting on a Saturday."
132+
},
133+
{
134+
expected: WEEKEND_DAYS,
135+
itinerary: {
136+
legs: [walkLeg, transitLegSunday]
137+
},
138+
title:
139+
"should be ['saturday', 'sunday'] for an itinerary starting on a Sunday."
140+
},
141+
{
142+
expected: WEEKDAYS,
143+
itinerary: {
144+
legs: [walkLeg],
145+
startTime: 1623341891000 // Thursday 2021-06-10 12:18 pm EDT
146+
},
147+
title:
148+
"should be ['monday' thru 'friday'] for an itinerary without transit starting on a weekday (fallback case)."
149+
},
150+
{
151+
expected: WEEKEND_DAYS,
152+
itinerary: {
153+
legs: [walkLeg],
154+
startTime: 1623514691000 // Saturday 2021-06-12 12:18 pm EDT
155+
},
156+
title:
157+
"should be ['saturday', 'sunday'] for an itinerary without transit starting on a Saturday (fallback case)."
158+
},
159+
{
160+
expected: WEEKEND_DAYS,
161+
itinerary: {
162+
legs: [walkLeg],
163+
startTime: 1623601091000 // Sunday 2021-06-13 12:18 pm EDT
164+
},
165+
title:
166+
"should be ['saturday', 'sunday'] for an itinerary without transit starting on a Sunday (fallback case)."
167+
}
168+
]
169+
170+
testCases.forEach(({ expected, itinerary, title }) => {
171+
it(`${title}`, () => {
172+
expect(getItineraryDefaultMonitoredDays(itinerary)).toBe(expected)
173+
})
174+
})
175+
})
176+
})

0 commit comments

Comments
 (0)