Skip to content

Commit

Permalink
feat: il est possible maintenant de poser des questions personnelles …
Browse files Browse the repository at this point in the history
…aux usagés via les missions (#246)

Co-authored-by: octo-guic <[email protected]>
  • Loading branch information
dlamande and OCTO-GUIC authored Jan 10, 2024
1 parent 50e5c51 commit 3fa9519
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 133 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ debug.log*
/yarn-error.log*
/_reports
/build
/playwright-report

# Ignore miscellaneous
.DS_Store
Expand Down
62 changes: 0 additions & 62 deletions playwright-report/index.html

This file was deleted.

4 changes: 4 additions & 0 deletions src/components/custom/ScoreHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@
ToDoListEventBusImpl.getInstance().subscribe(subscriberName, ToDoListEvent.TODO_QUIZ_ETE_TERMINE, () => {
mettreAJourLeScore();
});
ToDoListEventBusImpl.getInstance().subscribe(subscriberName, ToDoListEvent.TODO_KYC_A_ETE_REPONDU, () => {
mettreAJourLeScore();
});
});
onUnmounted(() => {
ToDoListEventBusImpl.getInstance().unsubscribe(subscriberName, ToDoListEvent.TODO_POINTS_ONT_ETE_RECUPERE);
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);
});
</script>

Expand Down
6 changes: 5 additions & 1 deletion src/components/pages/PageQuestionKyc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down
8 changes: 7 additions & 1 deletion src/kyc/envoyerReponseUsecase.ts
Original file line number Diff line number Diff line change
@@ -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<ToDoListEvent>
) {}

async execute(utilisateurId: string, questionId: string, reponse: string[]): Promise<void> {
await this.questionRepository.envoyerReponse(utilisateurId, questionId, reponse);
this.eventBus.publish(ToDoListEvent.TODO_KYC_A_ETE_REPONDU);
}
}
2 changes: 1 addition & 1 deletion src/shell/interactionType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export enum InteractionType {
QUIZ = 'quizz',
ARTICLE = 'article',
KYC = 'KYC',
KYC = 'kyc',
SUIVIDUJOUR = 'suivi_du_jour',
AIDE = 'aide',
COMPTE = 'profile',
Expand Down
2 changes: 1 addition & 1 deletion src/toDoList/adapters/toDoList.presenter.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/toDoList/toDoListEventBusImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToDoListEvent> {
Expand All @@ -15,6 +16,7 @@ export class ToDoListEventBusImpl extends EventBus<ToDoListEvent> {
[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();
Expand Down
68 changes: 3 additions & 65 deletions tests/e2e/authentification.spec.ts
Original file line number Diff line number Diff line change
@@ -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: '[email protected]',
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', '[email protected]');
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');
});
39 changes: 39 additions & 0 deletions tests/e2e/kyc.spec.ts
Original file line number Diff line number Diff line change
@@ -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 !'
);
});
69 changes: 69 additions & 0 deletions tests/e2e/utils/connecterUtilisateurs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Page, chromium } from '@playwright/test';

export const connecterUtilisateur: () => Promise<Page> = 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: '[email protected]',
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', '[email protected]');
await page.fill('#password-input', '');

await page.getByRole('button', { name: 'Se connecter' }).click();
await page.waitForURL('/coach/');

return page;
};
8 changes: 6 additions & 2 deletions tests/kyc/envoyerReponse.usecase.spec.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
});
});
1 change: 1 addition & 0 deletions tests/toDoList/spyTodoListEventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export class SpyToDoListEventBus extends EventBus<ToDoListEvent> {
[ToDoListEvent.TODO_ARTICLE_A_ETE_LU]: [],
[ToDoListEvent.TODO_A_ETE_TERMINEE]: [],
[ToDoListEvent.TODO_QUIZ_ETE_TERMINE]: [],
[ToDoListEvent.TODO_KYC_A_ETE_REPONDU]: [],
};
}

0 comments on commit 3fa9519

Please sign in to comment.