Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -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,46 @@
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,
}),
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
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 {
unMessageCourant,
unMessageFutur,
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,
];
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 +66,12 @@ describe("HomeUsagerComponent", () => {
it("should create", () => {
expect(component).toBeTruthy();
});

it("Filter out obsolete messages", fakeAsync(() => {
tick();
expect(component.structureInformation.length).toEqual(1);
expect(component.structureInformation[0].title).toEqual(
"Un message courant"
);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class HomeUsagerComponent implements OnInit {
private readonly usagerAuthService: UsagerAuthService,
private readonly titleService: Title,
private readonly router: Router,
private readonly structureInformationService: StructureInformationService,
private readonly structureInformationService: StructureInformationService
) {
this.usagerProfile = null;
this.titleService.setTitle("Mon DomiFa");
Expand All @@ -35,10 +35,9 @@ export class HomeUsagerComponent implements OnInit {
this.router.navigate(["/account/accept-terms"]);
return;
}

this.usagerProfile = apiResponse;
},
),
}
)
);

if (this.usagerProfile) {
Expand All @@ -51,22 +50,21 @@ export class HomeUsagerComponent implements OnInit {
this.structureInformationService.getAllStructureInformation().subscribe({
next: (structureInformation: StructureInformation[]) => {
const today = new Date();

this.structureInformation = structureInformation.filter((info) => {
if (!info.isTemporary) {
return true;
}

if (info.endDate && info.startDate) {
return isWithinInterval(today, {
start: info.startDate,
end: info.endDate,
start: new Date(info.startDate),
end: new Date(info.endDate),
});
}
return false;
});
},
}),
})
);
}
}
Loading