Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rGregnanin committed Jan 20, 2025
1 parent 56401c1 commit 40f9698
Showing 1 changed file with 47 additions and 53 deletions.
100 changes: 47 additions & 53 deletions packages/purpose-process/test/updatePurpose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getMockPurposeVersion,
getMockValidRiskAnalysisForm,
getMockValidRiskAnalysis,
writeInReadmodel,
decodeProtobufPayload,
getRandomAuthData,
getMockDelegation,
Expand All @@ -26,7 +25,6 @@ import {
Purpose,
purposeVersionState,
generateId,
toReadModelEService,
DraftPurposeUpdatedV2,
toPurposeV2,
PurposeId,
Expand All @@ -35,7 +33,6 @@ import {
EServiceId,
RiskAnalysis,
eserviceMode,
toReadModelTenant,
delegationKind,
delegationState,
Agreement,
Expand All @@ -62,9 +59,7 @@ import {
addOnePurpose,
createUpdatedPurpose,
readLastPurposeEvent,
eservices,
purposeService,
tenants,
addOneDelegation,
addOneTenant,
addOneEService,
Expand Down Expand Up @@ -146,8 +141,8 @@ describe("updatePurpose and updateReversePurpose", () => {

it("Should write on event store for the update of a purpose of an e-service in mode DELIVER (including title change)", async () => {
await addOnePurpose(purposeForDeliver);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

const { purpose, isRiskAnalysisValid } = await purposeService.updatePurpose(
purposeForDeliver.id,
Expand Down Expand Up @@ -187,8 +182,8 @@ describe("updatePurpose and updateReversePurpose", () => {
});
it("Should write on event store for the update of a purpose of an e-service in mode DELIVER (no title change)", async () => {
await addOnePurpose(purposeForDeliver);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

const updateContentWithoutTitle = {
...purposeUpdateContent,
Expand Down Expand Up @@ -233,8 +228,8 @@ describe("updatePurpose and updateReversePurpose", () => {
});
it("Should write on event store for the update of a purpose of an e-service in mode RECEIVE (including title change)", async () => {
await addOnePurpose(purposeForReceive);
await writeInReadmodel(toReadModelEService(eServiceReceive), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceReceive);
await addOneTenant(tenant);

const { purpose, isRiskAnalysisValid } =
await purposeService.updateReversePurpose(
Expand Down Expand Up @@ -292,8 +287,8 @@ describe("updatePurpose and updateReversePurpose", () => {
await addOnePurpose(delegatePurpose);
await addOneDelegation(delegation);
await addSomeRandomDelegations(delegatePurpose, addOneDelegation);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

const updateContentWithoutTitle = {
...purposeUpdateContent,
Expand Down Expand Up @@ -356,8 +351,8 @@ describe("updatePurpose and updateReversePurpose", () => {
await addOnePurpose(delegatePurpose);
await addOneDelegation(delegation);
await addSomeRandomDelegations(purposeForDeliver, addOneDelegation);
await writeInReadmodel(toReadModelEService(eServiceReceive), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceReceive);
await addOneTenant(tenant);

const { purpose, isRiskAnalysisValid } =
await purposeService.updateReversePurpose(
Expand Down Expand Up @@ -606,8 +601,8 @@ describe("updatePurpose and updateReversePurpose", () => {
expect(isRiskAnalysisValid).toBe(true);
});
it("Should throw purposeNotFound if the purpose doesn't exist", async () => {
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

const purposeId: PurposeId = unsafeBrandId(generateId());

Expand All @@ -627,8 +622,8 @@ describe("updatePurpose and updateReversePurpose", () => {
};

await addOnePurpose(mockPurpose);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

const organizationId: TenantId = unsafeBrandId(generateId());

Expand All @@ -654,8 +649,8 @@ describe("updatePurpose and updateReversePurpose", () => {
};

await addOnePurpose(mockPurpose);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updatePurpose(mockPurpose.id, purposeUpdateContent, {
Expand Down Expand Up @@ -702,7 +697,7 @@ describe("updatePurpose and updateReversePurpose", () => {
};

await addOnePurpose(mockPurpose);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneTenant(tenant);

expect(
purposeService.updatePurpose(mockPurpose.id, purposeUpdateContent, {
Expand All @@ -715,8 +710,8 @@ describe("updatePurpose and updateReversePurpose", () => {
});
it("should throw eServiceModeNotAllowed if the eService mode is incorrect when expecting DELIVER", async () => {
await addOnePurpose(purposeForReceive);
await writeInReadmodel(toReadModelEService(eServiceReceive), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceReceive);
await addOneTenant(tenant);

expect(
purposeService.updatePurpose(purposeForReceive.id, purposeUpdateContent, {
Expand All @@ -731,8 +726,8 @@ describe("updatePurpose and updateReversePurpose", () => {
});
it("should throw eServiceModeNotAllowed if the eService mode is incorrect when expecting RECEIVE", async () => {
await addOnePurpose(purposeForDeliver);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updateReversePurpose(
Expand All @@ -751,8 +746,8 @@ describe("updatePurpose and updateReversePurpose", () => {
});
it("Should throw missingFreeOfChargeReason if isFreeOfCharge is true but freeOfChargeReason is missing", async () => {
await addOnePurpose(purposeForDeliver);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updatePurpose(
Expand All @@ -772,8 +767,7 @@ describe("updatePurpose and updateReversePurpose", () => {
});
it("Should throw tenantNotFound if the tenant does not exist", async () => {
await addOnePurpose(purposeForDeliver);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);

await addOneEService(eServiceDeliver);
expect(
purposeService.updatePurpose(purposeForDeliver.id, purposeUpdateContent, {
authData: getRandomAuthData(tenant.id),
Expand All @@ -784,7 +778,7 @@ describe("updatePurpose and updateReversePurpose", () => {
).rejects.toThrowError(tenantNotFound(tenant.id));

await addOnePurpose(purposeForReceive);
await writeInReadmodel(toReadModelEService(eServiceReceive), eservices);
await addOneEService(eServiceReceive);

expect(
purposeService.updateReversePurpose(
Expand All @@ -806,8 +800,8 @@ describe("updatePurpose and updateReversePurpose", () => {
};

await addOnePurpose(purposeForDeliver);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(mockTenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(mockTenant);

expect(
purposeService.updatePurpose(purposeForDeliver.id, purposeUpdateContent, {
Expand All @@ -820,8 +814,8 @@ describe("updatePurpose and updateReversePurpose", () => {
});
it("Should throw riskAnalysisValidationFailed if the risk analysis is not valid in updatePurpose", async () => {
await addOnePurpose(purposeForDeliver);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

const invalidRiskAnalysis: RiskAnalysis = {
...validRiskAnalysis,
Expand Down Expand Up @@ -862,8 +856,8 @@ describe("updatePurpose and updateReversePurpose", () => {
};

await addOnePurpose(purposeWithInvalidRiskAnalysis);
await writeInReadmodel(toReadModelEService(eServiceReceive), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceReceive);
await addOneTenant(tenant);

expect(
purposeService.updateReversePurpose(
Expand Down Expand Up @@ -900,8 +894,8 @@ describe("updatePurpose and updateReversePurpose", () => {

await addOnePurpose(delegatePurpose);
await addOneDelegation(delegation);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);
expect(
purposeService.updatePurpose(delegatePurpose.id, purposeUpdateContent, {
authData,
Expand Down Expand Up @@ -936,8 +930,8 @@ describe("updatePurpose and updateReversePurpose", () => {

await addOnePurpose(delegatePurpose);
await addOneDelegation(delegation);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updateReversePurpose(
Expand Down Expand Up @@ -967,8 +961,8 @@ describe("updatePurpose and updateReversePurpose", () => {
};

await addOnePurpose(delegatePurpose);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updateReversePurpose(
Expand All @@ -995,8 +989,8 @@ describe("updatePurpose and updateReversePurpose", () => {
};

await addOnePurpose(delegatePurpose);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updateReversePurpose(
Expand Down Expand Up @@ -1030,8 +1024,8 @@ describe("updatePurpose and updateReversePurpose", () => {

await addOnePurpose(delegatePurpose);
await addOneDelegation(delegation);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updatePurpose(
Expand Down Expand Up @@ -1063,8 +1057,8 @@ describe("updatePurpose and updateReversePurpose", () => {

await addOnePurpose(delegatePurpose);
await addOneDelegation(delegation);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updateReversePurpose(
Expand Down Expand Up @@ -1097,8 +1091,8 @@ describe("updatePurpose and updateReversePurpose", () => {

await addOnePurpose(delegatePurpose);
await addOneDelegation(delegation);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updatePurpose(
Expand Down Expand Up @@ -1131,8 +1125,8 @@ describe("updatePurpose and updateReversePurpose", () => {

await addOnePurpose(delegatePurpose);
await addOneDelegation(delegation);
await writeInReadmodel(toReadModelEService(eServiceDeliver), eservices);
await writeInReadmodel(toReadModelTenant(tenant), tenants);
await addOneEService(eServiceDeliver);
await addOneTenant(tenant);

expect(
purposeService.updateReversePurpose(
Expand Down

0 comments on commit 40f9698

Please sign in to comment.