Skip to content

Commit

Permalink
MCR-4826: add round number to Question object (#3092)
Browse files Browse the repository at this point in the history
* add round number to Question object

* move add round number logic to resolver chain

* fix mocks

* Add resolver test, clean up resolver

* remove change to domain model
  • Loading branch information
pearl-truss authored Jan 23, 2025
1 parent eb30891 commit 7d265a2
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/mocks/src/apollo/contractPackageDataMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ function mockContractPackageSubmittedWithQuestions(
__typename: 'ContractQuestion' as const,
id: 'dmco-question-1-id',
contractID,
round: 1,
createdAt: new Date('2022-12-16'),
addedBy: mockValidCMSUser({
divisionAssignment: null,
Expand Down Expand Up @@ -549,6 +550,7 @@ function mockContractPackageSubmittedWithQuestions(
contractID,
createdAt: new Date('2022-12-18'),
addedBy: mockValidCMSUser() as CmsUser,
round: 1,
documents: [
{
s3URL: 's3://bucketname/key/dmco-question-2-document-1',
Expand Down Expand Up @@ -577,6 +579,7 @@ function mockContractPackageSubmittedWithQuestions(
id: 'dmcp-question-1-id',
contractID,
createdAt: new Date('2022-12-15'),
round: 1,
addedBy: mockValidCMSUser({
divisionAssignment: 'DMCP',
}) as CmsUser,
Expand Down Expand Up @@ -618,6 +621,7 @@ function mockContractPackageSubmittedWithQuestions(
id: 'oact-question-1-id',
contractID,
createdAt: new Date('2022-12-14'),
round: 1,
addedBy: mockValidCMSUser({
divisionAssignment: 'OACT',
}) as CmsUser,
Expand Down Expand Up @@ -657,6 +661,7 @@ function mockContractPackageSubmittedWithQuestions(
addedBy: mockValidCMSUser({
divisionAssignment: 'OACT',
}) as CmsUser,
round: 2,
documents: [
{
s3URL: 's3://bucketname/key/oact-question-1-document-1',
Expand Down Expand Up @@ -1509,6 +1514,7 @@ function mockContractPackageApprovedWithQuestions(
addedBy: mockValidCMSUser({
divisionAssignment: null,
}) as CmsUser,
round: 1,
documents: [
{
s3URL: 's3://bucketname/key/dmco-question-1-document-1',
Expand Down Expand Up @@ -1543,6 +1549,7 @@ function mockContractPackageApprovedWithQuestions(
contractID,
createdAt: new Date('2022-12-18'),
addedBy: mockValidCMSUser() as CmsUser,
round: 2,
documents: [
{
s3URL: 's3://bucketname/key/dmco-question-2-document-1',
Expand Down Expand Up @@ -1571,6 +1578,7 @@ function mockContractPackageApprovedWithQuestions(
id: 'dmcp-question-1-id',
contractID,
createdAt: new Date('2022-12-15'),
round: 1,
addedBy: mockValidCMSUser({
divisionAssignment: 'DMCP',
}) as CmsUser,
Expand Down Expand Up @@ -1615,6 +1623,7 @@ function mockContractPackageApprovedWithQuestions(
addedBy: mockValidCMSUser({
divisionAssignment: 'OACT',
}) as CmsUser,
round: 1,
documents: [
{
s3URL: 's3://bucketname/key/oact-question-1-document-1',
Expand Down Expand Up @@ -1648,6 +1657,7 @@ function mockContractPackageApprovedWithQuestions(
id: 'oact-question-2-id',
contractID: 'test-abc-123',
createdAt: new Date('2022-12-17'),
round: 2,
addedBy: mockValidCMSUser({
divisionAssignment: 'OACT',
}) as CmsUser,
Expand Down
4 changes: 4 additions & 0 deletions packages/mocks/src/apollo/questionResponseDataMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function mockQuestionsPayload(
downloadURL: expect.any(String),
},
],
round: 1,
division: 'DMCO',
responses: [
{
Expand Down Expand Up @@ -56,6 +57,7 @@ function mockQuestionsPayload(
contractID,
createdAt: new Date('2022-12-18'),
addedBy: mockValidCMSUser() as CmsUser,
round: 1,
documents: [
{
s3URL: 's3://bucketname/key/dmco-question-2-document-1',
Expand Down Expand Up @@ -110,6 +112,7 @@ function mockQuestionsPayload(
},
],
division: 'DMCP',
round: 1,
responses: [
{
__typename: 'QuestionResponse' as const,
Expand Down Expand Up @@ -143,6 +146,7 @@ function mockQuestionsPayload(
addedBy: mockValidCMSUser({
divisionAssignment: 'OACT',
}) as CmsUser,
round: 1,
documents: [
{
s3URL: 's3://bucketname/key/oact-question-1-document-1',
Expand Down
2 changes: 2 additions & 0 deletions services/app-api/src/resolvers/configureResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
questionResponseDocumentResolver,
createRateQuestionResolver,
createRateQuestionResponseResolver,
questionResolver,
} from './questionResponse'
import {
fetchCurrentUserResolver,
Expand Down Expand Up @@ -171,6 +172,7 @@ export function configureResolvers(
Rate: rateResolver(store, applicationEndpoint),
RateRevision: rateRevisionResolver(store),
RateFormData: rateFormDataResolver(),
ContractQuestion: questionResolver(store),
Contract: contractResolver(store, applicationEndpoint),
UnlockedContract: unlockedContractResolver(store, applicationEndpoint),
ContractRevision: contractRevisionResolver(store),
Expand Down
1 change: 1 addition & 0 deletions services/app-api/src/resolvers/questionResponse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { createContractQuestionResponseResolver } from './createContractQuestion
export { questionResponseDocumentResolver } from './questionResponseDocumentResolver'
export { createRateQuestionResolver } from './createRateQuestion'
export { createRateQuestionResponseResolver } from './createRateQuestionResponse'
export { questionResolver } from './questionResolver'
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
constructTestPostgresServer,
createTestQuestion,
} from '../../testHelpers/gqlHelpers'
import {
testCMSUser,
createDBUsersWithFullData,
} from '../../testHelpers/userHelpers'
import { testS3Client } from '../../testHelpers/s3Helpers'
import {
createAndSubmitTestContract,
fetchTestContractWithQuestions,
} from '../../testHelpers'

describe(`questionResolver`, () => {
const mockS3 = testS3Client()
const dmcpCMSUser = testCMSUser({
divisionAssignment: 'DMCP',
})

beforeAll(async () => {
//Inserting a new CMS user, with division assigned, in postgres in order to create the question to user relationship.
await createDBUsersWithFullData([dmcpCMSUser])
})

it('populates a round number on fetch', async () => {
const stateServer = await constructTestPostgresServer()

const dmcpCMSServer = await constructTestPostgresServer({
context: {
user: dmcpCMSUser,
},
s3Client: mockS3,
})

const contract = await createAndSubmitTestContract(stateServer)

const createdDMCPQuestion = await createTestQuestion(
dmcpCMSServer,
contract.id,
{
documents: [
{
name: 'Test Question 2',
s3URL: 's3://bucketname/key/test12',
},
],
}
)

const createdDMCPQuestion2 = await createTestQuestion(
dmcpCMSServer,
contract.id,
{
documents: [
{
name: 'Test Question 2',
s3URL: 's3://bucketname/key/test12',
},
],
}
)

const contractWithQuestions = await fetchTestContractWithQuestions(
stateServer,
contract.id
)
const indexQuestionsResult = contractWithQuestions.questions
const firstDMCPQuestion =
indexQuestionsResult?.DMCPQuestions.edges.find(
(q) => q.node.id === createdDMCPQuestion.question.id
)
const secondDMCPQuestion =
indexQuestionsResult?.DMCPQuestions.edges.find(
(q) => q.node.id === createdDMCPQuestion2.question.id
)
expect(firstDMCPQuestion?.node.round).toBe(1)
expect(secondDMCPQuestion?.node.round).toBe(2)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { Resolvers } from '../../gen/gqlServer'

import type { ContractQuestionType } from '../../domain-models'
import type { Store } from '../../postgres'
import { GraphQLError } from 'graphql'

export function questionResolver(store: Store): Resolvers['QuestionResolver'] {
return {
round: async (parent: ContractQuestionType) => {
const questions = await store.findAllQuestionsByContract(
parent.contractID
)
if (!questions) {
throw new Error(
`Questions not found for contract: ${parent.contractID}`
)
}
if (questions instanceof Error) {
const errMessage = `Issue return questions for contract message: ${questions.message}`

throw new GraphQLError(errMessage, {
extensions: {
code: 'INTERNAL_SERVER_ERROR',
cause: 'DB_ERROR',
},
})
}

const divisionQuestions = questions
.filter((q) => q.division === parent.division)
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime())

const matchingQuestion = divisionQuestions.find(
(question) => question.id == parent.id
)

if (!matchingQuestion) {
return 0
} else {
return divisionQuestions.indexOf(matchingQuestion) !== undefined
? divisionQuestions.indexOf(matchingQuestion) + 1
: 0
}
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fragment contractQuestionEdgeFragment on ContractQuestionEdge {
}
}
division
round
documents {
s3URL
name
Expand Down
1 change: 1 addition & 0 deletions services/app-graphql/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ type ContractQuestion {
addedBy: CMSUsersUnion!
documents: [Document!]!
division: Division!
round: Int!
# noteText: String
# dueDate: Date
# rateIDs: [String!]
Expand Down

0 comments on commit 7d265a2

Please sign in to comment.