Skip to content

Commit

Permalink
Fix unlock removed child rate crasher (#2397)
Browse files Browse the repository at this point in the history
  • Loading branch information
macrael authored May 1, 2024
1 parent 556ee7f commit e11893a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
12 changes: 11 additions & 1 deletion services/app-api/src/postgres/contractAndRates/unlockContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,18 @@ async function unlockContract(
},
})

// only unlock children that were submitted in the latest submission
const submissionPackageEntries =
currentRev.relatedSubmisions[0].submissionPackages

for (const childRate of childRates) {
childRateIDs.push(childRate.id)
if (
submissionPackageEntries.some(
(p) => p.rateRevision.rateID === childRate.id
)
) {
childRateIDs.push(childRate.id)
}
}
} else {
// without linked rates, we push all the valid rate revisions attached to the contract revision
Expand Down
83 changes: 83 additions & 0 deletions services/app-api/src/resolvers/contract/submitContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,89 @@ describe('submitContract', () => {
console.info(ThreeID, FourID, contractD0)
})

it('unlocks a submission with a removed child rate', async () => {
const ldService = testLDService({
'link-rates': true,
})

const stateServer = await constructTestPostgresServer({
ldService,
})
const cmsServer = await constructTestPostgresServer({
ldService,
context: {
user: testCMSUser(),
},
})

// 1. Submit A0 with Rate1 and Rate2
const draftA0 =
await createAndUpdateTestContractWithoutRates(stateServer)
const AID = draftA0.id
await addNewRateToTestContract(stateServer, draftA0)

const contractA0 = await submitTestContract(stateServer, AID)
const subA0 = contractA0.packageSubmissions[0]
const rate10 = subA0.rateRevisions[0]
const OneID = rate10.rateID

// 2. Submit B0 with Rate1 and Rate3
const draftB0 =
await createAndUpdateTestContractWithoutRates(stateServer)
const draftB010 = await addLinkedRateToTestContract(
stateServer,
draftB0,
OneID
)
await addNewRateToTestContract(stateServer, draftB010)

const contractB0 = await submitTestContract(stateServer, draftB0.id)
const subB0 = contractB0.packageSubmissions[0]

expect(subB0.rateRevisions[0].rateID).toBe(OneID)

// 3. unlock and resubmit B, removing Three
await unlockTestHealthPlanPackage(
cmsServer,
contractB0.id,
'remove that child rate'
)

const unlockedB0 = await fetchTestContract(stateServer, contractB0.id)

const unlockedBUpdateInput =
updateRatesInputFromDraftContract(unlockedB0)
unlockedBUpdateInput.updatedRates = [
unlockedBUpdateInput.updatedRates[0],
]

const updatedUnlockedB0 = await updateTestDraftRatesOnContract(
stateServer,
unlockedBUpdateInput
)

expect(updatedUnlockedB0.draftRates).toHaveLength(1)

await submitTestContract(
stateServer,
updatedUnlockedB0.id,
'resubmit without child'
)

// 4. Unlock again, should not error
await unlockTestHealthPlanPackage(
cmsServer,
updatedUnlockedB0.id,
'dont try and reunlock'
)
const unlockedB1 = await fetchTestContract(
stateServer,
updatedUnlockedB0.id
)

expect(unlockedB1.draftRates).toHaveLength(1)
})

it('handles complex submission etc', async () => {
const ldService = testLDService({
'link-rates': true,
Expand Down

0 comments on commit e11893a

Please sign in to comment.