-
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 timing point constraints and tests
A stop can't have loading time allowed if it is not a regulated timing point and a stop can't be a regulated timing point if it is not set as timing point. Resolves HSLdevcom/jore4#1369
- Loading branch information
1 parent
80db149
commit 6546af8
Showing
4 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...00009_R_after_migrate_add_constraints_to_scheduled_stop_point_in_journey_pattern/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,5 @@ | ||
ALTER TABLE journey_pattern.scheduled_stop_point_in_journey_pattern | ||
DROP CONSTRAINT ck_is_used_as_timing_point_state; | ||
|
||
ALTER TABLE journey_pattern.scheduled_stop_point_in_journey_pattern | ||
DROP CONSTRAINT ck_is_regulated_timing_point_state; |
5 changes: 5 additions & 0 deletions
5
...0000009_R_after_migrate_add_constraints_to_scheduled_stop_point_in_journey_pattern/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,5 @@ | ||
ALTER TABLE journey_pattern.scheduled_stop_point_in_journey_pattern | ||
ADD CONSTRAINT ck_is_used_as_timing_point_state CHECK(NOT (is_used_as_timing_point = false AND is_regulated_timing_point = true)); | ||
|
||
ALTER TABLE journey_pattern.scheduled_stop_point_in_journey_pattern | ||
ADD CONSTRAINT ck_is_regulated_timing_point_state CHECK(NOT (is_regulated_timing_point = false AND is_loading_time_allowed = true)); |
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
333 changes: 333 additions & 0 deletions
333
...asura/generic/networkdb/integration-tests/data-integrity/timing-point-constraints.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,333 @@ | ||
import * as config from '@config'; | ||
import * as dataset from '@util/dataset'; | ||
import { closeDbConnection, createDbConnection, DbConnection } from '@util/db'; | ||
import { expectErrorResponse, expectNoErrorResponse } from '@util/response'; | ||
import { getPropNameArray, setupDb } from '@util/setup'; | ||
import { scheduledStopPoints } from 'generic/networkdb/datasets/defaultSetup'; | ||
import { | ||
journeyPatterns, | ||
routesAndJourneyPatternsTableData, | ||
scheduledStopPointInJourneyPattern, | ||
} from 'generic/networkdb/datasets/routesAndJourneyPatterns'; | ||
import { | ||
ScheduledStopPointInJourneyPattern, | ||
scheduledStopPointInJourneyPatternProps, | ||
} from 'generic/networkdb/datasets/types'; | ||
import * as rp from 'request-promise'; | ||
|
||
const baseScheduledStopPoint: Partial<ScheduledStopPointInJourneyPattern> = { | ||
scheduled_stop_point_sequence: 0, | ||
journey_pattern_id: journeyPatterns[0].journey_pattern_id, | ||
scheduled_stop_point_label: scheduledStopPoints[0].label, | ||
is_used_as_timing_point: false, | ||
is_regulated_timing_point: false, | ||
is_loading_time_allowed: false, | ||
}; | ||
|
||
const buildInsertMutation = ( | ||
toBeInserted: Partial<ScheduledStopPointInJourneyPattern>, | ||
) => ` | ||
mutation { | ||
insert_journey_pattern_scheduled_stop_point_in_journey_pattern(objects: ${dataset.toGraphQlObject( | ||
{ | ||
...toBeInserted, | ||
}, | ||
)}) { | ||
returning { | ||
${getPropNameArray(scheduledStopPointInJourneyPatternProps).join(',')} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const buildUpdateMutation = ( | ||
toBeUpdated: Partial<ScheduledStopPointInJourneyPattern>, | ||
) => ` | ||
mutation { | ||
update_journey_pattern_scheduled_stop_point_in_journey_pattern_by_pk( | ||
pk_columns: { | ||
journey_pattern_id: "${ | ||
scheduledStopPointInJourneyPattern[0].journey_pattern_id | ||
}", | ||
scheduled_stop_point_sequence: "${ | ||
scheduledStopPointInJourneyPattern[0].scheduled_stop_point_sequence | ||
}" | ||
}, | ||
_set: ${dataset.toGraphQlObject(toBeUpdated)} | ||
) { | ||
${getPropNameArray(scheduledStopPointInJourneyPatternProps).join(',')} | ||
} | ||
} | ||
`; | ||
|
||
describe('Timing point constraints on scheduled_stop_point_on_journey_pattern', () => { | ||
let dbConnection: DbConnection; | ||
|
||
beforeAll(() => { | ||
dbConnection = createDbConnection(config.networkDbConfig); | ||
}); | ||
|
||
afterAll(() => closeDbConnection(dbConnection)); | ||
|
||
beforeEach(() => setupDb(dbConnection, routesAndJourneyPatternsTableData)); | ||
|
||
describe('with conflicts', () => { | ||
describe('loading time allowed but is not regulated timing point', () => { | ||
it('should not insert', async () => { | ||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { | ||
query: buildInsertMutation({ | ||
...baseScheduledStopPoint, | ||
is_loading_time_allowed: true, | ||
}), | ||
}, | ||
}); | ||
|
||
expectErrorResponse('Check constraint violation.')(response); | ||
expectErrorResponse('ck_is_regulated_timing_point_state')(response); | ||
}); | ||
|
||
it('should not update', async () => { | ||
const toBeUpdated: Partial<ScheduledStopPointInJourneyPattern> = { | ||
is_used_as_timing_point: false, | ||
is_regulated_timing_point: false, | ||
is_loading_time_allowed: true, | ||
}; | ||
|
||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildUpdateMutation(toBeUpdated) }, | ||
}); | ||
|
||
expectErrorResponse('Check constraint violation.')(response); | ||
expectErrorResponse('ck_is_regulated_timing_point_state')(response); | ||
}); | ||
}); | ||
|
||
describe('used as timing point and loading time is allowed but not set as regulated timing point', () => { | ||
it('should not insert', async () => { | ||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { | ||
query: buildInsertMutation({ | ||
...baseScheduledStopPoint, | ||
is_used_as_timing_point: true, | ||
is_loading_time_allowed: true, | ||
}), | ||
}, | ||
}); | ||
|
||
expectErrorResponse('Check constraint violation.')(response); | ||
expectErrorResponse('ck_is_regulated_timing_point_state')(response); | ||
}); | ||
|
||
it('should not update', async () => { | ||
const toBeUpdated: Partial<ScheduledStopPointInJourneyPattern> = { | ||
is_used_as_timing_point: true, | ||
is_regulated_timing_point: false, | ||
is_loading_time_allowed: true, | ||
}; | ||
|
||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildUpdateMutation(toBeUpdated) }, | ||
}); | ||
|
||
expectErrorResponse('Check constraint violation.')(response); | ||
expectErrorResponse('ck_is_regulated_timing_point_state')(response); | ||
}); | ||
}); | ||
|
||
describe('used as regulated timing point but not set as timing point', () => { | ||
it('should not insert', async () => { | ||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { | ||
query: buildInsertMutation({ | ||
...baseScheduledStopPoint, | ||
is_regulated_timing_point: true, | ||
}), | ||
}, | ||
}); | ||
|
||
expectErrorResponse('Check constraint violation.')(response); | ||
expectErrorResponse('ck_is_used_as_timing_point_state')(response); | ||
}); | ||
|
||
it('should not update', async () => { | ||
const toBeUpdated: Partial<ScheduledStopPointInJourneyPattern> = { | ||
is_used_as_timing_point: false, | ||
is_regulated_timing_point: true, | ||
is_loading_time_allowed: false, | ||
}; | ||
|
||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildUpdateMutation(toBeUpdated) }, | ||
}); | ||
|
||
expectErrorResponse('Check constraint violation.')(response); | ||
expectErrorResponse('ck_is_used_as_timing_point_state')(response); | ||
}); | ||
}); | ||
|
||
describe('used as regulated timing point, allowed loading time but is not set as timing point', () => { | ||
it('should not insert', async () => { | ||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { | ||
query: buildInsertMutation({ | ||
...baseScheduledStopPoint, | ||
is_regulated_timing_point: true, | ||
is_loading_time_allowed: true, | ||
}), | ||
}, | ||
}); | ||
|
||
expectErrorResponse('Check constraint violation.')(response); | ||
expectErrorResponse('ck_is_used_as_timing_point_state')(response); | ||
}); | ||
|
||
it('should not update', async () => { | ||
const toBeUpdated: Partial<ScheduledStopPointInJourneyPattern> = { | ||
is_used_as_timing_point: false, | ||
is_regulated_timing_point: true, | ||
is_loading_time_allowed: true, | ||
}; | ||
|
||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildUpdateMutation(toBeUpdated) }, | ||
}); | ||
|
||
expectErrorResponse('Check constraint violation.')(response); | ||
expectErrorResponse('ck_is_used_as_timing_point_state')(response); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('without conflicts', () => { | ||
describe('All timing point settings are set to false', () => { | ||
it('should insert without conflicts', async () => { | ||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildInsertMutation(baseScheduledStopPoint) }, | ||
}); | ||
|
||
expectNoErrorResponse(response); | ||
}); | ||
|
||
it('should update without conflicts', async () => { | ||
const toBeUpdated: Partial<ScheduledStopPointInJourneyPattern> = { | ||
is_used_as_timing_point: false, | ||
is_regulated_timing_point: false, | ||
is_loading_time_allowed: false, | ||
}; | ||
|
||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildUpdateMutation(toBeUpdated) }, | ||
}); | ||
|
||
expectNoErrorResponse(response); | ||
}); | ||
}); | ||
|
||
describe('used as timing point but not as regulated timing point', () => { | ||
it('should insert without conflicts', async () => { | ||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { | ||
query: buildInsertMutation({ | ||
...baseScheduledStopPoint, | ||
is_used_as_timing_point: true, | ||
}), | ||
}, | ||
}); | ||
|
||
expectNoErrorResponse(response); | ||
}); | ||
|
||
it('should update without conflicts', async () => { | ||
const toBeUpdated: Partial<ScheduledStopPointInJourneyPattern> = { | ||
is_used_as_timing_point: true, | ||
is_regulated_timing_point: false, | ||
is_loading_time_allowed: false, | ||
}; | ||
|
||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildUpdateMutation(toBeUpdated) }, | ||
}); | ||
|
||
expectNoErrorResponse(response); | ||
}); | ||
}); | ||
|
||
describe('used as timing point and as regulated timing point', () => { | ||
it('should insert without conflicts', async () => { | ||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { | ||
query: buildInsertMutation({ | ||
...baseScheduledStopPoint, | ||
is_used_as_timing_point: true, | ||
is_regulated_timing_point: true, | ||
}), | ||
}, | ||
}); | ||
|
||
expectNoErrorResponse(response); | ||
}); | ||
|
||
it('should update without conflicts', async () => { | ||
const toBeUpdated: Partial<ScheduledStopPointInJourneyPattern> = { | ||
is_used_as_timing_point: true, | ||
is_regulated_timing_point: true, | ||
is_loading_time_allowed: false, | ||
}; | ||
|
||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildUpdateMutation(toBeUpdated) }, | ||
}); | ||
|
||
expectNoErrorResponse(response); | ||
}); | ||
}); | ||
|
||
describe('used as timing point, regulated timing point and loading time is allowed', () => { | ||
it('should insert without conflicts', async () => { | ||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { | ||
query: buildInsertMutation({ | ||
...baseScheduledStopPoint, | ||
is_used_as_timing_point: true, | ||
is_regulated_timing_point: true, | ||
is_loading_time_allowed: true, | ||
}), | ||
}, | ||
}); | ||
|
||
expectNoErrorResponse(response); | ||
}); | ||
|
||
it('should update without conflicts', async () => { | ||
const toBeUpdated: Partial<ScheduledStopPointInJourneyPattern> = { | ||
is_used_as_timing_point: true, | ||
is_regulated_timing_point: true, | ||
is_loading_time_allowed: true, | ||
}; | ||
|
||
const response = await rp.post({ | ||
...config.hasuraRequestTemplate, | ||
body: { query: buildUpdateMutation(toBeUpdated) }, | ||
}); | ||
|
||
expectNoErrorResponse(response); | ||
}); | ||
}); | ||
}); | ||
}); |