From c65cf5d1543c2180866dcebaf57f252b1e4ebe4c Mon Sep 17 00:00:00 2001 From: horatio Date: Tue, 9 Jul 2024 11:29:45 -0400 Subject: [PATCH] the mock don't mock --- openapi/openapi.yaml | 4 +- .../capital-project.repository.schema.ts | 2 +- .../capital-project.repository.ts | 2 +- src/gen/schemas/CapitalProjectBudgeted.json | 4 +- src/gen/types/CapitalProjectBudgeted.ts | 2 +- src/gen/zod/capitalProjectBudgetedSchema.ts | 2 +- .../capital-project.e2e-spec.ts | 16 ++++++++ .../capital-project.repository.mock.ts | 41 +++++++++++++++++-- 8 files changed, 61 insertions(+), 12 deletions(-) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 44c7f42d..a2aad755 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -854,7 +854,7 @@ components: type: number description: The sum total of commitments for the capital project example: 200000 - sponsoringAgency: + sponsoringAgencies: type: array items: type: string @@ -868,7 +868,7 @@ components: example: ["Highways", "Highway Bridges"] required: - commitmentsTotal - - sponsoringAgency + - sponsoringAgencies - budgetTypes CityCouncilDistrict: type: object diff --git a/src/capital-project/capital-project.repository.schema.ts b/src/capital-project/capital-project.repository.schema.ts index 598e977b..1d1d9592 100644 --- a/src/capital-project/capital-project.repository.schema.ts +++ b/src/capital-project/capital-project.repository.schema.ts @@ -10,7 +10,7 @@ import { z } from "zod"; export const findByManagingCodeCapitalProjectIdRepoSchema = z.array( capitalProjectEntitySchema.extend({ - sponsoringAgency: z.array(agencyEntitySchema.shape.initials), + sponsoringAgencies: z.array(agencyEntitySchema.shape.initials), budgetTypes: z.array(agencyBudgetEntitySchema.shape.type), commitmentsTotal: capitalCommitmentFundEntitySchema.shape.value, }), diff --git a/src/capital-project/capital-project.repository.ts b/src/capital-project/capital-project.repository.ts index 95256d62..cb15ecd3 100644 --- a/src/capital-project/capital-project.repository.ts +++ b/src/capital-project/capital-project.repository.ts @@ -40,7 +40,7 @@ export class CapitalProjectRepository { minDate: capitalProject.minDate, maxDate: capitalProject.maxDate, category: capitalProject.category, - sponsoringAgency: sql< + sponsoringAgencies: sql< Array >`ARRAY_AGG(DISTINCT ${agencyBudget.sponsor})`, budgetTypes: sql< diff --git a/src/gen/schemas/CapitalProjectBudgeted.json b/src/gen/schemas/CapitalProjectBudgeted.json index 6a30014d..80292e04 100644 --- a/src/gen/schemas/CapitalProjectBudgeted.json +++ b/src/gen/schemas/CapitalProjectBudgeted.json @@ -68,7 +68,7 @@ "type": "number", "example": 200000 }, - "sponsoringAgency": { + "sponsoringAgencies": { "description": "An array containing string values representing the sponsoring agencies initials.", "type": "array", "items": { "type": "string" }, @@ -81,7 +81,7 @@ "example": ["Highways", "Highway Bridges"] } }, - "required": ["commitmentsTotal", "sponsoringAgency", "budgetTypes"] + "required": ["commitmentsTotal", "sponsoringAgencies", "budgetTypes"] } ], "x-readme-ref-name": "CapitalProjectBudgeted" diff --git a/src/gen/types/CapitalProjectBudgeted.ts b/src/gen/types/CapitalProjectBudgeted.ts index 3f479f40..f6aa0912 100644 --- a/src/gen/types/CapitalProjectBudgeted.ts +++ b/src/gen/types/CapitalProjectBudgeted.ts @@ -10,7 +10,7 @@ export type CapitalProjectBudgeted = CapitalProject & { * @description An array containing string values representing the sponsoring agencies initials. * @type array */ - sponsoringAgency: string[]; + sponsoringAgencies: string[]; /** * @description An array containing string values representing the budget types. * @type array diff --git a/src/gen/zod/capitalProjectBudgetedSchema.ts b/src/gen/zod/capitalProjectBudgetedSchema.ts index b2dabd50..5b393210 100644 --- a/src/gen/zod/capitalProjectBudgetedSchema.ts +++ b/src/gen/zod/capitalProjectBudgetedSchema.ts @@ -8,7 +8,7 @@ export const capitalProjectBudgetedSchema = z commitmentsTotal: z.coerce .number() .describe("The sum total of commitments for the capital project"), - sponsoringAgency: z + sponsoringAgencies: z .array(z.coerce.string()) .describe( "An array containing string values representing the sponsoring agencies initials.", diff --git a/test/capital-project/capital-project.e2e-spec.ts b/test/capital-project/capital-project.e2e-spec.ts index f5fcc044..01b2a741 100644 --- a/test/capital-project/capital-project.e2e-spec.ts +++ b/test/capital-project/capital-project.e2e-spec.ts @@ -145,4 +145,20 @@ describe("Capital Projects", () => { expect(response.body.error).toBe(HttpName.INTERNAL_SEVER_ERROR); }); }); + + describe("findCapitalCommitmentsByManagingCodeCapitalProjectId", () => { + it("should 200 and return a capital project with budget details", async () => { + const capitalProjectMock = + capitalProjectRepository.findCapitalCommitmentsByManagingCodeCapitalProjectId; + const { managingCode, id: capitalProjectId } = capitalProjectMock; + const response = await request(app.getHttpServer()) + .get(`/capital-projects/${managingCode}/${capitalProjectId}`) + .expect(200); + + expect(() => + findCapitalProjectByManagingCodeCapitalProjectIdQueryResponseSchema.parse( + response.body, + ), + ).not.toThrow(); + }); }); diff --git a/test/capital-project/capital-project.repository.mock.ts b/test/capital-project/capital-project.repository.mock.ts index d62fec50..95c803a6 100644 --- a/test/capital-project/capital-project.repository.mock.ts +++ b/test/capital-project/capital-project.repository.mock.ts @@ -10,8 +10,11 @@ import { FindCapitalCommitmentsByManagingCodeCapitalProjectIdPathParams, FindCapitalProjectByManagingCodeCapitalProjectIdPathParams, } from "src/gen"; -import { capitalCommitment } from "src/schema"; +import { capitalProject, managingCode } from "src/schema"; +// import { capitalCommitment } from "src/schema"; export class CapitalProjectRepositoryMock { + numberOfMocks = 1; + findByManagingCodeCapitalProjectIdMock = generateMock( findByManagingCodeCapitalProjectIdRepoSchema, { @@ -23,6 +26,21 @@ export class CapitalProjectRepositoryMock { }, ); + /* + capitalProjectMock { + managingCode: '158', + id: 'modi', + managingAgency: 'modi', + description: 'modi', + minDate: '2018-01-01', + maxDate: '2045-12-31', + category: 'Fixed Asset', + sponsoringAgencies: [ 'modi' ], + budgetTypes: [ 'modi' ], + commitmentsTotal: 1210245525274624 + } + */ + async findByManagingCodeCapitalProjectId({ managingCode, capitalProjectId, @@ -51,18 +69,33 @@ export class CapitalProjectRepositoryMock { return this.findTilesMock; } - findCapitalCommitmentsByManagingCodeCapitalProjectIdMocks = generateMock( + findCapitalCommitmentsByManagingCodeCapitalProjectIdMocks = + generateMock( findCapitalCommitmentsByManagingCodeCapitalProjectIdRepoSchema, ); + async findCapitalCommitmentsByManagingCodeCapitalProjectIdMocksTWO({ + managingCode, + capitalProjectId, + }: FindCapitalProjectByManagingCodeCapitalProjectIdPathParams) { + this.findByManagingCodeCapitalProjectIdMock.filter( + (capitalProject) => { + if (capitalProject.id === capitalProjectId && capitalProject.managingCode === managingCode) + return { + [`${managingCode}${capitalProjectId}`]: generateMock(findCapitalCommitmentsByManagingCodeCapitalProjectIdRepoSchema,) + } + } + ); + } + async findCapitalCommitmentsByManagingCodeCapitalProjectId({ managingCode, capitalProjectId, }: FindCapitalCommitmentsByManagingCodeCapitalProjectIdPathParams): Promise { - return this.findCapitalCommitmentsByManagingCodeCapitalProjectIdMocks.filter( + return this.findCapitalCommitmentsByManagingCodeCapitalProjectIdMocksTWO.filter( (capitalCommitments) => capitalCommitments.id === capitalProjectId && - capitalCommitment.managingCode === managingCode, + capitalCommitments. === managingCode, ); } }