-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a constraint that special priority frames must be exactly one day…
… long Since they are meant to be used for "special days".
- Loading branch information
Showing
4 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
...es/1697523182376_add_vehicle_schedule_frame_special_priority_validity_constraint/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE vehicle_schedule.vehicle_schedule_frame | ||
DROP CONSTRAINT special_priority_validity_exactly_one_day |
6 changes: 6 additions & 0 deletions
6
...bles/1697523182376_add_vehicle_schedule_frame_special_priority_validity_constraint/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ALTER TABLE vehicle_schedule.vehicle_schedule_frame | ||
ADD CONSTRAINT special_priority_validity_exactly_one_day | ||
CHECK (NOT ( | ||
priority = internal_utils.const_timetables_priority_special() | ||
AND validity_start != validity_end | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...ation-tests/data-integrity/vehicle-schedule-frame/special-day-validity-constraint.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { timetablesDbConfig } from '@config'; | ||
import { | ||
DbConnection, | ||
closeDbConnection, | ||
createDbConnection, | ||
singleQuery, | ||
} from '@util/db'; | ||
import { setupDb } from '@util/setup'; | ||
import { defaultTimetablesDataset } from 'generic/timetablesdb/datasets/defaultSetup/default-timetables-dataset'; | ||
import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; | ||
import { | ||
buildGenericTimetablesDataset, | ||
createGenericTableData, | ||
} from 'timetables-data-inserter'; | ||
|
||
describe('Vehicle schedule frame - special day priority validity range constraint', () => { | ||
let dbConnection: DbConnection; | ||
|
||
beforeAll(() => { | ||
dbConnection = createDbConnection(timetablesDbConfig); | ||
}); | ||
|
||
afterAll(() => closeDbConnection(dbConnection)); | ||
|
||
const builtDefaultDataset = buildGenericTimetablesDataset( | ||
defaultTimetablesDataset, | ||
); | ||
|
||
const testFrameId = | ||
builtDefaultDataset._vehicle_schedule_frames.winter2022 | ||
.vehicle_schedule_frame_id; | ||
|
||
beforeEach(async () => | ||
setupDb(dbConnection, createGenericTableData(builtDefaultDataset)), | ||
); | ||
|
||
const setTestFramePriorityAndValidity = ( | ||
priority: TimetablePriority, | ||
validityStart: string, | ||
validityEnd: string, | ||
) => { | ||
return singleQuery( | ||
dbConnection, | ||
`UPDATE vehicle_schedule.vehicle_schedule_frame | ||
SET "priority" = ${priority}, | ||
"validity_start" = '${validityStart}', | ||
"validity_end" = '${validityEnd}' | ||
WHERE "vehicle_schedule_frame_id" = '${testFrameId}' | ||
`, | ||
); | ||
}; | ||
|
||
it('should be able to set Special priority to have one day validity period', async () => { | ||
await expect( | ||
setTestFramePriorityAndValidity( | ||
TimetablePriority.Special, | ||
'2023-01-23', | ||
'2023-01-23', | ||
), | ||
).resolves.not.toThrow(); | ||
}); | ||
|
||
it('should not be able to set Special priority to have longer than one day validity period', async () => { | ||
await expect( | ||
setTestFramePriorityAndValidity( | ||
TimetablePriority.Special, | ||
'2023-01-23', | ||
'2023-01-24', | ||
), | ||
).rejects.toThrow('special_priority_validity_exactly_one_day'); | ||
}); | ||
|
||
const otherPrioritiesToTest: Array<keyof typeof TimetablePriority> = [ | ||
'Standard', | ||
'Temporary', | ||
'Draft', | ||
'Staging', | ||
]; | ||
otherPrioritiesToTest.forEach((priorityName) => { | ||
it(`should also be able to set other priorities to have one day validity range: ${priorityName}`, async () => { | ||
await expect( | ||
setTestFramePriorityAndValidity( | ||
TimetablePriority[priorityName], | ||
'2023-01-23', | ||
'2023-01-23', | ||
), | ||
).resolves.not.toThrow(); | ||
}); | ||
}); | ||
}); |