Skip to content

Commit

Permalink
Fix some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLin0991 committed Aug 23, 2023
1 parent b00f827 commit 73c231d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,14 @@ describe.each(flagValueTestParameters)(
})

it('errors if the id doesnt match the db', async () => {
// id is wrong
// createdAt is wrong? or just overwrite
//

const server = await constructTestPostgresServer({
ldService: mockLDService,
})
const createdDraft = await createTestHealthPlanPackage(server)

const formData = latestFormData(createdDraft)

formData.id = uuidv4()
formData.updatedAt = new Date(Date.UTC(2025, 5, 1))

const b64 = domainToBase64(formData)

Expand All @@ -375,9 +371,12 @@ describe.each(flagValueTestParameters)(
expect(updateResult.errors[0].extensions?.code).toBe(
'BAD_USER_INPUT'
)
expect(updateResult.errors[0].message).toBe(
'Transient server error: attempted to modify un-modifiable field(s): id. Please refresh the page to continue.'
)

const expectedErrorMsg = flagValue
? 'Transient server error: Concurrent editing occurred. Please refresh the page to continue.'
: 'Transient server error: attempted to modify un-modifiable field(s): updatedAt. Please refresh the page to continue.'

expect(updateResult.errors[0].message).toBe(expectedErrorMsg)
})

it('errors if the other payload values dont match the db', async () => {
Expand Down Expand Up @@ -413,9 +412,12 @@ describe.each(flagValueTestParameters)(
expect(updateResult.errors[0].extensions?.code).toBe(
'BAD_USER_INPUT'
)
expect(updateResult.errors[0].message).toBe(
'Transient server error: attempted to modify un-modifiable field(s): stateCode,stateNumber,createdAt,updatedAt. Please refresh the page to continue.'
)

const expectedErrorMsg = flagValue
? 'Transient server error: Concurrent editing occurred. Please refresh the page to continue.'
: 'Transient server error: attempted to modify un-modifiable field(s): stateCode,stateNumber,createdAt,updatedAt. Please refresh the page to continue.'

expect(updateResult.errors[0].message).toBe(expectedErrorMsg)
})

it('errors if the update call to the db fails', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ export function updateHealthPlanFormDataResolver(

// If updatedAt does not match concurrent editing occurred.
if (
contractWithHistory.draftRevision.updatedAt !==
unlockedFormData.updatedAt
contractWithHistory.draftRevision.updatedAt.getTime() !==
unlockedFormData.updatedAt.getTime()
) {
const errMessage = `Transient server error: Concurrent editing occurred. Please refresh the page to continue.`
logError('updateHealthPlanFormData', errMessage)
Expand Down

0 comments on commit 73c231d

Please sign in to comment.