Skip to content

Commit

Permalink
refactor: Explicitly export vehicleDataFactory (#2749)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlarson authored Aug 27, 2024
1 parent 84d2d3c commit 445884d
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 91 deletions.
164 changes: 83 additions & 81 deletions assets/tests/factories/vehicle_data.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,92 @@
import { Factory } from "fishery"
import { VehicleData } from "../../src/models/vehicleData"

export default Factory.define<VehicleData>(({ sequence }) => ({
id: `v${sequence}`,
label: `v${sequence}-label`,
run_id: `run-${sequence}`,
timestamp: 123,
latitude: 0,
longitude: 0,
direction_id: 0,
route_id: "39",
route_pattern_id: "39-_-0",
trip_id: `t${sequence}`,
headsign: "Forest Hills",
via_variant: "X",
operator_id: `op${sequence}`,
operator_first_name: "WILL",
operator_last_name: "SMITH",
operator_logon_time: Math.floor(
new Date("2018-08-15T13:38:21.000Z").getTime() / 1000
),
bearing: 33,
block_id: `block-${sequence}`,
previous_vehicle_id: `v${sequence + 1}`,
schedule_adherence_secs: 0,
incoming_trip_direction_id: null,
is_shuttle: false,
is_overload: false,
is_off_course: false,
is_revenue: true,
layover_departure_time: null,
pull_back_place_name: "Garage",
overload_offset: null,
sources: [],
data_discrepancies: [
{
attribute: "trip_id",
sources: [
{
id: "swiftly",
value: "swiftly-trip-id",
},
{
id: "busloc",
value: "busloc-trip-id",
},
],
},
{
attribute: "route_id",
sources: [
{
id: "swiftly",
value: null,
},
{
id: "busloc",
value: "busloc-route-id",
},
],
},
],
stop_status: {
stop_id: "s1",
stop_name: "Stop Name",
},
timepoint_status: {
timepoint_id: "tp1",
fraction_until_timepoint: 0.5,
},
scheduled_location: {
export const vehicleDataFactory = Factory.define<VehicleData>(
({ sequence }) => ({
id: `v${sequence}`,
label: `v${sequence}-label`,
run_id: `run-${sequence}`,
timestamp: 123,
latitude: 0,
longitude: 0,
direction_id: 0,
route_id: "39",
route_pattern_id: "39-_-0",
direction_id: 0,
trip_id: "scheduled trip",
run_id: "scheduled run",
time_since_trip_start_time: 0,
headsign: "scheduled headsign",
via_variant: "scheduled via variant",
trip_id: `t${sequence}`,
headsign: "Forest Hills",
via_variant: "X",
operator_id: `op${sequence}`,
operator_first_name: "WILL",
operator_last_name: "SMITH",
operator_logon_time: Math.floor(
new Date("2018-08-15T13:38:21.000Z").getTime() / 1000
),
bearing: 33,
block_id: `block-${sequence}`,
previous_vehicle_id: `v${sequence + 1}`,
schedule_adherence_secs: 0,
incoming_trip_direction_id: null,
is_shuttle: false,
is_overload: false,
is_off_course: false,
is_revenue: true,
layover_departure_time: null,
pull_back_place_name: "Garage",
overload_offset: null,
sources: [],
data_discrepancies: [
{
attribute: "trip_id",
sources: [
{
id: "swiftly",
value: "swiftly-trip-id",
},
{
id: "busloc",
value: "busloc-trip-id",
},
],
},
{
attribute: "route_id",
sources: [
{
id: "swiftly",
value: null,
},
{
id: "busloc",
value: "busloc-route-id",
},
],
},
],
stop_status: {
stop_id: "s1",
stop_name: "Stop Name",
},
timepoint_status: {
timepoint_id: "tp1",
fraction_until_timepoint: 0.5,
},
},
route_status: "on_route",
end_of_trip_type: "another_trip",
block_waivers: [],
crowding: null,
}))
scheduled_location: {
route_id: "39",
route_pattern_id: "39-_-0",
direction_id: 0,
trip_id: "scheduled trip",
run_id: "scheduled run",
time_since_trip_start_time: 0,
headsign: "scheduled headsign",
via_variant: "scheduled via variant",
timepoint_status: {
timepoint_id: "tp1",
fraction_until_timepoint: 0.5,
},
},
route_status: "on_route",
end_of_trip_type: "another_trip",
block_waivers: [],
crowding: null,
})
)
2 changes: 1 addition & 1 deletion assets/tests/hooks/useAutocompleteResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, test, expect } from "@jest/globals"
import { useAutocompleteResults } from "../../src/hooks/useAutocompleteResults"
import { renderHook } from "@testing-library/react"
import { makeMockSocket, makeMockChannel } from "../testHelpers/socketHelpers"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"
import { searchFiltersFactory } from "../factories/searchProperties"

