From bfa5dffb991878b2c15ac15fc56b56ac74556fc9 Mon Sep 17 00:00:00 2001 From: "Yassine R." Date: Mon, 20 Nov 2023 16:42:42 +0100 Subject: [PATCH] fix(mon-domifa): add user usager login in stats --- .talismanrc | 4 ++ .../db/dumps/domifa_test.postgres.custom.gz | Bin 92086 -> 91692 bytes ...domifa_test.postgres.restore-data-only.sql | 10 +-- ...st.postgres.truncate-restore-data-only.sql | 10 +-- .../portail-usagers-login.controller.ts | 4 +- .../interactionRepository.service.test.ts | 21 ++---- .../interactionRepository.service.ts | 64 ++++++++++++------ .../userUsagerLoginRepository.service.test.ts | 17 +++++ .../tests/usagers.controller.spec.ts | 2 +- ...historique-login-portail.component.spec.ts | 13 ++++ 10 files changed, 96 insertions(+), 49 deletions(-) create mode 100644 packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.test.ts diff --git a/.talismanrc b/.talismanrc index 3faffaac76..e6ee4d3dde 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,4 +1,8 @@ fileignoreconfig: +- filename: _scripts/db/dumps/domifa_test.postgres.restore-data-only.sql + checksum: 104c8036ca644bc51bb4c797e56b3a5b178a55b1c293a77308844e54ca7c404d +- filename: _scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql + checksum: 9976de417c719ab5c3bec9d4a1bafc40bfa8d4388d2dbd5da7d1ea4a11d2db75 - filename: yarn.lock checksum: 4ac842f95592d194e65b208fdc4b9a78a0bb6470ad2d4950626c2ffcec831a33 version: "1.0" diff --git a/_scripts/db/dumps/domifa_test.postgres.custom.gz b/_scripts/db/dumps/domifa_test.postgres.custom.gz index 782c0ddfa91a0e1fff209ff3f7905ea722a3de70..3d3b2a55ee4855f300038909097a7a888c1c1660 100644 GIT binary patch delta 6652 zcmai22Ut|c7T&pZft5vI1#}g~s6h1YExUI$B8Vjl$ch+6A7CQ{)L3{bDgxH%Lr^p5 z8l%{-#Armvur{p8Ge*R&gak`8Vu?xAXUFj7wjmGlKKVYj{O3Pq&YW{*?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)J1gs+6gzEhnb_rkP?ut zA_T$lRTr=V;GtYYd4Zyu?&IZShx4>7<=ov85cuwzoFnU<7#l&hv6JBZU)D(;h?pKaW^JXvW}Rjt3RA)@lT{;7pg@qN#3iSnbpsH--c;XJdwbvFcn_ z^nxGmznp15bVNJ*QiEH4@X9Y5;~&IEcDp-pY5q@#AHSd8rbFS*TQ{d1v?LGfm*YK7 z-!t%@`@>n!)2#WYZ@zQ=dh#X5{C~KdbiMyUBUAgYj;YHW6>VM0?qxcj*XG~e5whsV zxif>e?XQ1ywcs#%lD#qe>-51#di}h;c6VuQT9-lRMl9}ie(3Ek7f+23D(!Xt@0UK* zmTU|gmJ!}Qvejz)u>ry0(dzohPOG9bT>ez<<6W`yo%n%W59>}vZPNwpoP07mtmOT0 zty}pw`_3P^(XG>!mp?wfHgsq$oV6#|_h7{&v3lh<@KL)JPgfU>?B3u1W&7@_uQLYa zEFW80wrSTL@u%IPeR_ z`B59ITY2oOz~ytozwCP%qy{T!P3oza>iOA6XOoVzy0|N+hs0jnzkfon{d_}yIdh;c z!bNKtoVrkVt2$vb<5#iZ-t0Ty-hNOYmN|BdUzdr#A0vM*B*J&fiRjY}BX;<9_FcN5 zH0Dw3nd3j3T3QlN7(e(n=q+YNwyRw+{B!p&))!lsjL4dMao+S%VUIEk^zWFfrXQSC zS@pQ#@ZF5G>YNkx>rzX$HB7&@;Y3Bmx+#Y=j-&B24|uGfuK$5eOg_G@pzYS)g|@eX zx3sP8eA~V<^X7B+zb>rX)Tur!cj_E%_T;Ay&-eDNSeBRY?z$tl4|8$3Uw0m!vq$5T z+V=P{t!{MihJcB??|PSPO!Y{qUiEI6F)Ay)Vu@Ms$V&}+d2OC`*WkGkKOLCo+>Sf+ IP)gN*0p}tIFaQ7m diff --git a/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql b/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql index af255d41f1..b61809dbcd 100644 --- a/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql +++ b/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 14.9 (Debian 14.9-1.pgdg110+1) --- Dumped by pg_dump version 14.9 (Debian 14.9-1.pgdg110+1) +-- Dumped from database version 14.9 +-- Dumped by pg_dump version 14.9 SET statement_timeout = 0; SET lock_timeout = 0; @@ -256,8 +256,8 @@ e0bcefc6-f1be-4c83-ac9d-6ea47335a9c3 2021-03-15 16:53:55.740856+01 2023-09-05 23 -- COPY public.user_usager (uuid, "createdAt", "updatedAt", version, id, "usagerUUID", "structureId", login, password, salt, "isTemporaryPassword", "lastLogin", "passwordLastUpdate", "lastPasswordResetDate", "lastPasswordResetStructureUser", enabled) FROM stdin; -a03a9a49-ae31-4160-9879-bab02dc46361 2021-11-30 14:50:26.278073+01 2021-11-30 15:01:39.89434+01 10 2 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 LNQIFFBK $2a$10$u..ofvcb5t5a44N0Oriwbew6oz600aoOFzll9yl92Lx1VOb0E8o0a $2a$10$zmuPXxUOuQJ7nE6ag4.x6e f 2021-11-30 15:01:39.893+01 2021-11-30 15:01:39.675+01 2021-11-30 14:50:26.275+01 {"userId": 1, "userName": "Patrick Roméro"} t a657f4bd-e4d1-4c38-bdd0-ffd268b356df 2021-10-05 11:34:41.369505+02 2021-11-30 15:02:07.705535+01 18 1 b2c26e55-ab37-457d-b307-6fe161050a9b 1 WKYJBDXS $2a$10$cmwXTghEgrGRYTkGIJlj3Owjo8YVVDXOgceAGtkgzcD2M/Tf3Dhb. $2a$10$/uFyiR8hCe8XkRe7x2fYm. t 2021-11-30 15:02:07.69+01 \N 2021-10-05 11:34:41.365+02 {"userId": 1, "userName": "Patrick Roméro"} t +a03a9a49-ae31-4160-9879-bab02dc46361 2021-11-30 14:50:26.278073+01 2023-11-20 16:40:58.362384+01 17 2 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 LNQIFFBK $2a$10$u..ofvcb5t5a44N0Oriwbew6oz600aoOFzll9yl92Lx1VOb0E8o0a $2a$10$zmuPXxUOuQJ7nE6ag4.x6e f 2023-11-20 16:40:58.36+01 2021-11-30 15:01:39.675+01 2021-11-30 14:50:26.275+01 {"userId": 1, "userName": "Patrick Roméro"} t \. @@ -266,6 +266,8 @@ a657f4bd-e4d1-4c38-bdd0-ffd268b356df 2021-10-05 11:34:41.369505+02 2021-11-30 15 -- COPY public.user_usager_login (uuid, "createdAt", "updatedAt", version, "usagerUUID", "structureId") FROM stdin; +3927beaf-04d8-4cbb-9be7-c7c9086434b3 2023-11-20 16:40:44.4121+01 2023-11-20 16:40:44.4121+01 1 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 +e80dafea-8fe4-4792-92b9-3608c723aa1b 2023-11-20 16:40:58.289642+01 2023-11-20 16:40:58.289642+01 1 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 \. @@ -274,8 +276,8 @@ COPY public.user_usager_login (uuid, "createdAt", "updatedAt", version, "usagerU -- COPY public.user_usager_security (uuid, "createdAt", "updatedAt", version, "userId", "structureId", "eventsHistory") FROM stdin; -fadd55b6-ca41-48d4-bd56-238b1a3c6f7b 2021-11-30 14:50:26.290488+01 2021-11-30 15:01:39.66811+01 8 2 1 [{"date": "2021-11-30T13:50:38.357Z", "type": "login-success"}, {"date": "2021-11-30T13:51:20.351Z", "type": "login-success"}, {"date": "2021-11-30T13:51:20.608Z", "type": "change-password-success"}, {"date": "2021-11-30T14:00:55.533Z", "type": "login-error"}, {"date": "2021-11-30T14:01:21.310Z", "type": "login-success"}, {"date": "2021-11-30T14:01:39.398Z", "type": "login-success"}, {"date": "2021-11-30T14:01:39.667Z", "type": "change-password-success"}] 9bc8decb-5f78-48de-8c1b-9f61ea5acfba 2021-10-05 11:34:41.388922+02 2021-11-30 15:02:07.682311+01 3 1 1 [{"date": "2021-11-30T14:02:07.680Z", "type": "login-success"}] +fadd55b6-ca41-48d4-bd56-238b1a3c6f7b 2021-11-30 14:50:26.290488+01 2023-11-20 16:40:58.2674+01 10 2 1 [{"date": "2023-11-20T15:40:44.378Z", "type": "login-success"}, {"date": "2023-11-20T15:40:58.265Z", "type": "login-success"}] \. diff --git a/_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql b/_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql index 2bc1486707..dc93ba61ab 100644 --- a/_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql +++ b/_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql @@ -28,8 +28,8 @@ TRUNCATE TABLE public.usager_options_history RESTART IDENTITY CASCADE; -- PostgreSQL database dump -- --- Dumped from database version 14.9 (Debian 14.9-1.pgdg110+1) --- Dumped by pg_dump version 14.9 (Debian 14.9-1.pgdg110+1) +-- Dumped from database version 14.9 +-- Dumped by pg_dump version 14.9 SET statement_timeout = 0; SET lock_timeout = 0; @@ -282,8 +282,8 @@ e0bcefc6-f1be-4c83-ac9d-6ea47335a9c3 2021-03-15 16:53:55.740856+01 2023-09-05 23 -- COPY public.user_usager (uuid, "createdAt", "updatedAt", version, id, "usagerUUID", "structureId", login, password, salt, "isTemporaryPassword", "lastLogin", "passwordLastUpdate", "lastPasswordResetDate", "lastPasswordResetStructureUser", enabled) FROM stdin; -a03a9a49-ae31-4160-9879-bab02dc46361 2021-11-30 14:50:26.278073+01 2021-11-30 15:01:39.89434+01 10 2 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 LNQIFFBK $2a$10$u..ofvcb5t5a44N0Oriwbew6oz600aoOFzll9yl92Lx1VOb0E8o0a $2a$10$zmuPXxUOuQJ7nE6ag4.x6e f 2021-11-30 15:01:39.893+01 2021-11-30 15:01:39.675+01 2021-11-30 14:50:26.275+01 {"userId": 1, "userName": "Patrick Roméro"} t a657f4bd-e4d1-4c38-bdd0-ffd268b356df 2021-10-05 11:34:41.369505+02 2021-11-30 15:02:07.705535+01 18 1 b2c26e55-ab37-457d-b307-6fe161050a9b 1 WKYJBDXS $2a$10$cmwXTghEgrGRYTkGIJlj3Owjo8YVVDXOgceAGtkgzcD2M/Tf3Dhb. $2a$10$/uFyiR8hCe8XkRe7x2fYm. t 2021-11-30 15:02:07.69+01 \N 2021-10-05 11:34:41.365+02 {"userId": 1, "userName": "Patrick Roméro"} t +a03a9a49-ae31-4160-9879-bab02dc46361 2021-11-30 14:50:26.278073+01 2023-11-20 16:40:58.362384+01 17 2 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 LNQIFFBK $2a$10$u..ofvcb5t5a44N0Oriwbew6oz600aoOFzll9yl92Lx1VOb0E8o0a $2a$10$zmuPXxUOuQJ7nE6ag4.x6e f 2023-11-20 16:40:58.36+01 2021-11-30 15:01:39.675+01 2021-11-30 14:50:26.275+01 {"userId": 1, "userName": "Patrick Roméro"} t \. @@ -292,6 +292,8 @@ a657f4bd-e4d1-4c38-bdd0-ffd268b356df 2021-10-05 11:34:41.369505+02 2021-11-30 15 -- COPY public.user_usager_login (uuid, "createdAt", "updatedAt", version, "usagerUUID", "structureId") FROM stdin; +3927beaf-04d8-4cbb-9be7-c7c9086434b3 2023-11-20 16:40:44.4121+01 2023-11-20 16:40:44.4121+01 1 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 +e80dafea-8fe4-4792-92b9-3608c723aa1b 2023-11-20 16:40:58.289642+01 2023-11-20 16:40:58.289642+01 1 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 \. @@ -300,8 +302,8 @@ COPY public.user_usager_login (uuid, "createdAt", "updatedAt", version, "usagerU -- COPY public.user_usager_security (uuid, "createdAt", "updatedAt", version, "userId", "structureId", "eventsHistory") FROM stdin; -fadd55b6-ca41-48d4-bd56-238b1a3c6f7b 2021-11-30 14:50:26.290488+01 2021-11-30 15:01:39.66811+01 8 2 1 [{"date": "2021-11-30T13:50:38.357Z", "type": "login-success"}, {"date": "2021-11-30T13:51:20.351Z", "type": "login-success"}, {"date": "2021-11-30T13:51:20.608Z", "type": "change-password-success"}, {"date": "2021-11-30T14:00:55.533Z", "type": "login-error"}, {"date": "2021-11-30T14:01:21.310Z", "type": "login-success"}, {"date": "2021-11-30T14:01:39.398Z", "type": "login-success"}, {"date": "2021-11-30T14:01:39.667Z", "type": "change-password-success"}] 9bc8decb-5f78-48de-8c1b-9f61ea5acfba 2021-10-05 11:34:41.388922+02 2021-11-30 15:02:07.682311+01 3 1 1 [{"date": "2021-11-30T14:02:07.680Z", "type": "login-success"}] +fadd55b6-ca41-48d4-bd56-238b1a3c6f7b 2021-11-30 14:50:26.290488+01 2023-11-20 16:40:58.2674+01 10 2 1 [{"date": "2023-11-20T15:40:44.378Z", "type": "login-success"}, {"date": "2023-11-20T15:40:58.265Z", "type": "login-success"}] \. diff --git a/packages/backend/src/_portail-usager/portail-usager-login/portail-usagers-login.controller.ts b/packages/backend/src/_portail-usager/portail-usager-login/portail-usagers-login.controller.ts index 8878c8911e..45de1deedb 100644 --- a/packages/backend/src/_portail-usager/portail-usager-login/portail-usagers-login.controller.ts +++ b/packages/backend/src/_portail-usager/portail-usager-login/portail-usagers-login.controller.ts @@ -60,7 +60,7 @@ export class PortailUsagersLoginController { id: user.structureId, }); - await userUsagerLoginRepository.save( + const lastLogin = await userUsagerLoginRepository.save( new UserUsagerLoginTable({ usagerUUID: usager.uuid, structureId: usager.structureId, @@ -68,7 +68,7 @@ export class PortailUsagersLoginController { ); if (structure.portailUsager.usagerLoginUpdateLastInteraction) { - usager.lastInteraction.dateInteraction = new Date(); + usager.lastInteraction.dateInteraction = lastLogin.createdAt; await usagerRepository.update( { uuid: usager.uuid }, { lastInteraction: usager.lastInteraction } diff --git a/packages/backend/src/database/services/interaction/interactionRepository.service.test.ts b/packages/backend/src/database/services/interaction/interactionRepository.service.test.ts index 5541cc0e16..010a8075e9 100644 --- a/packages/backend/src/database/services/interaction/interactionRepository.service.test.ts +++ b/packages/backend/src/database/services/interaction/interactionRepository.service.test.ts @@ -10,21 +10,10 @@ describe("interactionRepository", () => { }); it("get all interactions", async () => { - { - const interactions = await interactionRepository.findBy({ - structureId: 1, - usagerRef: 7, - }); - - expect(interactions.length).toEqual(9); - } - { - const interactions = await interactionRepository.findBy({ - structureId: 1, - usagerRef: 7, - }); - - expect(interactions.length).toBeGreaterThan(2); - } + const interactions = await interactionRepository.findBy({ + structureId: 1, + usagerRef: 7, + }); + expect(interactions.length).toEqual(8); }); }); diff --git a/packages/backend/src/database/services/interaction/interactionRepository.service.ts b/packages/backend/src/database/services/interaction/interactionRepository.service.ts index b732b90819..c328cbb790 100644 --- a/packages/backend/src/database/services/interaction/interactionRepository.service.ts +++ b/packages/backend/src/database/services/interaction/interactionRepository.service.ts @@ -13,6 +13,8 @@ import { import { InteractionsTable } from "../../entities"; import { myDataSource } from "../_postgres"; import { InteractionType } from "@domifa/common"; +import { userUsagerLoginRepository } from "../user-usager"; +import { differenceInMinutes, parseISO } from "date-fns"; export const interactionRepository = myDataSource .getRepository(InteractionsTable) @@ -122,13 +124,6 @@ async function countPendingInteractionsIn({ lastInteractionOut: Date | null; }> { const INTERACTIONS_TO_CHECK = Object.assign([], INTERACTION_OK_LIST); - - if (structure.portailUsager.usagerLoginUpdateLastInteraction) { - INTERACTIONS_TO_CHECK.push("loginPortail"); - } - - const inArray = INTERACTIONS_TO_CHECK.join(", "); - // NOTE: cette requête ne renvoit pas de résultats pour les usagers de cette structure qui n'ont pas d'interaction const query = `SELECT coalesce (SUM(CASE WHEN i.type = 'courrierIn' THEN "nbCourrier" END), 0) AS "courrierIn", @@ -138,31 +133,52 @@ async function countPendingInteractionsIn({ FROM interactions i WHERE i."usagerUUID" = $2 AND i."interactionOutUUID" is null GROUP BY i."usagerRef"`; + const results = await interactionRepository.query(query, [ - inArray, + INTERACTIONS_TO_CHECK.join(", "), usagerUUID, ]); - const defaultResult = { - courrierIn: 0, - recommandeIn: 0, - colisIn: 0, - lastInteractionOut: null, - }; - - if (typeof results[0] === "undefined") { - return defaultResult; + if ( + typeof results[0] === "undefined" || + results[0] === null || + results[0]?.length === 0 + ) { + return { + courrierIn: 0, + recommandeIn: 0, + colisIn: 0, + lastInteractionOut: null, + }; } - if (results[0] === null || results[0].length === 0) { - return defaultResult; + let lastInteractionOut: Date | null = + results[0].lastInteractionOut !== null + ? results[0].lastInteractionOut === "string" + ? parseISO(results[0].lastInteractionOut) + : results[0].lastInteractionOut + : null; + + if (structure.portailUsager.usagerLoginUpdateLastInteraction) { + const lastUserUsagerLogin = await userUsagerLoginRepository.findOne({ + where: { + usagerUUID, + }, + order: { createdAt: "DESC" }, + }); + + if ( + differenceInMinutes(lastInteractionOut, lastUserUsagerLogin.createdAt) > 0 + ) { + lastInteractionOut = lastUserUsagerLogin.createdAt; + } } return { courrierIn: parseInt(results[0].courrierIn, 10), recommandeIn: parseInt(results[0].recommandeIn, 10), colisIn: parseInt(results[0].colisIn, 10), - lastInteractionOut: results[0].lastInteractionOut, + lastInteractionOut, }; } @@ -263,7 +279,11 @@ async function totalInteractionAllUsagersStructure({ const results = await interactionRepository.query(query, [structureId]); - // TODO: add loginPortail + const loginPortailStats = await userUsagerLoginRepository.query( + `SELECT u."usagerRef", coalesce (COUNT(uuid THEN 1 END), 0) AS "loginPortail" FROM user_usager_login u WHERE u."structureId" = $1 GROUP BY u."usagerRef"`, + [structureId] + ); + return results.map((x: any) => ({ usagerRef: x.usagerRef, courrierIn: parseInt(x.courrierIn, 10), @@ -274,7 +294,7 @@ async function totalInteractionAllUsagersStructure({ colisOut: parseInt(x.colisOut, 10), appel: parseInt(x.appel, 10), visite: parseInt(x.visite, 10), - loginPortail: 0, + loginPortail: loginPortailStats, npai: parseInt(x.npai, 10), })); } diff --git a/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.test.ts b/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.test.ts new file mode 100644 index 0000000000..cc95e332fb --- /dev/null +++ b/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.test.ts @@ -0,0 +1,17 @@ +import { AppTestHelper } from "../../../util/test"; +import { userUsagerLoginRepository } from "./userUsagerLoginRepository.service"; + +describe("userUsagerLoginRepository", () => { + beforeAll(async () => { + await AppTestHelper.bootstrapTestConnection(); + }); + + afterAll(async () => { + await AppTestHelper.tearDownTestConnection(); + }); + + it("Count all logins made", async () => { + const users = await userUsagerLoginRepository.count(); + expect(users).toBeGreaterThan(2); + }); +}); diff --git a/packages/backend/src/usagers/controllers/tests/usagers.controller.spec.ts b/packages/backend/src/usagers/controllers/tests/usagers.controller.spec.ts index 84c569d3b1..69a700468e 100644 --- a/packages/backend/src/usagers/controllers/tests/usagers.controller.spec.ts +++ b/packages/backend/src/usagers/controllers/tests/usagers.controller.spec.ts @@ -84,7 +84,7 @@ describe("Usagers Controller", () => { expect(usager.ayantsDroits[0].nom).toEqual( exceptedResponse.ayantsDroits[0].nom ); - console.log("XXX"); + expect(usager.ayantsDroits[0].prenom).toEqual( exceptedResponse.ayantsDroits[0].prenom ); diff --git a/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.spec.ts b/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.spec.ts index 6b1258bcc2..1fb9367cce 100644 --- a/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.spec.ts +++ b/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.spec.ts @@ -1,6 +1,12 @@ import { ComponentFixture, TestBed } from "@angular/core/testing"; import { ProfilHistoriqueLoginPortailComponent } from "./profil-historique-login-portail.component"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; +import { NoopAnimationsModule } from "@angular/platform-browser/animations"; +import { StoreModule } from "@ngrx/store"; +import { _usagerReducer } from "../../../../../shared"; +import { UsagerFormModel } from "../../../../usager-shared/interfaces"; +import { SharedModule } from "../../../../shared/shared.module"; describe("ProfilHistoriqueLoginPortailComponent", () => { let component: ProfilHistoriqueLoginPortailComponent; @@ -9,10 +15,17 @@ describe("ProfilHistoriqueLoginPortailComponent", () => { beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ProfilHistoriqueLoginPortailComponent], + imports: [ + HttpClientTestingModule, + StoreModule.forRoot({ app: _usagerReducer }), + NoopAnimationsModule, + SharedModule, + ], }).compileComponents(); fixture = TestBed.createComponent(ProfilHistoriqueLoginPortailComponent); component = fixture.componentInstance; + component.usager = new UsagerFormModel(); fixture.detectChanges(); });