Skip to content

Commit

Permalink
the disappoiting children
Browse files Browse the repository at this point in the history
  • Loading branch information
horatiorosa committed Jul 29, 2024
1 parent 522d2c0 commit 43ce5de
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
33 changes: 33 additions & 0 deletions src/capital-project/capital-project.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CapitalProjectRepository } from "./capital-project.repository";
import {
findCapitalCommitmentsByManagingCodeCapitalProjectIdQueryResponseSchema,
findCapitalProjectByManagingCodeCapitalProjectIdQueryResponseSchema,
findCapitalProjectGeoJsonByManagingCodeCapitalProjectIdQueryResponseSchema,
findCapitalProjectTilesQueryResponseSchema,
} from "src/gen";
import { ResourceNotFoundException } from "src/exception";
Expand Down Expand Up @@ -58,6 +59,38 @@ describe("CapitalProjectService", () => {
});
});

describe.only("findGeoJsonByManagingCodeCapitalProjectId", () => {
it("should return a capital project geojson with a valid request", async () => {
const capitalProjectGeoJsonMock =
capitalProjectRepository
.findGeoJsonByManagingCodeCapitalProjectIdMock[0];
const { managingCode, id: capitalProjectId } = capitalProjectGeoJsonMock;
const capitalProjectGeoJson =
await capitalProjectService.findGeoJsonByManagingCodeCapitalProjectId({
managingCode,
capitalProjectId,
});

expect(() =>
findCapitalProjectGeoJsonByManagingCodeCapitalProjectIdQueryResponseSchema.parse(
capitalProjectGeoJson,
),
).not.toThrow();
});

it("should throw a resource error when requesting a missing project", async () => {
const missingManagingCode = "890";
const missingCapitalProjectId = "ABCD";

expect(
capitalProjectService.findGeoJsonByManagingCodeCapitalProjectId({
managingCode: missingManagingCode,
capitalProjectId: missingCapitalProjectId,
}),
).rejects.toThrow(ResourceNotFoundException);
});
});

describe("findTiles", () => {
it("should return an mvt when requesting coordinates", async () => {
const mvt = await capitalProjectService.findTiles({
Expand Down
18 changes: 10 additions & 8 deletions src/capital-project/capital-project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export class CapitalProjectService {
async findGeoJsonByManagingCodeCapitalProjectId(
params: FindCapitalProjectGeoJsonByManagingCodeCapitalProjectIdPathParams,
) {
const capitalProjectCheck =
await this.capitalProjectRepository.checkByManagingCodeCapitalProjectId(
params.managingCode,
params.capitalProjectId,
);
if (capitalProjectCheck === undefined)
throw new ResourceNotFoundException();
// const capitalProjectCheck =
// await this.capitalProjectRepository.checkByManagingCodeCapitalProjectId(
// params.managingCode,
// params.capitalProjectId,
// );
// if (capitalProjectCheck === undefined)
// throw new ResourceNotFoundException();

const capitalProjects =
await this.capitalProjectRepository.findGeoJsonByManagingCodeCapitalProjectId(
Expand All @@ -50,6 +50,8 @@ export class CapitalProjectService {
if (capitalProjects.length < 1) throw new ResourceNotFoundException();

const capitalProject = capitalProjects[0];
// console.debug(`capitalProject`, capitalProject);
console.debug(`capitalProject Geo`, capitalProject.geometry);
const geometry =
capitalProject.geometry === null
? null
Expand All @@ -63,7 +65,7 @@ export class CapitalProjectService {
) as CapitalProjectBudgetedEntity;

return {
id: `${properties.managingCode}${properties.id}`,
id: `${capitalProject.managingCode}${capitalProject.id}`,
type: "Feature",
properties,
geometry,
Expand Down
17 changes: 9 additions & 8 deletions test/capital-project/capital-project.repository.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export class CapitalProjectRepositoryMock {
);
}

// findGeoJsonByManagingCodeCapitalProjectIdMock = Array.from(
// Array(1),
// (_, seed) =>
// generateMock(findGeoJsonByManagingCodeCapitalProjectIdRepoSchema, {
// seed: seed + 1,
// }),
// );

findGeoJsonByManagingCodeCapitalProjectIdMock = generateMock(
findGeoJsonByManagingCodeCapitalProjectIdRepoSchema,
{
Expand All @@ -99,20 +107,13 @@ export class CapitalProjectRepositoryMock {
managingCode,
capitalProjectId,
}: FindCapitalProjectGeoJsonByManagingCodeCapitalProjectIdPathParams): Promise<FindGeoJsonByManagingCodeCapitalProjectIdRepo> {
// const compositeKey = `${managingCode}${capitalProjectId}`;
// const results = this.findGeoJsonByManagingCodeCapitalProjectIdMock.find(
// (capitalProjectsGeoJson) => compositeKey in capitalProjectsGeoJson,
// );

// return results === undefined ? [] : results[compositeKey];

const results = this.findGeoJsonByManagingCodeCapitalProjectIdMock.filter(
(capitalProjectGeoJson) =>
capitalProjectGeoJson.id === capitalProjectId &&
capitalProjectGeoJson.managingCode === managingCode,
);

console.debug(`results`, results);
// console.debug(`results`, results);
return results === undefined ? [] : results;
}

Expand Down

0 comments on commit 43ce5de

Please sign in to comment.