Skip to content

Commit

Permalink
[test] add unit tests for fares helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhyde committed Jun 23, 2023
1 parent 51e435c commit 5893a48
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions source/fares/unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { getFarePrice } from '~/fares/helpers.ts'
import { type Fare } from '~/fares/types.ts'

describe('getFarePrice', () => {
it('should return 0 if Fare price is null', () => {
const fare: Fare = {
day: '2023-09-01',
arrivalDate: '2023-09-01T12:40:00',
departureDate: '2023-09-01T11:15:00',
price: null,
soldOut: false,
unavailable: false
}
expect(getFarePrice(fare)).toBe(0)
})

it('should return Fare price if not null', () => {
const fare: Fare = {
day: '2023-09-01',
arrivalDate: '2023-09-01T12:40:00',
departureDate: '2023-09-01T11:15:00',
price: {
value: 56.12,
valueMainUnit: '56',
valueFractionalUnit: '12',
currencyCode: 'EUR',
currencySymbol: '€'
},
soldOut: false,
unavailable: false
}
expect(getFarePrice(fare)).toBe(56.12)
})
})

0 comments on commit 5893a48

Please sign in to comment.