From 8cc6e6013fad59024c609cbed36765d9a9406a35 Mon Sep 17 00:00:00 2001 From: Jason Lin Date: Fri, 20 Oct 2023 11:43:14 -0400 Subject: [PATCH] Use newly updates contract data for submitting rates. Add tests. --- .../submitHealthPlanPackage.test.ts | 28 ++++++++++++++++ .../submitHealthPlanPackage.ts | 32 +++++++++++-------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.test.ts b/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.test.ts index ce1565f061..ac886eecd2 100644 --- a/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.test.ts +++ b/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.test.ts @@ -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, @@ -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, @@ -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 () => { diff --git a/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.ts b/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.ts index d60bc9b518..b74e363735 100644 --- a/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.ts +++ b/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.ts @@ -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[] = [] - 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... @@ -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, })