Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIN-5934 getPurposes delegation test #1367

Draft
wants to merge 1 commit into
base: PIN-5881-UpdatePurposeDelegtionTest
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions packages/purpose-process/test/getPurposes.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
Agreement,
EService,
EServiceId,
Purpose,
TenantId,
agreementState,
delegationKind,
delegationState,
generateId,
Expand All @@ -19,9 +21,12 @@ import {
getMockValidRiskAnalysisForm,
getMockDelegation,
getMockTenant,
addSomeRandomDelegations,
getMockAgreement,
} from "pagopa-interop-commons-test/index.js";
import { genericLogger } from "pagopa-interop-commons";
import {
addOneAgreement,
addOneDelegation,
addOneEService,
addOnePurpose,
Expand Down Expand Up @@ -526,6 +531,133 @@ describe("getPurposes", async () => {
expect(result.totalCount).toBe(0);
expect(result.results).toEqual([]);
});
it("should get the purposes if the requester is an e-service delegated consumer", async () => {
const delegation = getMockDelegation({
kind: delegationKind.delegatedConsumer,
eserviceId: mockPurpose1.eserviceId,
delegatorId: mockPurpose1.consumerId,
delegateId: consumerId1,
state: delegationState.active,
});

await addOneDelegation(delegation);

const result = await purposeService.getPurposes(
delegation.delegateId,
{
eservicesIds: [],
consumersIds: [],
producersIds: [],
states: [],
excludeDraft: undefined,
},
{ offset: 0, limit: 50 },
genericLogger
);
expect(result.totalCount).toBe(7);
expect(result.results).toEqual([
mockPurpose1,
mockPurpose2,
mockPurpose3,
mockPurpose4,
mockPurpose5,
mockPurpose6,
mockPurpose7,
]);
});
it("should succeed when requester is Consumer Delegate and the eservice was created by a delegated tenant and you should get the purposes", async () => {
const producer = {
...getMockTenant(),
id: generateId<TenantId>(),
kind: tenantKind.PA,
};
const producerDelegate = {
...getMockTenant(),
id: generateId<TenantId>(),
kind: tenantKind.PA,
};
const consumer = {
...getMockTenant(),
id: generateId<TenantId>(),
kind: tenantKind.PA,
};
const consumerDelegate = {
...getMockTenant(),
id: generateId<TenantId>(),
kind: tenantKind.PA,
};

const eservice: EService = {
...getMockEService(),
producerId: producer.id,
};
const agreement: Agreement = {
...getMockAgreement(),
producerId: producer.id,
consumerId: consumer.id,
eserviceId: eservice.id,
state: agreementState.active,
};

const delegatePurpose: Purpose = {
...getMockPurpose(),
consumerId: consumer.id,
eserviceId: eservice.id,
versions: [getMockPurposeVersion(purposeVersionState.active)],
};

const producerDelegation = getMockDelegation({
kind: delegationKind.delegatedProducer,
eserviceId: eservice.id,
delegatorId: producer.id,
delegateId: producerDelegate.id,
state: delegationState.active,
});

const consumerDelegation = getMockDelegation({
kind: delegationKind.delegatedConsumer,
eserviceId: eservice.id,
delegatorId: consumer.id,
delegateId: consumerDelegate.id,
state: delegationState.active,
});

await addOneTenant(producerDelegate);
await addOneTenant(producer);
await addOneTenant(consumerDelegate);
await addOneTenant(consumer);
await addOneEService(eservice);
await addOneAgreement(agreement);
await addOnePurpose(delegatePurpose);
await addOneDelegation(producerDelegation);
await addOneDelegation(consumerDelegation);
await addSomeRandomDelegations(delegatePurpose, addOneDelegation);

const result = await purposeService.getPurposes(
consumerDelegation.delegateId,
{
eservicesIds: [],
consumersIds: [],
producersIds: [],
states: [],
excludeDraft: undefined,
},
{ offset: 0, limit: 50 },
genericLogger
);

expect(result.totalCount).toBe(8);
expect(result.results).toEqual([
mockPurpose1,
delegatePurpose,
mockPurpose2,
mockPurpose3,
mockPurpose4,
mockPurpose5,
mockPurpose6,
mockPurpose7,
]);
});

describe("Producer Delegation active for provided producerIds filter", async () => {
it("should get the purposes if they exist (parameters: producersIds with only delegateId)", async () => {
Expand Down
Loading