Skip to content

Commit

Permalink
the mock don't mock
Browse files Browse the repository at this point in the history
  • Loading branch information
horatiorosa committed Jul 9, 2024
1 parent 7e9a840 commit c65cf5d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 12 deletions.
4 changes: 2 additions & 2 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -868,7 +868,7 @@ components:
example: ["Highways", "Highway Bridges"]
required:
- commitmentsTotal
- sponsoringAgency
- sponsoringAgencies
- budgetTypes
CityCouncilDistrict:
type: object
Expand Down
2 changes: 1 addition & 1 deletion src/capital-project/capital-project.repository.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/capital-project/capital-project.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CapitalProjectRepository {
minDate: capitalProject.minDate,
maxDate: capitalProject.maxDate,
category: capitalProject.category,
sponsoringAgency: sql<
sponsoringAgencies: sql<
Array<string>
>`ARRAY_AGG(DISTINCT ${agencyBudget.sponsor})`,
budgetTypes: sql<
Expand Down
4 changes: 2 additions & 2 deletions src/gen/schemas/CapitalProjectBudgeted.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -81,7 +81,7 @@
"example": ["Highways", "Highway Bridges"]
}
},
"required": ["commitmentsTotal", "sponsoringAgency", "budgetTypes"]
"required": ["commitmentsTotal", "sponsoringAgencies", "budgetTypes"]
}
],
"x-readme-ref-name": "CapitalProjectBudgeted"
Expand Down
2 changes: 1 addition & 1 deletion src/gen/types/CapitalProjectBudgeted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gen/zod/capitalProjectBudgetedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
16 changes: 16 additions & 0 deletions test/capital-project/capital-project.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
41 changes: 37 additions & 4 deletions test/capital-project/capital-project.repository.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -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,
Expand Down Expand Up @@ -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<FindCapitalCommitmentsByManagingCodeCapitalProjectIdRepo> {
return this.findCapitalCommitmentsByManagingCodeCapitalProjectIdMocks.filter(
return this.findCapitalCommitmentsByManagingCodeCapitalProjectIdMocksTWO.filter(
(capitalCommitments) =>
capitalCommitments.id === capitalProjectId &&
capitalCommitment.managingCode === managingCode,
capitalCommitments. === managingCode,
);
}
}

0 comments on commit c65cf5d

Please sign in to comment.