describe("useAutocompleteResults", () => {
Expand Down
2 changes: 1 addition & 1 deletion assets/tests/hooks/usePullbackVehicles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { renderHook } from "@testing-library/react"
import usePullbackVehicles from "../../src/hooks/usePullbackVehicles"
import { Vehicle } from "../../src/realtime.d"
import { makeMockChannel, makeMockSocket } from "../testHelpers/socketHelpers"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"
import { vehicleFromData } from "../../src/models/vehicleData"

const pullBackVehicle = vehicleDataFactory.build({
Expand Down
2 changes: 1 addition & 1 deletion assets/tests/hooks/useSearchResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { VehiclePropertyQuery } from "../../src/models/searchQuery"
import { VehicleData, vehicleFromData } from "../../src/models/vehicleData"
import { makeMockChannel, makeMockSocket } from "../testHelpers/socketHelpers"

import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"

describe("useSearchResults", () => {
test("when query given and loading, returns loading", () => {
Expand Down
2 changes: 1 addition & 1 deletion assets/tests/hooks/useShuttleVehicles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { renderHook } from "@testing-library/react"
import useShuttleVehicles from "../../src/hooks/useShuttleVehicles"
import { Vehicle } from "../../src/realtime.d"
import { makeMockChannel, makeMockSocket } from "../testHelpers/socketHelpers"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"
import { vehicleFromData } from "../../src/models/vehicleData"

const shuttle = vehicleDataFactory.build({ is_shuttle: true })
Expand Down
2 changes: 1 addition & 1 deletion assets/tests/hooks/useVehicleForId.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
makeMockOneShotChannel,
makeMockSocket,
} from "../testHelpers/socketHelpers"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"
import { renderHook } from "@testing-library/react"
import useVehicleForId from "../../src/hooks/useVehicleForId"

Expand Down
2 changes: 1 addition & 1 deletion assets/tests/hooks/useVehicleForNotification.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
makeMockOneShotChannel,
makeMockSocket,
} from "../testHelpers/socketHelpers"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"
import ghostDataFactory from "../factories/ghost_data"
import { tagManagerEvent } from "../../src/helpers/googleTagManager"
import { fullStoryEvent } from "../../src/helpers/fullStory"
Expand Down
2 changes: 1 addition & 1 deletion assets/tests/hooks/useVehicles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Ghost, Vehicle } from "../../src/realtime.d"
import { RouteId } from "../../src/schedule.d"
import { makeMockChannel, makeMockSocket } from "../testHelpers/socketHelpers"
import ghostFactory from "../factories/ghost"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"
import ghostDataFactory from "../factories/ghost_data"
import * as Sentry from "@sentry/react"

Expand Down
2 changes: 1 addition & 1 deletion assets/tests/hooks/useVehiclesForBlockIds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { renderHook } from "@testing-library/react"
import useVehicleForBlockIds from "../../src/hooks/useVehiclesForBlockIds"
import { vehicleFromData } from "../../src/models/vehicleData"
import { makeMockChannel, makeMockSocket } from "../testHelpers/socketHelpers"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"

describe("useVehiclesForBlockIds", () => {
test("returns data", () => {
Expand Down
2 changes: 1 addition & 1 deletion assets/tests/hooks/useVehiclesForRunIds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { renderHook } from "@testing-library/react"
import useVehiclesForRunIds from "../../src/hooks/useVehiclesForRunIds"
import { VehicleData, vehicleFromData } from "../../src/models/vehicleData"
import { makeMockChannel, makeMockSocket } from "../testHelpers/socketHelpers"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"

describe("useVehiclesForRunIds", () => {
test("returns data", () => {
Expand Down
2 changes: 1 addition & 1 deletion assets/tests/models/vehicleData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, test, expect } from "@jest/globals"
import { ghostFromData, vehicleFromData } from "../../src/models/vehicleData"
import { dateFromEpochSeconds } from "../../src/util/dateTime"
import ghostDataFactory from "../factories/ghost_data"
import vehicleDataFactory from "../factories/vehicle_data"
import { vehicleDataFactory } from "../factories/vehicle_data"

describe("vehicleFromData", () => {
test("returns vehicle data in expected format", () => {
Expand Down

0 comments on commit 445884d

Please sign in to comment.