diff --git a/test/hasura/generic/networkdb/integration-tests/function-get_distances_between_stop_points/get-distances-between-stops-points-in-journey-patterns.spec.ts b/test/hasura/generic/networkdb/integration-tests/function-get_distances_between_stop_points/get-distances-between-stops-points-in-journey-patterns.spec.ts index 26e98549..62406cfc 100644 --- a/test/hasura/generic/networkdb/integration-tests/function-get_distances_between_stop_points/get-distances-between-stops-points-in-journey-patterns.spec.ts +++ b/test/hasura/generic/networkdb/integration-tests/function-get_distances_between_stop_points/get-distances-between-stops-points-in-journey-patterns.spec.ts @@ -2,11 +2,10 @@ import * as config from '@config'; import * as db from '@util/db'; import { closeDbConnection, createDbConnection, DbConnection } from '@util/db'; import { setupDb } from '@util/setup'; -import { randomUUID } from 'crypto'; import { - infrastructureLinks as sourceInfrastructureLinks, - journeyPatterns, routesAndJourneyPatternsTableData as baseTableConfig, + journeyPatterns, + infrastructureLinks as sourceInfrastructureLinks, scheduledStopPoints as sourceScheduledStopPoints, } from 'generic/networkdb/datasets/routesAndJourneyPatterns'; import { GenericNetworkDbTables } from 'generic/networkdb/datasets/schema'; @@ -19,6 +18,7 @@ import { VehicleSubmodeOnInfrastructureLink, } from 'generic/networkdb/datasets/types'; import { DateTime } from 'luxon'; +import { v4 as uuidv4 } from 'uuid'; describe('Function service_pattern.get_distances_between_stop_points_in_journey_patterns', () => { let dbConnection: DbConnection; @@ -447,7 +447,7 @@ describe('Function service_pattern.get_distances_between_stop_points_in_journey_ // Set a different location along the associated infrastructure link. const higherPriorityStopVariant: ScheduledStopPoint = { ...scheduledStopPoints[7], - scheduled_stop_point_id: randomUUID(), + scheduled_stop_point_id: uuidv4(), priority: newPriority, measured_location: { type: 'Point', diff --git a/test/hasura/generic/networkdb/unit-tests/function-maximum_priority_validity_spans/route.spec.ts b/test/hasura/generic/networkdb/unit-tests/function-maximum_priority_validity_spans/route.spec.ts index 707511de..a35c9f56 100644 --- a/test/hasura/generic/networkdb/unit-tests/function-maximum_priority_validity_spans/route.spec.ts +++ b/test/hasura/generic/networkdb/unit-tests/function-maximum_priority_validity_spans/route.spec.ts @@ -3,11 +3,11 @@ import { buildLocalizedString } from '@util/dataset'; import * as db from '@util/db'; import { closeDbConnection, createDbConnection, DbConnection } from '@util/db'; import { setupDb } from '@util/setup'; -import { randomUUID } from 'crypto'; import { Route, RouteDirection } from 'generic/networkdb/datasets/types'; import { DateTime } from 'luxon'; +import { v4 as uuidv4 } from 'uuid'; -const dummyLineId = randomUUID(); +const dummyLineId = uuidv4(); const defaultRouteLabel = 'route 1'; const defaultCommonRouteProps = { @@ -65,8 +65,8 @@ describe('Function maximum_priority_validity_spans should return correct route r // expected result: // |---earlier---| |----later----| - const earlierRouteId = randomUUID(); - const laterRouteId = randomUUID(); + const earlierRouteId = uuidv4(); + const laterRouteId = uuidv4(); const earlierRouteValidityStart = DateTime.fromISO('2020-01-04'); const earlierRouteValidityEnd = DateTime.fromISO('2021-04-04'); @@ -115,8 +115,8 @@ describe('Function maximum_priority_validity_spans should return correct route r // expected result: // |---earlier---|----later----| - const earlierRouteId = randomUUID(); - const laterRouteId = randomUUID(); + const earlierRouteId = uuidv4(); + const laterRouteId = uuidv4(); const earlierRouteValidityStart = DateTime.fromISO('2020-01-04'); const earlierRouteValidityEnd = DateTime.fromISO('2021-04-04'); @@ -163,8 +163,8 @@ describe('Function maximum_priority_validity_spans should return correct route r // expected result: // |--low prio--|---high prio---| - const earlierLowerPrioRouteId = randomUUID(); - const laterHigherPrioRouteId = randomUUID(); + const earlierLowerPrioRouteId = uuidv4(); + const laterHigherPrioRouteId = uuidv4(); const earlierLowerPrioRouteValidityStart = DateTime.fromISO('2020-01-04'); const earlierLowerPrioRouteValidityEnd = DateTime.fromISO('2024-04-04'); @@ -215,8 +215,8 @@ describe('Function maximum_priority_validity_spans should return correct route r // expected result: // |--low prio----| - const earlierLowerPrioRouteId = randomUUID(); - const laterHigherPrioRouteId = randomUUID(); + const earlierLowerPrioRouteId = uuidv4(); + const laterHigherPrioRouteId = uuidv4(); const earlierLowerPrioRouteValidityStart = DateTime.fromISO('2020-01-04'); const earlierLowerPrioRouteValidityEnd = DateTime.fromISO('2024-04-04'); @@ -270,8 +270,8 @@ describe('Function maximum_priority_validity_spans should return correct route r // |--low prio----| // | label: A | - const earlierLowerPrioRouteId = randomUUID(); - const laterHigherPrioRouteId = randomUUID(); + const earlierLowerPrioRouteId = uuidv4(); + const laterHigherPrioRouteId = uuidv4(); const earlierLowerPrioRouteValidityStart = DateTime.fromISO('2020-01-04'); const earlierLowerPrioRouteValidityEnd = DateTime.fromISO('2024-04-04'); @@ -318,8 +318,8 @@ describe('Function maximum_priority_validity_spans should return correct route r // expected result: // |--low prio--|---high prio---|--low prio---| - const lowerPrioRouteId = randomUUID(); - const higherPrioRouteId = randomUUID(); + const lowerPrioRouteId = uuidv4(); + const higherPrioRouteId = uuidv4(); const lowerPrioRouteValidityStart = DateTime.fromISO('2020-01-04'); const lowerPrioRouteValidityEnd = DateTime.fromISO('2025-04-04'); @@ -375,8 +375,8 @@ describe('Function maximum_priority_validity_spans should return correct route r // expected result: // |----------------high prio-----------------| - const lowerPrioRouteId = randomUUID(); - const higherPrioRouteId = randomUUID(); + const lowerPrioRouteId = uuidv4(); + const higherPrioRouteId = uuidv4(); const lowerPrioRouteValidityStart = DateTime.fromISO('2022-01-04'); const lowerPrioRouteValidityEnd = DateTime.fromISO('2024-04-04'); @@ -422,8 +422,8 @@ describe('Function maximum_priority_validity_spans should return correct route r // expected result for priority < 20: // |---prio: 10----| - const lowerPrioRouteId = randomUUID(); - const higherPrioRouteId = randomUUID(); + const lowerPrioRouteId = uuidv4(); + const higherPrioRouteId = uuidv4(); const lowerPrioRouteValidityStart = DateTime.fromISO('2022-01-04'); const lowerPrioRouteValidityEnd = DateTime.fromISO('2024-04-04'); diff --git a/test/hasura/generic/networkdb/unit-tests/function-maximum_priority_validity_spans/scheduled-stop-point.spec.ts b/test/hasura/generic/networkdb/unit-tests/function-maximum_priority_validity_spans/scheduled-stop-point.spec.ts index dd256736..d9d62fec 100644 --- a/test/hasura/generic/networkdb/unit-tests/function-maximum_priority_validity_spans/scheduled-stop-point.spec.ts +++ b/test/hasura/generic/networkdb/unit-tests/function-maximum_priority_validity_spans/scheduled-stop-point.spec.ts @@ -7,7 +7,6 @@ import { singleQuery, } from '@util/db'; import { setupDb } from '@util/setup'; -import { randomUUID } from 'crypto'; import { InfrastructureLink, JourneyPattern, @@ -17,10 +16,11 @@ import { ScheduledStopPoint, } from 'generic/networkdb/datasets/types'; import { DateTime } from 'luxon'; +import { v4 as uuidv4 } from 'uuid'; const defaultRouteLabel = 'route 2'; const stopLabel = 'stop A'; -const infraLinkId = randomUUID(); +const infraLinkId = uuidv4(); const defaultCommonStopProps: Partial = { located_on_infrastructure_link_id: infraLinkId, @@ -38,8 +38,8 @@ const defaultCommonStopProps: Partial = { }; const route: Partial = { - route_id: randomUUID(), - on_line_id: randomUUID(), + route_id: uuidv4(), + on_line_id: uuidv4(), label: defaultRouteLabel, direction: RouteDirection.Outbound, priority: 10, @@ -49,7 +49,7 @@ const route: Partial = { }; const journeyPattern: Partial = { - journey_pattern_id: randomUUID(), + journey_pattern_id: uuidv4(), on_route_id: route.route_id, }; @@ -147,8 +147,8 @@ describe('Function maximum_priority_validity_spans should return correct schedul // expected result: // |---earlier---| |----later----| - const earlierStopId = randomUUID(); - const laterStopId = randomUUID(); + const earlierStopId = uuidv4(); + const laterStopId = uuidv4(); const earlierStopValidityStart = DateTime.fromISO('2020-01-04'); const earlierStopValidityEnd = DateTime.fromISO('2021-04-05'); @@ -197,8 +197,8 @@ describe('Function maximum_priority_validity_spans should return correct schedul // expected result: // |---earlier---|----later----| - const earlierStopId = randomUUID(); - const laterStopId = randomUUID(); + const earlierStopId = uuidv4(); + const laterStopId = uuidv4(); const earlierStopValidityStart = DateTime.fromISO('2020-01-04'); const earlierStopValidityEnd = DateTime.fromISO('2021-04-05'); @@ -245,8 +245,8 @@ describe('Function maximum_priority_validity_spans should return correct schedul // expected result: // |--low prio--|---high prio---| - const earlierLowerPrioStopId = randomUUID(); - const laterHigherPrioStopId = randomUUID(); + const earlierLowerPrioStopId = uuidv4(); + const laterHigherPrioStopId = uuidv4(); const earlierLowerPrioStopValidityStart = DateTime.fromISO('2020-01-04'); const earlierLowerPrioStopValidityEnd = DateTime.fromISO('2024-04-05'); @@ -297,8 +297,8 @@ describe('Function maximum_priority_validity_spans should return correct schedul // expected result: // |--low prio----| - const earlierLowerPrioStopId = randomUUID(); - const laterHigherPrioStopId = randomUUID(); + const earlierLowerPrioStopId = uuidv4(); + const laterHigherPrioStopId = uuidv4(); const earlierLowerPrioStopValidityStart = DateTime.fromISO('2020-01-04'); const earlierLowerPrioStopValidityEnd = DateTime.fromISO('2024-04-05'); @@ -351,8 +351,8 @@ describe('Function maximum_priority_validity_spans should return correct schedul // expected result for label B: // (empty) - const earlierLowerPrioStopId = randomUUID(); - const laterHigherPrioStopId = randomUUID(); + const earlierLowerPrioStopId = uuidv4(); + const laterHigherPrioStopId = uuidv4(); const earlierLowerPrioStopValidityStart = DateTime.fromISO('2020-01-04'); const earlierLowerPrioStopValidityEnd = DateTime.fromISO('2024-04-05'); @@ -393,8 +393,8 @@ describe('Function maximum_priority_validity_spans should return correct schedul // expected result: // |--low prio--|---high prio---|--low prio---| - const lowerPrioStopId = randomUUID(); - const higherPrioStopId = randomUUID(); + const lowerPrioStopId = uuidv4(); + const higherPrioStopId = uuidv4(); const lowerPrioStopValidityStart = DateTime.fromISO('2020-01-04'); const lowerPrioStopValidityEnd = DateTime.fromISO('2025-04-05'); @@ -450,8 +450,8 @@ describe('Function maximum_priority_validity_spans should return correct schedul // expected result: // |----------------high prio-----------------| - const lowerPrioStopId = randomUUID(); - const higherPrioStopId = randomUUID(); + const lowerPrioStopId = uuidv4(); + const higherPrioStopId = uuidv4(); const lowerPrioStopValidityStart = DateTime.fromISO('2022-01-04'); const lowerPrioStopValidityEnd = DateTime.fromISO('2024-04-05'); @@ -497,8 +497,8 @@ describe('Function maximum_priority_validity_spans should return correct schedul // expected result for priority < 20: // |---prio: 10----| - const lowerPrioStopId = randomUUID(); - const higherPrioStopId = randomUUID(); + const lowerPrioStopId = uuidv4(); + const higherPrioStopId = uuidv4(); const lowerPrioStopValidityStart = DateTime.fromISO('2022-01-04'); const lowerPrioStopValidityEnd = DateTime.fromISO('2024-04-05'); diff --git a/test/hasura/generic/timetablesdb/datasets/defaultSetup/index.ts b/test/hasura/generic/timetablesdb/datasets/defaultSetup/index.ts index bfd618ca..139a9789 100644 --- a/test/hasura/generic/timetablesdb/datasets/defaultSetup/index.ts +++ b/test/hasura/generic/timetablesdb/datasets/defaultSetup/index.ts @@ -1,4 +1,3 @@ -export * from './day-types'; export * from './journey-pattern-refs'; export * from './passing-times'; export * from './stop-points'; diff --git a/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-schedule-frames/summer-2023.ts b/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-schedule-frames/summer-2023.ts index ce637c0a..c67acb08 100644 --- a/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-schedule-frames/summer-2023.ts +++ b/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-schedule-frames/summer-2023.ts @@ -1,5 +1,5 @@ import { DateTime } from 'luxon'; -import { defaultDayTypeIds } from '../day-types'; +import { defaultDayTypeIds } from '../../../../../timetables-data-inserter/day-types'; export const summer2023VehicleScheduleFrame = { validity_start: DateTime.fromISO('2023-06-01'), diff --git a/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-schedule-frames/winter-2022.ts b/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-schedule-frames/winter-2022.ts index 92f6b27b..76a81469 100644 --- a/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-schedule-frames/winter-2022.ts +++ b/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-schedule-frames/winter-2022.ts @@ -1,5 +1,5 @@ import { DateTime, Duration } from 'luxon'; -import { defaultDayTypeIds } from '../day-types'; +import { defaultDayTypeIds } from '../../../../../timetables-data-inserter/day-types'; export const winter2022VehicleScheduleFrame = { validity_start: DateTime.fromISO('2022-07-01'), diff --git a/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-services.ts b/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-services.ts index 6d53cc5a..a8004efd 100644 --- a/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-services.ts +++ b/test/hasura/generic/timetablesdb/datasets/defaultSetup/vehicle-services.ts @@ -1,5 +1,5 @@ +import { defaultDayTypeIds } from '../../../../timetables-data-inserter/day-types'; import { VehicleService } from '../types'; -import { defaultDayTypeIds } from './day-types'; import { vehicleScheduleFramesByName } from './vehicle-schedules-frames'; export const vehicleServicesByName = { diff --git a/test/hasura/generic/timetablesdb/integration-tests/data-integrity/vehicle-schedule-frame/journey-pattern-ref-unique.spec.ts b/test/hasura/generic/timetablesdb/integration-tests/data-integrity/vehicle-schedule-frame/journey-pattern-ref-unique.spec.ts index e5e1c51b..05b02edb 100644 --- a/test/hasura/generic/timetablesdb/integration-tests/data-integrity/vehicle-schedule-frame/journey-pattern-ref-unique.spec.ts +++ b/test/hasura/generic/timetablesdb/integration-tests/data-integrity/vehicle-schedule-frame/journey-pattern-ref-unique.spec.ts @@ -8,7 +8,6 @@ import { import { addMutationWrapper, postQuery } from '@util/graphql'; import { expectErrorResponse, expectNoErrorResponse } from '@util/response'; import { getPartialTableData, insertTableData, setupDb } from '@util/setup'; -import { defaultDayTypeIds } from 'generic/timetablesdb/datasets/defaultSetup'; import { defaultTimetablesDataset } from 'generic/timetablesdb/datasets/defaultSetup/default-timetables-dataset'; import { GenericTimetablesDbTables } from 'generic/timetablesdb/datasets/schema'; import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; @@ -24,6 +23,7 @@ import { DateTime } from 'luxon'; import { buildGenericTimetablesDataset, createGenericTableData, + defaultDayTypeIds, GenericTimetablesDatasetInput, genericVehicleScheduleFrameToDbFormat, timetabledPassingTimeToDbFormat, diff --git a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/draftSunApril2023Dataset.ts b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/draftSunApril2023Dataset.ts index bd4f56bc..7972dd63 100644 --- a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/draftSunApril2023Dataset.ts +++ b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/draftSunApril2023Dataset.ts @@ -1,9 +1,7 @@ -import { - defaultDayTypeIds, - journeyPatternRefsByName, -} from 'generic/timetablesdb/datasets/defaultSetup'; +import { journeyPatternRefsByName } from 'generic/timetablesdb/datasets/defaultSetup'; import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; import { DateTime } from 'luxon'; +import { defaultDayTypeIds } from '../../../../../timetables-data-inserter/day-types'; import { buildHslVehicleScheduleFrame } from '../../factories'; import { HslTimetablesDbTables } from '../../schema'; diff --git a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/draftSunApril2024Dataset.ts b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/draftSunApril2024Dataset.ts index 52b6c918..db77d781 100644 --- a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/draftSunApril2024Dataset.ts +++ b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/draftSunApril2024Dataset.ts @@ -1,9 +1,7 @@ -import { - defaultDayTypeIds, - journeyPatternRefsByName, -} from 'generic/timetablesdb/datasets/defaultSetup'; +import { journeyPatternRefsByName } from 'generic/timetablesdb/datasets/defaultSetup'; import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; import { DateTime } from 'luxon'; +import { defaultDayTypeIds } from '../../../../../timetables-data-inserter/day-types'; import { buildHslVehicleScheduleFrame } from '../../factories'; import { HslTimetablesDbTables } from '../../schema'; diff --git a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/specialAprilFools2023Dataset.ts b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/specialAprilFools2023Dataset.ts index 1dbb1bcc..e9c139bb 100644 --- a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/specialAprilFools2023Dataset.ts +++ b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/specialAprilFools2023Dataset.ts @@ -1,9 +1,7 @@ -import { - defaultDayTypeIds, - journeyPatternRefsByName, -} from 'generic/timetablesdb/datasets/defaultSetup'; +import { journeyPatternRefsByName } from 'generic/timetablesdb/datasets/defaultSetup'; import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; import { DateTime } from 'luxon'; +import { defaultDayTypeIds } from '../../../../../timetables-data-inserter/day-types'; import { buildHslVehicleScheduleFrame } from '../../factories'; import { HslTimetablesDbTables } from '../../schema'; diff --git a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/stagingSunApril2024Dataset.ts b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/stagingSunApril2024Dataset.ts index 6f656dca..a4380b41 100644 --- a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/stagingSunApril2024Dataset.ts +++ b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/stagingSunApril2024Dataset.ts @@ -1,9 +1,7 @@ -import { - defaultDayTypeIds, - journeyPatternRefsByName, -} from 'generic/timetablesdb/datasets/defaultSetup'; +import { journeyPatternRefsByName } from 'generic/timetablesdb/datasets/defaultSetup'; import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; import { DateTime } from 'luxon'; +import { defaultDayTypeIds } from '../../../../../timetables-data-inserter/day-types'; import { buildHslVehicleScheduleFrame } from '../../factories'; import { HslTimetablesDbTables } from '../../schema'; diff --git a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/temporarySatFirstHalfApril2023Dataset.ts b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/temporarySatFirstHalfApril2023Dataset.ts index 14dad172..ff046fbb 100644 --- a/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/temporarySatFirstHalfApril2023Dataset.ts +++ b/test/hasura/hsl/timetablesdb/datasets/additional-sets/timetables/temporarySatFirstHalfApril2023Dataset.ts @@ -1,9 +1,7 @@ -import { - defaultDayTypeIds, - journeyPatternRefsByName, -} from 'generic/timetablesdb/datasets/defaultSetup'; +import { journeyPatternRefsByName } from 'generic/timetablesdb/datasets/defaultSetup'; import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; import { DateTime } from 'luxon'; +import { defaultDayTypeIds } from '../../../../../timetables-data-inserter/day-types'; import { buildHslVehicleScheduleFrame } from '../../factories'; import { HslTimetablesDbTables } from '../../schema'; diff --git a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/default-timetables-dataset.ts b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/default-timetables-dataset.ts index ab9efd53..6f0340ee 100644 --- a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/default-timetables-dataset.ts +++ b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/default-timetables-dataset.ts @@ -1,4 +1,3 @@ -import { defaultDayTypeIds } from 'generic/timetablesdb/datasets/defaultSetup'; import { defaultTimetablesDataset as defaultGenericTimetablesDataset } from 'generic/timetablesdb/datasets/defaultSetup/default-timetables-dataset'; import { TimetablePriority, @@ -6,6 +5,7 @@ import { } from 'generic/timetablesdb/datasets/types'; import { DateTime } from 'luxon'; import { mergeTimetablesDatasets } from 'timetables-data-inserter'; +import { defaultDayTypeIds } from '../../../../timetables-data-inserter/day-types'; import { DayOfWeek } from '../types'; const defaultTimetablesDatasetHslAdditions = { diff --git a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/vehicle-services.ts b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/vehicle-services.ts index 6e2ab04f..42d54151 100644 --- a/test/hasura/hsl/timetablesdb/datasets/defaultSetup/vehicle-services.ts +++ b/test/hasura/hsl/timetablesdb/datasets/defaultSetup/vehicle-services.ts @@ -1,8 +1,6 @@ -import { - defaultDayTypeIds, - vehicleServices, -} from 'generic/timetablesdb/datasets/defaultSetup'; +import { vehicleServices } from 'generic/timetablesdb/datasets/defaultSetup'; import { VehicleService } from 'generic/timetablesdb/datasets/types'; +import { defaultDayTypeIds } from '../../../../timetables-data-inserter/day-types'; import { hslVehicleScheduleFramesByName } from './vehicle-schedule-frames'; export const hslVehicleServicesByName = { diff --git a/test/hasura/hsl/timetablesdb/integration-tests/function-get-timetable-versions-by-journey-pattern-ids/get-timetable-versions-by-journey-pattern-ids.spec.ts b/test/hasura/hsl/timetablesdb/integration-tests/function-get-timetable-versions-by-journey-pattern-ids/get-timetable-versions-by-journey-pattern-ids.spec.ts index a2996723..58c262ad 100644 --- a/test/hasura/hsl/timetablesdb/integration-tests/function-get-timetable-versions-by-journey-pattern-ids/get-timetable-versions-by-journey-pattern-ids.spec.ts +++ b/test/hasura/hsl/timetablesdb/integration-tests/function-get-timetable-versions-by-journey-pattern-ids/get-timetable-versions-by-journey-pattern-ids.spec.ts @@ -2,7 +2,6 @@ import * as config from '@config'; import * as db from '@util/db'; import { closeDbConnection, createDbConnection, DbConnection } from '@util/db'; import { setupDb } from '@util/setup'; -import { defaultDayTypeIds } from 'generic/timetablesdb/datasets/defaultSetup'; import { draftSunApril2023Timetable, draftSunApril2024Timetable, @@ -22,6 +21,7 @@ import { DateTime } from 'luxon'; import { buildHslTimetablesDataset, createHslTableData, + defaultDayTypeIds, mergeTimetablesDatasets, } from 'timetables-data-inserter'; import { createHslTimetablesDatasetHelper } from 'timetables-data-inserter/hsl/timetables-dataset-helper'; diff --git a/test/hasura/hsl/timetablesdb/integration-tests/function-get_timetables_and_substitute_operating_days/get-timetables-and-substitute-operating-days.spec.ts b/test/hasura/hsl/timetablesdb/integration-tests/function-get_timetables_and_substitute_operating_days/get-timetables-and-substitute-operating-days.spec.ts index 60c5ebca..5acb435c 100644 --- a/test/hasura/hsl/timetablesdb/integration-tests/function-get_timetables_and_substitute_operating_days/get-timetables-and-substitute-operating-days.spec.ts +++ b/test/hasura/hsl/timetablesdb/integration-tests/function-get_timetables_and_substitute_operating_days/get-timetables-and-substitute-operating-days.spec.ts @@ -2,10 +2,7 @@ import * as config from '@config'; import * as db from '@util/db'; import { closeDbConnection, createDbConnection, DbConnection } from '@util/db'; import { setupDb } from '@util/setup'; -import { - defaultDayTypeIds, - journeyPatternRefsByName, -} from 'generic/timetablesdb/datasets/defaultSetup'; +import { journeyPatternRefsByName } from 'generic/timetablesdb/datasets/defaultSetup'; import { draftSunApril2024Timetable, expressBusServiceSubstitutesSaturday20230520Dataset, @@ -25,6 +22,7 @@ import { DateTime } from 'luxon'; import { buildHslTimetablesDataset, createHslTableData, + defaultDayTypeIds, mergeTimetablesDatasets, } from 'timetables-data-inserter'; import { createHslTimetablesDatasetHelper } from 'timetables-data-inserter/hsl/timetables-dataset-helper'; diff --git a/test/hasura/hsl/timetablesdb/integration-tests/function-get_vehicle_schedules_on_date/get-vehicle-schedules-on-date.spec.ts b/test/hasura/hsl/timetablesdb/integration-tests/function-get_vehicle_schedules_on_date/get-vehicle-schedules-on-date.spec.ts index 0e6c6a06..8f2117fb 100644 --- a/test/hasura/hsl/timetablesdb/integration-tests/function-get_vehicle_schedules_on_date/get-vehicle-schedules-on-date.spec.ts +++ b/test/hasura/hsl/timetablesdb/integration-tests/function-get_vehicle_schedules_on_date/get-vehicle-schedules-on-date.spec.ts @@ -2,10 +2,7 @@ import * as config from '@config'; import * as db from '@util/db'; import { closeDbConnection, createDbConnection, DbConnection } from '@util/db'; import { setupDb } from '@util/setup'; -import { - defaultDayTypeIds, - journeyPatternRefsByName, -} from 'generic/timetablesdb/datasets/defaultSetup'; +import { journeyPatternRefsByName } from 'generic/timetablesdb/datasets/defaultSetup'; import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; import { draftSunApril2023Timetable, @@ -26,6 +23,7 @@ import { DateTime, Duration } from 'luxon'; import { buildHslTimetablesDataset, createHslTableData, + defaultDayTypeIds, mergeTimetablesDatasets, } from 'timetables-data-inserter'; diff --git a/test/hasura/package.json b/test/hasura/package.json index 8f75fb0c..51d43365 100644 --- a/test/hasura/package.json +++ b/test/hasura/package.json @@ -1,4 +1,14 @@ { + "name": "@hsl/timetables-data-inserter", + "version": "1.0.0", + "main": "dist/timetables-data-inserter/index.js", + "typesVersions": { + "*": { + "*": [ + "./dist/timetables-data-inserter/index.d.ts" + ] + } + }, "scripts": { "lint": "eslint './**/*.{ts,tsx}' --max-warnings=0", "prettier": "prettier --write .", @@ -19,6 +29,7 @@ "@types/luxon": "^3.2.0", "@types/pg": "^8.6.1", "@types/request-promise": "^4.1.48", + "@types/uuid": "^9.0.3", "@types/uuid-validate": "^0.0.1", "commander": "^11.0.0", "dotenv": "^10.0.0", @@ -34,6 +45,7 @@ "ts-jest": "^29.0.5", "tsc-alias": "^1.8.7", "typescript": "^4.9.5", + "uuid": "^9.0.1", "uuid-validate": "^0.0.3", "wkx": "^0.5.0", "zod": "^3.21.4" diff --git a/test/hasura/timetables-data-inserter/cli.ts b/test/hasura/timetables-data-inserter/cli.ts index 84b4e5e9..de31dd8a 100644 --- a/test/hasura/timetables-data-inserter/cli.ts +++ b/test/hasura/timetables-data-inserter/cli.ts @@ -3,8 +3,8 @@ import { program } from 'commander'; import fs from 'fs'; import { ConnectionConfig } from 'pg'; -import { insertDatasetFromJson as insertGenericDatasetFromJson } from './generic/json-parser'; -import { insertDatasetFromJson as insertHslDatasetFromJson } from './hsl/json-parser'; +import { insertDatasetFromJson as insertGenericDatasetFromJson } from './generic/data-insert'; +import { insertDatasetFromJson as insertHslDatasetFromJson } from './hsl/data-insert'; const buildDbConfig = ( options: Record, diff --git a/test/hasura/generic/timetablesdb/datasets/defaultSetup/day-types.ts b/test/hasura/timetables-data-inserter/day-types.ts similarity index 100% rename from test/hasura/generic/timetablesdb/datasets/defaultSetup/day-types.ts rename to test/hasura/timetables-data-inserter/day-types.ts diff --git a/test/hasura/timetables-data-inserter/generic/data-insert.ts b/test/hasura/timetables-data-inserter/generic/data-insert.ts new file mode 100644 index 00000000..dafc7a9d --- /dev/null +++ b/test/hasura/timetables-data-inserter/generic/data-insert.ts @@ -0,0 +1,28 @@ +import { timetablesDbConfig } from '@config'; +import { closeDbConnection, createDbConnection } from '@util/db'; +import { setupDb } from '@util/setup'; +import { ConnectionConfig } from 'pg'; +import { buildGenericTimetablesDataset } from './dataset'; +import { parseGenericDatasetJson } from './json-parser'; +import { createGenericTableData } from './table-data'; +import { GenericTimetablesDatasetInput } from './types'; + +export const insertGenericDataset = async ( + input: GenericTimetablesDatasetInput, + dbConfig: ConnectionConfig = timetablesDbConfig, +) => { + const builtDataset = buildGenericTimetablesDataset(input); + const tableData = createGenericTableData(builtDataset); + const dbConnection = createDbConnection(dbConfig); + await setupDb(dbConnection, tableData); + closeDbConnection(dbConnection); + return builtDataset; +}; + +export const insertDatasetFromJson = async ( + input: string, + dbConfig: ConnectionConfig = timetablesDbConfig, +) => { + const datasetInput = parseGenericDatasetJson(input); + return insertGenericDataset(datasetInput, dbConfig); +}; diff --git a/test/hasura/timetables-data-inserter/generic/json-parser.ts b/test/hasura/timetables-data-inserter/generic/json-parser.ts index fe17dc10..40bd1bc5 100644 --- a/test/hasura/timetables-data-inserter/generic/json-parser.ts +++ b/test/hasura/timetables-data-inserter/generic/json-parser.ts @@ -1,10 +1,4 @@ -import { timetablesDbConfig } from '@config'; -import { closeDbConnection, createDbConnection } from '@util/db'; -import { setupDb } from '@util/setup'; -import { ConnectionConfig } from 'pg'; -import { buildGenericTimetablesDataset } from './dataset'; import { genericTimetablesJsonSchema } from './json-schemas'; -import { createGenericTableData } from './table-data'; import { GenericTimetablesDatasetInput } from './types'; export const parseGenericDatasetJson = ( @@ -14,16 +8,3 @@ export const parseGenericDatasetJson = ( const parsedDatasetInput = genericTimetablesJsonSchema.parse(parsedJson); return parsedDatasetInput; }; - -export const insertDatasetFromJson = async ( - input: string, - dbConfig: ConnectionConfig = timetablesDbConfig, -) => { - const result = parseGenericDatasetJson(input); - const builtDataset = buildGenericTimetablesDataset(result); - const dbConnection = createDbConnection(dbConfig); - const tableData = createGenericTableData(builtDataset); - await setupDb(dbConnection, tableData); - closeDbConnection(dbConnection); - return builtDataset; -}; diff --git a/test/hasura/timetables-data-inserter/generic/json-schemas.ts b/test/hasura/timetables-data-inserter/generic/json-schemas.ts index 18810f18..20c02e0d 100644 --- a/test/hasura/timetables-data-inserter/generic/json-schemas.ts +++ b/test/hasura/timetables-data-inserter/generic/json-schemas.ts @@ -1,8 +1,8 @@ import { TypeOfLine } from 'generic/networkdb/datasets/types'; -import { defaultDayTypeIds } from 'generic/timetablesdb/datasets/defaultSetup'; import { TimetablePriority } from 'generic/timetablesdb/datasets/types'; import { DateTime, Duration } from 'luxon'; import { z } from 'zod'; +import { defaultDayTypeIds } from '../day-types'; // TODO: could add some validation? export const dateSchema = z diff --git a/test/hasura/timetables-data-inserter/generic/models/journey-pattern-ref.ts b/test/hasura/timetables-data-inserter/generic/models/journey-pattern-ref.ts index 40f61894..10dc326a 100644 --- a/test/hasura/timetables-data-inserter/generic/models/journey-pattern-ref.ts +++ b/test/hasura/timetables-data-inserter/generic/models/journey-pattern-ref.ts @@ -1,9 +1,9 @@ -import { randomUUID } from 'crypto'; import { TypeOfLine } from 'generic/networkdb/datasets/types'; import { JourneyPatternRef } from 'generic/timetablesdb/datasets/types'; import { omit } from 'lodash'; import { DateTime } from 'luxon'; import { assignId } from 'timetables-data-inserter/utils'; +import { v4 as uuidv4 } from 'uuid'; import { JourneyPatternRefInput, JourneyPatternRefOutput } from '../types'; import { processScheduledStopPoint } from './scheduled-stop-point'; @@ -18,7 +18,7 @@ export const processJourneyPatternRef = ( ); return { - journey_pattern_id: randomUUID(), + journey_pattern_id: uuidv4(), type_of_line: TypeOfLine.StoppingBusService, observation_timestamp: DateTime.fromISO('2023-07-01T00:00:00+00:00'), snapshot_timestamp: DateTime.fromISO('2023-09-28T00:00:00+00:00'), diff --git a/test/hasura/timetables-data-inserter/generic/models/vehicle-service.ts b/test/hasura/timetables-data-inserter/generic/models/vehicle-service.ts index ea400203..27e24a00 100644 --- a/test/hasura/timetables-data-inserter/generic/models/vehicle-service.ts +++ b/test/hasura/timetables-data-inserter/generic/models/vehicle-service.ts @@ -1,9 +1,9 @@ -import { defaultDayTypeIds } from 'generic/timetablesdb/datasets/defaultSetup/day-types'; import { VehicleScheduleFrame, VehicleService, } from 'generic/timetablesdb/datasets/types'; import { omit } from 'lodash'; +import { defaultDayTypeIds } from 'timetables-data-inserter/day-types'; import { TimetablesDatasetInput } from 'timetables-data-inserter/types'; import { assignId } from 'timetables-data-inserter/utils'; import { VehicleServiceInput, VehicleServiceOutput } from '../types'; diff --git a/test/hasura/timetables-data-inserter/generic/timetables-data-inserter.spec.ts b/test/hasura/timetables-data-inserter/generic/timetables-data-inserter.spec.ts index e6873f29..9f5e116a 100644 --- a/test/hasura/timetables-data-inserter/generic/timetables-data-inserter.spec.ts +++ b/test/hasura/timetables-data-inserter/generic/timetables-data-inserter.spec.ts @@ -1,11 +1,11 @@ import * as config from '@config'; import { DbConnection, closeDbConnection, createDbConnection } from '@util/db'; import { queryTable } from '@util/setup'; -import { defaultDayTypeIds } from 'generic/timetablesdb/datasets/defaultSetup'; import { genericTimetablesDbSchema } from 'generic/timetablesdb/datasets/schema'; import { get } from 'lodash'; +import { defaultDayTypeIds } from 'timetables-data-inserter/day-types'; +import { insertDatasetFromJson } from './data-insert'; import * as testDatasetJson from './example.json'; -import { insertDatasetFromJson } from './json-parser'; import { GenericTimetablesDatasetOutput, GenericVehicleScheduleFrameOutput, diff --git a/test/hasura/timetables-data-inserter/hsl/data-insert.ts b/test/hasura/timetables-data-inserter/hsl/data-insert.ts new file mode 100644 index 00000000..bf0603d3 --- /dev/null +++ b/test/hasura/timetables-data-inserter/hsl/data-insert.ts @@ -0,0 +1,28 @@ +import { timetablesDbConfig } from '@config'; +import { closeDbConnection, createDbConnection } from '@util/db'; +import { setupDb } from '@util/setup'; +import { ConnectionConfig } from 'pg'; +import { buildHslTimetablesDataset } from './dataset'; +import { parseHslDatasetJson } from './json-parser'; +import { createHslTableData } from './table-data'; +import { HslTimetablesDatasetInput } from './types'; + +export const insertHslDataset = async ( + input: HslTimetablesDatasetInput, + dbConfig: ConnectionConfig = timetablesDbConfig, +) => { + const builtDataset = buildHslTimetablesDataset(input); + const tableData = createHslTableData(builtDataset); + const dbConnection = createDbConnection(dbConfig); + await setupDb(dbConnection, tableData); + closeDbConnection(dbConnection); + return builtDataset; +}; + +export const insertDatasetFromJson = async ( + input: string, + dbConfig: ConnectionConfig = timetablesDbConfig, +) => { + const datasetInput = parseHslDatasetJson(input); + return insertHslDataset(datasetInput, dbConfig); +}; diff --git a/test/hasura/timetables-data-inserter/hsl/hsl-timetables-data-inserter.spec.ts b/test/hasura/timetables-data-inserter/hsl/hsl-timetables-data-inserter.spec.ts index 2db44e54..f2e0e94c 100644 --- a/test/hasura/timetables-data-inserter/hsl/hsl-timetables-data-inserter.spec.ts +++ b/test/hasura/timetables-data-inserter/hsl/hsl-timetables-data-inserter.spec.ts @@ -2,8 +2,8 @@ import * as config from '@config'; import { DbConnection, closeDbConnection, createDbConnection } from '@util/db'; import { queryTable } from '@util/setup'; import { hslTimetablesDbSchema } from 'hsl/timetablesdb/datasets/schema'; +import { insertDatasetFromJson } from './data-insert'; import * as testDatasetJson from './example.json'; -import { insertDatasetFromJson } from './json-parser'; import { HslTimetablesDatasetOutput, HslVehicleScheduleFrameOutput, diff --git a/test/hasura/timetables-data-inserter/hsl/index.ts b/test/hasura/timetables-data-inserter/hsl/index.ts index f16be848..0bbbc121 100644 --- a/test/hasura/timetables-data-inserter/hsl/index.ts +++ b/test/hasura/timetables-data-inserter/hsl/index.ts @@ -1,3 +1,4 @@ +export * from './data-insert'; export * from './dataset'; export * from './models'; export * from './table-data'; diff --git a/test/hasura/timetables-data-inserter/hsl/json-parser.ts b/test/hasura/timetables-data-inserter/hsl/json-parser.ts index 3d46236d..a923044e 100644 --- a/test/hasura/timetables-data-inserter/hsl/json-parser.ts +++ b/test/hasura/timetables-data-inserter/hsl/json-parser.ts @@ -1,10 +1,4 @@ -import { timetablesDbConfig } from '@config'; -import { closeDbConnection, createDbConnection } from '@util/db'; -import { setupDb } from '@util/setup'; -import { ConnectionConfig } from 'pg'; -import { buildHslTimetablesDataset } from './dataset'; import { hslTimetablesJsonSchema } from './json-schemas'; -import { createHslTableData } from './table-data'; import { HslTimetablesDatasetInput } from './types'; export const parseHslDatasetJson = ( @@ -14,16 +8,3 @@ export const parseHslDatasetJson = ( const parsedDatasetInput = hslTimetablesJsonSchema.parse(parsedJson); return parsedDatasetInput; }; - -export const insertDatasetFromJson = async ( - input: string, - dbConfig: ConnectionConfig = timetablesDbConfig, -) => { - const result = parseHslDatasetJson(input); - const builtDataset = buildHslTimetablesDataset(result); - const dbConnection = createDbConnection(dbConfig); - const tableData = createHslTableData(builtDataset); - await setupDb(dbConnection, tableData); - closeDbConnection(dbConnection); - return builtDataset; -}; diff --git a/test/hasura/timetables-data-inserter/index.ts b/test/hasura/timetables-data-inserter/index.ts index bbd710d3..819034d2 100644 --- a/test/hasura/timetables-data-inserter/index.ts +++ b/test/hasura/timetables-data-inserter/index.ts @@ -1,3 +1,4 @@ +export * from './day-types'; export * from './db'; export * from './generic'; export * from './hsl'; diff --git a/test/hasura/timetables-data-inserter/utils.ts b/test/hasura/timetables-data-inserter/utils.ts index ed54a815..cdd5fbc6 100644 --- a/test/hasura/timetables-data-inserter/utils.ts +++ b/test/hasura/timetables-data-inserter/utils.ts @@ -1,6 +1,6 @@ import { writeLatestTimetablesDatasetToFile } from '@config'; -import { randomUUID } from 'crypto'; import fs from 'fs'; +import { v4 as uuidv4 } from 'uuid'; export const assignId = (item: T, idField: K) => { return { @@ -8,7 +8,7 @@ export const assignId = (item: T, idField: K) => { // In theory the latter part should be same as Required>, but doesn't seem so. ...item, ...({ - [idField]: item[idField] || (randomUUID() as T[K]), + [idField]: item[idField] || (uuidv4() as T[K]), } as { [P in K]-?: NonNullable }), }; }; diff --git a/test/hasura/tsconfig-cli.json b/test/hasura/tsconfig-cli.json index a92507ae..0eb7eb3b 100644 --- a/test/hasura/tsconfig-cli.json +++ b/test/hasura/tsconfig-cli.json @@ -6,5 +6,5 @@ "module": "commonjs", "noEmit": false }, - "exclude": ["node_modules", "**/*.spec.ts"] + "exclude": ["node_modules", "**/*.spec.ts", "dist"] } diff --git a/test/hasura/tsconfig.json b/test/hasura/tsconfig.json index bf7bab33..662efe9a 100644 --- a/test/hasura/tsconfig.json +++ b/test/hasura/tsconfig.json @@ -11,6 +11,7 @@ "alwaysStrict": true, "noFallthroughCasesInSwitch": true, "forceConsistentCasingInFileNames": true, + "declaration": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "node", diff --git a/test/hasura/yarn.lock b/test/hasura/yarn.lock index feb68091..f71b627c 100644 --- a/test/hasura/yarn.lock +++ b/test/hasura/yarn.lock @@ -893,6 +893,11 @@ resolved "https://registry.yarnpkg.com/@types/uuid-validate/-/uuid-validate-0.0.1.tgz#b4eedecbd9db25851490d65a58f13feaa89dd509" integrity sha512-RbX9q0U00SLoV+l7loYX0Wrtv4QTClBC0QcdNts6x2b5G1HJN8NI9YlS1HNA6THrI9EH3OXSgya6eMQIlDjKFA== +"@types/uuid@^9.0.3": + version "9.0.4" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.4.tgz#e884a59338da907bda8d2ed03e01c5c49d036f1c" + integrity sha512-zAuJWQflfx6dYJM62vna+Sn5aeSWhh3OB+wfUEACNcqUSc0AGc5JKl+ycL1vrH7frGTXhJchYjE1Hak8L819dA== + "@types/yargs-parser@*": version "20.2.1" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.1.tgz#3b9ce2489919d9e4fea439b76916abc34b2df129" @@ -4157,6 +4162,11 @@ uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== +uuid@^9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" + integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== + v8-to-istanbul@^9.0.1: version "9.0.1" resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-9.0.1.tgz#b6f994b0b5d4ef255e17a0d17dc444a9f5132fa4"