Skip to content

Commit

Permalink
Repeatable tests with feature flag state as parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLin0991 committed Jul 15, 2023
1 parent 23fabb2 commit 8647b14
Showing 1 changed file with 75 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,34 @@ import { constructTestPostgresServer } from '../../testHelpers/gqlHelpers'
import { latestFormData } from '../../testHelpers/healthPlanPackageHelpers'
import { testCMSUser } from '../../testHelpers/userHelpers'
import { testLDService } from '../../testHelpers/launchDarklyHelpers'
import {
FeatureFlagLDConstant,
FlagValue,
} from '../../../../app-web/src/common-code/featureFlags'

describe('createHealthPlanPackage', () => {
it('returns package with unlocked form data', async () => {
const server = await constructTestPostgresServer()
const flagValueTestParameters: {
flagName: FeatureFlagLDConstant
flagValue: FlagValue
testName: string
}[] = [
{
flagName: 'rates-db-refactor',
flagValue: true,
testName: 'createHealthPlanPackage with all feature flags off',
},
{
flagName: 'rates-db-refactor',
flagValue: true,
testName: 'createHealthPlanPackage with rates-db-refactor on',
},
]

const input: CreateHealthPlanPackageInput = {
programIDs: [
'5c10fe9f-bec9-416f-a20c-718b152ad633',
'037af66b-81eb-4472-8b80-01edf17d12d9',
],
riskBasedContract: false,
submissionType: 'CONTRACT_ONLY',
submissionDescription: 'A real submission',
contractType: 'BASE',
}
const res = await server.executeOperation({
query: CREATE_HEALTH_PLAN_PACKAGE,
variables: { input },
})

expect(res.errors).toBeUndefined()

const pkg = res.data?.createHealthPlanPackage.pkg
const draft = latestFormData(pkg)

expect(draft.submissionDescription).toBe('A real submission')
expect(draft.submissionType).toBe('CONTRACT_ONLY')
expect(draft.programIDs).toEqual([
'5c10fe9f-bec9-416f-a20c-718b152ad633',
'037af66b-81eb-4472-8b80-01edf17d12d9',
])
expect(draft.documents).toHaveLength(0)
expect(draft.managedCareEntities).toHaveLength(0)
expect(draft.federalAuthorities).toHaveLength(0)
expect(draft.contractDateStart).toBeUndefined()
expect(draft.contractDateEnd).toBeUndefined()
})

it('returns an error if the program id is not in valid', async () => {
const server = await constructTestPostgresServer()
const input: CreateHealthPlanPackageInput = {
programIDs: ['xyz123'],
riskBasedContract: false,
submissionType: 'CONTRACT_ONLY',
submissionDescription: 'A real submission',
contractType: 'BASE',
}
const res = await server.executeOperation({
query: CREATE_HEALTH_PLAN_PACKAGE,
variables: { input },
})

expect(res.errors).toBeDefined()
expect(res.errors && res.errors[0].message).toBe(
'The program id xyz123 does not exist in state FL'
)
})

it('returns an error if a CMS user attempts to create', async () => {
const server = await constructTestPostgresServer({
context: {
user: testCMSUser(),
},
})

const input: CreateHealthPlanPackageInput = {
programIDs: ['xyz123'],
riskBasedContract: false,
submissionType: 'CONTRACT_ONLY',
submissionDescription: 'A real submission',
contractType: 'BASE',
}
const res = await server.executeOperation({
query: CREATE_HEALTH_PLAN_PACKAGE,
variables: { input },
})

expect(res.errors).toBeDefined()
expect(res.errors && res.errors[0].message).toBe(
'user not authorized to create state data'
)
})
describe.each(flagValueTestParameters)(
`Tests $testName`,
({ flagName, flagValue }) => {
const mockLDService = testLDService({ [flagName]: flagValue })

describe('ratesDatabaseRefactor feature flag on', () => {
it('inserts contract to new tables and returns a health plan package', async () => {
const mockLDService = testLDService({ 'rates-db-refactor': true })
it('returns package with unlocked form data', async () => {
const server = await constructTestPostgresServer({
ldService: mockLDService,
})
Expand Down Expand Up @@ -126,5 +68,53 @@ describe('createHealthPlanPackage', () => {
expect(draft.contractDateStart).toBeUndefined()
expect(draft.contractDateEnd).toBeUndefined()
})
})
})

it('returns an error if the program id is not in valid', async () => {
const server = await constructTestPostgresServer({
ldService: mockLDService,
})
const input: CreateHealthPlanPackageInput = {
programIDs: ['xyz123'],
riskBasedContract: false,
submissionType: 'CONTRACT_ONLY',
submissionDescription: 'A real submission',
contractType: 'BASE',
}
const res = await server.executeOperation({
query: CREATE_HEALTH_PLAN_PACKAGE,
variables: { input },
})

expect(res.errors).toBeDefined()
expect(res.errors && res.errors[0].message).toBe(
'The program id xyz123 does not exist in state FL'
)
})

it('returns an error if a CMS user attempts to create', async () => {
const server = await constructTestPostgresServer({
context: {
user: testCMSUser(),
},
ldService: mockLDService,
})

const input: CreateHealthPlanPackageInput = {
programIDs: ['xyz123'],
riskBasedContract: false,
submissionType: 'CONTRACT_ONLY',
submissionDescription: 'A real submission',
contractType: 'BASE',
}
const res = await server.executeOperation({
query: CREATE_HEALTH_PLAN_PACKAGE,
variables: { input },
})

expect(res.errors).toBeDefined()
expect(res.errors && res.errors[0].message).toBe(
'user not authorized to create state data'
)
})
}
)

0 comments on commit 8647b14

Please sign in to comment.