diff --git a/services/app-api/src/testHelpers/contractAndRates/contractHelpers.ts b/services/app-api/src/testHelpers/contractAndRates/contractHelpers.ts index 2bd7e37d8c..3464c0c8e0 100644 --- a/services/app-api/src/testHelpers/contractAndRates/contractHelpers.ts +++ b/services/app-api/src/testHelpers/contractAndRates/contractHelpers.ts @@ -1,7 +1,4 @@ import type { InsertContractArgsType } from '../../postgres/contractAndRates/insertContract' -import type { State } from '@prisma/client' -import { must } from '../errorHelpers' -import type { PrismaClient } from '@prisma/client' import { v4 as uuidv4 } from 'uuid' import type { ContractRevisionTableWithRates, @@ -9,14 +6,7 @@ import type { } from '../../postgres/contractAndRates/prismaSubmittedContractHelpers' import type { StateCodeType } from 'app-web/src/common-code/healthPlanFormDataType' import type { ContractFormDataType } from '../../domain-models/contractAndRates' -import type { ProgramType } from '../../domain-models' -import statePrograms from 'app-web/src/common-code/data/statePrograms.json' - -function getProgramsFromState(stateCode: StateCodeType): ProgramType[] { - const state = statePrograms.states.find((st) => st.code === stateCode) - - return state?.programs || [] -} +import { getProgramsFromState } from '../stateHelpers' const createInsertContractData = ({ stateCode = 'MN', @@ -38,25 +28,6 @@ const createInsertContractData = ({ } } -const getStateRecord = async ( - client: PrismaClient, - stateCode: string -): Promise => { - const state = must( - await client.state.findFirst({ - where: { - stateCode, - }, - }) - ) - - if (!state) { - throw new Error('Unexpected prisma error: state record not found') - } - - return state -} - const createDraftContractData = ( contract?: Partial ): ContractTableFullPayload => ({ @@ -191,9 +162,7 @@ const createContractRevision = ( export { createInsertContractData, - getStateRecord, createContractRevision, createContractData, createDraftContractData, - getProgramsFromState, } diff --git a/services/app-api/src/testHelpers/contractAndRates/rateHelpers.ts b/services/app-api/src/testHelpers/contractAndRates/rateHelpers.ts index e28d0d315b..067a88dc1b 100644 --- a/services/app-api/src/testHelpers/contractAndRates/rateHelpers.ts +++ b/services/app-api/src/testHelpers/contractAndRates/rateHelpers.ts @@ -4,7 +4,7 @@ import type { RateTableFullPayload, RateRevisionTableWithContracts, } from '../../postgres/contractAndRates/prismaSubmittedRateHelpers' -import { getProgramsFromState } from './contractHelpers' +import { getProgramsFromState } from '../stateHelpers' import type { StateCodeType } from 'app-web/src/common-code/healthPlanFormDataType' const createInsertRateData = ( diff --git a/services/app-api/src/testHelpers/gqlHelpers.ts b/services/app-api/src/testHelpers/gqlHelpers.ts index a717b43712..3badabe096 100644 --- a/services/app-api/src/testHelpers/gqlHelpers.ts +++ b/services/app-api/src/testHelpers/gqlHelpers.ts @@ -36,11 +36,11 @@ import { sharedTestPrismaClient } from './storeHelpers' import { domainToBase64 } from 'app-web/src/common-code/proto/healthPlanFormDataProto' import type { EmailParameterStore } from '../parameterStore' import { newLocalEmailParameterStore } from '../parameterStore' -import statePrograms from 'app-web/src/common-code/data/statePrograms.json' import { testLDService } from './launchDarklyHelpers' import type { LDService } from '../launchDarkly/launchDarkly' import { insertUserToLocalAurora } from '../authn' import { testStateUser } from './userHelpers' +import { getProgramsFromState } from './stateHelpers' // Since our programs are checked into source code, we have a program we // use as our default @@ -60,12 +60,6 @@ function defaultFloridaRateProgram(): ProgramType { } } -function getProgramsFromState(stateCode: StateCodeType): ProgramType[] { - const state = statePrograms.states.find((st) => st.code === stateCode) - - return state?.programs || [] -} - const defaultContext = (): Context => { return { user: testStateUser(), diff --git a/services/app-api/src/testHelpers/index.ts b/services/app-api/src/testHelpers/index.ts index 83bb67c633..1ed448dc40 100644 --- a/services/app-api/src/testHelpers/index.ts +++ b/services/app-api/src/testHelpers/index.ts @@ -8,9 +8,9 @@ export { must } from './errorHelpers' export { createInsertContractData, - getStateRecord, createContractData, createContractRevision, createDraftContractData, - getProgramsFromState, } from './contractAndRates/contractHelpers' + +export { getProgramsFromState, getStateRecord } from './stateHelpers' diff --git a/services/app-api/src/testHelpers/stateHelpers.ts b/services/app-api/src/testHelpers/stateHelpers.ts new file mode 100644 index 0000000000..cec1ba1d30 --- /dev/null +++ b/services/app-api/src/testHelpers/stateHelpers.ts @@ -0,0 +1,32 @@ +import type { StateCodeType } from 'app-web/src/common-code/healthPlanFormDataType' +import type { ProgramType } from '../domain-models' +import statePrograms from 'app-web/src/common-code/data/statePrograms.json' +import type { PrismaClient, State } from '@prisma/client' +import { must } from './errorHelpers' + +function getProgramsFromState(stateCode: StateCodeType): ProgramType[] { + const state = statePrograms.states.find((st) => st.code === stateCode) + + return state?.programs || [] +} + +async function getStateRecord( + client: PrismaClient, + stateCode: string +): Promise { + const state = must( + await client.state.findFirst({ + where: { + stateCode, + }, + }) + ) + + if (!state) { + throw new Error('Unexpected prisma error: state record not found') + } + + return state +} + +export { getProgramsFromState, getStateRecord }