Skip to content

Commit

Permalink
feat(cms): clean type
Browse files Browse the repository at this point in the history
  • Loading branch information
juliebrunetto83 committed Sep 28, 2023
1 parent 8745e77 commit faaea38
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 98 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/faq/domain/FAQ';
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
12 changes: 5 additions & 7 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 { PageContextParamsException } from '~/server/exceptions/pageContextParams.exception';
import {
Question,
QuestionSlug,
FAQ,
} from '~/server/faq/domain/FAQ';
import { PageContextParamsException } from '~/server/exceptions/pageContextParams.exception';
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 @@ -60,7 +59,6 @@ export async function getStaticProps(context: GetStaticPropsContext<FAQRéponse>
props: {
faqRéponse: removeUndefinedKeys(result),
},
// TODO (BRUJ 26-09-2023): Que faire de ça ??
revalidate: dependencies.cmsDependencies.duréeDeValiditéEnSecondes(),
};

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/faq/domain/FAQ';
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
5 changes: 2 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/faq/domain/FAQ';
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 @@ -62,7 +62,6 @@ export async function getStaticProps(): Promise<GetStaticPropsResult<FaqPageProp
props: {
listeDeQuestionRéponse: listeDeQuestionRéponse.result,
},
// TODO (BRUJ 26-09-2023): que faire de ça ???
revalidate: dependencies.cmsDependencies.duréeDeValiditéEnSecondes(),
};
}
11 changes: 0 additions & 11 deletions src/server/cms/useCases/consulterFAQ.useCase.ts

This file was deleted.

30 changes: 13 additions & 17 deletions src/server/faq/domain/FAQ.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
import { FAQResponse, Question } from '~/server/faq/domain/FAQ';
import { FAQ,FAQResponseStrapi } from '~/server/faq/domain/FAQ';

