Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ajouter activité bénéficiaire dans portefeuille context #1552

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function CreationBeneficiaireFranceTravailPage(): ReactElement {
email: nouveauBeneficiaire.email,
})

setPortefeuille(portefeuille.concat(beneficiaireCree))
setPortefeuille(
portefeuille.concat({ ...beneficiaireCree, estAArchiver: false })
)
setAlerte(AlerteParam.creationBeneficiaire, beneficiaireCree.id)
router.push('/mes-jeunes')
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ function CreationBeneficiaireMiloPage() {
surcharge
)

setPortefeuille(portefeuille.concat(beneficiaireCree))
setPortefeuille(
portefeuille.concat({ ...beneficiaireCree, estAArchiver: false })
)
setAlerte(AlerteParam.creationBeneficiaire, beneficiaireCree.id)
router.push('/mes-jeunes')
router.refresh()
Expand Down
21 changes: 13 additions & 8 deletions fixtures/beneficiaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
BeneficiaireAvecCompteursActionsRdvs,
BeneficiaireEtChat,
BeneficiaireFromListe,
BeneficiaireWithActivity,
CategorieSituation,
Chat,
ConseillerHistorique,
Expand Down Expand Up @@ -35,6 +36,16 @@ export const uneBaseBeneficiaire = (
return { ...defaults, ...overrides }
}

export const unBeneficiaireWithActivity = (
overrides: Partial<BeneficiaireWithActivity> = {}
): BeneficiaireWithActivity => {
const defaults: BeneficiaireWithActivity = {
...uneBaseBeneficiaire(),
estAArchiver: false,
}
return { ...defaults, ...overrides }
}

export const unDetailBeneficiaire = (
overrides: Partial<DetailBeneficiaire> = {}
): DetailBeneficiaire => {
Expand Down Expand Up @@ -103,10 +114,9 @@ export const unItemBeneficiaire = (
overrides: Partial<BeneficiaireFromListe> = {}
): BeneficiaireFromListe => {
const defaults: BeneficiaireFromListe = {
...uneBaseBeneficiaire(),
...unBeneficiaireWithActivity({ lastActivity: '2021-12-07T17:30:07.756Z' }),
isActivated: true,
isReaffectationTemporaire: false,
lastActivity: '2021-12-07T17:30:07.756Z',
situationCourante: CategorieSituation.SANS_SITUATION,
}
return { ...defaults, ...overrides }
Expand Down Expand Up @@ -167,6 +177,7 @@ export const unItemBeneficiaireJson = (
id: 'beneficiaire-1',
firstName: 'Kenji',
lastName: 'Jirac',
estAArchiver: false,
isActivated: true,
isReaffectationTemporaire: false,
lastActivity: '2021-12-07T17:30:07.756Z',
Expand Down Expand Up @@ -311,12 +322,6 @@ export const desConseillersBeneficiaireJson =
}))
}

export function extractBaseBeneficiaire(
base: BaseBeneficiaire
): BaseBeneficiaire {
return { id: base.id, nom: base.nom, prenom: base.prenom }
}

export const desIndicateursSemaineJson = (
overrides: Partial<IndicateursSemaineJson> = {}
): IndicateursSemaineJson => {
Expand Down
84 changes: 32 additions & 52 deletions interfaces/beneficiaire.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DateTime } from 'luxon'

import { StatutDemarche } from 'interfaces/json/beneficiaire'
import { compareDates, compareDatesDesc } from 'utils/date'

