Skip to content
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

MCR-4826: add round number to Question object #3092

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/mocks/src/apollo/contractPackageDataMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,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 @@ -548,6 +549,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 @@ -576,6 +578,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 @@ -617,6 +620,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 @@ -656,6 +660,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 @@ -1508,6 +1513,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 @@ -1542,6 +1548,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 @@ -1570,6 +1577,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 @@ -1614,6 +1622,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 @@ -1647,6 +1656,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
Loading