export const aStrapiListeDeQuestion = (): Array<FAQResponse.FAQ> => {
return [
aStrapiQuestion(),
aStrapiQuestion({
problematique: 'Je n’arrive pas à candidater à une offre d’emploi',
slug: 'Je n’arrive pas à candidater à une offre d’emploi'.replace(' ', '-'),
}),
];
export const aStrapiQuestionEtReponse = (override?: Partial<FAQResponseStrapi.QuestionEtReponse>): FAQResponseStrapi.QuestionEtReponse => {
return {
contenu: 'mon contenu explicatif',
problematique: 'Comment constituer un dossier locatif ?',
slug: 'Comment-constituer-un-dossier-locatif ?',
...override,
};
};



export const aStrapiQuestion = (override?: Partial<FAQResponse.Réponse>): FAQResponse.Réponse => {
export const aStrapiQuestion = (override?: Partial<FAQResponseStrapi.Question>): FAQResponseStrapi.Question => {
return {
contenu: 'mon contenu explicatif',
problematique: 'Comment constituer un dossier locatif ?',
slug: 'Comment constituer un dossier locatif ?'.replace(' ', '-'),
slug: 'Comment-constituer-un-dossier-locatif ?',
...override,
};
};

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

export const aQuestion = (override?: Partial<Question>): Question => {
export const aQuestion = (override?: Partial<FAQ.Question>): FAQ.Question => {
return {
problématique: 'Comment constituer un dossier locatif ?',
slug: 'question-slug',
...override,
};
};

export const aQuestionRéponse = (override?: Partial<Question.QuestionRéponse>): Question.QuestionRéponse => {
export const aQuestionEtReponse = (override?: Partial<FAQ.QuestionEtReponse>): FAQ.QuestionEtReponse => {
return {
contenu: 'mon contenu explicatif',
problématique: 'Comment constituer un dossier locatif ?',
Expand Down
8 changes: 4 additions & 4 deletions src/server/faq/domain/FAQ.repository.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Either } from '~/server/errors/either';

import { Question, QuestionSlug } from './FAQ';
import { FAQ } from './FAQ';

export interface FAQRepository {
getFAQBySlug(slug: QuestionSlug): Promise<Either<Question.QuestionRéponse>>
getAllFAQ(): Promise<Either<Array<Question>>>
listAllFAQSlug(): Promise<Either<Array<string>>>
getFAQBySlug(slug: FAQ.Slug): Promise<Either<FAQ.QuestionEtReponse>>
getAllFAQ(): Promise<Either<Array<FAQ.Question>>>
listAllFAQSlug(): Promise<Either<Array<FAQ.Slug>>>
}
26 changes: 16 additions & 10 deletions src/server/faq/domain/FAQ.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
export type QuestionSlug = string
export namespace FAQ {

export namespace Question {
export interface QuestionRéponse extends Question {
export type Slug = string

export interface Question {
problématique: string
slug: FAQ.Slug
}

export interface QuestionEtReponse extends Question {
contenu: string
}
}

export interface Question {
problématique: string
slug: QuestionSlug
}

export namespace FAQResponseStrapi {

export interface QuestionSlug {
slug: string
}

export namespace FAQResponse {
export interface FAQ {
export interface Question {
problematique: string
slug: string
}

export interface Réponse extends FAQ {
export interface QuestionEtReponse extends Question {
contenu: string
}
}
18 changes: 10 additions & 8 deletions src/server/faq/infra/strapiFAQ.mapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
* @jest-environment jsdom
*/

import { aQuestion, aQuestionRéponse, aStrapiQuestion } from '~/server/faq/domain/FAQ.fixture';
import {
aQuestion,
aQuestionEtReponse,
aStrapiQuestion,
aStrapiQuestionEtReponse,
} from '~/server/faq/domain/FAQ.fixture';
import { flatMapSlug, mapQuestion, mapQuestionRéponse } from '~/server/faq/infra/strapiFAQ.mapper';

describe('mapQuestion', () => {
it('retourne le résultat formaté', () => {
const result= mapQuestion(aStrapiQuestion({
contenu: 'mon contenu explicatif',
problematique: 'Comment constituer un dossier locatif ?',
slug: 'Comment-constituer-un-dossier-locatif-?',
}));
Expand All @@ -22,13 +26,13 @@ describe('mapQuestion', () => {

describe('mapQuestionRéponse', () => {
it('retourne le résultat formaté', () => {
const result = mapQuestionRéponse(aStrapiQuestion({
const result = mapQuestionRéponse(aStrapiQuestionEtReponse({
contenu: 'mon contenu explicatif',
problematique: 'Comment constituer un dossier locatif ?',
slug: 'Comment-constituer-un-dossier-locatif-?',
}));

expect(result).toStrictEqual(aQuestionRéponse({
expect(result).toStrictEqual(aQuestionEtReponse({
contenu: 'mon contenu explicatif',
problématique: 'Comment constituer un dossier locatif ?',
slug: 'Comment-constituer-un-dossier-locatif-?',
Expand All @@ -38,11 +42,9 @@ describe('mapQuestionRéponse', () => {

describe('flatMapSlug', () => {
it('renvoie le slug', () => {
const result= flatMapSlug(aStrapiQuestion({
contenu: 'mon contenu explicatif',
problematique: 'Comment constituer un dossier locatif ?',
const result= flatMapSlug({
slug: 'Comment-constituer-un-dossier-locatif-?',
}));
});

expect(result).toEqual('Comment-constituer-un-dossier-locatif-?');
});
Expand Down
8 changes: 4 additions & 4 deletions src/server/faq/infra/strapiFAQ.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { FAQResponse, Question } from '~/server/faq/domain/FAQ';
import { FAQ,FAQResponseStrapi } from '~/server/faq/domain/FAQ';

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

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

export const flatMapSlug = (faq: FAQResponse.FAQ): string => faq.slug;
export const flatMapSlug = (faq: FAQResponseStrapi.QuestionSlug): FAQ.Slug => faq.slug;

4 changes: 2 additions & 2 deletions src/server/faq/infra/strapiFAQ.repository.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createSuccess } from '~/server/errors/either';

import { aListeDeQuestion, aListeFAQSlug, aQuestionRéponse } from '../domain/FAQ.fixture';
import { aListeDeQuestion, aListeFAQSlug, aQuestionEtReponse } from '../domain/FAQ.fixture';
import { FAQRepository } from '../domain/FAQ.repository';

export function aFAQRepository(override?:Partial<FAQRepository>): FAQRepository {
return {
getAllFAQ: jest.fn().mockResolvedValue(createSuccess(aListeDeQuestion())),
getFAQBySlug: jest.fn().mockResolvedValue(createSuccess(aQuestionRéponse())),
getFAQBySlug: jest.fn().mockResolvedValue(createSuccess(aQuestionEtReponse())),
listAllFAQSlug: jest.fn().mockResolvedValue(createSuccess(aListeFAQSlug())),
...override,
};
Expand Down
Loading

0 comments on commit faaea38

Please sign in to comment.