From 0a4d33fdd12da069a0c98fdec4ed85625d64fae2 Mon Sep 17 00:00:00 2001 From: Malek Zemni Date: Fri, 16 Jun 2023 11:26:28 +0200 Subject: [PATCH] feat(sessions-milo): ajout de la structure Milo pour le jeune --- src/app.module.ts | 4 +- .../creer-jeune-milo.command.handler.ts | 2 +- ...ecuperer-situations-jeunes-milo.command.ts | 21 +++++---- .../get-dossier-milo-jeune.query.handler.ts | 2 +- .../query-models/jeunes.query-model.ts | 2 +- src/domain/{jeune => milo}/jeune.milo.ts | 5 +++ src/infrastructure/jdd/situation.jdd.ts | 2 +- .../repositories/dto/milo.dto.ts | 2 +- .../jeune-milo-http-sql.repository.db.ts | 27 +++++++++++- .../repositories/mappers/jeunes.mappers.ts | 3 +- ...616070001-ajout-id-structure-milo-jeune.js | 29 ++++++++++++ .../sequelize/models/conseiller.sql-model.ts | 4 +- .../sequelize/models/jeune.sql-model.ts | 11 +++++ .../models/situations-milo.sql-model.ts | 2 +- .../creer-jeune-milo.command.handler.test.ts | 2 +- ...rer-situations-jeunes-milo.command.test.ts | 12 +++-- .../get-detail-jeune.query.handler.db.test.ts | 2 +- ...t-dossier-milo-jeune.query.handler.test.ts | 2 +- test/domain/jeune/jeune.milo.test.ts | 2 +- test/fixtures/milo.fixture.ts | 5 ++- test/fixtures/sql-models/jeune.sql-model.ts | 3 +- .../jeune-milo-http-sql.repository.db.test.ts | 44 ++++++++++++++++++- 22 files changed, 154 insertions(+), 34 deletions(-) rename src/application/{commands => }/jobs/handle-job-recuperer-situations-jeunes-milo.command.ts (81%) rename src/domain/{jeune => milo}/jeune.milo.ts (95%) create mode 100644 src/infrastructure/sequelize/migrations/20230616070001-ajout-id-structure-milo-jeune.js rename test/application/{commands => }/jobs/handle-job-recuperer-situations-jeunes-milo.command.test.ts (94%) diff --git a/src/app.module.ts b/src/app.module.ts index 5f221b7fb..734230766 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -195,7 +195,7 @@ import { ModifierConseillerCommandHandler } from './application/commands/modifie import { HandleJobNotifierNouvellesOffresEmploiCommandHandler } from './application/commands/jobs/handle-job-notifier-nouvelles-offres-emploi.command' import { HandleJobNotifierNouveauxServicesCiviqueCommandHandler } from './application/commands/jobs/handle-job-notification-recherche-service-civique.command.handler' import { GetFavorisServiceCiviqueJeuneQueryHandler } from './application/queries/get-favoris-service-civique-jeune.query.handler.db' -import { HandleJobRecupererSituationsJeunesMiloCommandHandler } from './application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command' +import { HandleJobRecupererSituationsJeunesMiloCommandHandler } from './application/jobs/handle-job-recuperer-situations-jeunes-milo.command' import { CampagnesController } from './infrastructure/routes/campagnes.controller' import { Campagne, CampagneRepositoryToken } from './domain/campagne' import { CampagneSqlRepository } from './infrastructure/repositories/campagne-sql.repository.db' @@ -298,7 +298,7 @@ import { RendezVousMilo, MiloRendezVousRepositoryToken } from './domain/rendez-vous/rendez-vous.milo' -import { MiloJeuneRepositoryToken } from './domain/jeune/jeune.milo' +import { MiloJeuneRepositoryToken } from './domain/milo/jeune.milo' import { HandleJobFakeCommandHandler } from './application/commands/jobs/handle-job-fake.command' import { MettreAJourLesJeunesCejPeCommandHandler } from './application/commands/mettre-a-jour-les-jeunes-cej-pe.command.handler' import { UpdateAgenceConseillerCommandHandler } from './application/commands/support/update-agence-conseiller.command.handler' diff --git a/src/application/commands/creer-jeune-milo.command.handler.ts b/src/application/commands/creer-jeune-milo.command.handler.ts index 236e7b4f0..844ec7a5d 100644 --- a/src/application/commands/creer-jeune-milo.command.handler.ts +++ b/src/application/commands/creer-jeune-milo.command.handler.ts @@ -27,7 +27,7 @@ import { Jeune, JeunesRepositoryToken } from '../../domain/jeune/jeune' import { JeuneMilo, MiloJeuneRepositoryToken -} from '../../domain/jeune/jeune.milo' +} from '../../domain/milo/jeune.milo' import { ConseillerAuthorizer } from '../authorizers/conseiller-authorizer' import { IdentiteJeuneQueryModel } from '../queries/query-models/jeunes.query-model' diff --git a/src/application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command.ts b/src/application/jobs/handle-job-recuperer-situations-jeunes-milo.command.ts similarity index 81% rename from src/application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command.ts rename to src/application/jobs/handle-job-recuperer-situations-jeunes-milo.command.ts index 0279c5e94..f36bc9780 100644 --- a/src/application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command.ts +++ b/src/application/jobs/handle-job-recuperer-situations-jeunes-milo.command.ts @@ -1,15 +1,15 @@ import { Inject, Injectable } from '@nestjs/common' -import { Job } from '../../../building-blocks/types/job' -import { JobHandler } from '../../../building-blocks/types/job-handler' -import { isFailure } from '../../../building-blocks/types/result' -import { Jeune, JeunesRepositoryToken } from '../../../domain/jeune/jeune' -import { Planificateur, ProcessJobType } from '../../../domain/planificateur' -import { SuiviJob, SuiviJobServiceToken } from '../../../domain/suivi-job' -import { DateService } from '../../../utils/date-service' +import { Job } from '../../building-blocks/types/job' +import { JobHandler } from '../../building-blocks/types/job-handler' +import { isFailure } from '../../building-blocks/types/result' +import { Jeune, JeunesRepositoryToken } from '../../domain/jeune/jeune' +import { Planificateur, ProcessJobType } from '../../domain/planificateur' +import { SuiviJob, SuiviJobServiceToken } from '../../domain/suivi-job' +import { DateService } from '../../utils/date-service' import { JeuneMilo, MiloJeuneRepositoryToken -} from '../../../domain/jeune/jeune.milo' +} from '../../domain/milo/jeune.milo' const PAGINATION_NOMBRE_DE_JEUNES_MAXIMUM = 100 @@ -71,6 +71,11 @@ export class HandleJobRecupererSituationsJeunesMiloCommandHandler extends JobHan const jeuneAvecDateFinCEJ = Jeune.mettreAJour(jeune, { dateFinCEJ }) await this.jeuneRepository.save(jeuneAvecDateFinCEJ) + await this.miloRepository.saveStructureJeune( + jeune.id, + dossier.data.nomStructure + ) + const situationsTriees = JeuneMilo.trierSituations( dossier.data.situations ) diff --git a/src/application/queries/get-dossier-milo-jeune.query.handler.ts b/src/application/queries/get-dossier-milo-jeune.query.handler.ts index 421d3bfaa..6013158ee 100644 --- a/src/application/queries/get-dossier-milo-jeune.query.handler.ts +++ b/src/application/queries/get-dossier-milo-jeune.query.handler.ts @@ -7,7 +7,7 @@ import { estMilo } from '../../domain/core' import { JeuneMilo, MiloJeuneRepositoryToken -} from '../../domain/jeune/jeune.milo' +} from '../../domain/milo/jeune.milo' import { ConseillerAuthorizer } from '../authorizers/conseiller-authorizer' import { DossierJeuneMiloQueryModel } from './query-models/milo.query-model' diff --git a/src/application/queries/query-models/jeunes.query-model.ts b/src/application/queries/query-models/jeunes.query-model.ts index cb191c0de..bdb4c331b 100644 --- a/src/application/queries/query-models/jeunes.query-model.ts +++ b/src/application/queries/query-models/jeunes.query-model.ts @@ -1,5 +1,5 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' -import { JeuneMilo } from '../../../domain/jeune/jeune.milo' +import { JeuneMilo } from '../../../domain/milo/jeune.milo' import { Jeune } from '../../../domain/jeune/jeune' class SituationQueryModel { diff --git a/src/domain/jeune/jeune.milo.ts b/src/domain/milo/jeune.milo.ts similarity index 95% rename from src/domain/jeune/jeune.milo.ts rename to src/domain/milo/jeune.milo.ts index 3845c1eed..6bb747e8b 100644 --- a/src/domain/jeune/jeune.milo.ts +++ b/src/domain/milo/jeune.milo.ts @@ -24,6 +24,7 @@ export namespace JeuneMilo { codePostal: string situations: Situation[] dateFinCEJ?: DateTime + nomStructure: string } export enum EtatSituation { @@ -45,6 +46,10 @@ export namespace JeuneMilo { export interface Repository { getDossier(id: string): Promise> saveSituationsJeune(situations: Situations): Promise + saveStructureJeune( + idJeune: string, + nomOfficielStructureMilo: string + ): Promise getSituationsByJeune(idJeune: string): Promise creerJeune( idDossier: string diff --git a/src/infrastructure/jdd/situation.jdd.ts b/src/infrastructure/jdd/situation.jdd.ts index 786034fd3..1a2943cf8 100644 --- a/src/infrastructure/jdd/situation.jdd.ts +++ b/src/infrastructure/jdd/situation.jdd.ts @@ -1,6 +1,6 @@ import { SituationsMiloDto } from '../sequelize/models/situations-milo.sql-model' import { AsSql } from '../sequelize/types' -import { JeuneMilo } from '../../domain/jeune/jeune.milo' +import { JeuneMilo } from '../../domain/milo/jeune.milo' export const uneSituationsMiloJdd = ( args: Partial = {} diff --git a/src/infrastructure/repositories/dto/milo.dto.ts b/src/infrastructure/repositories/dto/milo.dto.ts index a42395e57..a5e10cced 100644 --- a/src/infrastructure/repositories/dto/milo.dto.ts +++ b/src/infrastructure/repositories/dto/milo.dto.ts @@ -1,4 +1,4 @@ -import { JeuneMilo } from '../../../domain/jeune/jeune.milo' +import { JeuneMilo } from '../../../domain/milo/jeune.milo' export interface DossierMiloDto { idDossier: number diff --git a/src/infrastructure/repositories/jeune/jeune-milo-http-sql.repository.db.ts b/src/infrastructure/repositories/jeune/jeune-milo-http-sql.repository.db.ts index d268cd5ab..b179c35f5 100644 --- a/src/infrastructure/repositories/jeune/jeune-milo-http-sql.repository.db.ts +++ b/src/infrastructure/repositories/jeune/jeune-milo-http-sql.repository.db.ts @@ -5,11 +5,13 @@ import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.excepti import { firstValueFrom } from 'rxjs' import { ErreurHttp } from '../../../building-blocks/types/domain-error' import { Result, failure, success } from '../../../building-blocks/types/result' +import { JeuneMilo } from '../../../domain/milo/jeune.milo' import { DateService } from '../../../utils/date-service' import { RateLimiterService } from '../../../utils/rate-limiter.service' +import { JeuneSqlModel } from '../../sequelize/models/jeune.sql-model' import { SituationsMiloSqlModel } from '../../sequelize/models/situations-milo.sql-model' +import { StructureMiloSqlModel } from '../../sequelize/models/structure-milo.sql-model' import { DossierMiloDto } from '../dto/milo.dto' -import { JeuneMilo } from '../../../domain/jeune/jeune.milo' @Injectable() export class MiloJeuneHttpSqlRepository implements JeuneMilo.Repository { @@ -57,7 +59,8 @@ export class MiloJeuneHttpSqlRepository implements JeuneMilo.Repository { categorie: situation.categorieSituation, dateFin: situation.dateFin ?? undefined } - }) + }), + nomStructure: dossierDto.data.structureRattachement.nomOfficiel }) } catch (e) { this.logger.error(e) @@ -125,6 +128,26 @@ export class MiloJeuneHttpSqlRepository implements JeuneMilo.Repository { ) } + async saveStructureJeune( + idJeune: string, + nomOfficielStructureMilo: string + ): Promise { + const structureSql = await StructureMiloSqlModel.findOne({ + where: { + nomOfficiel: nomOfficielStructureMilo + } + }) + + if (structureSql) { + await JeuneSqlModel.update( + { + idStructureMilo: structureSql.id + }, + { where: { id: idJeune } } + ) + } + } + async getSituationsByJeune( idJeune: string ): Promise { diff --git a/src/infrastructure/repositories/mappers/jeunes.mappers.ts b/src/infrastructure/repositories/mappers/jeunes.mappers.ts index 42ecb75e5..21626bb67 100644 --- a/src/infrastructure/repositories/mappers/jeunes.mappers.ts +++ b/src/infrastructure/repositories/mappers/jeunes.mappers.ts @@ -66,7 +66,8 @@ export function toSqlJeune( email: jeune.email ?? null, structure: jeune.structure, idPartenaire: jeune.idPartenaire ?? null, - partageFavoris: jeune.preferences.partageFavoris + partageFavoris: jeune.preferences.partageFavoris, + idStructureMilo: null } } diff --git a/src/infrastructure/sequelize/migrations/20230616070001-ajout-id-structure-milo-jeune.js b/src/infrastructure/sequelize/migrations/20230616070001-ajout-id-structure-milo-jeune.js new file mode 100644 index 000000000..591f564d4 --- /dev/null +++ b/src/infrastructure/sequelize/migrations/20230616070001-ajout-id-structure-milo-jeune.js @@ -0,0 +1,29 @@ +'use strict' + +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.sequelize.transaction(async transaction => { + await queryInterface.addColumn( + 'jeune', + 'id_structure_milo', + { + type: Sequelize.STRING, + allowNull: true, + references: { + model: 'structure_milo', + key: 'id' + } + }, + { transaction } + ) + }) + }, + + async down(queryInterface, Sequelize) { + await queryInterface.sequelize.transaction(async transaction => { + await queryInterface.removeColumn('jeune', 'id_structure_milo', { + transaction + }) + }) + } +} diff --git a/src/infrastructure/sequelize/models/conseiller.sql-model.ts b/src/infrastructure/sequelize/models/conseiller.sql-model.ts index 44c994c26..f9a22464b 100644 --- a/src/infrastructure/sequelize/models/conseiller.sql-model.ts +++ b/src/infrastructure/sequelize/models/conseiller.sql-model.ts @@ -105,10 +105,10 @@ export class ConseillerSqlModel extends ConseillerDto { @HasMany(() => JeuneSqlModel) jeunes!: JeuneSqlModel[] - @BelongsTo(() => AgenceSqlModel, 'id_agence') + @BelongsTo(() => AgenceSqlModel) agence?: AgenceSqlModel - @BelongsTo(() => StructureMiloSqlModel, 'id_structure_milo') + @BelongsTo(() => StructureMiloSqlModel) structureMilo?: StructureMiloSqlModel static async creer(conseillerDto: AsSql): Promise { diff --git a/src/infrastructure/sequelize/models/jeune.sql-model.ts b/src/infrastructure/sequelize/models/jeune.sql-model.ts index eb84a4069..f850c2741 100644 --- a/src/infrastructure/sequelize/models/jeune.sql-model.ts +++ b/src/infrastructure/sequelize/models/jeune.sql-model.ts @@ -18,6 +18,7 @@ import { RendezVousJeuneAssociationSqlModel } from './rendez-vous-jeune-associat import { RendezVousSqlModel } from './rendez-vous.sql-model' import { SituationsMiloSqlModel } from './situations-milo.sql-model' import { TransfertConseillerSqlModel } from './transfert-conseiller.sql-model' +import { StructureMiloSqlModel } from './structure-milo.sql-model' export class JeuneDto extends Model { @PrimaryKey @@ -141,6 +142,13 @@ export class JeuneDto extends Model { type: DataType.BOOLEAN }) partageFavoris: boolean + + @ForeignKey(() => StructureMiloSqlModel) + @Column({ + field: 'id_structure_milo', + type: DataType.STRING + }) + idStructureMilo?: string | null } @Table({ @@ -166,6 +174,9 @@ export class JeuneSqlModel extends JeuneDto { @HasOne(() => SituationsMiloSqlModel) situations?: SituationsMiloSqlModel + @BelongsTo(() => StructureMiloSqlModel) + structureMilo?: StructureMiloSqlModel + static async creer(jeuneDto: AsSql): Promise { return JeuneSqlModel.create(jeuneDto) } diff --git a/src/infrastructure/sequelize/models/situations-milo.sql-model.ts b/src/infrastructure/sequelize/models/situations-milo.sql-model.ts index d6f7b64ae..24e85eddc 100644 --- a/src/infrastructure/sequelize/models/situations-milo.sql-model.ts +++ b/src/infrastructure/sequelize/models/situations-milo.sql-model.ts @@ -8,7 +8,7 @@ import { Table } from 'sequelize-typescript' import { JeuneSqlModel } from './jeune.sql-model' -import { JeuneMilo } from '../../../domain/jeune/jeune.milo' +import { JeuneMilo } from '../../../domain/milo/jeune.milo' export interface Situation { etat: JeuneMilo.EtatSituation diff --git a/test/application/commands/creer-jeune-milo.command.handler.test.ts b/test/application/commands/creer-jeune-milo.command.handler.test.ts index 8c593dd56..39e803b87 100644 --- a/test/application/commands/creer-jeune-milo.command.handler.test.ts +++ b/test/application/commands/creer-jeune-milo.command.handler.test.ts @@ -23,7 +23,7 @@ import { Chat } from '../../../src/domain/chat' import { Conseiller } from '../../../src/domain/conseiller/conseiller' import { Core, estMilo } from '../../../src/domain/core' import { Jeune } from '../../../src/domain/jeune/jeune' -import { JeuneMilo } from '../../../src/domain/jeune/jeune.milo' +import { JeuneMilo } from '../../../src/domain/milo/jeune.milo' import { DateService } from '../../../src/utils/date-service' import { IdService } from '../../../src/utils/id-service' import { unUtilisateurConseiller } from '../../fixtures/authentification.fixture' diff --git a/test/application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command.test.ts b/test/application/jobs/handle-job-recuperer-situations-jeunes-milo.command.test.ts similarity index 94% rename from test/application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command.test.ts rename to test/application/jobs/handle-job-recuperer-situations-jeunes-milo.command.test.ts index f441fc3a9..184b28761 100644 --- a/test/application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command.test.ts +++ b/test/application/jobs/handle-job-recuperer-situations-jeunes-milo.command.test.ts @@ -1,6 +1,6 @@ import { StubbedType, stubInterface } from '@salesforce/ts-sinon' import { SinonSandbox } from 'sinon' -import { HandleJobRecupererSituationsJeunesMiloCommandHandler } from 'src/application/commands/jobs/handle-job-recuperer-situations-jeunes-milo.command' +import { HandleJobRecupererSituationsJeunesMiloCommandHandler } from 'src/application/jobs/handle-job-recuperer-situations-jeunes-milo.command' import { ErreurHttp } from 'src/building-blocks/types/domain-error' import { failure, success } from 'src/building-blocks/types/result' import { Core } from 'src/domain/core' @@ -9,9 +9,9 @@ import { SuiviJob } from 'src/domain/suivi-job' import { uneDatetime } from 'test/fixtures/date.fixture' import { unJeune } from 'test/fixtures/jeune.fixture' import { unDossierMilo } from 'test/fixtures/milo.fixture' -import { DateService } from '../../../../src/utils/date-service' -import { createSandbox, expect, StubbedClass, stubClass } from '../../../utils' -import { JeuneMilo } from '../../../../src/domain/jeune/jeune.milo' +import { DateService } from '../../../src/utils/date-service' +import { createSandbox, expect, StubbedClass, stubClass } from '../../utils' +import { JeuneMilo } from '../../../src/domain/milo/jeune.milo' describe('HandleJobRecupererSituationsJeunesMiloCommandHandler', () => { let handleJobRecupererSituationsJeunesMiloCommandHandler: HandleJobRecupererSituationsJeunesMiloCommandHandler @@ -60,6 +60,7 @@ describe('HandleJobRecupererSituationsJeunesMiloCommandHandler', () => { await handleJobRecupererSituationsJeunesMiloCommandHandler.handle() // Then + expect(miloRepository.saveStructureJeune).to.have.callCount(0) expect(miloRepository.saveSituationsJeune).to.have.callCount(0) expect(result.succes).to.equal(true) expect(result.resultat).to.deep.equal({ @@ -90,6 +91,9 @@ describe('HandleJobRecupererSituationsJeunesMiloCommandHandler', () => { await handleJobRecupererSituationsJeunesMiloCommandHandler.handle() // Then + expect( + miloRepository.saveStructureJeune + ).to.have.been.calledOnceWithExactly(jeune1.id, 'ML') expect(miloRepository.saveSituationsJeune).to.have.callCount(1) expect( miloRepository.saveSituationsJeune diff --git a/test/application/queries/get-detail-jeune.query.handler.db.test.ts b/test/application/queries/get-detail-jeune.query.handler.db.test.ts index 68cd1af73..91aea1d85 100644 --- a/test/application/queries/get-detail-jeune.query.handler.db.test.ts +++ b/test/application/queries/get-detail-jeune.query.handler.db.test.ts @@ -20,7 +20,7 @@ import { GetDetailJeuneQuery, GetDetailJeuneQueryHandler } from '../../../src/application/queries/get-detail-jeune.query.handler.db' -import { JeuneMilo } from '../../../src/domain/jeune/jeune.milo' +import { JeuneMilo } from '../../../src/domain/milo/jeune.milo' import { unUtilisateurConseiller, unUtilisateurJeune diff --git a/test/application/queries/get-dossier-milo-jeune.query.handler.test.ts b/test/application/queries/get-dossier-milo-jeune.query.handler.test.ts index 2f5db5391..cf21b8d26 100644 --- a/test/application/queries/get-dossier-milo-jeune.query.handler.test.ts +++ b/test/application/queries/get-dossier-milo-jeune.query.handler.test.ts @@ -6,7 +6,7 @@ import { GetDossierMiloJeuneQueryHandler } from '../../../src/application/queries/get-dossier-milo-jeune.query.handler' import { estMilo } from '../../../src/domain/core' -import { JeuneMilo } from '../../../src/domain/jeune/jeune.milo' +import { JeuneMilo } from '../../../src/domain/milo/jeune.milo' import { unUtilisateurConseiller } from '../../fixtures/authentification.fixture' import { unDossierMilo } from '../../fixtures/milo.fixture' import { StubbedClass, createSandbox, expect, stubClass } from '../../utils' diff --git a/test/domain/jeune/jeune.milo.test.ts b/test/domain/jeune/jeune.milo.test.ts index c6d216c31..74b38ed84 100644 --- a/test/domain/jeune/jeune.milo.test.ts +++ b/test/domain/jeune/jeune.milo.test.ts @@ -1,5 +1,5 @@ import { expect } from '../../utils' -import { JeuneMilo } from '../../../src/domain/jeune/jeune.milo' +import { JeuneMilo } from '../../../src/domain/milo/jeune.milo' describe('Milo', () => { const situationsPrevuEmploi = { diff --git a/test/fixtures/milo.fixture.ts b/test/fixtures/milo.fixture.ts index bc913bea5..18a7c950c 100644 --- a/test/fixtures/milo.fixture.ts +++ b/test/fixtures/milo.fixture.ts @@ -1,6 +1,6 @@ import { SituationsMiloDto } from 'src/infrastructure/sequelize/models/situations-milo.sql-model' import { AsSql } from 'src/infrastructure/sequelize/types' -import { JeuneMilo } from '../../src/domain/jeune/jeune.milo' +import { JeuneMilo } from '../../src/domain/milo/jeune.milo' export const unDossierMilo = ( args: Partial = {} @@ -12,7 +12,8 @@ export const unDossierMilo = ( dateDeNaissance: '1888-09-01', codePostal: '91580', email: 'jack.dawson@milo.com', - situations: [] + situations: [], + nomStructure: 'ML' } return { ...defaults, ...args } } diff --git a/test/fixtures/sql-models/jeune.sql-model.ts b/test/fixtures/sql-models/jeune.sql-model.ts index 385f001be..205d7a10d 100644 --- a/test/fixtures/sql-models/jeune.sql-model.ts +++ b/test/fixtures/sql-models/jeune.sql-model.ts @@ -26,7 +26,8 @@ export function unJeuneDto( installationId: '123456', instanceId: 'abcdef', partageFavoris: true, - timezone: 'Europe/Paris' + timezone: 'Europe/Paris', + idStructureMilo: null } return { ...defaults, ...args } diff --git a/test/infrastructure/repositories/jeune/jeune-milo-http-sql.repository.db.test.ts b/test/infrastructure/repositories/jeune/jeune-milo-http-sql.repository.db.test.ts index 0c7e96228..0a5c173aa 100644 --- a/test/infrastructure/repositories/jeune/jeune-milo-http-sql.repository.db.test.ts +++ b/test/infrastructure/repositories/jeune/jeune-milo-http-sql.repository.db.test.ts @@ -17,11 +17,13 @@ import { testConfig } from '../../../utils/module-for-testing' import { unConseiller } from '../../../fixtures/conseiller.fixture' import { stubClass } from '../../../utils' import { FirebaseClient } from '../../../../src/infrastructure/clients/firebase-client' -import { JeuneMilo } from '../../../../src/domain/jeune/jeune.milo' +import { JeuneMilo } from '../../../../src/domain/milo/jeune.milo' import { DatabaseForTesting, getDatabase } from '../../../utils/database-for-testing' +import { StructureMiloSqlModel } from '../../../../src/infrastructure/sequelize/models/structure-milo.sql-model' +import { JeuneSqlModel } from '../../../../src/infrastructure/sequelize/models/jeune.sql-model' describe('MiloHttpRepository', () => { let databaseForTesting: DatabaseForTesting @@ -85,7 +87,8 @@ describe('MiloHttpRepository', () => { etat: 'EN_COURS', dateFin: undefined } - ] + ], + nomStructure: '65-ML TARBES' }) ) }) @@ -246,6 +249,43 @@ describe('MiloHttpRepository', () => { }) }) + describe('saveStructureJeune', () => { + it('sauvegarde la structure du jeune quand trouvée', async () => { + // Given + const idStructureMilo = 1 + const nomOfficiel = 'structure-du-jeune' + await StructureMiloSqlModel.create({ + id: idStructureMilo, + nomOfficiel + }) + + // When + await miloHttpSqlRepository.saveStructureJeune(jeune.id, nomOfficiel) + + // Then + const jeuneTrouve = await JeuneSqlModel.findByPk(jeune.id) + + expect(jeuneTrouve?.idStructureMilo).to.equal(idStructureMilo.toString()) + }) + it('ne sauvegarde pas la structure du jeune quand non trouvée', async () => { + // Given + const idStructureMilo = 1 + const nomOfficiel = 'structure-du-jeune' + await StructureMiloSqlModel.create({ + id: idStructureMilo, + nomOfficiel: 'structure-pas-du-jeune' + }) + + // When + await miloHttpSqlRepository.saveStructureJeune(jeune.id, nomOfficiel) + + // Then + const jeuneTrouve = await JeuneSqlModel.findByPk(jeune.id) + + expect(jeuneTrouve?.idStructureMilo).to.be.null() + }) + }) + describe('getSituationsByJeune', () => { it('recupere les situations', async () => { // Given