Skip to content

Commit

Permalink
feat(cms): scinder la partie FAQ (#2051)
Browse files Browse the repository at this point in the history
* feat(cms): scinder la FAQ du contexte CMS

* feat(cms): clean type

* feat(faq): retour review 1

* feat(faq): retour review 2

* feat(faq): deplacer les info necessaire dans infra

* feat(faq): linter

* feat(faq): ne pas passer de mapper au strapi service

* feat(faq): refactor import relatif et accent mapper

---------

Co-authored-by: Suxue LI <[email protected]>
  • Loading branch information
juliebrunetto83 and suli-octo authored Oct 27, 2023
1 parent 14d795e commit 3fe053e
Show file tree
Hide file tree
Showing 33 changed files with 439 additions and 264 deletions.
7 changes: 4 additions & 3 deletions src/pages/faq/[id].page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import { render } from '@testing-library/react';

import { mockUseRouter } from '~/client/components/useRouter.mock';
import ConsulterArticlePage from '~/pages/faq/[id].page';
import { Question } from '~/server/cms/domain/FAQ.type';
import { FAQ } from '~/server/faq/domain/FAQ';
import { aQuestionEtReponse } from '~/server/faq/domain/FAQ.fixture';

describe('<ConsulterArticlePage />', () => {
it('n‘a pas de défaut d‘accessibilité', async () => {
const faqRéponse: Question.QuestionRéponse = {
const faqRéponse: FAQ.QuestionEtReponse = aQuestionEtReponse({
contenu: 'Contenu de la réponse',
problématique: 'Problématique de la question',
slug: 'slug-de-la-question',
};
});

mockUseRouter({});

Expand Down
15 changes: 7 additions & 8 deletions src/pages/faq/[id].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ import React from 'react';
import { ConsulterArticle } from '~/client/components/features/Article/ConsulterArticle';
import { Head } from '~/client/components/head/Head';
import { Article } from '~/server/cms/domain/article';
import {
Question,
QuestionSlug,
} from '~/server/cms/domain/FAQ.type';
import { PageContextParamsException } from '~/server/exceptions/pageContextParams.exception';
import {
FAQ,
} from '~/server/faq/domain/FAQ';
import { removeUndefinedKeys } from '~/server/removeUndefinedKeys.utils';
import { dependencies } from '~/server/start';

type ConsulterFAQRéponsePageProps = {
faqRéponse: Question.QuestionRéponse
faqRéponse: FAQ.QuestionEtReponse
}

interface FAQRéponse extends ParsedUrlQuery {
id: QuestionSlug
id: FAQ.Slug
}

const faqRéponseMapToArticleFormat = (faqRéponse: Question.QuestionRéponse): Article => {
const faqRéponseMapToArticleFormat = (faqRéponse: FAQ.QuestionEtReponse): Article => {
return {
contenu: faqRéponse.contenu,
titre: faqRéponse.problématique,
Expand Down Expand Up @@ -49,7 +48,7 @@ export async function getStaticProps(context: GetStaticPropsContext<FAQRéponse>
}

const { id } = context.params;
const faqRéponse = await dependencies.cmsDependencies.consulterFAQ.handle(id);
const faqRéponse = await dependencies.faqDependencies.consulterFAQ.handle(id);

if (faqRéponse.instance === 'failure') {
return { notFound: true, revalidate: 1 };
Expand Down
30 changes: 16 additions & 14 deletions src/pages/faq/index.page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import { mockSmallScreen } from '~/client/components/window.mock';
import { DependenciesProvider } from '~/client/context/dependenciesContainer.context';
import { anAnalyticsService } from '~/client/services/analytics/analytics.service.fixture';
import FaqPage from '~/pages/faq/index.page';
import { Question } from '~/server/cms/domain/FAQ.type';
import { FAQ } from '~/server/faq/domain/FAQ';
import { aQuestion } from '~/server/faq/domain/FAQ.fixture';

const listeDeQuestionRéponse: Array<Question> = [
{
const listeDeQuestionResultat: Array<FAQ.Question> = [
aQuestion({
problématique: 'Comment constituer un dossier locatif ?',
slug: 'Comment-constituer-un-dossier-locatif-?',
}, {
}),
aQuestion({
problématique: 'Je n’arrive pas à candidater à une offre d’emploi',
slug: 'Je-n’arrive-pas-à-candidater-à-une-offre-d’emploi',
},
}),
];

describe('Page FAQ', () => {
Expand All @@ -41,7 +43,7 @@ describe('Page FAQ', () => {

const { container } = render(
<DependenciesProvider analyticsService={analyticsService}>
<FaqPage listeDeQuestionRéponse={listeDeQuestionRéponse}/>
<FaqPage listeDeQuestionRéponse={listeDeQuestionResultat}/>
</DependenciesProvider>,
);

Expand All @@ -52,7 +54,7 @@ describe('Page FAQ', () => {
const analyticsService = anAnalyticsService();
render(
<DependenciesProvider analyticsService={analyticsService}>
<FaqPage listeDeQuestionRéponse={listeDeQuestionRéponse}/>
<FaqPage listeDeQuestionRéponse={listeDeQuestionResultat}/>
</DependenciesProvider>,
);

Expand All @@ -67,7 +69,7 @@ describe('Page FAQ', () => {
it('affiche le titre de la page', async () => {
render(
<DependenciesProvider analyticsService={anAnalyticsService()}>
<FaqPage listeDeQuestionRéponse={listeDeQuestionRéponse}/>
<FaqPage listeDeQuestionRéponse={listeDeQuestionResultat}/>
</DependenciesProvider>);

const title = await screen.findByRole('heading', { level: 1 });
Expand All @@ -77,7 +79,7 @@ describe('Page FAQ', () => {
it('affiche le sous titre de la page', async () => {
render(
<DependenciesProvider analyticsService={anAnalyticsService()}>
<FaqPage listeDeQuestionRéponse={listeDeQuestionRéponse}/>
<FaqPage listeDeQuestionRéponse={listeDeQuestionResultat}/>
</DependenciesProvider>);

const sousTitre = await screen.findByRole('heading', { level: 2 });
Expand All @@ -88,7 +90,7 @@ describe('Page FAQ', () => {
it('affiche une liste de question', async () => {
render(
<DependenciesProvider analyticsService={anAnalyticsService()}>
<FaqPage listeDeQuestionRéponse={listeDeQuestionRéponse}/>
<FaqPage listeDeQuestionRéponse={listeDeQuestionResultat}/>
</DependenciesProvider>);

const listeDeQuestion = screen.getByRole('list');
Expand All @@ -101,16 +103,16 @@ describe('Page FAQ', () => {
it('affiche les questions sous forme de lien', async () => {
render(
<DependenciesProvider analyticsService={anAnalyticsService()}>
<FaqPage listeDeQuestionRéponse={listeDeQuestionRéponse}/>
<FaqPage listeDeQuestionRéponse={listeDeQuestionResultat}/>
</DependenciesProvider>);

const listeDeQuestion = screen.getByRole('list');
const questions = within(listeDeQuestion).getAllByRole('listitem');

questions.forEach((question, index) => {
const lien = within(question).getByRole('link');
expect(lien).toHaveTextContent(listeDeQuestionRéponse[index].problématique);
expect(lien).toHaveAttribute('href', `/faq/${listeDeQuestionRéponse[index].slug}`);
expect(lien).toHaveTextContent(listeDeQuestionResultat[index].problématique);
expect(lien).toHaveAttribute('href', `/faq/${listeDeQuestionResultat[index].slug}`);
});
});

Expand All @@ -131,7 +133,7 @@ describe('Page FAQ', () => {
const analyticsService = anAnalyticsService();
render(
<DependenciesProvider analyticsService={analyticsService}>
<FaqPage listeDeQuestionRéponse={listeDeQuestionRéponse}/>
<FaqPage listeDeQuestionRéponse={listeDeQuestionResultat}/>
</DependenciesProvider>,
);

Expand Down
6 changes: 3 additions & 3 deletions src/pages/faq/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { LinkStyledAsButtonWithIcon } from '~/client/components/ui/LinkStyledAsB
import useAnalytics from '~/client/hooks/useAnalytics';
import analytics from '~/pages/faq/index.analytics';
import styles from '~/pages/faq/index.module.scss';
import { Question } from '~/server/cms/domain/FAQ.type';
import { FAQ } from '~/server/faq/domain/FAQ';
import { dependencies } from '~/server/start';

type FaqPageProps = {
listeDeQuestionRéponse: Array<Question>
listeDeQuestionRéponse: Array<FAQ.Question>
}

const MAIL_TO = '[email protected]';
Expand Down Expand Up @@ -53,7 +53,7 @@ export default function FaqPage({ listeDeQuestionRéponse }: FaqPageProps) {
}

export async function getStaticProps(): Promise<GetStaticPropsResult<FaqPageProps>> {
const listeDeQuestionRéponse = await dependencies.cmsDependencies.listerQuestionsFAQ.handle();
const listeDeQuestionRéponse = await dependencies.faqDependencies.listerQuestionsFAQ.handle();
if (listeDeQuestionRéponse.instance === 'failure') {
return { notFound: true };
}
Expand Down
6 changes: 0 additions & 6 deletions src/server/cms/configuration/dependencies.container.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { CmsRepository } from '~/server/cms/domain/cms.repository';
import { ConsulterAnnonceLogementUseCase } from '~/server/cms/useCases/consulterAnnonceLogement.useCase';
import { ConsulterArticleUseCase } from '~/server/cms/useCases/consulterArticle.useCase';
import { ConsulterFAQUseCase } from '~/server/cms/useCases/consulterFAQ.useCase';
import { ConsulterMentionObligatoireUseCase } from '~/server/cms/useCases/consulterMentionObligatoire.useCase';
import { ConsulterOffreStageUseCase } from '~/server/cms/useCases/consulterOffreStage.useCase';
import { enregistrerOffreDeStageUseCase } from '~/server/cms/useCases/enregistrerOffreDeStage.useCase';
import { ListerFAQUseCase } from '~/server/cms/useCases/listerFAQ.useCase';
import { ListerServicesJeunesUseCase } from '~/server/cms/useCases/listerServicesJeunes.useCase';
import { RécupérerActualitésUseCase } from '~/server/cms/useCases/récupérerActualités.useCase';
import { RécupérerMesuresEmployeursUseCase } from '~/server/cms/useCases/récupérerMesuresEmployeurs.useCase';
Expand All @@ -17,12 +15,10 @@ import { ConfigurationService } from '~/server/services/configuration.service';
export interface CmsDependencies {
consulterAnnonceLogement: ConsulterAnnonceLogementUseCase
consulterArticle: ConsulterArticleUseCase
consulterFAQ: ConsulterFAQUseCase
consulterMentionObligatoire: ConsulterMentionObligatoireUseCase
consulterOffreStage: ConsulterOffreStageUseCase
enregistrerOffreDeStage: enregistrerOffreDeStageUseCase
duréeDeValiditéEnSecondes: () => number
listerQuestionsFAQ: ListerFAQUseCase
récupérerActualités: RécupérerActualitésUseCase
listerServicesJeunes: ListerServicesJeunesUseCase
récupérerMesuresEmployeurs: RécupérerMesuresEmployeursUseCase
Expand All @@ -38,12 +34,10 @@ export function cmsDependenciesContainer(cmsRepository: CmsRepository, configura
return {
consulterAnnonceLogement: new ConsulterAnnonceLogementUseCase(cmsRepository),
consulterArticle: new ConsulterArticleUseCase(cmsRepository),
consulterFAQ: new ConsulterFAQUseCase(cmsRepository),
consulterMentionObligatoire: new ConsulterMentionObligatoireUseCase(cmsRepository),
consulterOffreStage: new ConsulterOffreStageUseCase(cmsRepository),
duréeDeValiditéEnSecondes: () => duréeDeValiditéEnSecondes,
enregistrerOffreDeStage: new enregistrerOffreDeStageUseCase(cmsRepository),
listerQuestionsFAQ: new ListerFAQUseCase(cmsRepository),
listerServicesJeunes: new ListerServicesJeunesUseCase(cmsRepository),
recupererVideosCampagneApprentissage: new RecupererVideosCampagneApprentissageUseCase(cmsRepository),
récupérerActualités: new RécupérerActualitésUseCase(cmsRepository),
Expand Down
45 changes: 0 additions & 45 deletions src/server/cms/domain/FAQ.fixture.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/server/cms/domain/FAQ.type.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/server/cms/domain/cms.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Actualité } from '~/server/cms/domain/actualité';
import { AnnonceDeLogement } from '~/server/cms/domain/annonceDeLogement.type';
import { Article, ArticleSlug } from '~/server/cms/domain/article';
import { Question, QuestionSlug } from '~/server/cms/domain/FAQ.type';
import { MentionsObligatoires } from '~/server/cms/domain/mentionsObligatoires';
import { MesureEmployeur } from '~/server/cms/domain/mesureEmployeur';
import { OffreDeStage, OffreDeStageDepot } from '~/server/cms/domain/offreDeStage.type';
Expand All @@ -12,16 +11,12 @@ import { Either } from '~/server/errors/either';
export interface CmsRepository {
getActualitéList(): Promise<Either<Actualité[]>>

getAllFAQ(): Promise<Either<Array<Question>>>

getAnnonceDeLogementBySlug(slug: string): Promise<Either<AnnonceDeLogement>>

getArticleBySlug(slug: ArticleSlug): Promise<Either<Article>>

getServiceJeuneList(): Promise<Either<Array<ServiceJeune>>>

getFAQBySlug(slug: QuestionSlug): Promise<Either<Question.QuestionRéponse>>

getMentionObligatoire(mentionsObligatoires: MentionsObligatoires): Promise<Either<Article>>

getMesuresEmployeurs(): Promise<Either<MesureEmployeur[]>>
Expand All @@ -34,8 +29,6 @@ export interface CmsRepository {

listAllArticleSlug(): Promise<Either<Array<string>>>

listAllFAQSlug(): Promise<Either<Array<string>>>

listAllOffreDeStageSlug(): Promise<Either<Array<string>>>

saveOffreDeStage(offre: OffreDeStageDepot): Promise<Either<void>>
Expand Down
17 changes: 0 additions & 17 deletions src/server/cms/infra/repositories/strapi.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { v4 as uuidv4 } from 'uuid';
import { Actualité } from '~/server/cms/domain/actualité';
import { AnnonceDeLogement } from '~/server/cms/domain/annonceDeLogement.type';
import { Article } from '~/server/cms/domain/article';
import { Question } from '~/server/cms/domain/FAQ.type';
import { Image } from '~/server/cms/domain/image';
import { MesureEmployeur } from '~/server/cms/domain/mesureEmployeur';
import { Domaines, OffreDeStage, OffreDeStageDepot, SourceDesDonnées } from '~/server/cms/domain/offreDeStage.type';
Expand Down Expand Up @@ -244,21 +243,6 @@ export function mapEnregistrerOffreDeStage(body: OffreDeStageDepot): Strapi.Coll
};
}

export const mapQuestion = (faq: Strapi.CollectionType.FAQ): Question => {
return {
problématique: faq.problematique,
slug: faq.slug,
};
};

export const mapQuestionRéponse = (faq: Strapi.CollectionType.FAQ.Réponse): Question.QuestionRéponse => {
return {
contenu: faq.contenu,
problématique: faq.problematique,
slug: faq.slug,
};
};

export function mapVideoCampagneApprentissage(video: Strapi.CollectionType.VideoCampagneApprentissage): VideoCampagneApprentissage {
const videoIdWithPotentialParams = video.Url.split('v=')[1];
const videoId = videoIdWithPotentialParams.split('&')[0];
Expand All @@ -268,4 +252,3 @@ export function mapVideoCampagneApprentissage(video: Strapi.CollectionType.Video
videoId: videoId,
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import { StrapiRepository } from './strapi.repository';
export function aStrapiCmsRepository(override?: Partial<StrapiRepository>): CmsRepository {
return {
getActualitéList: jest.fn(),
getAllFAQ: jest.fn(),
getAllVideosCampagneApprentissage: jest.fn(),
getAnnonceDeLogementBySlug: jest.fn(),
getArticleBySlug: jest.fn(),
getCollectionType: jest.fn(),
getCollectionTypeDeprecated: jest.fn(),
getFAQBySlug: jest.fn(),
getFirstFromCollectionType: jest.fn(),
getMentionObligatoire: jest.fn(),
getMesuresEmployeurs: jest.fn(),
getOffreDeStageBySlug: jest.fn(),
getServiceJeuneList: jest.fn(),
listAllAnnonceDeLogementSlug: jest.fn(),
listAllArticleSlug: jest.fn(),
listAllFAQSlug: jest.fn(),
listAllOffreDeStageSlug: jest.fn(),
save: jest.fn(),
saveOffreDeStage: jest.fn(),
Expand Down
Loading

0 comments on commit 3fe053e

Please sign in to comment.