export enum EtatSituation {
EN_COURS = 'en cours',
Expand All @@ -21,27 +20,33 @@ export enum CategorieSituation {
SANS_SITUATION = 'Sans situation',
}

export interface BaseBeneficiaire {
export type Portefeuille = BeneficiaireWithActivity[]

export type BaseBeneficiaire = {
id: string
prenom: string
nom: string
}

export interface BeneficiaireFromListe extends BaseBeneficiaire {
export type BeneficiaireWithActivity = BaseBeneficiaire & {
estAArchiver: boolean
lastActivity?: string
dateFinCEJ?: string
}

export type BeneficiaireFromListe = BeneficiaireWithActivity & {
isActivated: boolean
isReaffectationTemporaire: boolean
lastActivity?: string
conseillerPrecedent?: {
nom: string
prenom: string
email?: string
}
situationCourante: CategorieSituation
structureMilo?: { id: string }
dateFinCEJ?: string
}

export interface DetailBeneficiaire extends BaseBeneficiaire {
export type DetailBeneficiaire = BaseBeneficiaire & {
creationDate: string
isActivated: boolean
isReaffectationTemporaire: boolean
Expand All @@ -60,7 +65,7 @@ export interface DetailBeneficiaire extends BaseBeneficiaire {
structureMilo?: { id: string }
}

export interface MetadonneesFavoris {
export type MetadonneesFavoris = {
autoriseLePartage: boolean
offres: {
total: number
Expand Down Expand Up @@ -95,7 +100,7 @@ export type BeneficiaireEtablissement = {
dateDerniereActivite?: string
}

export interface Chat {
export type Chat = {
chatId: string
seenByConseiller: boolean
flaggedByConseiller: boolean
Expand All @@ -110,7 +115,7 @@ export interface Chat {

export type BeneficiaireEtChat = BaseBeneficiaire & Chat

export interface DossierMilo {
export type DossierMilo = {
id: string
prenom: string
nom: string
Expand All @@ -119,7 +124,7 @@ export interface DossierMilo {
email?: string
}

export interface ConseillerHistorique {
export type ConseillerHistorique = {
id: string
nom: string
prenom: string
Expand Down Expand Up @@ -163,13 +168,6 @@ export function compareBeneficiairesByNom(
)
}

export function compareBeneficiairesByLastNameDesc(
beneficiaire1: BaseBeneficiaire,
beneficiaire2: BaseBeneficiaire
): number {
return -compareBeneficiairesByNom(beneficiaire1, beneficiaire2)
}

export function compareBeneficiairesBySituation(
beneficiaire1: BeneficiaireFromListe,
beneficiaire2: BeneficiaireFromListe
Expand All @@ -179,13 +177,6 @@ export function compareBeneficiairesBySituation(
)
}

export function compareBeneficiairesBySituationDesc(
beneficiaire1: BeneficiaireFromListe,
beneficiaire2: BeneficiaireFromListe
): number {
return -compareBeneficiairesBySituation(beneficiaire1, beneficiaire2)
}

export function compareBeneficiaireChat(
a: BeneficiaireEtChat,
b: BeneficiaireEtChat
Expand All @@ -197,34 +188,6 @@ export function compareBeneficiaireChat(
)
}

export function compareBeneficiairesByLastActivity(
beneficiaire1: BeneficiaireFromListe,
beneficiaire2: BeneficiaireFromListe,
sortStatutCompteActif: number
) {
const date1 = beneficiaire1.lastActivity
? DateTime.fromISO(beneficiaire1.lastActivity)
: undefined
const date2 = beneficiaire2.lastActivity
? DateTime.fromISO(beneficiaire2.lastActivity)
: undefined
return compareDates(date1, date2) || sortStatutCompteActif
}

export function compareBeneficiairesByLastActivityDesc(
beneficiaire1: BeneficiaireFromListe,
beneficiaire2: BeneficiaireFromListe,
sortStatutCompteActif: number
) {
const date1 = beneficiaire1.lastActivity
? DateTime.fromISO(beneficiaire1.lastActivity)
: undefined
const date2 = beneficiaire2.lastActivity
? DateTime.fromISO(beneficiaire2.lastActivity)
: undefined
return compareDatesDesc(date1, date2) || -sortStatutCompteActif
}

export function getNomBeneficiaireComplet(
b: Pick<BaseBeneficiaire, 'nom' | 'prenom'>
): string {
Expand Down Expand Up @@ -265,3 +228,20 @@ function comparerParDate(a: BeneficiaireEtChat, b: BeneficiaireEtChat): number {
}
return 0
}

export function extractBaseBeneficiaire(
base: BaseBeneficiaire
): BaseBeneficiaire {
return { id: base.id, nom: base.nom, prenom: base.prenom }
}

export function extractBeneficiaireWithActivity(
beneficiaire: BeneficiaireWithActivity
): BeneficiaireWithActivity {
return {
...extractBaseBeneficiaire(beneficiaire),
estAArchiver: beneficiaire.estAArchiver,
lastActivity: beneficiaire.lastActivity,
dateFinCEJ: beneficiaire.dateFinCEJ,
}
}
1 change: 1 addition & 0 deletions interfaces/json/beneficiaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface BaseBeneficiaireJson {
export interface ItemBeneficiaireJson extends BaseBeneficiaireJson {
isActivated: boolean
isReaffectationTemporaire: boolean
estAArchiver: boolean
lastActivity?: string
situationCourante?: Situation
dateFinCEJ?: string
Expand Down
3 changes: 1 addition & 2 deletions tests/components/ChatContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import React from 'react'
import ChatContainer from 'components/chat/ChatContainer'
import {
desItemsBeneficiaires,
extractBaseBeneficiaire,
unBeneficiaireChat,
} from 'fixtures/beneficiaire'
import { desListesDeDiffusion } from 'fixtures/listes-de-diffusion'
import { BaseBeneficiaire, BeneficiaireEtChat } from 'interfaces/beneficiaire'
import { BaseBeneficiaire, BeneficiaireEtChat, extractBaseBeneficiaire } from 'interfaces/beneficiaire'
import { getConseillersDuJeuneClientSide } from 'services/beneficiaires.service'
import { getListesDeDiffusionClientSide } from 'services/listes-de-diffusion.service'
import { getMessageImportant } from 'services/messages.service'
Expand Down
7 changes: 5 additions & 2 deletions tests/components/ChatRoom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import ChatRoom from 'components/chat/ChatRoom'
import AlerteDisplayer from 'components/layouts/AlerteDisplayer'
import {
desItemsBeneficiaires,
extractBaseBeneficiaire,
unBeneficiaireChat,
} from 'fixtures/beneficiaire'
import { unConseiller } from 'fixtures/conseiller'
import { BaseBeneficiaire, BeneficiaireEtChat } from 'interfaces/beneficiaire'
import {
BaseBeneficiaire,
BeneficiaireEtChat,
extractBaseBeneficiaire,
} from 'interfaces/beneficiaire'
import {
desactiverMessageImportant,
getMessageImportant,
Expand Down
26 changes: 14 additions & 12 deletions tests/pages/CreationBeneficiaireFranceTravailPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { axe } from 'jest-axe'
import { Mock } from 'jest-mock'
import { useRouter } from 'next/navigation'

import CreationBeneficiaireFranceTravailPage from 'app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireFranceTravailPage'
import {
desItemsBeneficiaires,
extractBaseBeneficiaire,
unBeneficiaireWithActivity,
uneBaseBeneficiaire,
} from 'fixtures/beneficiaire'
import { BaseBeneficiaire } from 'interfaces/beneficiaire'
import {
extractBeneficiaireWithActivity,
Portefeuille,
} from 'interfaces/beneficiaire'
import { AlerteParam } from 'referentiel/alerteParam'
import { createCompteJeuneFranceTravail } from 'services/beneficiaires.service'
import renderWithContexts from 'tests/renderWithContexts'
Expand All @@ -21,17 +23,17 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => {
let container: HTMLElement
let submitButton: HTMLElement

let push: Function
let push: () => void
let alerteSetter: (key: AlerteParam | undefined, target?: string) => void
let portefeuilleSetter: (updatedBeneficiaires: BaseBeneficiaire[]) => void
let portefeuille: BaseBeneficiaire[]
let portefeuilleSetter: (updatedBeneficiaires: Portefeuille) => void
let portefeuille: Portefeuille
const emailLabel: string = '* E-mail (ex : monemail@exemple.com)'
beforeEach(async () => {
push = jest.fn(() => Promise.resolve())
push = jest.fn()
;(useRouter as jest.Mock).mockReturnValue({ push })
alerteSetter = jest.fn()
portefeuilleSetter = jest.fn()
portefeuille = desItemsBeneficiaires().map(extractBaseBeneficiaire)
portefeuille = desItemsBeneficiaires().map(extractBeneficiaireWithActivity)
;({ container } = renderWithContexts(
<CreationBeneficiaireFranceTravailPage />,
{
Expand Down Expand Up @@ -139,7 +141,7 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => {

it('a11y', async () => {
// Given
;(createCompteJeuneFranceTravail as Mock<any>).mockResolvedValue(
;(createCompteJeuneFranceTravail as jest.Mock).mockResolvedValue(
uneBaseBeneficiaire()
)

Expand All @@ -153,7 +155,7 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => {

it('devrait revenir sur la page des jeunes du conseiller', async () => {
// Given
;(createCompteJeuneFranceTravail as Mock<any>).mockResolvedValue(
;(createCompteJeuneFranceTravail as jest.Mock).mockResolvedValue(
uneBaseBeneficiaire()
)

Expand All @@ -170,7 +172,7 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => {

expect(portefeuilleSetter).toHaveBeenCalledWith([
...portefeuille,
uneBaseBeneficiaire(),
unBeneficiaireWithActivity(),
])
expect(alerteSetter).toHaveBeenCalledWith(
'creationBeneficiaire',
Expand All @@ -181,7 +183,7 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => {

it("devrait afficher un message d'erreur en cas de création de compte en échec", async () => {
// Given
;(createCompteJeuneFranceTravail as Mock<any>).mockRejectedValue({
;(createCompteJeuneFranceTravail as jest.Mock).mockRejectedValue({
message: "un message d'erreur",
})

Expand Down
Loading
Loading