diff --git a/services/app-api/src/resolvers/contract/contractResolver.ts b/services/app-api/src/resolvers/contract/contractResolver.ts index 74c20f8cc6..6722f8c329 100644 --- a/services/app-api/src/resolvers/contract/contractResolver.ts +++ b/services/app-api/src/resolvers/contract/contractResolver.ts @@ -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) { diff --git a/services/app-api/src/resolvers/contract/fetchContract.test.ts b/services/app-api/src/resolvers/contract/fetchContract.test.ts index b57058424b..87ab12eb69 100644 --- a/services/app-api/src/resolvers/contract/fetchContract.test.ts +++ b/services/app-api/src/resolvers/contract/fetchContract.test.ts @@ -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 () => { @@ -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() diff --git a/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.ts b/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.ts index a584ec161c..392b76c176 100644 --- a/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.ts +++ b/services/app-api/src/resolvers/healthPlanPackage/submitHealthPlanPackage.ts @@ -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[] = [] - // 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, diff --git a/services/app-api/src/resolvers/healthPlanPackage/unlockHealthPlanPackage.ts b/services/app-api/src/resolvers/healthPlanPackage/unlockHealthPlanPackage.ts index 0de1962b47..64d5624144 100644 --- a/services/app-api/src/resolvers/healthPlanPackage/unlockHealthPlanPackage.ts +++ b/services/app-api/src/resolvers/healthPlanPackage/unlockHealthPlanPackage.ts @@ -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,