Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…e-review into mcr-4014-submission-submmary-v2
  • Loading branch information
pearl-truss committed Apr 18, 2024
2 parents 8b09893 + 6f305d0 commit 7784374
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 96 deletions.
12 changes: 9 additions & 3 deletions services/app-api/src/resolvers/contract/contractResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import type {

export function contractResolver(): Resolvers['Contract'] {
return {
initiallySubmittedAt(_parent) {
// we're only working on drafts for now, this will need to change to
// look at the revisions when we expand
initiallySubmittedAt(parent) {
if (parent.packageSubmissions.length > 0) {
const firstSubmission =
parent.packageSubmissions[
parent.packageSubmissions.length - 1
]
return firstSubmission.submitInfo.updatedAt
}

return null
},
state(parent) {
Expand Down
67 changes: 66 additions & 1 deletion services/app-api/src/resolvers/contract/fetchContract.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import {
constructTestPostgresServer,
createAndUpdateTestHealthPlanPackage,
unlockTestHealthPlanPackage,
} from '../../testHelpers/gqlHelpers'

import FETCH_CONTRACT from '../../../../app-graphql/src/queries/fetchContract.graphql'
import type { RateType } from '../../domain-models'
import { testStateUser } from '../../testHelpers/userHelpers'
import { testCMSUser, testStateUser } from '../../testHelpers/userHelpers'
import {
createAndUpdateTestContractWithoutRates,
fetchTestContract,
submitTestContract,
} from '../../testHelpers/gqlContractHelpers'
import { addNewRateToTestContract } from '../../testHelpers/gqlRateHelpers'
import { testLDService } from '../../testHelpers/launchDarklyHelpers'

describe('fetchContract', () => {
it('fetches the draft contract and a new child rate', async () => {
Expand Down Expand Up @@ -57,6 +65,63 @@ describe('fetchContract', () => {
expect(draftContract.contractName).toMatch(/MCR-FL-\d{4}-MMA/)
})

it('returns a stable initially submitted at', async () => {
const ldService = testLDService({
'link-rates': true,
})
const stateServer = await constructTestPostgresServer({
ldService,
})
const cmsServer = await constructTestPostgresServer({
ldService,
context: {
user: testCMSUser(),
},
})

const draftA0 =
await createAndUpdateTestContractWithoutRates(stateServer)
const AID = draftA0.id
const draftA010 = await addNewRateToTestContract(stateServer, draftA0)
await addNewRateToTestContract(stateServer, draftA010)

const unsubmitted = await fetchTestContract(stateServer, AID)
expect(unsubmitted.initiallySubmittedAt).toBeNull()

const intiallySubmitted = await submitTestContract(stateServer, AID)

await unlockTestHealthPlanPackage(cmsServer, AID, 'Unlock A.0')
await submitTestContract(stateServer, AID, 'Submit A.1')

await unlockTestHealthPlanPackage(cmsServer, AID, 'Unlock A.1')
await submitTestContract(stateServer, AID, 'Submit A.2')

await unlockTestHealthPlanPackage(cmsServer, AID, 'Unlock A.2')
await submitTestContract(stateServer, AID, 'Submit A.3')

await unlockTestHealthPlanPackage(cmsServer, AID, 'Unlock A.3')
await submitTestContract(stateServer, AID, 'Submit A.4')

const submittedMultiply = await fetchTestContract(stateServer, AID)

expect(submittedMultiply.packageSubmissions).toHaveLength(5)

expect(submittedMultiply.initiallySubmittedAt).toBeTruthy()
expect(submittedMultiply.initiallySubmittedAt).toEqual(
intiallySubmitted.initiallySubmittedAt
)

await unlockTestHealthPlanPackage(cmsServer, AID, 'Unlock A.4')

const finallyUnlocked = await fetchTestContract(stateServer, AID)
expect(finallyUnlocked.packageSubmissions).toHaveLength(5)

expect(finallyUnlocked.initiallySubmittedAt).toBeTruthy()
expect(finallyUnlocked.initiallySubmittedAt).toEqual(
intiallySubmitted.initiallySubmittedAt
)
})

it('errors if the wrong state user calls it', async () => {
const stateServerFL = await constructTestPostgresServer()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,51 +367,6 @@ export function submitHealthPlanPackageResolver(

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

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

// const submitRatesResult = await Promise.all(ratePromises)
// // if any of the promises reject, which shouldn't happen b/c we don't throw...
// if (submitRatesResult instanceof Error) {
// const errMessage = `Failed to submit contract revision's rates with ID: ${contractRevisionID}; ${submitRatesResult.message}`
// logError('submitHealthPlanPackage', errMessage)
// setErrorAttributesOnActiveSpan(errMessage, span)
// throw new GraphQLError(errMessage, {
// extensions: {
// code: 'INTERNAL_SERVER_ERROR',
// cause: 'DB_ERROR',
// },
// })
// }
// const submitRateErrors: Error[] = submitRatesResult.filter(
// (res) => res instanceof Error
// ) as Error[]
// if (submitRateErrors.length > 0) {
// console.error('Errors submitting Rates: ', submitRateErrors)
// const errMessage = `Failed to submit contract revision's rates with ID: ${contractRevisionID}; ${submitRateErrors.map(
// (err) => err.message
// )}`
// logError('submitHealthPlanPackage', errMessage)
// setErrorAttributesOnActiveSpan(errMessage, span)
// throw new GraphQLError(errMessage, {
// extensions: {
// code: 'INTERNAL_SERVER_ERROR',
// cause: 'DB_ERROR',
// },
// })
// }
// }

// then submit the contract!
const submitContractResult = await store.submitContract({
contractID: updateResult.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,53 +80,6 @@ export function unlockHealthPlanPackageResolver(
})
}

// unlock all the revisions, then unlock the contract, in a transaction.
// const currentRateRevIDs = contract.revisions[0].rateRevisions.map(
// (rr) => rr.id
// )
// const unlockRatePromises = []
// for (const rateRevisionID of currentRateRevIDs) {
// const resPromise = store.unlockRate({
// rateRevisionID,
// unlockReason: unlockedReason,
// unlockedByUserID: user.id,
// })

// unlockRatePromises.push(resPromise)
// }

// const unlockRateResults = await Promise.all(unlockRatePromises)
// // if any of the promises reject, which shouldn't happen b/c we don't throw...
// if (unlockRateResults instanceof Error) {
// const errMessage = `Failed to unlock contract rates with ID: ${contract.id}; ${unlockRateResults.message}`
// logError('unlockHealthPlanPackage', errMessage)
// setErrorAttributesOnActiveSpan(errMessage, span)
// throw new GraphQLError(errMessage, {
// extensions: {
// code: 'INTERNAL_SERVER_ERROR',
// cause: 'DB_ERROR',
// },
// })
// }

// const unlockRateErrors: Error[] = unlockRateResults.filter(
// (res) => res instanceof Error
// ) as Error[]
// if (unlockRateErrors.length > 0) {
// console.error('Errors unlocking Rates: ', unlockRateErrors)
// const errMessage = `Failed to submit contract revision's rates with ID: ${
// contract.id
// }; ${unlockRateErrors.map((err) => err.message)}`
// logError('unlockHealthPlanPackage', errMessage)
// setErrorAttributesOnActiveSpan(errMessage, span)
// throw new GraphQLError(errMessage, {
// extensions: {
// code: 'INTERNAL_SERVER_ERROR',
// cause: 'DB_ERROR',
// },
// })
// }

// Now, unlock the contract!
const unlockContractResult = await store.unlockContract({
contractID: contract.id,
Expand Down

0 comments on commit 7784374

Please sign in to comment.