Skip to content

Commit

Permalink
Add bad case in test
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrotaje committed Nov 6, 2024
1 parent f02882f commit 60e0808
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions packages/agreement-process/test/rejectAgreement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getMockAgreement,
getMockCertifiedTenantAttribute,
getMockDeclaredTenantAttribute,
getMockDelegationProducer,
getMockDescriptorPublished,
getMockEService,
getMockEServiceAttribute,
Expand All @@ -26,6 +27,7 @@ import {
TenantId,
VerifiedTenantAttribute,
agreementState,
delegationState,
generateId,
toAgreementV2,
} from "pagopa-interop-models";
Expand All @@ -41,6 +43,7 @@ import {
} from "../src/model/domain/errors.js";
import {
addOneAgreement,
addOneDelegation,
addOneEService,
addOneTenant,
agreementService,
Expand Down Expand Up @@ -378,4 +381,87 @@ describe("reject agreement", () => {
descriptorNotFound(eservice.id, agreement.descriptorId)
);
});

it("should throw operationNotAllowed when the requester is the producer and there is an active delegation", async () => {
const eservice: EService = {
...getMockEService(),
descriptors: [getMockDescriptorPublished()],
};
const consumer = getMockTenant();
const delegate = getMockTenant();
const agreement = {
...getMockAgreement(),
state: randomArrayItem(agreementRejectableStates),
eserviceId: eservice.id,
producerId: eservice.producerId,
consumerId: consumer.id,
descriptorId: eservice.descriptors[0].id,
};
const authData = getRandomAuthData(agreement.producerId);
const delegation = getMockDelegationProducer({
delegateId: delegate.id,
eserviceId: eservice.id,
state: delegationState.active,
});

await addOneAgreement(agreement);
await addOneEService(eservice);
await addOneTenant(consumer);
await addOneTenant(delegate);
await addOneDelegation(delegation);

await expect(
agreementService.rejectAgreement(
agreement.id,
"Rejected by producer due to test reasons",
{
authData,
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
}
)
).rejects.toThrowError(operationNotAllowed(authData.organizationId));
});

it("should throw a operationNotAllowed error when the requester is the delegate but the delegation in not active", async () => {
const eservice: EService = {
...getMockEService(),
descriptors: [getMockDescriptorPublished()],
};
const consumer = getMockTenant();
const agreement = {
...getMockAgreement(),
state: randomArrayItem(agreementRejectableStates),
eserviceId: eservice.id,
producerId: eservice.producerId,
consumerId: consumer.id,
descriptorId: eservice.descriptors[0].id,
};
const authData = getRandomAuthData();
const delegation = getMockDelegationProducer({
delegateId: authData.organizationId,
eserviceId: eservice.id,
state: delegationState.waitingForApproval,
});

await addOneAgreement(agreement);
await addOneEService(eservice);
await addOneTenant(consumer);
await addOneDelegation(delegation);

await expect(
agreementService.rejectAgreement(
agreement.id,
"Rejected by producer due to test reasons",

{
authData,
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
}
)
).rejects.toThrowError(operationNotAllowed(authData.organizationId));
});
});

0 comments on commit 60e0808

Please sign in to comment.