From 23cd4f9f69d3e02c5822de6b50cae4e7ccea0626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adriana=20Ceri=C4=87?= <62163307+AdrianaCeric@users.noreply.github.com> Date: Fri, 28 Apr 2023 13:07:45 -0400 Subject: [PATCH 1/5] Address unchanged files with check annotations --- __tests__/test-utils/index.js | 8 +- __tests__/util/itinerary.js | 176 +++++++++++++++++++--------------- 2 files changed, 104 insertions(+), 80 deletions(-) diff --git a/__tests__/test-utils/index.js b/__tests__/test-utils/index.js index 4c5466f88..3ad253868 100644 --- a/__tests__/test-utils/index.js +++ b/__tests__/test-utils/index.js @@ -1,7 +1,7 @@ // Sun Aug 04 2019 19:34:56 GMT-0700 const DEFAULT_TEST_TIME = Date.UTC(2019, 7, 5, 2, 34, 56, 78) -export function timeoutPromise (ms) { +export function timeoutPromise(ms): void { return new Promise((resolve, reject) => { setTimeout(resolve, ms) }) @@ -17,7 +17,7 @@ export function timeoutPromise (ms) { * https://stackoverflow.com/a/42787232/915811 (basically, moment.js uses * Date#now internally). */ -export function setTestTime (time) { +export function setTestTime(time): void { const date = new Date(time) // Log human-readable date to help out human testers. console.log(`Setting test time to ${date}`) @@ -28,7 +28,7 @@ export function setTestTime (time) { * Sets the default mock test time for a variety of tests such that various * calculations and feed version statuses resolve to a certain state. */ -export function setDefaultTestTime () { +export function setDefaultTestTime(): void { setTestTime(DEFAULT_TEST_TIME) } @@ -36,6 +36,6 @@ export function setDefaultTestTime () { * Restore the standard functionality of Date library. This should be used in * the afterEach clause in test suites that require a mocked date. */ -export function restoreDateNowBehavior () { +export function restoreDateNowBehavior(): void { Date.now.mockRestore && Date.now.mockRestore() } diff --git a/__tests__/util/itinerary.js b/__tests__/util/itinerary.js index 61452f0be..526d3edf0 100644 --- a/__tests__/util/itinerary.js +++ b/__tests__/util/itinerary.js @@ -33,54 +33,65 @@ describe('util > itinerary', () => { mode: 'CAR_HAIL' } - const testCases = [{ - expected: true, - itinerary: { - legs: [transitLeg, walkLeg] + const testCases = [ + { + expected: true, + itinerary: { + legs: [transitLeg, walkLeg] + }, + title: + 'should be true for an itinerary with transit, no rentals/ride hail.' }, - title: 'should be true for an itinerary with transit, no rentals/ride hail.' - }, { - expected: false, - itinerary: { - legs: [walkLeg, rentalBikeLeg] + { + expected: false, + itinerary: { + legs: [walkLeg, rentalBikeLeg] + }, + title: 'should be false for an itinerary without transit.' }, - title: 'should be false for an itinerary without transit.' - }, { - expected: false, - itinerary: { - legs: [walkLeg, transitLeg, rentalBikeLeg] + { + expected: false, + itinerary: { + legs: [walkLeg, transitLeg, rentalBikeLeg] + }, + title: 'should be false for an itinerary with transit and rental bike.' }, - title: 'should be false for an itinerary with transit and rental bike.' - }, { - expected: false, - itinerary: { - legs: [walkLeg, transitLeg, rentalCarLeg] + { + expected: false, + itinerary: { + legs: [walkLeg, transitLeg, rentalCarLeg] + }, + title: 'should be false for an itinerary with transit and rental car.' }, - title: 'should be false for an itinerary with transit and rental car.' - }, { - expected: false, - itinerary: { - legs: [walkLeg, transitLeg, rentalMicromobilityLeg] + { + expected: false, + itinerary: { + legs: [walkLeg, transitLeg, rentalMicromobilityLeg] + }, + title: + 'should be false for an itinerary with transit and rental micromobility.' }, - title: 'should be false for an itinerary with transit and rental micromobility.' - }, { - expected: false, - itinerary: { - legs: [walkLeg, transitLeg, rideHailLeg] + { + expected: false, + itinerary: { + legs: [walkLeg, transitLeg, rideHailLeg] + }, + title: 'should be false for an itinerary with transit and ride hail.' }, - title: 'should be false for an itinerary with transit and ride hail.' - }, { - expected: false, - itinerary: {}, - title: 'should be false for a blank itinerary.' - }, { - expected: false, - itinerary: null, - title: 'should be false for a null itinerary.' - }] + { + expected: false, + itinerary: {}, + title: 'should be false for a blank itinerary.' + }, + { + expected: false, + itinerary: null, + title: 'should be false for a null itinerary.' + } + ] testCases.forEach(({ expected, itinerary, title }) => { - it(title, () => { + it(`${title}`, () => { expect(itineraryCanBeMonitored(itinerary)).toBe(expected) }) }) @@ -102,49 +113,62 @@ describe('util > itinerary', () => { transitLeg: true } - const testCases = [{ - expected: WEEKDAYS, - itinerary: { - legs: [walkLeg, transitLegWeekday] - }, - title: 'should be [\'monday\' thru \'friday\'] for an itinerary starting on a weekday.' - }, { - expected: WEEKEND_DAYS, - itinerary: { - legs: [walkLeg, transitLegSaturday] + const testCases = [ + { + expected: WEEKDAYS, + itinerary: { + legs: [walkLeg, transitLegWeekday] + }, + title: + "should be ['monday' thru 'friday'] for an itinerary starting on a weekday." }, - title: 'should be [\'saturday\', \'sunday\'] for an itinerary starting on a Saturday.' - }, { - expected: WEEKEND_DAYS, - itinerary: { - legs: [walkLeg, transitLegSunday] + { + expected: WEEKEND_DAYS, + itinerary: { + legs: [walkLeg, transitLegSaturday] + }, + title: + "should be ['saturday', 'sunday'] for an itinerary starting on a Saturday." }, - title: 'should be [\'saturday\', \'sunday\'] for an itinerary starting on a Sunday.' - }, { - expected: WEEKDAYS, - itinerary: { - legs: [walkLeg], - startTime: 1623341891000 // Thursday 2021-06-10 12:18 pm EDT + { + expected: WEEKEND_DAYS, + itinerary: { + legs: [walkLeg, transitLegSunday] + }, + title: + "should be ['saturday', 'sunday'] for an itinerary starting on a Sunday." }, - title: 'should be [\'monday\' thru \'friday\'] for an itinerary without transit starting on a weekday (fallback case).' - }, { - expected: WEEKEND_DAYS, - itinerary: { - legs: [walkLeg], - startTime: 1623514691000 // Saturday 2021-06-12 12:18 pm EDT + { + expected: WEEKDAYS, + itinerary: { + legs: [walkLeg], + startTime: 1623341891000 // Thursday 2021-06-10 12:18 pm EDT + }, + title: + "should be ['monday' thru 'friday'] for an itinerary without transit starting on a weekday (fallback case)." }, - title: 'should be [\'saturday\', \'sunday\'] for an itinerary without transit starting on a Saturday (fallback case).' - }, { - expected: WEEKEND_DAYS, - itinerary: { - legs: [walkLeg], - startTime: 1623601091000 // Sunday 2021-06-13 12:18 pm EDT + { + expected: WEEKEND_DAYS, + itinerary: { + legs: [walkLeg], + startTime: 1623514691000 // Saturday 2021-06-12 12:18 pm EDT + }, + title: + "should be ['saturday', 'sunday'] for an itinerary without transit starting on a Saturday (fallback case)." }, - title: 'should be [\'saturday\', \'sunday\'] for an itinerary without transit starting on a Sunday (fallback case).' - }] + { + expected: WEEKEND_DAYS, + itinerary: { + legs: [walkLeg], + startTime: 1623601091000 // Sunday 2021-06-13 12:18 pm EDT + }, + title: + "should be ['saturday', 'sunday'] for an itinerary without transit starting on a Sunday (fallback case)." + } + ] testCases.forEach(({ expected, itinerary, title }) => { - it(title, () => { + it(`${title}`, () => { expect(getItineraryDefaultMonitoredDays(itinerary)).toBe(expected) }) }) From d93e0c1a17417d17a20e10add51d87b766bb58e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adriana=20Ceri=C4=87?= <62163307+AdrianaCeric@users.noreply.github.com> Date: Fri, 28 Apr 2023 13:19:25 -0400 Subject: [PATCH 2/5] Add types --- __tests__/test-utils/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/test-utils/index.js b/__tests__/test-utils/index.js index 3ad253868..8e7d3ad19 100644 --- a/__tests__/test-utils/index.js +++ b/__tests__/test-utils/index.js @@ -1,8 +1,8 @@ // Sun Aug 04 2019 19:34:56 GMT-0700 const DEFAULT_TEST_TIME = Date.UTC(2019, 7, 5, 2, 34, 56, 78) -export function timeoutPromise(ms): void { - return new Promise((resolve, reject) => { +export function timeoutPromise(ms: number): void { + return new Promise((resolve) => { setTimeout(resolve, ms) }) } @@ -17,7 +17,7 @@ export function timeoutPromise(ms): void { * https://stackoverflow.com/a/42787232/915811 (basically, moment.js uses * Date#now internally). */ -export function setTestTime(time): void { +export function setTestTime(time: string): void { const date = new Date(time) // Log human-readable date to help out human testers. console.log(`Setting test time to ${date}`) From 2bd738f4650f459c81f22039203ee98277065270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adriana=20Ceri=C4=87?= <62163307+AdrianaCeric@users.noreply.github.com> Date: Fri, 28 Apr 2023 13:33:51 -0400 Subject: [PATCH 3/5] Fix type --- __tests__/test-utils/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/test-utils/index.js b/__tests__/test-utils/index.js index 8e7d3ad19..e27084410 100644 --- a/__tests__/test-utils/index.js +++ b/__tests__/test-utils/index.js @@ -1,7 +1,7 @@ // Sun Aug 04 2019 19:34:56 GMT-0700 const DEFAULT_TEST_TIME = Date.UTC(2019, 7, 5, 2, 34, 56, 78) -export function timeoutPromise(ms: number): void { +export function timeoutPromise(ms: number): Promise { return new Promise((resolve) => { setTimeout(resolve, ms) }) From 279154b8c98350b3d9cdea04bfb7ba59ddd667c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adriana=20Ceri=C4=87?= <62163307+AdrianaCeric@users.noreply.github.com> Date: Mon, 1 May 2023 13:37:18 -0400 Subject: [PATCH 4/5] test: change from js to ts file --- __tests__/test-utils/{index.js => index.ts} | 7 ++++--- __tests__/util/{itinerary.js => itinerary.ts} | 0 2 files changed, 4 insertions(+), 3 deletions(-) rename __tests__/test-utils/{index.js => index.ts} (89%) rename __tests__/util/{itinerary.js => itinerary.ts} (100%) diff --git a/__tests__/test-utils/index.js b/__tests__/test-utils/index.ts similarity index 89% rename from __tests__/test-utils/index.js rename to __tests__/test-utils/index.ts index e27084410..2709233e2 100644 --- a/__tests__/test-utils/index.js +++ b/__tests__/test-utils/index.ts @@ -15,9 +15,9 @@ export function timeoutPromise(ms: number): Promise { * * Note: this stack overflow page gives more info on why we're using this: * https://stackoverflow.com/a/42787232/915811 (basically, moment.js uses - * Date#now internally). + * Date.now internally). */ -export function setTestTime(time: string): void { +export function setTestTime(time: number): void { const date = new Date(time) // Log human-readable date to help out human testers. console.log(`Setting test time to ${date}`) @@ -37,5 +37,6 @@ export function setDefaultTestTime(): void { * the afterEach clause in test suites that require a mocked date. */ export function restoreDateNowBehavior(): void { - Date.now.mockRestore && Date.now.mockRestore() + const now = Date.now as jest.Mock + now.mockRestore && now.mockRestore() } diff --git a/__tests__/util/itinerary.js b/__tests__/util/itinerary.ts similarity index 100% rename from __tests__/util/itinerary.js rename to __tests__/util/itinerary.ts From 0f051285379f739268f5168e8e5a41134271379c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adriana=20Ceri=C4=87?= <62163307+AdrianaCeric@users.noreply.github.com> Date: Tue, 2 May 2023 13:52:34 -0400 Subject: [PATCH 5/5] Revert comment --- __tests__/test-utils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/test-utils/index.ts b/__tests__/test-utils/index.ts index 2709233e2..e562441af 100644 --- a/__tests__/test-utils/index.ts +++ b/__tests__/test-utils/index.ts @@ -15,7 +15,7 @@ export function timeoutPromise(ms: number): Promise { * * Note: this stack overflow page gives more info on why we're using this: * https://stackoverflow.com/a/42787232/915811 (basically, moment.js uses - * Date.now internally). + * Date#now internally). */ export function setTestTime(time: number): void { const date = new Date(time)