Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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,44 @@
import { StructureInformation } from "./../interfaces/StructureInformation.interface";
import { createDate } from "../../_core";
import { UserStructureResume } from "../../users";
import { isWithinInterval } from "date-fns";

export class StructureInformationMessage implements StructureInformation {
public title: string;
public description: string;
public startDate: Date;
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: StructureInformation) {
this.title = options.title;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faudrait mettre des valeurs par défaut

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valeurs par défaut dans quel sens ?

this.description = options.description;
this.startDate = options.startDate;
this.endDate = options.endDate;
this.type = options.type;
this.createdAt = createDate(options.createdAt) ?? undefined;
this.updatedAt = createDate(options.updatedAt) ?? undefined;
this.createdBy = options.createdBy;
this.structureId = options.structureId;
this.isTemporary = options.isTemporary;
this.isExpired = this.isMessageExpired();
this.uuid = options.uuid;
this.version = options.version;
}

public isMessageExpired(): boolean {
if (!this.endDate || !this.startDate || !this.isTemporary) return false;
const today = new Date();
return !isWithinInterval(today, {
start: new Date(this.startDate),
end: new Date(this.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";
1 change: 1 addition & 0 deletions packages/common/src/structure-information/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
export * from "./constants";
export * from "./interfaces";
export * from "./types";
export * from "./classes";
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,68 @@
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,
};

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

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

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

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(),
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,63 @@
import { provideHttpClientTesting } from "@angular/common/http/testing";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import {
ComponentFixture,
fakeAsync,
TestBed,
tick,
} from "@angular/core/testing";

import { HomeUsagerComponent } from "./home-usager.component";
import { UsagerAccountModule } from "../../usager-account.module";
import { RouterModule } from "@angular/router";
import { StructureInformationService } from "../../services/structure-information.service";
import { BehaviorSubject, of } from "rxjs";
import { PortailUsagerProfile, StructureInformation } from "@domifa/common";
import {
unMessageAvecIsoDate,
unMessageCourant,
unMessageFutur,
unMessageFuturAvecIsoDate,
unMessagePasse,
} from "../../../../../_tests/mocks/STRUCTURE_INFORMATION.mock";
import { unProfilUsager } from "../../../../../_tests/mocks/PORTAIL_USAGER_PROFILE.mock";
import { UsagerAuthService } from "../../../usager-auth/services/usager-auth.service";
import { NO_ERRORS_SCHEMA } from "@angular/core";

describe("HomeUsagerComponent", () => {
const messagesStructures: StructureInformation[] = [
unMessageCourant,
unMessagePasse,
unMessageFutur,
unMessageAvecIsoDate as unknown as StructureInformation, // un message avec date string
unMessageFuturAvecIsoDate as unknown as StructureInformation,
];
const structureInformationService = {
getAllStructureInformation: jest.fn(() => of(messagesStructures)),
};
const authService = {
currentUsagerSubject: new BehaviorSubject<PortailUsagerProfile>(
unProfilUsager
),
};
let component: HomeUsagerComponent;
let fixture: ComponentFixture<HomeUsagerComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [HomeUsagerComponent],
imports: [UsagerAccountModule, RouterModule.forRoot([])],
providers: [provideHttpClientTesting()],
providers: [
provideHttpClientTesting(),
{
provide: StructureInformationService,
useValue: structureInformationService,
},
{
provide: UsagerAuthService,
useValue: authService,
},
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
});

Expand All @@ -26,4 +70,15 @@ describe("HomeUsagerComponent", () => {
it("should create", () => {
expect(component).toBeTruthy();
});

it("Filter out obsolete messages", fakeAsync(() => {
tick();
expect(component.structureInformation.length).toEqual(2);
expect(component.structureInformation[0].title).toEqual(
"Un message courant"
);
expect(component.structureInformation[1].title).toEqual(
"Un message courant avec text date"
);
}));
});
Loading
Loading