Fixing isAvailableForReservation function and adding unit tests
This commit is contained in:
parent
472f2c5d42
commit
3e6f7473b4
2 changed files with 24 additions and 1 deletions
|
|
@ -80,7 +80,11 @@ export class Reservation {
|
||||||
*/
|
*/
|
||||||
@Exclude()
|
@Exclude()
|
||||||
public isAvailableForReservation(): boolean {
|
public isAvailableForReservation(): boolean {
|
||||||
return this.dateRangeStart.diff(dayjs(), 'hour') <= 7 * 24
|
const maxDateToReserve = dayjs()
|
||||||
|
.add(7, 'day')
|
||||||
|
.set('hour', 23)
|
||||||
|
.set('minute', 59)
|
||||||
|
return this.dateRangeStart.isBefore(maxDateToReserve)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
19
test/unit/reservations/entity.spec.ts
Normal file
19
test/unit/reservations/entity.spec.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import dayjs from '../../../src/common/dayjs'
|
||||||
|
import { Reservation } from '../../../src/reservations/entity'
|
||||||
|
|
||||||
|
describe('reservations.entity', () => {
|
||||||
|
describe('isAvailableForReservation', () => {
|
||||||
|
it.each([
|
||||||
|
{ dateRangeStart: dayjs().add(7, 'day').set('hour', 23), result: true },
|
||||||
|
{ dateRangeStart: dayjs().subtract(1, 'day'), result: true },
|
||||||
|
{ dateRangeStart: dayjs(), result: true },
|
||||||
|
{ dateRangeStart: dayjs().add(8, 'day'), result: false },
|
||||||
|
])(
|
||||||
|
'should handle reservation starting at $dateRangeStart and return $result',
|
||||||
|
({ dateRangeStart, result }) => {
|
||||||
|
const r = new Reservation({ dateRangeStart })
|
||||||
|
expect(r.isAvailableForReservation()).toBe(result)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Add table
Reference in a new issue