-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AUTO DIAGNOSTIC] Publie l’événement AUTO_DIAGNOSTIC_LANCE et crée la…
… relation avec la demande correspondante
- Loading branch information
Showing
10 changed files
with
196 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
mon-aide-cyber-api/src/auto-diagnostic/consommateursEvenements.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { AdaptateurRelations } from '../relation/AdaptateurRelations'; | ||
import { ConsommateurEvenement, Evenement } from '../domaine/BusEvenement'; | ||
import { AutoDiagnosticLance } from './CapteurSagaLanceAutoDiagnostic'; | ||
import crypto from 'crypto'; | ||
import { DefinitionTuple, Tuple, unTuple } from '../relation/Tuple'; | ||
|
||
export const demandeInitieAutoDiagnostic = ( | ||
adaptateurRelations: AdaptateurRelations | ||
) => | ||
new (class implements ConsommateurEvenement { | ||
async consomme<E extends Evenement<unknown> = AutoDiagnosticLance>( | ||
evenement: E | ||
): Promise<void> { | ||
const diagnosticLance = evenement as AutoDiagnosticLance; | ||
const tuple = unTupleAidantInitieDiagnostic( | ||
diagnosticLance.corps.idDemande, | ||
diagnosticLance.corps.idDiagnostic | ||
); | ||
|
||
return adaptateurRelations.creeTuple(tuple); | ||
} | ||
})(); | ||
|
||
export const unTupleAidantInitieDiagnostic = ( | ||
identifiantDemande: crypto.UUID, | ||
identifiantDiagnostic: crypto.UUID | ||
): Tuple => | ||
unTuple<DefinitionAidantInitieDiagnostic>(definitionAidantInitieDiagnostic) | ||
.avecUtilisateur(identifiantDemande) | ||
.avecObjet(identifiantDiagnostic) | ||
.construis(); | ||
|
||
export type DefinitionAidantInitieDiagnostic = DefinitionTuple & { | ||
relation: 'initiateur'; | ||
typeObjet: 'auto-diagnostic'; | ||
typeUtilisateur: 'demande-aide'; | ||
}; | ||
|
||
export const definitionAidantInitieDiagnostic: { | ||
definition: DefinitionAidantInitieDiagnostic; | ||
} = { | ||
definition: { | ||
relation: 'initiateur', | ||
typeObjet: 'auto-diagnostic', | ||
typeUtilisateur: 'demande-aide', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { beforeEach, describe } from 'vitest'; | ||
import { EntrepotsMemoire } from '../../src/infrastructure/entrepots/memoire/EntrepotsMemoire'; | ||
import { | ||
AutoDiagnosticLance, | ||
CapteurSagaLanceAutoDiagnostic, | ||
DemandeAutoDiagnostic, | ||
} from '../../src/auto-diagnostic/CapteurSagaLanceAutoDiagnostic'; | ||
|
@@ -38,18 +39,19 @@ describe('Capteur pour lancer un Auto-Diagnostic', () => { | |
adaptateurEnvoiMail, | ||
unConstructeurDeServices(entrepots.aidants()) | ||
); | ||
const referentiel = unReferentiel().construis(); | ||
adaptateurReferentiel.ajoute(referentiel); | ||
}); | ||
|
||
it('Crée la demande correspondante', async () => { | ||
FournisseurHorlogeDeTest.initialise(new Date()); | ||
const identifiantDemande = crypto.randomUUID(); | ||
adaptateurUUID.genereUUID = () => identifiantDemande; | ||
const referentiel = unReferentiel().construis(); | ||
adaptateurReferentiel.ajoute(referentiel); | ||
|
||
await new CapteurSagaLanceAutoDiagnostic( | ||
entrepots, | ||
busCommande, | ||
busEvenement, | ||
adaptateurReferentiel, | ||
adaptateurMesures | ||
).execute({ | ||
|
@@ -65,4 +67,33 @@ describe('Capteur pour lancer un Auto-Diagnostic', () => { | |
dateSignatureCGU: FournisseurHorloge.maintenant(), | ||
}); | ||
}); | ||
|
||
it('Publie l’événement AUTO_DIAGNOSTIC_LANCE', async () => { | ||
FournisseurHorlogeDeTest.initialise(new Date()); | ||
|
||
await new CapteurSagaLanceAutoDiagnostic( | ||
entrepots, | ||
busCommande, | ||
busEvenement, | ||
adaptateurReferentiel, | ||
adaptateurMesures | ||
).execute({ | ||
type: 'SagaLanceAutoDiagnostic', | ||
email: '[email protected]', | ||
dateSignatureCGU: FournisseurHorloge.maintenant(), | ||
}); | ||
|
||
expect( | ||
busEvenement.consommateursTestes.get('AUTO_DIAGNOSTIC_LANCE')?.[0] | ||
.evenementConsomme | ||
).toStrictEqual<AutoDiagnosticLance>({ | ||
identifiant: expect.any(String), | ||
type: 'AUTO_DIAGNOSTIC_LANCE', | ||
date: FournisseurHorloge.maintenant(), | ||
corps: { | ||
idDiagnostic: expect.any(String), | ||
idDemande: expect.any(String), | ||
}, | ||
}); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
mon-aide-cyber-api/test/auto-diagnostic/consommateursEvenements.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, it } from 'vitest'; | ||
import { AdaptateurRelationsMAC } from '../../src/relation/AdaptateurRelationsMAC'; | ||
import { EntrepotRelationMemoire } from '../../src/relation/infrastructure/EntrepotRelationMemoire'; | ||
import crypto from 'crypto'; | ||
import { BusEvenementDeTest } from '../infrastructure/bus/BusEvenementDeTest'; | ||
import { EntrepotEvenementJournalMemoire } from '../../src/infrastructure/entrepots/memoire/EntrepotMemoire'; | ||
import { FournisseurHorloge } from '../../src/infrastructure/horloge/FournisseurHorloge'; | ||
|
||
describe("Les consommateurs d'évènements de l’auto diagnostic", () => { | ||
describe("Lorsque l’événement 'AUTO_DIAGNOSTIC_LANCE' est consommé", () => { | ||
it('Crée la relation entre la demande et l’auto diagnostic', async () => { | ||
const adaptateurRelations = new AdaptateurRelationsMAC( | ||
new EntrepotRelationMemoire() | ||
); | ||
const identifiantDemande = crypto.randomUUID(); | ||
const identifiantDiagnostic = crypto.randomUUID(); | ||
const busEvenement = new BusEvenementDeTest( | ||
{ | ||
adaptateurRelations, | ||
entrepotJournalisation: new EntrepotEvenementJournalMemoire(), | ||
}, | ||
['AUTO_DIAGNOSTIC_LANCE'] | ||
); | ||
|
||
await busEvenement.publie({ | ||
identifiant: crypto.randomUUID(), | ||
type: 'AUTO_DIAGNOSTIC_LANCE', | ||
date: FournisseurHorloge.maintenant(), | ||
corps: { | ||
idDiagnostic: identifiantDiagnostic, | ||
idDemande: identifiantDemande, | ||
}, | ||
}); | ||
|
||
expect( | ||
await adaptateurRelations.identifiantsObjetsLiesAUtilisateur( | ||
identifiantDemande | ||
) | ||
).toStrictEqual([identifiantDiagnostic]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters