Skip to content

Commit

Permalink
Use newly updates contract data for submitting rates. Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLin0991 committed Oct 20, 2023
1 parent 663f0c1 commit 8cc6e60
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SUBMIT_HEALTH_PLAN_PACKAGE from '../../../../app-graphql/src/mutations/submitHealthPlanPackage.graphql'
import FETCH_RATE from '../../../../app-graphql/src/queries/fetchRate.graphql'
import {
constructTestPostgresServer,
createAndUpdateTestHealthPlanPackage,
Expand Down Expand Up @@ -58,6 +59,9 @@ describe.each(flagValueTestParameters)(
const cmsUser = testCMSUser()
const mockLDService = testLDService({ [flagName]: flagValue })

afterEach(() => {
jest.clearAllMocks()
})
it('returns a StateSubmission if complete', async () => {
const server = await constructTestPostgresServer({
ldService: mockLDService,
Expand Down Expand Up @@ -579,6 +583,30 @@ describe.each(flagValueTestParameters)(
],
})
)

//Flag on only tests
if (!flagValue) {
return
}

// Check to make sure disconnected rates were not submitted.
const draftFormData = latestFormData(draft)
const draftRates = draftFormData.rateInfos

for (const rate of draftRates) {
const rateWithHistory = await server.executeOperation({
query: FETCH_RATE,
variables: {
input: {
rateID: rate.id,
},
},
})

const rateStatus = rateWithHistory.data?.fetchRate.rate.status

expect(rateStatus).not.toBe('SUBMITTED')
}
})

it('removes any invalid modified provisions from CHIP submission and submits successfully', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,26 @@ export function submitHealthPlanPackageResolver(
})
}

if (!updateResult.draftRevision) {
throw new Error(
'PROGRAMMING ERROR: draft contract does not contain a draft revision'
)
}

// From this point forward we use updateResult instead of contractWithHistory because it is now old data.

// If there are rates, submit those first
if (contractWithHistory.draftRevision.rateRevisions.length > 0) {
if (updateResult.draftRevision.rateRevisions.length > 0) {
const ratePromises: Promise<Error | RateType>[] = []
contractWithHistory.draftRevision.rateRevisions.forEach(
(rateRev) => {
ratePromises.push(
store.submitRate({
rateRevisionID: rateRev.id,
submittedByUserID: user.id,
submitReason: updateInfo.updatedReason,
})
)
}
)
updateResult.draftRevision.rateRevisions.forEach((rateRev) => {
ratePromises.push(
store.submitRate({
rateRevisionID: rateRev.id,
submittedByUserID: user.id,
submitReason: updateInfo.updatedReason,
})
)
})

const submitRatesResult = await Promise.all(ratePromises)
// if any of the promises reject, which shouldn't happen b/c we don't throw...
Expand Down Expand Up @@ -415,7 +421,7 @@ export function submitHealthPlanPackageResolver(

// then submit the contract!
const submitContractResult = await store.submitContract({
contractID: contractWithHistory.id,
contractID: updateResult.id,
submittedByUserID: user.id,
submitReason: updateInfo.updatedReason,
})
Expand Down

0 comments on commit 8cc6e60

Please sign in to comment.