From 3fa951927685b1cd6bb5c6e1ec44e128a6dbae97 Mon Sep 17 00:00:00 2001 From: dlamande Date: Wed, 10 Jan 2024 16:24:21 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20il=20est=20possible=20maintenant=20de?= =?UTF-8?q?=20poser=20des=20questions=20personnelles=20aux=20usag=C3=A9s?= =?UTF-8?q?=20via=20les=20missions=20(#246)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: octo-guic --- .gitignore | 1 + playwright-report/index.html | 62 ----------------- src/components/custom/ScoreHeader.vue | 4 ++ src/components/pages/PageQuestionKyc.vue | 6 +- src/kyc/envoyerReponseUsecase.ts | 8 ++- src/shell/interactionType.ts | 2 +- .../adapters/toDoList.presenter.impl.ts | 2 +- src/toDoList/toDoListEventBusImpl.ts | 2 + tests/e2e/authentification.spec.ts | 68 +----------------- tests/e2e/kyc.spec.ts | 39 +++++++++++ tests/e2e/utils/connecterUtilisateurs.ts | 69 +++++++++++++++++++ tests/kyc/envoyerReponse.usecase.spec.ts | 8 ++- tests/toDoList/spyTodoListEventBus.ts | 1 + 13 files changed, 139 insertions(+), 133 deletions(-) delete mode 100644 playwright-report/index.html create mode 100644 tests/e2e/kyc.spec.ts create mode 100644 tests/e2e/utils/connecterUtilisateurs.ts diff --git a/.gitignore b/.gitignore index d0fa9e5ef..67949df83 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ debug.log* /yarn-error.log* /_reports /build +/playwright-report # Ignore miscellaneous .DS_Store diff --git a/playwright-report/index.html b/playwright-report/index.html deleted file mode 100644 index d189fd145..000000000 --- a/playwright-report/index.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - Playwright Test Report - - - - -
- - - - \ No newline at end of file diff --git a/src/components/custom/ScoreHeader.vue b/src/components/custom/ScoreHeader.vue index 499d60c62..609ac1367 100644 --- a/src/components/custom/ScoreHeader.vue +++ b/src/components/custom/ScoreHeader.vue @@ -96,6 +96,9 @@ ToDoListEventBusImpl.getInstance().subscribe(subscriberName, ToDoListEvent.TODO_QUIZ_ETE_TERMINE, () => { mettreAJourLeScore(); }); + ToDoListEventBusImpl.getInstance().subscribe(subscriberName, ToDoListEvent.TODO_KYC_A_ETE_REPONDU, () => { + mettreAJourLeScore(); + }); }); onUnmounted(() => { @@ -103,6 +106,7 @@ ToDoListEventBusImpl.getInstance().unsubscribe(subscriberName, ToDoListEvent.TODO_ARTICLE_A_ETE_LU); ToDoListEventBusImpl.getInstance().unsubscribe(subscriberName, ToDoListEvent.TODO_A_ETE_TERMINEE); ToDoListEventBusImpl.getInstance().unsubscribe(subscriberName, ToDoListEvent.TODO_QUIZ_ETE_TERMINE); + ToDoListEventBusImpl.getInstance().unsubscribe(subscriberName, ToDoListEvent.TODO_KYC_A_ETE_REPONDU); }); diff --git a/src/components/pages/PageQuestionKyc.vue b/src/components/pages/PageQuestionKyc.vue index 95142be4f..f065f6ee7 100644 --- a/src/components/pages/PageQuestionKyc.vue +++ b/src/components/pages/PageQuestionKyc.vue @@ -55,6 +55,7 @@ import InputCheckbox from '@/components/custom/InputCheckbox.vue'; import BoutonRadio from '@/components/custom/BoutonRadio.vue'; import KYCFin from '@/components/custom/KYC/KYCFin.vue'; + import { ToDoListEventBusImpl } from '@/toDoList/toDoListEventBusImpl'; const route = useRoute(); const questionId = Array.isArray(route.params.id) ? route.params.id[0] : route.params.id; @@ -74,7 +75,10 @@ ); const validerLaReponse = async () => { - const envoyerReponseUsecase = new EnvoyerReponseUsecase(new QuestionRepositoryAxios()); + const envoyerReponseUsecase = new EnvoyerReponseUsecase( + new QuestionRepositoryAxios(), + ToDoListEventBusImpl.getInstance() + ); envoyerReponseUsecase.execute(utilisateurId, questionId, [reponse.value].flat()); reponseAEteDonnee.value = true; }; diff --git a/src/kyc/envoyerReponseUsecase.ts b/src/kyc/envoyerReponseUsecase.ts index f073cc581..b4e7b1bde 100644 --- a/src/kyc/envoyerReponseUsecase.ts +++ b/src/kyc/envoyerReponseUsecase.ts @@ -1,9 +1,15 @@ import { QuestionRepository } from '@/kyc/ports/question.repository'; +import { EventBus } from '@/shell/eventBus'; +import { ToDoListEvent } from '@/toDoList/toDoListEventBusImpl'; export class EnvoyerReponseUsecase { - constructor(private readonly questionRepository: QuestionRepository) {} + constructor( + private readonly questionRepository: QuestionRepository, + private readonly eventBus: EventBus + ) {} async execute(utilisateurId: string, questionId: string, reponse: string[]): Promise { await this.questionRepository.envoyerReponse(utilisateurId, questionId, reponse); + this.eventBus.publish(ToDoListEvent.TODO_KYC_A_ETE_REPONDU); } } diff --git a/src/shell/interactionType.ts b/src/shell/interactionType.ts index 7ec9881fa..ef68f8262 100644 --- a/src/shell/interactionType.ts +++ b/src/shell/interactionType.ts @@ -1,7 +1,7 @@ export enum InteractionType { QUIZ = 'quizz', ARTICLE = 'article', - KYC = 'KYC', + KYC = 'kyc', SUIVIDUJOUR = 'suivi_du_jour', AIDE = 'aide', COMPTE = 'profile', diff --git a/src/toDoList/adapters/toDoList.presenter.impl.ts b/src/toDoList/adapters/toDoList.presenter.impl.ts index c6b6f00a6..11256c3b2 100644 --- a/src/toDoList/adapters/toDoList.presenter.impl.ts +++ b/src/toDoList/adapters/toDoList.presenter.impl.ts @@ -64,7 +64,7 @@ export class ToDoListPresenterImpl implements ToDoListPresenter { case InteractionType.ARTICLE: return `/article/${todo.titre}`; case InteractionType.KYC: - return ''; + return `/kyc/${todo.contentId}`; case InteractionType.SUIVIDUJOUR: return '/coach/suivi-du-jour'; case InteractionType.COMPTE: diff --git a/src/toDoList/toDoListEventBusImpl.ts b/src/toDoList/toDoListEventBusImpl.ts index dca8625e1..4b2b58641 100644 --- a/src/toDoList/toDoListEventBusImpl.ts +++ b/src/toDoList/toDoListEventBusImpl.ts @@ -5,6 +5,7 @@ export enum ToDoListEvent { TODO_ARTICLE_A_ETE_LU, TODO_A_ETE_TERMINEE, TODO_QUIZ_ETE_TERMINE, + TODO_KYC_A_ETE_REPONDU, } export class ToDoListEventBusImpl extends EventBus { @@ -15,6 +16,7 @@ export class ToDoListEventBusImpl extends EventBus { [ToDoListEvent.TODO_ARTICLE_A_ETE_LU]: [], [ToDoListEvent.TODO_A_ETE_TERMINEE]: [], [ToDoListEvent.TODO_QUIZ_ETE_TERMINE]: [], + [ToDoListEvent.TODO_KYC_A_ETE_REPONDU]: [], }; private constructor() { super(); diff --git a/tests/e2e/authentification.spec.ts b/tests/e2e/authentification.spec.ts index 763826c96..f351d7030 100644 --- a/tests/e2e/authentification.spec.ts +++ b/tests/e2e/authentification.spec.ts @@ -1,70 +1,8 @@ -import { test, expect, chromium } from '@playwright/test'; +import { test, expect } from '@playwright/test'; +import { connecterUtilisateur } from './utils/connecterUtilisateurs'; test('has title', async () => { - const browser = await chromium.launch(); - const context = await browser.newContext(); - const page = await context.newPage(); - - await page.route('https://agir-back-dev.osc-fr1.scalingo.io/utilisateurs/login', route => { - route.fulfill({ - status: 200, - contentType: 'application/json', - body: JSON.stringify({ - utilisateur: { - id: 'wojtek', - nom: 'WOJCIK', - prenom: 'Wojtek', - email: 'ww@w.com', - code_postal: '91120', - commune: 'PALAISEAU', - revenu_fiscal: null, - nombre_de_parts_fiscales: 2.5, - quizzProfile: { - climat: { - level: 1, - isCompleted: false, - }, - dechet: { - level: 1, - isCompleted: false, - }, - loisir: { - level: 1, - isCompleted: false, - }, - logement: { - level: 2, - isCompleted: false, - }, - transport: { - level: 1, - isCompleted: false, - }, - alimentation: { - level: 1, - isCompleted: false, - }, - consommation: { - level: 1, - isCompleted: false, - }, - }, - created_at: '2023-12-20T16:28:07.766Z', - fonctionnalites_debloquees: ['aides', 'services', 'recommandations'], - }, - token: - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dGlsaXNhdGV1cklkIjoid29qdGVrIiwiaWF0IjoxNzAzMTU1MzM2LCJleHAiOjE3MDU3NDczMzZ9.bJOxx98NUoYDq3e0mXKgv-YjAq-ZfSRc4S05bgwvKdA', - }), - }); - }); - - await page.goto('/authentification'); - - await page.fill('#email', 'exemple@domaine.com'); - await page.fill('#password-input', ''); - - await page.getByRole('button', { name: 'Se connecter' }).click(); - await page.waitForURL('/coach/'); + const page = await connecterUtilisateur(); await expect(page).toHaveTitle('Agir ! - Coach'); }); diff --git a/tests/e2e/kyc.spec.ts b/tests/e2e/kyc.spec.ts new file mode 100644 index 000000000..d64e54bae --- /dev/null +++ b/tests/e2e/kyc.spec.ts @@ -0,0 +1,39 @@ +import { test, expect, Page } from '@playwright/test'; +import { connecterUtilisateur } from './utils/connecterUtilisateurs'; + +let page: Page; + +test.beforeAll(async () => { + page = await connecterUtilisateur(); + + await page.route('https://agir-back-dev.osc-fr1.scalingo.io/kyc/1', route => { + route.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ + id: '1', + question: 'Comment avez vous connu le service ?', + categorie: 'service', + points: 10, + type: 'libre', + is_NGC: false, + }), + }); + }); + + await page.goto('/kyc/1'); +}); + +test('doit afficher le bon title et titre', async () => { + await expect(page).toHaveTitle('Agir !'); + await expect(page.getByRole('heading', { level: 1 })).toHaveText('Question pour mieux vous connaître'); +}); + +test('reponse a un kyc doit afficher "Merci pour votre réponse"', async () => { + await page.fill('#reponse', 'Ma réponse, lorem ipsum dolor'); + await page.getByRole('button', { name: 'Valider' }).click(); + + expect(await page.textContent('#app > div > main > div > div > div > span.fr-display--xs.fr-mb-2w')).toBe( + 'Merci pour votre réponse !' + ); +}); diff --git a/tests/e2e/utils/connecterUtilisateurs.ts b/tests/e2e/utils/connecterUtilisateurs.ts new file mode 100644 index 000000000..6549277e1 --- /dev/null +++ b/tests/e2e/utils/connecterUtilisateurs.ts @@ -0,0 +1,69 @@ +import { Page, chromium } from '@playwright/test'; + +export const connecterUtilisateur: () => Promise = async () => { + const browser = await chromium.launch(); + const context = await browser.newContext(); + const page = await context.newPage(); + + await page.route('https://agir-back-dev.osc-fr1.scalingo.io/utilisateurs/login', route => { + route.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ + utilisateur: { + id: 'wojtek', + nom: 'WOJCIK', + prenom: 'Wojtek', + email: 'ww@w.com', + code_postal: '91120', + commune: 'PALAISEAU', + revenu_fiscal: null, + nombre_de_parts_fiscales: 2.5, + quizzProfile: { + climat: { + level: 1, + isCompleted: false, + }, + dechet: { + level: 1, + isCompleted: false, + }, + loisir: { + level: 1, + isCompleted: false, + }, + logement: { + level: 2, + isCompleted: false, + }, + transport: { + level: 1, + isCompleted: false, + }, + alimentation: { + level: 1, + isCompleted: false, + }, + consommation: { + level: 1, + isCompleted: false, + }, + }, + created_at: '2023-12-20T16:28:07.766Z', + fonctionnalites_debloquees: ['aides', 'services', 'recommandations'], + }, + token: + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dGlsaXNhdGV1cklkIjoid29qdGVrIiwiaWF0IjoxNzAzMTU1MzM2LCJleHAiOjE3MDU3NDczMzZ9.bJOxx98NUoYDq3e0mXKgv-YjAq-ZfSRc4S05bgwvKdA', + }), + }); + }); + + await page.goto('/authentification'); + await page.fill('#email', 'exemple@domaine.com'); + await page.fill('#password-input', ''); + + await page.getByRole('button', { name: 'Se connecter' }).click(); + await page.waitForURL('/coach/'); + + return page; +}; diff --git a/tests/kyc/envoyerReponse.usecase.spec.ts b/tests/kyc/envoyerReponse.usecase.spec.ts index 6b3796376..1a0668f9a 100644 --- a/tests/kyc/envoyerReponse.usecase.spec.ts +++ b/tests/kyc/envoyerReponse.usecase.spec.ts @@ -1,13 +1,16 @@ import { EnvoyerReponseUsecase } from '@/kyc/envoyerReponseUsecase'; import { SpyQuestionRepository } from './adapters/question.repository.spy'; +import { SpyToDoListEventBus } from '../toDoList/spyTodoListEventBus'; +import { expect } from 'vitest'; +import { ToDoListEvent } from '@/toDoList/toDoListEventBusImpl'; describe("Fichier de tests pour envoyer la réponse d'une question KYC", () => { it("En donnant un id d'utilisateur, l'id de la question KYC et la réponse doit appeler le back pour sauvegarder la réponse", async () => { // GIVEN const questionRepository = new SpyQuestionRepository(); - + const spyEventBus = new SpyToDoListEventBus(); // WHEN - const usecase = new EnvoyerReponseUsecase(questionRepository); + const usecase = new EnvoyerReponseUsecase(questionRepository, spyEventBus); await usecase.execute('utilisateurId', 'questionId', ['Ma réponse, lorem ipsum dolor']); // THEN @@ -17,5 +20,6 @@ describe("Fichier de tests pour envoyer la réponse d'une question KYC", () => { questionId: 'questionId', reponse: ['Ma réponse, lorem ipsum dolor'], }); + expect(spyEventBus.eventName).toEqual(ToDoListEvent.TODO_KYC_A_ETE_REPONDU); }); }); diff --git a/tests/toDoList/spyTodoListEventBus.ts b/tests/toDoList/spyTodoListEventBus.ts index e31e31e45..1067b3d64 100644 --- a/tests/toDoList/spyTodoListEventBus.ts +++ b/tests/toDoList/spyTodoListEventBus.ts @@ -17,5 +17,6 @@ export class SpyToDoListEventBus extends EventBus { [ToDoListEvent.TODO_ARTICLE_A_ETE_LU]: [], [ToDoListEvent.TODO_A_ETE_TERMINEE]: [], [ToDoListEvent.TODO_QUIZ_ETE_TERMINE]: [], + [ToDoListEvent.TODO_KYC_A_ETE_REPONDU]: [], }; }