Skip to content

Commit

Permalink
Fix newadminregion not being set for new supplier intervention type
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Jul 17, 2023
1 parent 0226612 commit 04a821e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,21 @@ export class InterventionBuilder {
}
}
if (type === SCENARIO_INTERVENTION_TYPE.NEW_SUPPLIER) {
newIntervention.newAdminRegion =
await this.adminRegionService.getAdminRegionById(
newSourcingLocations[0].adminRegionId!,
);
if (newSourcingLocations[0].producerId) {
newIntervention.newProducer =
await this.suppliersService.getSupplierById(
newSourcingLocations[0].producerId,
);
newIntervention.newAdminRegion =
await this.adminRegionService.getAdminRegionById(
newSourcingLocations[0].adminRegionId!,
);
}
if (newSourcingLocations[0].t1SupplierId) {
newIntervention.newT1Supplier =
await this.suppliersService.getSupplierById(
newSourcingLocations[0].t1SupplierId,
);
newIntervention.newAdminRegion =
await this.adminRegionService.getAdminRegionById(
newSourcingLocations[0].adminRegionId!,
);
}
}
return newIntervention;
Expand Down
44 changes: 39 additions & 5 deletions api/test/e2e/scenario-interventions/scenario-interventions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1871,10 +1871,10 @@ describe('ScenarioInterventionsModule (e2e)', () => {
);
expect(createdScenarioIntervention1.replacedT1Suppliers[0].id).toEqual(
childSupplier.id,
),
expect(
createdScenarioIntervention1.replacedBusinessUnits[0].id,
).toEqual(parentBusinessUnit.id);
);
expect(
createdScenarioIntervention1.replacedBusinessUnits[0].id,
).toEqual(parentBusinessUnit.id);

const responseBusinessUnits = await request(
testApplication.getHttpServer(),
Expand Down Expand Up @@ -1937,7 +1937,7 @@ describe('ScenarioInterventionsModule (e2e)', () => {
);

test(
'When I create a new Intervention to switch to a new Material' +
'When I create a new Intervention to switch to a new Material ' +
'Then said Intervention should retrieve the new Material and the new Admin Region',
async () => {
// ARRANGE
Expand Down Expand Up @@ -2100,6 +2100,40 @@ describe('ScenarioInterventionsModule (e2e)', () => {
expect(
(intervention as ScenarioIntervention).newAdminRegion.id,
).toEqual(newAdminRegion.id);

const responseOfChangeSupplierInterventionType = await request(
testApplication.getHttpServer(),
)
.post('/api/v1/scenario-interventions')
.set('Authorization', `Bearer ${jwtToken}`)
.send({
title: 'scenario intervention material',
startYear: 2020,
percentage: 50,
scenarioId: scenario.id,
materialIds: [parentMaterial.id],
t1SupplierIds: [childSupplier.id],
businessUnitIds: [parentBusinessUnit.id],
adminRegionIds: [parentAdminRegion.id],
type: SCENARIO_INTERVENTION_TYPE.NEW_SUPPLIER,
newLocationType: LOCATION_TYPES.ADMINISTRATIVE_REGION_OF_PRODUCTION,
newLocationCountryInput: parentAdminRegion.name,
newLocationAdminRegionInput: newAdminRegion.name,
});

const intervention2: ScenarioIntervention | null =
await scenarioInterventionRepository.findOne({
where: {
id: responseOfChangeSupplierInterventionType.body.data.id,
},
});

//ASSERT;
expect(intervention2).toBeTruthy();
expect((intervention2 as ScenarioIntervention).newMaterial).toBeFalsy();
expect(
(intervention2 as ScenarioIntervention).newAdminRegion.id,
).toEqual(newAdminRegion.id);
},
);

Expand Down

0 comments on commit 04a821e

Please sign in to comment.