-
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] Implémente l’entrepôt postgres de demande d’auto di…
…agnostic
- Loading branch information
Showing
5 changed files
with
111 additions
and
8 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...-cyber-api/src/infrastructure/entrepots/postgres/EntrepotDemandeAutoDiagnosticPostgres.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,38 @@ | ||
import { DTO, EntrepotPostgres } from './EntrepotPostgres'; | ||
import { | ||
DemandeAutoDiagnostic, | ||
EntrepotDemandeAutoDiagnostic, | ||
} from '../../../auto-diagnostic/CapteurSagaLanceAutoDiagnostic'; | ||
import { FournisseurHorloge } from '../../horloge/FournisseurHorloge'; | ||
|
||
type DemandeAutoDiagnosticDTO = DTO & { | ||
donnees: { dateSignatureCGU: string }; | ||
}; | ||
|
||
export class EntrepotDemandeAutoDiagnosticPostgres | ||
extends EntrepotPostgres<DemandeAutoDiagnostic, DemandeAutoDiagnosticDTO> | ||
implements EntrepotDemandeAutoDiagnostic | ||
{ | ||
protected champsAMettreAJour( | ||
entiteDTO: DemandeAutoDiagnosticDTO | ||
): Partial<DemandeAutoDiagnosticDTO> { | ||
return { donnees: entiteDTO.donnees }; | ||
} | ||
protected nomTable(): string { | ||
return 'demandes-auto-diagnostic'; | ||
} | ||
protected deEntiteADTO( | ||
entite: DemandeAutoDiagnostic | ||
): DemandeAutoDiagnosticDTO { | ||
return { | ||
donnees: { dateSignatureCGU: entite.dateSignatureCGU.toISOString() }, | ||
id: entite.identifiant, | ||
}; | ||
} | ||
protected deDTOAEntite(dto: DemandeAutoDiagnosticDTO): DemandeAutoDiagnostic { | ||
return { | ||
dateSignatureCGU: FournisseurHorloge.enDate(dto.donnees.dateSignatureCGU), | ||
identifiant: dto.id, | ||
}; | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...ucture/entrepots/postgres/migrations/20241115112336_cree-table-demande-auto-diagnostic.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,16 @@ | ||
import { Knex } from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
return knex.schema.createTable( | ||
'demandes-auto-diagnostic', | ||
(fabriqueDeTable) => { | ||
fabriqueDeTable.uuid('id'); | ||
fabriqueDeTable.primary(['id']); | ||
fabriqueDeTable.jsonb('donnees'); | ||
} | ||
); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
return knex.schema.dropTable('demandes-auto-diagnostic'); | ||
} |
34 changes: 34 additions & 0 deletions
34
...-api/test/infrastructure/entrepots/postgres/EntrepotDemandeAutoDiagnosticPostgres.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,34 @@ | ||
import { beforeEach, describe } from 'vitest'; | ||
import { nettoieLaBaseDeDonneesDemandeAutoDiagnostic } from '../../../utilitaires/nettoyeurBDD'; | ||
import { EntrepotDemandeAutoDiagnosticPostgres } from '../../../../src/infrastructure/entrepots/postgres/EntrepotDemandeAutoDiagnosticPostgres'; | ||
import { DemandeAutoDiagnostic } from '../../../../src/auto-diagnostic/CapteurSagaLanceAutoDiagnostic'; | ||
import { FournisseurHorloge } from '../../../../src/infrastructure/horloge/FournisseurHorloge'; | ||
import { FournisseurHorlogeDeTest } from '../../horloge/FournisseurHorlogeDeTest'; | ||
import crypto from 'crypto'; | ||
|
||
describe('Entrepot demande auto diagnostic', () => { | ||
beforeEach(async () => { | ||
await nettoieLaBaseDeDonneesDemandeAutoDiagnostic(); | ||
}); | ||
|
||
it('Persiste une demande d’auto diagnostic', async () => { | ||
FournisseurHorlogeDeTest.initialise(new Date()); | ||
const demandeAutoDiagnostic = { | ||
identifiant: crypto.randomUUID(), | ||
dateSignatureCGU: FournisseurHorloge.maintenant(), | ||
}; | ||
|
||
await new EntrepotDemandeAutoDiagnosticPostgres().persiste( | ||
demandeAutoDiagnostic | ||
); | ||
|
||
const demandeAutoDiagnosticRecue = | ||
await new EntrepotDemandeAutoDiagnosticPostgres().lis( | ||
demandeAutoDiagnostic.identifiant | ||
); | ||
expect(demandeAutoDiagnosticRecue).toStrictEqual<DemandeAutoDiagnostic>({ | ||
identifiant: demandeAutoDiagnostic.identifiant, | ||
dateSignatureCGU: FournisseurHorloge.maintenant(), | ||
}); | ||
}); | ||
}); |
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