-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚚 Séparer les steps de raccordement en plusieurs fichiers (#2643)
- Loading branch information
1 parent
092dc0d
commit 86afb18
Showing
16 changed files
with
724 additions
and
690 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/specifications/src/raccordement/demandeComplèteRaccordement.world.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,14 @@ | ||
import { ModifierDemandeComplèteRaccordementFixture } from './fixtures/modifierDemandeComplèteDeRaccordement.fixture'; | ||
import { TransmettreDemandeComplèteRaccordementFixture } from './fixtures/transmettreDemandeComplèteDeRaccordement.fixture'; | ||
|
||
export class DemandeComplèteRaccordementWorld { | ||
readonly transmettreFixture = new TransmettreDemandeComplèteRaccordementFixture(); | ||
readonly modifierFixture = new ModifierDemandeComplèteRaccordementFixture(); | ||
|
||
mapToExpected(nouvelleRéférenceDossier: string | undefined) { | ||
return ( | ||
this.modifierFixture.mapToExpected(nouvelleRéférenceDossier) ?? | ||
this.transmettreFixture.mapToExpected(nouvelleRéférenceDossier) | ||
); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
packages/specifications/src/raccordement/propositionTechniqueEtFinancière.world.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,14 @@ | ||
import { ModifierPropositionTechniqueEtFinancièreFixture } from './fixtures/modifierPropositionTechniqueEtFinancière.fixture'; | ||
import { TransmettrePropositionTechniqueEtFinancièreFixture } from './fixtures/transmettrePropositionTechniqueEtFinancière.fixture'; | ||
|
||
export class PropositionTechniqueEtFinancièreWorld { | ||
readonly transmettreFixture = new TransmettrePropositionTechniqueEtFinancièreFixture(); | ||
readonly modifierFixture = new ModifierPropositionTechniqueEtFinancièreFixture(); | ||
|
||
mapToExpected(nouvelleRéférenceDossier: string | undefined) { | ||
return ( | ||
this.modifierFixture.mapToExpected(nouvelleRéférenceDossier) ?? | ||
this.transmettreFixture.mapToExpected(nouvelleRéférenceDossier) | ||
); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
packages/specifications/src/raccordement/stepDefinitions/dateMiseEnService.given.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 { Given as EtantDonné } from '@cucumber/cucumber'; | ||
import { mediator } from 'mediateur'; | ||
|
||
import { DateTime } from '@potentiel-domain/common'; | ||
import { Raccordement } from '@potentiel-domain/reseau'; | ||
|
||
import { PotentielWorld } from '../../potentiel.world'; | ||
|
||
EtantDonné( | ||
'une date de mise en service pour le dossier de raccordement du projet lauréat', | ||
async function (this: PotentielWorld) { | ||
const { identifiantProjet } = this.lauréatWorld; | ||
const { référenceDossier } = this.raccordementWorld; | ||
const { dateMiseEnService } = this.raccordementWorld.transmettreDateMiseEnServiceFixture.créer({ | ||
identifiantProjet: identifiantProjet.formatter(), | ||
référenceDossier, | ||
}); | ||
|
||
try { | ||
await mediator.send<Raccordement.RaccordementUseCase>({ | ||
type: 'Réseau.Raccordement.UseCase.TransmettreDateMiseEnService', | ||
data: { | ||
identifiantProjetValue: identifiantProjet.formatter(), | ||
référenceDossierValue: référenceDossier, | ||
dateMiseEnServiceValue: dateMiseEnService, | ||
transmiseLeValue: DateTime.now().formatter(), | ||
transmiseParValue: this.utilisateurWorld.adminFixture.email, | ||
}, | ||
}); | ||
} catch (e) { | ||
this.error = e as Error; | ||
} | ||
}, | ||
); |
29 changes: 29 additions & 0 deletions
29
packages/specifications/src/raccordement/stepDefinitions/dateMiseEnService.then.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,29 @@ | ||
import { Then as Alors } from '@cucumber/cucumber'; | ||
import { mediator } from 'mediateur'; | ||
import waitForExpect from 'wait-for-expect'; | ||
|
||
import { Raccordement } from '@potentiel-domain/reseau'; | ||
|
||
import { PotentielWorld } from '../../potentiel.world'; | ||
|
||
import { vérifierDossierRaccordement } from './raccordement.then'; | ||
|
||
Alors( | ||
`la date de mise en service devrait être consultable dans le dossier de raccordement du projet lauréat`, | ||
async function (this: PotentielWorld) { | ||
const { identifiantProjet } = this.lauréatWorld; | ||
const { référenceDossier } = this.raccordementWorld; | ||
await waitForExpect(async () => { | ||
const dossierRaccordement = | ||
await mediator.send<Raccordement.ConsulterDossierRaccordementQuery>({ | ||
type: 'Réseau.Raccordement.Query.ConsulterDossierRaccordement', | ||
data: { | ||
référenceDossierRaccordementValue: référenceDossier, | ||
identifiantProjetValue: identifiantProjet.formatter(), | ||
}, | ||
}); | ||
|
||
vérifierDossierRaccordement.call(this, identifiantProjet, dossierRaccordement); | ||
}); | ||
}, | ||
); |
60 changes: 60 additions & 0 deletions
60
packages/specifications/src/raccordement/stepDefinitions/dateMiseEnService.when.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,60 @@ | ||
import { DataTable, When as Quand } from '@cucumber/cucumber'; | ||
import { mediator } from 'mediateur'; | ||
|
||
import { Raccordement } from '@potentiel-domain/reseau'; | ||
import { DateTime, IdentifiantProjet } from '@potentiel-domain/common'; | ||
|
||
import { PotentielWorld } from '../../potentiel.world'; | ||
|
||
Quand( | ||
`le gestionnaire de réseau transmet la date de mise en service pour le dossier de raccordement du projet lauréat avec :`, | ||
async function (this: PotentielWorld, datatable: DataTable) { | ||
const { identifiantProjet } = this.lauréatWorld; | ||
const { référenceDossier } = this.raccordementWorld; | ||
|
||
await transmettreDateMiseEnService.call( | ||
this, | ||
identifiantProjet, | ||
référenceDossier, | ||
datatable.rowsHash(), | ||
); | ||
}, | ||
); | ||
|
||
Quand( | ||
`le gestionnaire de réseau transmet la date de mise en service pour le dossier de raccordement du projet lauréat`, | ||
async function (this: PotentielWorld) { | ||
const { identifiantProjet } = this.lauréatWorld; | ||
const { référenceDossier } = this.raccordementWorld; | ||
|
||
await transmettreDateMiseEnService.call(this, identifiantProjet, référenceDossier); | ||
}, | ||
); | ||
|
||
async function transmettreDateMiseEnService( | ||
this: PotentielWorld, | ||
identifiantProjet: IdentifiantProjet.ValueType, | ||
référence: string, | ||
data: Record<string, string> = {}, | ||
) { | ||
const { dateMiseEnService, référenceDossier } = | ||
this.raccordementWorld.transmettreDateMiseEnServiceFixture.créer({ | ||
identifiantProjet: identifiantProjet.formatter(), | ||
référenceDossier: référence, | ||
...this.raccordementWorld.transmettreDateMiseEnServiceFixture.mapExempleToFixtureValues(data), | ||
}); | ||
try { | ||
await mediator.send<Raccordement.RaccordementUseCase>({ | ||
type: 'Réseau.Raccordement.UseCase.TransmettreDateMiseEnService', | ||
data: { | ||
identifiantProjetValue: identifiantProjet.formatter(), | ||
référenceDossierValue: référenceDossier, | ||
dateMiseEnServiceValue: dateMiseEnService, | ||
transmiseLeValue: DateTime.now().formatter(), | ||
transmiseParValue: this.utilisateurWorld.grdFixture.email, | ||
}, | ||
}); | ||
} catch (e) { | ||
this.error = e as Error; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ages/specifications/src/raccordement/stepDefinitions/demandeComplèteRaccordement.given.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,23 @@ | ||
import { DataTable, Given as EtantDonné } from '@cucumber/cucumber'; | ||
|
||
import { PotentielWorld } from '../../potentiel.world'; | ||
|
||
import { transmettreDemandeComplèteRaccordement } from './demandeComplèteRaccordement.when'; | ||
|
||
EtantDonné( | ||
'une demande complète de raccordement pour le projet lauréat', | ||
async function (this: PotentielWorld) { | ||
await transmettreDemandeComplèteRaccordement.call(this, this.lauréatWorld.identifiantProjet); | ||
}, | ||
); | ||
|
||
EtantDonné( | ||
'une demande complète de raccordement pour le projet lauréat avec :', | ||
async function (this: PotentielWorld, datatable: DataTable) { | ||
await transmettreDemandeComplèteRaccordement.call( | ||
this, | ||
this.lauréatWorld.identifiantProjet, | ||
datatable.rowsHash(), | ||
); | ||
}, | ||
); |
91 changes: 91 additions & 0 deletions
91
packages/specifications/src/raccordement/stepDefinitions/demandeComplèteRaccordement.then.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,91 @@ | ||
import { Then as Alors } from '@cucumber/cucumber'; | ||
import { mediator } from 'mediateur'; | ||
import waitForExpect from 'wait-for-expect'; | ||
import { assert } from 'chai'; | ||
|
||
import { Raccordement } from '@potentiel-domain/reseau'; | ||
import { Option } from '@potentiel-libraries/monads'; | ||
import { ConsulterDocumentProjetQuery } from '@potentiel-domain/document'; | ||
import { IdentifiantProjet } from '@potentiel-domain/common'; | ||
import { mapToPlainObject } from '@potentiel-domain/core'; | ||
|
||
import { PotentielWorld } from '../../potentiel.world'; | ||
import { convertReadableStreamToString } from '../../helpers/convertReadableToString'; | ||
|
||
import { vérifierDossierRaccordement } from './raccordement.then'; | ||
|
||
Alors( | ||
`la demande complète de raccordement devrait être consultable dans le dossier de raccordement du projet lauréat`, | ||
async function (this: PotentielWorld) { | ||
const { identifiantProjet } = this.lauréatWorld; | ||
const { référenceDossier } = this.raccordementWorld; | ||
await waitForExpect(async () => { | ||
const raccordement = await mediator.send<Raccordement.ConsulterRaccordementQuery>({ | ||
type: 'Réseau.Raccordement.Query.ConsulterRaccordement', | ||
data: { | ||
identifiantProjetValue: identifiantProjet.formatter(), | ||
}, | ||
}); | ||
|
||
const dossierRaccordement = | ||
await mediator.send<Raccordement.ConsulterDossierRaccordementQuery>({ | ||
type: 'Réseau.Raccordement.Query.ConsulterDossierRaccordement', | ||
data: { | ||
identifiantProjetValue: identifiantProjet.formatter(), | ||
référenceDossierRaccordementValue: référenceDossier, | ||
}, | ||
}); | ||
|
||
vérifierRaccordement.call(this, identifiantProjet, raccordement); | ||
vérifierDossierRaccordement.call(this, identifiantProjet, dossierRaccordement); | ||
|
||
assert(Option.isSome(dossierRaccordement), 'dossierRaccordement is undefined'); | ||
assert( | ||
dossierRaccordement.demandeComplèteRaccordement, | ||
'demandeComplèteRaccordement is undefined', | ||
); | ||
const actualAccuséRéception = dossierRaccordement.demandeComplèteRaccordement.accuséRéception; | ||
const { accuséRéception: expectedAccuséRéception } = this.raccordementWorld | ||
.demandeComplèteDeRaccordement.modifierFixture.aÉtéCréé | ||
? this.raccordementWorld.demandeComplèteDeRaccordement.modifierFixture | ||
: this.raccordementWorld.demandeComplèteDeRaccordement.transmettreFixture; | ||
|
||
assert(actualAccuséRéception, 'actualAccuséRéception is not defined'); | ||
const result = await mediator.send<ConsulterDocumentProjetQuery>({ | ||
type: 'Document.Query.ConsulterDocumentProjet', | ||
data: { | ||
documentKey: actualAccuséRéception.formatter(), | ||
}, | ||
}); | ||
|
||
const actualContent = await convertReadableStreamToString(result.content); | ||
const expectedContent = await convertReadableStreamToString(expectedAccuséRéception.content); | ||
actualContent.should.be.equal(expectedContent); | ||
}); | ||
}, | ||
); | ||
|
||
function vérifierRaccordement( | ||
this: PotentielWorld, | ||
identifiantProjet: IdentifiantProjet.ValueType, | ||
raccordement: Option.Type<Raccordement.ConsulterRaccordementReadModel>, | ||
) { | ||
const { raccordement: expectedRaccordement } = mapToPlainObject( | ||
this.raccordementWorld.mapToExpected(identifiantProjet), | ||
); | ||
const actualRaccordement = mapToPlainObject(raccordement); | ||
|
||
// HACK : misÀJourLe vaut la date de l'event (created_at), | ||
// on ne peut pas calculer cette date de manière exacte dans les tests | ||
if (Option.isSome(actualRaccordement)) { | ||
for (const doss of actualRaccordement.dossiers) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
delete (doss as any).misÀJourLe; | ||
} | ||
} | ||
|
||
actualRaccordement.should.be.deep.equal( | ||
expectedRaccordement, | ||
`le raccordement n'est pas identique`, | ||
); | ||
} |
Oops, something went wrong.