From 8a1c491f427686386e16765fa3998004d0672bfc Mon Sep 17 00:00:00 2001 From: "Yassine R." Date: Wed, 27 Dec 2023 12:10:50 +0100 Subject: [PATCH] fix(stats): do not load on test --- .../1703081808851-manual-migration.ts | 2 +- .../stats.public.controller.spec.ts | 384 +++++++++--------- .../src/stats/services/publicStats.service.ts | 6 +- 3 files changed, 200 insertions(+), 192 deletions(-) diff --git a/packages/backend/src/_migrations/1703081808851-manual-migration.ts b/packages/backend/src/_migrations/1703081808851-manual-migration.ts index d9976f900a..e9293d5dfc 100644 --- a/packages/backend/src/_migrations/1703081808851-manual-migration.ts +++ b/packages/backend/src/_migrations/1703081808851-manual-migration.ts @@ -62,7 +62,7 @@ export class ManualMigration1703081808851 implements MigrationInterface { // } - private counteMigratedStats(): Promise { + private async counteMigratedStats(): Promise { return usagerHistoryRepository.countBy({ migrated: false }); } } diff --git a/packages/backend/src/stats/controllers/stats.public.controller.spec.ts b/packages/backend/src/stats/controllers/stats.public.controller.spec.ts index e90d1ecd8e..f6eb163c4b 100644 --- a/packages/backend/src/stats/controllers/stats.public.controller.spec.ts +++ b/packages/backend/src/stats/controllers/stats.public.controller.spec.ts @@ -50,202 +50,206 @@ describe("Stats Public Controller", () => { ); }); - it("Stats HomePage", async () => { - const response = await supertest(context.app.getHttpServer()).get( - "/stats/home" - ); - - expect(response.status).toBe(HttpStatus.OK); - - const content = response.body as HomeStats; - expect(content.interactions).toEqual(5); - expect(content.structures).toEqual(5); - expect(content.usagers).toEqual(20); - expect(content.actifs).toEqual(11); + it("should be defined", () => { + expect(controller).toBeDefined(); }); - it("Stats Page : national", async () => { - const response = await supertest(context.app.getHttpServer()).get( - "/stats/public-stats" - ); + describe("Homepage", () => { + it("Stats HomePage", async () => { + const response = await supertest(context.app.getHttpServer()).get( + "/stats/home" + ); - const retour: PublicStats = { - usagersCount: 20, - usersCount: 10, - structuresCount: 5, - courrierInCount: 5, - courrierOutCount: 2, - structuresCountByRegion: [ - { count: 2, region: "52" }, - { count: 1, region: "03" }, - { count: 1, region: "11" }, - { count: 1, region: "75" }, - ], - structuresCountByTypeMap: { asso: 2, cias: 2, ccas: 1, mairie: 0 }, - interactionsCountByMonth: [ - { name: "août", value: 0 }, - { name: "sept.", value: 0 }, - { name: "oct.", value: 0 }, - { name: "nov.", value: 0 }, - { name: "déc.", value: 0 }, - { name: "janv.", value: 0 }, - { name: "févr.", value: 0 }, - { name: "mars", value: 0 }, - { name: "avr.", value: 0 }, - { name: "mai", value: 0 }, - { name: "juin", value: 0 }, - { name: "juil.", value: 0 }, - ], - usagersCountByMonth: [ - { name: "août", value: 0 }, - { name: "sept.", value: 0 }, - { name: "oct.", value: 0 }, - { name: "nov.", value: 4 }, - { name: "déc.", value: 0 }, - { name: "janv.", value: 0 }, - { name: "févr.", value: 0 }, - { name: "mars", value: 1 }, - { name: "avr.", value: 0 }, - { name: "mai", value: 0 }, - { name: "juin", value: 0 }, - { name: "juil.", value: 0 }, - ], - }; + expect(response.status).toBe(HttpStatus.OK); - expect(response.status).toBe(HttpStatus.OK); - expect(response.body).toEqual(retour); + const content = response.body as HomeStats; + expect(content.interactions).toEqual(5); + expect(content.structures).toEqual(5); + expect(content.usagers).toEqual(20); + expect(content.actifs).toEqual(11); + }); }); - it("Statistiques régionales : Pays de la Loire", async () => { - const response = await supertest(context.app.getHttpServer()).get( - "/stats/public-stats/52" - ); - - const retour: PublicStats = { - usagersCount: 0, - usersCount: 5, - structuresCount: 2, - courrierInCount: 0, - courrierOutCount: 0, - structuresCountByRegion: [ - { - count: 2, - region: "44", - }, - ], - structuresCountByTypeMap: { - asso: 2, - cias: 0, - ccas: 0, - mairie: 0, - }, - interactionsCountByMonth: [ - { - name: "août", - value: 0, - }, - { - name: "sept.", - value: 0, - }, - { - name: "oct.", - value: 0, - }, - { - name: "nov.", - value: 0, - }, - { - name: "déc.", - value: 0, - }, - { - name: "janv.", - value: 0, - }, - { - name: "févr.", - value: 0, - }, - { - name: "mars", - value: 0, - }, - { - name: "avr.", - value: 0, - }, - { - name: "mai", - value: 0, - }, - { - name: "juin", - value: 0, - }, - { - name: "juil.", - value: 0, - }, - ], - usagersCountByMonth: [ - { - name: "août", - value: 0, - }, - { - name: "sept.", - value: 0, - }, - { - name: "oct.", - value: 0, - }, - { - name: "nov.", - value: 0, - }, - { - name: "déc.", - value: 0, - }, - { - name: "janv.", - value: 0, - }, - { - name: "févr.", - value: 0, - }, - { - name: "mars", - value: 0, - }, - { - name: "avr.", - value: 0, - }, - { - name: "mai", - value: 0, - }, - { - name: "juin", - value: 0, - }, - { - name: "juil.", - value: 0, - }, - ], - }; - - expect(response.status).toBe(HttpStatus.OK); - expect(response.body).toEqual(retour); - }); + describe("National page", () => { + it("Should display stats for France", async () => { + const response = await supertest(context.app.getHttpServer()).get( + "/stats/public-stats" + ); + + const retour: PublicStats = { + usagersCount: 20, + usersCount: 10, + structuresCount: 5, + courrierInCount: 5, + courrierOutCount: 2, + structuresCountByRegion: [ + { count: 2, region: "52" }, + { count: 1, region: "03" }, + { count: 1, region: "11" }, + { count: 1, region: "75" }, + ], + structuresCountByTypeMap: { asso: 2, cias: 2, ccas: 1, mairie: 0 }, + interactionsCountByMonth: [ + { name: "août", value: 0 }, + { name: "sept.", value: 0 }, + { name: "oct.", value: 0 }, + { name: "nov.", value: 0 }, + { name: "déc.", value: 0 }, + { name: "janv.", value: 0 }, + { name: "févr.", value: 0 }, + { name: "mars", value: 0 }, + { name: "avr.", value: 0 }, + { name: "mai", value: 0 }, + { name: "juin", value: 0 }, + { name: "juil.", value: 0 }, + ], + usagersCountByMonth: [ + { name: "août", value: 0 }, + { name: "sept.", value: 0 }, + { name: "oct.", value: 0 }, + { name: "nov.", value: 4 }, + { name: "déc.", value: 0 }, + { name: "janv.", value: 0 }, + { name: "févr.", value: 0 }, + { name: "mars", value: 1 }, + { name: "avr.", value: 0 }, + { name: "mai", value: 0 }, + { name: "juin", value: 0 }, + { name: "juil.", value: 0 }, + ], + }; + + expect(response.status).toBe(HttpStatus.OK); + expect(response.body).toEqual(retour); + }); - it("should be defined", () => { - expect(controller).toBeDefined(); + it("Should display stats for 'Pays de la Loire'", async () => { + const response = await supertest(context.app.getHttpServer()).get( + "/stats/public-stats/52" + ); + + const retour: PublicStats = { + usagersCount: 0, + usersCount: 5, + structuresCount: 2, + courrierInCount: 0, + courrierOutCount: 0, + structuresCountByRegion: [ + { + count: 2, + region: "44", + }, + ], + structuresCountByTypeMap: { + asso: 2, + cias: 0, + ccas: 0, + mairie: 0, + }, + interactionsCountByMonth: [ + { + name: "août", + value: 0, + }, + { + name: "sept.", + value: 0, + }, + { + name: "oct.", + value: 0, + }, + { + name: "nov.", + value: 0, + }, + { + name: "déc.", + value: 0, + }, + { + name: "janv.", + value: 0, + }, + { + name: "févr.", + value: 0, + }, + { + name: "mars", + value: 0, + }, + { + name: "avr.", + value: 0, + }, + { + name: "mai", + value: 0, + }, + { + name: "juin", + value: 0, + }, + { + name: "juil.", + value: 0, + }, + ], + usagersCountByMonth: [ + { + name: "août", + value: 0, + }, + { + name: "sept.", + value: 0, + }, + { + name: "oct.", + value: 0, + }, + { + name: "nov.", + value: 0, + }, + { + name: "déc.", + value: 0, + }, + { + name: "janv.", + value: 0, + }, + { + name: "févr.", + value: 0, + }, + { + name: "mars", + value: 0, + }, + { + name: "avr.", + value: 0, + }, + { + name: "mai", + value: 0, + }, + { + name: "juin", + value: 0, + }, + { + name: "juil.", + value: 0, + }, + ], + }; + + expect(response.status).toBe(HttpStatus.OK); + expect(response.body).toEqual(retour); + }); }); }); diff --git a/packages/backend/src/stats/services/publicStats.service.ts b/packages/backend/src/stats/services/publicStats.service.ts index ea0adfbc7a..3c027a6f73 100644 --- a/packages/backend/src/stats/services/publicStats.service.ts +++ b/packages/backend/src/stats/services/publicStats.service.ts @@ -24,7 +24,11 @@ export class PublicStatsService implements OnModuleInit { onModuleInit() { // Inutile de rafraichir le cache sur le pod des tâches CRON - if (domifaConfig().envId !== "local" && !isCronEnabled()) { + if ( + domifaConfig().envId !== "local" && + domifaConfig().envId !== "test" && + !isCronEnabled() + ) { this.updateAllStatsCache(); } }