Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,6 @@ describe("PortailUsagersProfileController", () => {
);
expect(controller).toBeDefined();
});

describe("GET /portail-usagers/profile/structure-information", () => {
it("should return structure information for authenticated usager", async () => {
const response = await supertest(context.app.getHttpServer())
.get("/portail-usagers/profile/structure-information")
.set("Authorization", `Bearer ${authToken}`)
.expect(HttpStatus.OK);

expect(response.body).toBeDefined();
expect(Array.isArray(response.body)).toBe(true);
});

it("should return 401 for unauthenticated request", async () => {
await supertest(context.app.getHttpServer())
.get("/portail-usagers/profile/structure-information")
.expect(HttpStatus.UNAUTHORIZED);
});

it("should return 401 for invalid token", async () => {
await supertest(context.app.getHttpServer())
.get("/portail-usagers/profile/structure-information")
.set("Authorization", "Bearer invalid-token")
.expect(HttpStatus.UNAUTHORIZED);
});
});

describe("GET /portail-usagers/profile/me", () => {
it("should return user profile for authenticated usager", async () => {
const response = await supertest(context.app.getHttpServer())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,74 @@
import { Test, TestingModule } from "@nestjs/testing";
import { HttpStatus } from "@nestjs/common";
import supertest from "supertest";

import { AuthModule } from "../../../../auth/auth.module";
import { AppTestContext, AppTestHelper } from "../../../../util/test";
import { TESTS_USERS_USAGER } from "../../../../_tests";
import { PortailUsagersModule } from "../../portail-usagers.module";
import { StructureInformationController } from "./structure-information.controller";

const PERMANENT_PASS_USER = TESTS_USERS_USAGER.ALL.find(
(x) => x.login === "LNQIFFBK"
);

describe("StructureInformationController", () => {
let controller: StructureInformationController;
let context: AppTestContext;
let authToken: string;

beforeAll(async () => {
context = await AppTestHelper.bootstrapTestApp(
{
controllers: [],
imports: [PortailUsagersModule, AuthModule],
providers: [],
},
{ initApp: true }
);

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [StructureInformationController],
}).compile();
// Login to get auth token for authenticated requests
const loginResponse = await supertest(context.app.getHttpServer())
.post("/portail-usagers/auth/login")
.send({
login: PERMANENT_PASS_USER.login,
password: PERMANENT_PASS_USER.password,
});

controller = module.get<StructureInformationController>(
authToken = loginResponse.body.token;
});

afterAll(async () => {
await AppTestHelper.tearDownTestApp(context);
});

it("should be defined", async () => {
const controller = context.module.get<StructureInformationController>(
StructureInformationController
);
expect(controller).toBeDefined();
});

it("should be defined", () => {
expect(controller).toBeDefined();
describe("GET /portail-usagers/profile/structure-information", () => {
it("should return structure information for authenticated usager", async () => {
const response = await supertest(context.app.getHttpServer())
.get("/portail-usagers/profile/structure-information")
.set("Authorization", `Bearer ${authToken}`)
.expect(HttpStatus.OK);

expect(response.body).toBeDefined();
expect(Array.isArray(response.body)).toBe(true);
});

it("should return 401 for unauthenticated request", async () => {
await supertest(context.app.getHttpServer())
.get("/portail-usagers/profile/structure-information")
.expect(HttpStatus.UNAUTHORIZED);
});

it("should return 401 for invalid token", async () => {
await supertest(context.app.getHttpServer())
.get("/portail-usagers/profile/structure-information")
.set("Authorization", "Bearer invalid-token")
.expect(HttpStatus.UNAUTHORIZED);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { AppEntity } from "./../../_core/interfaces/AppEntity.interface";
import { createDate } from "../../_core";
import { UserStructureResume } from "../../users";
import { isWithinInterval } from "date-fns";

export class StructureInformation implements AppEntity {
public title: string;
public description: string;
public startDate?: Date | null;
public endDate?: Date | null;
public type: "closing" | "opening-hours" | "general" | "other";
public createdBy?: UserStructureResume;
public structureId?: number;
public isTemporary?: boolean;
public isExpired?: boolean;
public uuid?: string | undefined;
public createdAt?: Date;
public updatedAt?: Date;
public version?: number;
constructor(options: Partial<StructureInformation>) {
this.title = options.title || "";
this.description = options.description || "";
this.startDate = options.startDate || null;
this.endDate = options.endDate || null;
this.type = options.type || "other";
this.createdAt = createDate(options.createdAt) ?? new Date();
this.updatedAt = createDate(options.updatedAt) ?? new Date();
this.createdBy = options.createdBy;
this.structureId = options.structureId;
this.isTemporary = options.isTemporary;
this.isExpired = isMessageExpired(options);
this.uuid = options.uuid;
this.version = options.version;
}
}

export function isMessageExpired(
message: Partial<StructureInformation>
): boolean {
if (!message.endDate || !message.startDate || !message.isTemporary)
return false;
const today = new Date();
return !isWithinInterval(today, {
start: new Date(message.startDate),
end: new Date(message.endDate),
});
}
1 change: 1 addition & 0 deletions packages/common/src/structure-information/classes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./StructureInformation.class";
2 changes: 1 addition & 1 deletion packages/common/src/structure-information/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./constants";
export * from "./interfaces";
export * from "./types";
export * from "./classes";

This file was deleted.

2 changes: 0 additions & 2 deletions packages/common/src/structure-information/interfaces/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/common/src/structure/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./StructureCommon.type";
export * from "../../structure-information/types/StructureInformationType.type";
export * from "./StructureLight.type";
export * from "./StructureType.type";
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { PortailUsagerProfile, PortailUsagerPublic } from "@domifa/common";

const usager: PortailUsagerPublic = {
uuid: "4dcdcddc-fad2-4827-aac5-0acf1df7b5bc",
ref: 5,
customRef: "5",
structureId: 1,
nom: "Derick",
prenom: "Inspecteur",
sexe: "homme",
dateNaissance: new Date("1911-05-24T00:00:00.000Z"),
villeNaissance: "Dreux",
email: null,
telephone: {
numero: "",
countryCode: "FR",
},
contactByPhone: false,
datePremiereDom: new Date("2025-08-13T00:00:00.000Z"),
typeDom: "PREMIERE_DOM",
decision: {
uuid: "4328c843-e4bd-432d-b60b-b72a13ee3c9c",
statut: "VALIDE",
userId: 1,
dateFin: new Date("2026-08-12T00:00:00.000Z"),
userName: "Patrick Roméro",
dateDebut: new Date("2025-08-13T00:00:00.000Z"),
dateDecision: new Date("2025-08-13T14:29:36.624Z"),
},
historique: [],
ayantsDroits: [],
lastInteraction: {
colisIn: 0,
enAttente: false,
courrierIn: 0,
recommandeIn: 0,
dateInteraction: new Date("2025-08-13T00:00:00.000Z"),
},
etapeDemande: 5,
rdv: {
userId: 2,
dateRdv: new Date("2019-10-07T19:30:02.675Z"),
userName: "Juste Isabelle",
},
options: {
transfert: {
nom: "",
dateDebut: null,
dateFin: null,
isExpired: false,
adresse: null,
actif: false,
},
procurations: [],
portailUsagerEnabled: true,
npai: {
actif: false,
dateDebut: null,
},
},
};

export const unProfilUsager: PortailUsagerProfile = {
acceptTerms: new Date(),
usager: usager,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { StructureInformation } from "@domifa/common";
import { add, sub } from "date-fns";

export const unMessageCourant: StructureInformation = {
uuid: "1",
createdAt: new Date("2025-08-13T15:28:52.311Z"),
updatedAt: new Date("2025-08-13T15:28:52.311Z"),
version: 1,
title: "Un message courant",
description: "Un message",
isTemporary: true,
startDate: sub(new Date(), {
days: 1,
}),
endDate: add(new Date(), {
days: 1,
}),
type: "general",
createdBy: {
userId: 1,
userName: "Patrick Roméro",
},
structureId: 1,
isExpired: false,
};

export const unMessagePasse: StructureInformation = {
...unMessageCourant,
title: "Un message passé",
startDate: sub(new Date(), {
days: 4,
}),
endDate: sub(new Date(), {
days: 1,
}),
isExpired: true,
};

export const unMessageFutur: StructureInformation = {
...unMessageCourant,
title: "Un message futur",
startDate: add(new Date(), {
days: 2,
}),
endDate: add(new Date(), {
days: 4,
}),
isExpired: true,
};

export const unMessageFuturAvecIsoDate = {
...unMessageCourant,
title: "Un message futur",
startDate: add(new Date(), {
days: 2,
}).toISOString(),
endDate: add(new Date(), {
days: 4,
}).toISOString(),
isExpired: true,
};

export const unMessageAvecIsoDate = {
...unMessageCourant,
title: "Un message courant avec text date",
startDate: sub(new Date(), {
days: 4,
}).toISOString(),
endDate: add(new Date(), {
days: 1,
}).toISOString(),
isExpired: false,
};
Loading
Loading