Skip to content

Commit

Permalink
Fix test for strict rate id checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLin0991 committed Oct 19, 2023
1 parent 048d75b commit fd1b9c5
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 122 deletions.
154 changes: 81 additions & 73 deletions services/app-api/src/resolvers/contractAndRates/fetchRate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { testCMSUser } from '../../testHelpers/userHelpers'
import { testLDService } from '../../testHelpers/launchDarklyHelpers'
import { latestFormData } from '../../testHelpers/healthPlanPackageHelpers'
import { must } from '../../testHelpers'
import { v4 as uuidv4 } from 'uuid'

describe('fetchRate', () => {
const mockLDService = testLDService({ 'rates-db-refactor': true })
Expand All @@ -28,75 +29,85 @@ describe('fetchRate', () => {
ldService: mockLDService,
})

const initialRateInfos = [
{
rateType: 'NEW' as const,
rateDateStart: new Date(Date.UTC(2025, 5, 1)),
rateDateEnd: new Date(Date.UTC(2026, 4, 30)),
rateDateCertified: new Date(Date.UTC(2025, 3, 15)),
rateDocuments: [
{
name: 'rateDocument.pdf',
s3URL: 'fakeS3URL',
sha256: 'fakesha',
documentCategories: ['RATES' as const],
},
],
supportingDocuments: [],
rateProgramIDs: [defaultFloridaRateProgram().id],
actuaryContacts: [
{
name: 'test name',
titleRole: 'test title',
email: 'email@example.com',
actuarialFirm: 'MERCER' as const,
actuarialFirmOther: '',
},
],
actuaryCommunicationPreference: 'OACT_TO_ACTUARY' as const,
packagesWithSharedRateCerts: [],
},
]
const initialRateInfos = () => ({
id: uuidv4(),
rateType: 'NEW' as const,
rateDateStart: new Date(Date.UTC(2025, 5, 1)),
rateDateEnd: new Date(Date.UTC(2026, 4, 30)),
rateDateCertified: new Date(Date.UTC(2025, 3, 15)),
rateDocuments: [
{
name: 'rateDocument.pdf',
s3URL: 'fakeS3URL',
sha256: 'fakesha',
documentCategories: ['RATES' as const],
},
],
supportingDocuments: [],
rateProgramIDs: [defaultFloridaRateProgram().id],
actuaryContacts: [
{
name: 'test name',
titleRole: 'test title',
email: 'email@example.com',
actuarialFirm: 'MERCER' as const,
actuarialFirmOther: '',
},
],
actuaryCommunicationPreference: 'OACT_TO_ACTUARY' as const,
packagesWithSharedRateCerts: [],
})

// First, create new submission and unlock to edit rate
const submittedEditedRates = await createAndSubmitTestHealthPlanPackage(
server,
{
rateInfos: initialRateInfos,
rateInfos: [initialRateInfos()],
}
)
const packageID = submittedEditedRates.id
const rateID =
latestFormData(submittedEditedRates).rateInfos[0].id || 'NO_ID'
await unlockTestHealthPlanPackage(

// Unlock submission
const unlockedHPP = await unlockTestHealthPlanPackage(
cmsServer,
submittedEditedRates.id,
packageID,
'Unlock to edit an existing rate'
)

// edit the sake rate
// Decode unlocked submission form data
const unlockedHppFormData = latestFormData(unlockedHPP)
// Get the data of the first and only rate in the HPP
const unlockedRate = unlockedHppFormData.rateInfos[0]

// edit the same rate
await updateTestHealthPlanPackage(server, packageID, {
rateInfos: [
{
...initialRateInfos[0],
id: rateID, // edit same rate, use same id
...unlockedRate,
id: unlockedRate.id, // edit same rate, use same id
rateDateStart: new Date(Date.UTC(2025, 1, 1)),
rateDateEnd: new Date(Date.UTC(2027, 1, 1)),
},
],
})

await resubmitTestHealthPlanPackage(
// Resubmit
const resubmittedHPP = await resubmitTestHealthPlanPackage(
server,
packageID,
'Resubmit with edited rate description'
)

// Decode resubmitted HPP form data
const resubmittedHppFormData = latestFormData(resubmittedHPP)

// fetch and check rate
const result = await cmsServer.executeOperation({
query: FETCH_RATE,
variables: {
input: { rateID },
input: {
rateID: resubmittedHppFormData.rateInfos[0].id,
},
},
})

Expand Down Expand Up @@ -142,41 +153,40 @@ describe('fetchRate', () => {
ldService: mockLDService,
})

const initialRateInfos = [
{
rateType: 'NEW' as const,
rateDateStart: new Date(Date.UTC(2025, 5, 1)),
rateDateEnd: new Date(Date.UTC(2026, 4, 30)),
rateDateCertified: new Date(Date.UTC(2025, 3, 15)),
rateDocuments: [
{
name: 'rateDocument.pdf',
s3URL: 'fakeS3URL',
sha256: 'fakesha',
documentCategories: ['RATES' as const],
},
],
supportingDocuments: [],
rateProgramIDs: [defaultFloridaRateProgram().id],
actuaryContacts: [
{
name: 'test name',
titleRole: 'test title',
email: 'email@example.com',
actuarialFirm: 'MERCER' as const,
actuarialFirmOther: '',
},
],
actuaryCommunicationPreference: 'OACT_TO_ACTUARY' as const,
packagesWithSharedRateCerts: [],
},
]
const initialRateInfos = () => ({
id: uuidv4(),
rateType: 'NEW' as const,
rateDateStart: new Date(Date.UTC(2025, 5, 1)),
rateDateEnd: new Date(Date.UTC(2026, 4, 30)),
rateDateCertified: new Date(Date.UTC(2025, 3, 15)),
rateDocuments: [
{
name: 'rateDocument.pdf',
s3URL: 'fakeS3URL',
sha256: 'fakesha',
documentCategories: ['RATES' as const],
},
],
supportingDocuments: [],
rateProgramIDs: [defaultFloridaRateProgram().id],
actuaryContacts: [
{
name: 'test name',
titleRole: 'test title',
email: 'email@example.com',
actuarialFirm: 'MERCER' as const,
actuarialFirmOther: '',
},
],
actuaryCommunicationPreference: 'OACT_TO_ACTUARY' as const,
packagesWithSharedRateCerts: [],
})

// First, create new submission and unlock to edit rate
const submittedInitial = await createAndSubmitTestHealthPlanPackage(
server,
{
rateInfos: initialRateInfos,
rateInfos: [initialRateInfos()],
}
)

Expand All @@ -192,11 +202,9 @@ describe('fetchRate', () => {
expect(existingFormData.rateInfos).toHaveLength(1)
await updateTestHealthPlanPackage(server, submittedInitial.id, {
rateInfos: [
{ ...initialRateInfos[0], id: firstRateID }, // first rate unchanged

existingFormData.rateInfos[0], // first rate unchanged
{
...initialRateInfos[0],
id: undefined, // this is a new rate
...initialRateInfos(),
rateDateStart: new Date(Date.UTC(2030, 1, 1)),
rateDateEnd: new Date(Date.UTC(2030, 12, 1)),
rateDateCertified: new Date(Date.UTC(2029, 10, 31)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,44 +152,43 @@ describe.each(flagValueTestParameters)(
ldService: mockLDService,
})

const initialRateInfos = [
{
rateType: 'NEW' as const,
rateDateStart: new Date(Date.UTC(2025, 5, 1)),
rateDateEnd: new Date(Date.UTC(2026, 4, 30)),
rateDateCertified: new Date(Date.UTC(2025, 3, 15)),
rateDocuments: [
{
name: 'rateDocument.pdf',
s3URL: 'fakeS3URL',
sha256: 'fakesha',
documentCategories: ['RATES' as const],
},
],
supportingDocuments: [],
rateProgramIDs: [defaultFloridaRateProgram().id],
actuaryContacts: [
{
name: 'test name',
titleRole: 'test title',
email: 'email@example.com',
actuarialFirm: 'MERCER' as const,
actuarialFirmOther: '',
},
],
actuaryCommunicationPreference: 'OACT_TO_ACTUARY' as const,
packagesWithSharedRateCerts: [],
},
]
const initialRateInfos = () => ({
id: uuidv4(),
rateType: 'NEW' as const,
rateDateStart: new Date(Date.UTC(2025, 5, 1)),
rateDateEnd: new Date(Date.UTC(2026, 4, 30)),
rateDateCertified: new Date(Date.UTC(2025, 3, 15)),
rateDocuments: [
{
name: 'rateDocument.pdf',
s3URL: 'fakeS3URL',
sha256: 'fakesha',
documentCategories: ['RATES' as const],
},
],
supportingDocuments: [],
rateProgramIDs: [defaultFloridaRateProgram().id],
actuaryContacts: [
{
name: 'test name',
titleRole: 'test title',
email: 'email@example.com',
actuarialFirm: 'MERCER' as const,
actuarialFirmOther: '',
},
],
actuaryCommunicationPreference: 'OACT_TO_ACTUARY' as const,
packagesWithSharedRateCerts: [],
})

// First, create new submissions
const submittedEditedRates =
await createAndSubmitTestHealthPlanPackage(server, {
rateInfos: initialRateInfos,
rateInfos: [initialRateInfos()],
})
const submittedNewRates =
await createAndSubmitTestHealthPlanPackage(server, {
rateInfos: initialRateInfos,
rateInfos: [initialRateInfos()],
})

// Unlock both - one to be rate edited in place, the other to add new rate
Expand All @@ -206,14 +205,11 @@ describe.each(flagValueTestParameters)(

// update one with a new rate start and end date
const existingFormData = latestFormData(existingRate1)
const firstPackageInitialRateID =
existingFormData.rateInfos[0]?.id || 'NO_ID'
expect(existingFormData.rateInfos).toHaveLength(1)
await updateTestHealthPlanPackage(server, submittedEditedRates.id, {
rateInfos: [
{
...initialRateInfos[0],
id: firstPackageInitialRateID, // this should be id from existing rate, using the id that is coming back in toDomain to imitate frontend
...existingFormData.rateInfos[0],
rateDateStart: new Date(Date.UTC(2025, 1, 1)),
rateDateEnd: new Date(Date.UTC(2027, 1, 1)),
},
Expand All @@ -222,18 +218,13 @@ describe.each(flagValueTestParameters)(

// update the other with additional new rate
const existingFormData2 = latestFormData(existingRate2)
const secondPackageInitialRateID =
existingFormData2.rateInfos[0]?.id || 'NO_ID'
expect(existingFormData2.rateInfos).toHaveLength(1)
await updateTestHealthPlanPackage(server, submittedNewRates.id, {
rateInfos: [
existingFormData2.rateInfos[0],
{
...initialRateInfos[0],
id: secondPackageInitialRateID, // this should be id from existing rate, using the id that is coming back in toDomain to imitate frontend
},
{
...initialRateInfos[0],
id: undefined, // this is a new rate
...initialRateInfos(),
id: uuidv4(), // this is a new rate
rateDateStart: new Date(Date.UTC(2030, 1, 1)),
rateDateEnd: new Date(Date.UTC(2030, 12, 1)),
},
Expand Down Expand Up @@ -274,10 +265,10 @@ describe.each(flagValueTestParameters)(
expect(latestFormData(newRatesPackage).rateInfos).toHaveLength(2)
expect(
latestFormData(newRatesPackage).rateInfos[0].rateDateStart
).toMatchObject(initialRateInfos[0].rateDateStart)
).toMatchObject(initialRateInfos().rateDateStart)
expect(
latestFormData(newRatesPackage).rateInfos[0].rateDateEnd
).toMatchObject(initialRateInfos[0].rateDateEnd)
).toMatchObject(initialRateInfos().rateDateEnd)
expect(
latestFormData(newRatesPackage).rateInfos[1].rateDateStart
).toMatchObject(new Date(Date.UTC(2030, 1, 1)))
Expand All @@ -294,21 +285,21 @@ describe.each(flagValueTestParameters)(
)
expect(
previousFormData(editedRatesPackage).rateInfos[0].rateDateStart
).toMatchObject(initialRateInfos[0].rateDateStart)
).toMatchObject(initialRateInfos().rateDateStart)
expect(
previousFormData(editedRatesPackage).rateInfos[0].rateDateEnd
).toMatchObject(initialRateInfos[0].rateDateEnd)
).toMatchObject(initialRateInfos().rateDateEnd)
expect(
editedRatesPackage.revisions[1].node.submitInfo?.updatedReason
).toBe('Initial submission')

expect(previousFormData(newRatesPackage).rateInfos).toHaveLength(1)
expect(
previousFormData(newRatesPackage).rateInfos[0].rateDateStart
).toMatchObject(initialRateInfos[0].rateDateStart)
).toMatchObject(initialRateInfos().rateDateStart)
expect(
previousFormData(newRatesPackage).rateInfos[0].rateDateEnd
).toMatchObject(initialRateInfos[0].rateDateEnd)
).toMatchObject(initialRateInfos().rateDateEnd)
expect(
newRatesPackage.revisions[1].node.submitInfo?.updatedReason
).toBe('Initial submission')
Expand Down

0 comments on commit fd1b9c5

Please sign in to comment.