Skip to content

Commit

Permalink
Move state helpers to stateHelpers.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLin0991 committed Aug 29, 2023
1 parent 5a52265 commit d261287
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
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,
ContractTableFullPayload,
} 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',
Expand All @@ -38,25 +28,6 @@ const createInsertContractData = ({
}
}

const getStateRecord = async (
client: PrismaClient,
stateCode: string
): Promise<State> => {
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>
): ContractTableFullPayload => ({
Expand Down Expand Up @@ -191,9 +162,7 @@ const createContractRevision = (

export {
createInsertContractData,
getStateRecord,
createContractRevision,
createContractData,
createDraftContractData,
getProgramsFromState,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
8 changes: 1 addition & 7 deletions services/app-api/src/testHelpers/gqlHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/src/testHelpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export { must } from './errorHelpers'

export {
createInsertContractData,
getStateRecord,
createContractData,
createContractRevision,
createDraftContractData,
getProgramsFromState,
} from './contractAndRates/contractHelpers'

export { getProgramsFromState, getStateRecord } from './stateHelpers'
32 changes: 32 additions & 0 deletions services/app-api/src/testHelpers/stateHelpers.ts
Original file line number Diff line number Diff line change
@@ -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<State> {
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 }

0 comments on commit d261287

Please sign in to comment.