Skip to content

Commit

Permalink
feat: add screens to choose kind of express urban project
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhenin committed Oct 30, 2024
1 parent c232a9f commit 3f2658f
Show file tree
Hide file tree
Showing 28 changed files with 565 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,82 @@ describe("ReconversionProjects controller", () => {
});
});

describe("POST /create-from-site", () => {
const siteId = "f590f643-cd9a-4187-8973-f90e9f1998c8";
beforeEach(async () => {
await sqlConnection("sites").insert({
id: siteId,
name: "Site name",
surface_area: 14000,
is_friche: false,
owner_structure_type: "company",
created_at: new Date(),
});
await sqlConnection("addresses").insert({
id: "e869d8db-3d63-4fd5-93ab-7728c1c19a1e",
ban_id: "e869d8db-3d63-4fd5-93ab-7728c1c19a1e",
value: "Grenoble",
city: "Grenoble",
city_code: "38100",
post_code: "38000",
site_id: siteId,
});
});

it("can't create a reconversion project without category", async () => {
const response = await supertest(app.getHttpServer())
.post("/reconversion-projects/create-from-site")
.send({
reconversionProjectId: "64789135-afad-46ea-97a2-f14ba460d485",
createdBy: "612d16c7-b6e4-4e2c-88a8-0512cc51946c",
siteId: siteId,
});

expect(response.status).toEqual(400);
expect(response.body).toHaveProperty("errors");

const responseErrors = (response.body as BadRequestResponseBody).errors;
expect(responseErrors).toHaveLength(1);
expect(responseErrors[0]?.path).toContain("category");
});

it.each([
"PUBLIC_FACILITIES",
"RESIDENTIAL_TENSE_AREA",
"RESIDENTIAL_NORMAL_AREA",
"NEW_URBAN_CENTER",
])(
"get a 201 response and reconversion project is created with category %s",
async (category) => {
const requestBody = {
reconversionProjectId: "64789135-afad-46ea-97a2-f14ba460d485",
createdBy: "612d16c7-b6e4-4e2c-88a8-0512cc51946c",
siteId: siteId,
category,
};

const response = await supertest(app.getHttpServer())
.post("/reconversion-projects/create-from-site")
.send(requestBody);
expect(response.status).toEqual(201);

const reconversionProjectsInDb = await sqlConnection("reconversion_projects").select(
"id",
"created_by",
"related_site_id",
"creation_mode",
);
expect(reconversionProjectsInDb.length).toEqual(1);
expect(reconversionProjectsInDb[0]).toEqual({
id: requestBody.reconversionProjectId,
created_by: requestBody.createdBy,
related_site_id: requestBody.siteId,
creation_mode: "express",
});
},
);
});

describe("GET /reconversion-projects/list-by-site", () => {
it("gets a 400 response when no userId provided", async () => {
const response = await supertest(app.getHttpServer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class CreateExpressReconversionProjectBodyDto extends createZodDto(
reconversionProjectId: z.string(),
siteId: z.string(),
createdBy: z.string(),
category: z.enum([
"PUBLIC_FACILITIES",
"RESIDENTIAL_TENSE_AREA",
"RESIDENTIAL_NORMAL_AREA",
"NEW_URBAN_CENTER",
]),
}),
) {}

Expand Down Expand Up @@ -76,7 +82,7 @@ export class ReconversionProjectController {
async createExpressReconversionProject(
@Body() createReconversionProjectDto: CreateExpressReconversionProjectBodyDto,
) {
await this.createExpressReconversionProjectUseCase.execute(createReconversionProjectDto);
return await this.createExpressReconversionProjectUseCase.execute(createReconversionProjectDto);
}

@Get("list-by-site")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const RESALE_RATIO_PER_SQUARE_METERS = {
};

export class NewUrbanCenterProjectExpressCreationService extends UrbanProjectExpressCreationService {
override name = "Nouvelle centralité";
override name = "Centralité urbaine";

override get spacesDistribution() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { roundTo2Digits } from "shared";
import { UrbanProjectExpressCreationService } from "./UrbanProjectExpressCreationService";

export class ResidentialProjectExpressCreationService extends UrbanProjectExpressCreationService {
override name = "Résidentiel zone détendue";
override name = "Résidentiel secteur détendu";

override get spacesDistribution() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { UrbanProjectExpressCreationService } from "./UrbanProjectExpressCreationService";

export class ResidentialTenseAreaProjectExpressCreationService extends UrbanProjectExpressCreationService {
override name = "Résidentiel zone tendue";
override name = "Résidentiel secteur tendu";

override get spacesDistribution() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ describe("CreateReconversionProject Use Case", () => {

let expectedName = "";
if (expressCategory === "NEW_URBAN_CENTER") {
expectedName = "Nouvelle centralité";
expectedName = "Centralité urbaine";
} else if (expressCategory === "PUBLIC_FACILITIES") {
expectedName = "Équipement public";
} else if (expressCategory === "RESIDENTIAL_TENSE_AREA") {
expectedName = "Résidentiel zone tendue";
expectedName = "Résidentiel secteur tendu";
} else {
expectedName = "Résidentiel zone détendue";
expectedName = "Résidentiel secteur détendu";
}

const createdReconversionProjects: ReconversionProject[] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { z } from "zod";
import { UseCase } from "src/shared-kernel/usecase";
import { Address } from "src/sites/core/models/site";

import { MixedUseNeighbourhoodProjectExpressCreationService } from "../model/create-from-site-services/MixedUseNeighbourhoodProjectExpressCreationService";
import { NewUrbanCenterProjectExpressCreationService } from "../model/create-from-site-services/NewUrbanCenterProjectExpressCreationService";
import { PublicFacilitiesProjectExpressCreationService } from "../model/create-from-site-services/PublicFacilitiesProjectExpressCreationService";
import { ResidentialProjectExpressCreationService } from "../model/create-from-site-services/ResidentialProjectExpressCreationService";
Expand Down Expand Up @@ -50,6 +49,11 @@ type Request = {
| "NEW_URBAN_CENTER";
};

type Response = {
id: string;
name: string;
};

const getCreationServiceClass = (category: Request["category"]) => {
switch (category) {
case "NEW_URBAN_CENTER":
Expand All @@ -61,18 +65,18 @@ const getCreationServiceClass = (category: Request["category"]) => {
case "PUBLIC_FACILITIES":
return PublicFacilitiesProjectExpressCreationService;
default:
return MixedUseNeighbourhoodProjectExpressCreationService;
return ResidentialProjectExpressCreationService;
}
};

export class CreateExpressReconversionProjectUseCase implements UseCase<Request, void> {
export class CreateExpressReconversionProjectUseCase implements UseCase<Request, Response> {
constructor(
private readonly dateProvider: DateProvider,
private readonly siteQuery: SiteQuery,
private readonly reconversionProjectRepository: ReconversionProjectRepository,
) {}

async execute(props: Request): Promise<void> {
async execute(props: Request): Promise<Response> {
const siteData = await this.siteQuery.getById(props.siteId);
if (!siteData) {
throw new Error(`Site with id ${props.siteId} does not exist`);
Expand All @@ -89,5 +93,7 @@ export class CreateExpressReconversionProjectUseCase implements UseCase<Request,
const reconversionProject = creationService.getReconversionProject();

await this.reconversionProjectRepository.save(reconversionProject);

return { id: reconversionProject.id, name: reconversionProject.name };
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3f2658f

Please sign in to comment.