Skip to content

Commit

Permalink
Merge pull request #879 from opentripplanner/unchanged-files-check-an…
Browse files Browse the repository at this point in the history
…notations

Address unchanged files with check annotations
  • Loading branch information
AdrianaCeric authored May 2, 2023
2 parents f230ae9 + 0f05128 commit 839358d
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 158 deletions.
13 changes: 7 additions & 6 deletions __tests__/test-utils/index.js → __tests__/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -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) {
return new Promise((resolve, reject) => {
export function timeoutPromise(ms: number): Promise<void> {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}
Expand All @@ -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: number): void {
const date = new Date(time)
// Log human-readable date to help out human testers.
console.log(`Setting test time to ${date}`)
Expand All @@ -28,14 +28,15 @@ 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)
}

/**
* 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 () {
Date.now.mockRestore && Date.now.mockRestore()
export function restoreDateNowBehavior(): void {
const now = Date.now as jest.Mock
now.mockRestore && now.mockRestore()
}
152 changes: 0 additions & 152 deletions __tests__/util/itinerary.js

This file was deleted.

176 changes: 176 additions & 0 deletions __tests__/util/itinerary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* globals describe, expect, it */

import {
getItineraryDefaultMonitoredDays,
itineraryCanBeMonitored
} from '../../lib/util/itinerary'
import { WEEKDAYS, WEEKEND_DAYS } from '../../lib/util/monitored-trip'

const walkLeg = {
mode: 'WALK'
}

describe('util > itinerary', () => {
describe('itineraryCanBeMonitored', () => {
const transitLeg = {
mode: 'BUS',
transitLeg: true
}
const rentalBikeLeg = {
mode: 'BICYCLE_RENT',
rentedBike: true
}
const rentalCarLeg = {
mode: 'CAR_RENT',
rentedCar: true
}
const rentalMicromobilityLeg = {
mode: 'MICROMOBILITY_RENT',
rentedVehicle: true
}
const rideHailLeg = {
hailedCar: true,
mode: 'CAR_HAIL'
}

const testCases = [
{
expected: true,
itinerary: {
legs: [transitLeg, walkLeg]
},
title:
'should be true for an itinerary with transit, no rentals/ride hail.'
},
{
expected: false,
itinerary: {
legs: [walkLeg, rentalBikeLeg]
},
title: 'should be false for an itinerary without transit.'
},
{
expected: false,
itinerary: {
legs: [walkLeg, transitLeg, rentalBikeLeg]
},
title: 'should be false for an itinerary with transit and rental bike.'
},
{
expected: false,
itinerary: {
legs: [walkLeg, transitLeg, rentalCarLeg]
},
title: 'should be false for an itinerary with transit and rental car.'
},
{
expected: false,
itinerary: {
legs: [walkLeg, transitLeg, rentalMicromobilityLeg]
},
title:
'should be false for an itinerary with transit and rental micromobility.'
},
{
expected: false,
itinerary: {
legs: [walkLeg, transitLeg, rideHailLeg]
},
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.'
}
]

testCases.forEach(({ expected, itinerary, title }) => {
it(`${title}`, () => {
expect(itineraryCanBeMonitored(itinerary)).toBe(expected)
})
})
})
describe('getItineraryDefaultMonitoredDays', () => {
const transitLegWeekday = {
mode: 'BUS',
serviceDate: '20210609', // Wednesday
transitLeg: true
}
const transitLegSaturday = {
mode: 'BUS',
serviceDate: '20210612', // Saturday
transitLeg: true
}
const transitLegSunday = {
mode: 'BUS',
serviceDate: '20210613', // Sunday
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]
},
title:
"should be ['saturday', 'sunday'] for an itinerary starting on a Saturday."
},
{
expected: WEEKEND_DAYS,
itinerary: {
legs: [walkLeg, transitLegSunday]
},
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
},
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
},
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
},
title:
"should be ['saturday', 'sunday'] for an itinerary without transit starting on a Sunday (fallback case)."
}
]

testCases.forEach(({ expected, itinerary, title }) => {
it(`${title}`, () => {
expect(getItineraryDefaultMonitoredDays(itinerary)).toBe(expected)
})
})
})
})

0 comments on commit 839358d

Please sign in to comment.