-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MR-3186: migrate indexhpp resolver #1890
Merged
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
18f3a52
find all contracts function
JasonLin0991 d30e60b
Add new function to postgresStore.ts and add LD to resolver.
JasonLin0991 3ced644
Add find all contracts by submittedAt.
JasonLin0991 dd3e021
Rename function.
JasonLin0991 421fc8f
Test for find contracts by submit info.
JasonLin0991 0933f3d
Update and add find all contracts functions.
JasonLin0991 d7c3b36
Add find contracts functions to index resolver.
JasonLin0991 91a2bca
Merge remote-tracking branch 'origin/main' into jl-mr-3186-migrate-in…
JasonLin0991 e583b57
Add find contracts for CMS, Admin and help desk users. Update error m…
JasonLin0991 f1ee9ac
Fix tests from merge.
JasonLin0991 e8ddfdc
Add todo test for unlock and submit resolver migration.
JasonLin0991 d343e49
Test for filtering and logging errors.
JasonLin0991 2ee3045
Fix test name.
JasonLin0991 7b4f930
Merge branch 'main' into jl-mr-3186-migrate-indexhpp
JasonLin0991 1992b1b
Fix programs in test data.
JasonLin0991 5a52265
Update test name.
JasonLin0991 d261287
Move state helpers to stateHelpers.ts
JasonLin0991 c80cb6e
Move validateContractsAndConvert to helper file.
JasonLin0991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
services/app-api/src/postgres/contractAndRates/findAllContractsWithHistoryByState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { PrismaTransactionType } from '../prismaTypes' | ||
import type { ContractType } from '../../domain-models/contractAndRates' | ||
import { NotFoundError } from '../storeError' | ||
import { parseContractWithHistory } from './parseContractWithHistory' | ||
import { includeFullContract } from './prismaSubmittedContractHelpers' | ||
|
||
type ContractOrErrorType = { | ||
contractID: string | ||
contract: ContractType | Error | ||
} | ||
|
||
type ContractOrErrorArrayType = ContractOrErrorType[] | ||
|
||
async function findAllContractsWithHistoryByState( | ||
client: PrismaTransactionType, | ||
stateCode: string | ||
): Promise<ContractOrErrorArrayType | NotFoundError | Error> { | ||
try { | ||
const contracts = await client.contractTable.findMany({ | ||
where: { | ||
stateCode: { | ||
equals: stateCode, | ||
}, | ||
}, | ||
include: includeFullContract, | ||
}) | ||
|
||
if (!contracts) { | ||
const err = `PRISMA ERROR: Cannot find contracts with state code: ${stateCode}` | ||
console.error(err) | ||
return new NotFoundError(err) | ||
} | ||
|
||
const parsedContractsOrErrors: ContractOrErrorArrayType = contracts.map( | ||
(contract) => ({ | ||
contractID: contract.id, | ||
contract: parseContractWithHistory(contract), | ||
}) | ||
) | ||
|
||
return parsedContractsOrErrors | ||
} catch (err) { | ||
console.error('PRISMA ERROR', err) | ||
return err | ||
} | ||
} | ||
|
||
export { findAllContractsWithHistoryByState } | ||
export type { ContractOrErrorArrayType } |
128 changes: 128 additions & 0 deletions
128
...ces/app-api/src/postgres/contractAndRates/findAllContractsWithHistoryBySubmitInfo.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { findAllContractsWithHistoryBySubmitInfo } from './findAllContractsWithHistoryBySubmitInfo' | ||
import { sharedTestPrismaClient } from '../../testHelpers/storeHelpers' | ||
import { createInsertContractData, must } from '../../testHelpers' | ||
import { v4 as uuidv4 } from 'uuid' | ||
import { insertDraftContract } from './insertContract' | ||
import { submitContract } from './submitContract' | ||
import { unlockContract } from './unlockContract' | ||
|
||
describe('findAllContractsWithHistoryBySubmittedInfo', () => { | ||
it('returns only contracts that have been submitted or unlocked', async () => { | ||
const client = await sharedTestPrismaClient() | ||
const stateUser = await client.user.create({ | ||
data: { | ||
id: uuidv4(), | ||
givenName: 'Aang', | ||
familyName: 'Avatar', | ||
email: 'aang@example.com', | ||
role: 'STATE_USER', | ||
stateCode: 'NM', | ||
}, | ||
}) | ||
|
||
const cmsUser = await client.user.create({ | ||
data: { | ||
id: uuidv4(), | ||
givenName: 'Zuko', | ||
familyName: 'Hotman', | ||
email: 'zuko@example.com', | ||
role: 'CMS_USER', | ||
}, | ||
}) | ||
|
||
const draftContractData = createInsertContractData({ | ||
submissionDescription: 'one contract', | ||
}) | ||
|
||
// make two submitted contracts and submit them | ||
const contractOne = must( | ||
await insertDraftContract(client, draftContractData) | ||
) | ||
const contractTwo = must( | ||
await insertDraftContract(client, draftContractData) | ||
) | ||
const submittedContractOne = must( | ||
await submitContract( | ||
client, | ||
contractOne.id, | ||
stateUser.id, | ||
'contractOne submit' | ||
) | ||
) | ||
const submittedContractTwo = must( | ||
await submitContract( | ||
client, | ||
contractTwo.id, | ||
stateUser.id, | ||
'contractTwo submit' | ||
) | ||
) | ||
|
||
// make two draft contracts | ||
const draftContractOne = must( | ||
await insertDraftContract(client, draftContractData) | ||
) | ||
const draftContractTwo = must( | ||
await insertDraftContract(client, draftContractData) | ||
) | ||
|
||
// make one unlocked contract | ||
const contractThree = must( | ||
await insertDraftContract(client, draftContractData) | ||
) | ||
must( | ||
await submitContract( | ||
client, | ||
contractThree.id, | ||
stateUser.id, | ||
'unlockContractOne submit' | ||
) | ||
) | ||
const unlockedContract = must( | ||
await unlockContract( | ||
client, | ||
contractThree.id, | ||
cmsUser.id, | ||
'unlock unlockContractOne' | ||
) | ||
) | ||
|
||
// call the find by submit info function | ||
const contracts = must( | ||
await findAllContractsWithHistoryBySubmitInfo(client) | ||
) | ||
|
||
// expect our two submitted contracts | ||
expect(contracts).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
contractID: submittedContractOne.id, | ||
}), | ||
expect.objectContaining({ | ||
contractID: submittedContractTwo.id, | ||
}), | ||
]) | ||
) | ||
|
||
// expect our one unlocked contract | ||
expect(contracts).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
contractID: unlockedContract.id, | ||
}), | ||
]) | ||
) | ||
|
||
// expect our two draft contracts to not be in the results | ||
expect(contracts).not.toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
contractID: draftContractOne.id, | ||
}), | ||
expect.objectContaining({ | ||
contractID: draftContractTwo.id, | ||
}), | ||
]) | ||
) | ||
}) | ||
}) |
47 changes: 47 additions & 0 deletions
47
services/app-api/src/postgres/contractAndRates/findAllContractsWithHistoryBySubmitInfo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { PrismaTransactionType } from '../prismaTypes' | ||
import { NotFoundError } from '../storeError' | ||
import { parseContractWithHistory } from './parseContractWithHistory' | ||
import { includeFullContract } from './prismaSubmittedContractHelpers' | ||
import type { ContractOrErrorArrayType } from './findAllContractsWithHistoryByState' | ||
|
||
async function findAllContractsWithHistoryBySubmitInfo( | ||
client: PrismaTransactionType | ||
): Promise<ContractOrErrorArrayType | NotFoundError | Error> { | ||
try { | ||
const contracts = await client.contractTable.findMany({ | ||
where: { | ||
revisions: { | ||
some: { | ||
submitInfo: { | ||
isNot: null, | ||
}, | ||
}, | ||
}, | ||
stateCode: { | ||
not: 'AS', // exclude test state as per ADR 019 | ||
}, | ||
}, | ||
include: includeFullContract, | ||
}) | ||
|
||
if (!contracts) { | ||
const err = `PRISMA ERROR: Cannot find all contracts by submit info` | ||
console.error(err) | ||
return new NotFoundError(err) | ||
} | ||
|
||
const parsedContracts: ContractOrErrorArrayType = contracts.map( | ||
(contract) => ({ | ||
contractID: contract.id, | ||
contract: parseContractWithHistory(contract), | ||
}) | ||
) | ||
|
||
return parsedContracts | ||
} catch (err) { | ||
console.error('PRISMA ERROR', err) | ||
return err | ||
} | ||
} | ||
|
||
export { findAllContractsWithHistoryBySubmitInfo } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export type { InsertContractArgsType } from './insertContract' | ||
export type { UpdateContractArgsType } from './updateDraftContract' | ||
export type { ContractOrErrorArrayType } from './findAllContractsWithHistoryByState' | ||
export { insertDraftContract } from './insertContract' | ||
export { findContractWithHistory } from './findContractWithHistory' | ||
export { updateDraftContract } from './updateDraftContract' | ||
export { findAllContractsWithHistoryByState } from './findAllContractsWithHistoryByState' | ||
export { findAllContractsWithHistoryBySubmitInfo } from './findAllContractsWithHistoryBySubmitInfo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: file organization - this function takes parameter from the rates refactor (
ContractType
) whereas everything else in this file is about the domain model HPP and takes HPP related arguments. Should be separate file in domain models.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I could see this being in
domain-models/contractAndRates
in some file that contains all the converter functions we will have. I think though, I want to punt this to your ticket. I think you have to make converter functions for locked HPP. Maybe you could find a good home and name for this file.