Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ecamellini committed Nov 19, 2024
1 parent 27c4429 commit 9f4c5c9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
3 changes: 2 additions & 1 deletion packages/delegation-process/test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": ["../../../.eslintrc.cjs"],
"rules": {
"functional/immutable-data": "off",
"sonarjs/no-identical-functions": "off"
"sonarjs/no-identical-functions": "off",
"@typescript-eslint/no-non-null-assertion": "off"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getMockDelegation,
getMockTenant,
getMockEService,
getMockAuthData,
getRandomAuthData,
} from "pagopa-interop-commons-test/index.js";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import {
Expand Down Expand Up @@ -63,6 +63,7 @@ describe("approve producer delegation", () => {

it("should approve delegation if validations succeed", async () => {
const delegationId = generateId<DelegationId>();
const authData = getRandomAuthData(delegate.id);

const delegation = getMockDelegation({
kind: delegationKind.delegatedProducer,
Expand All @@ -77,7 +78,7 @@ describe("approve producer delegation", () => {
expect(version).toBe("0");

await delegationProducerService.approveProducerDelegation(delegation.id, {
authData: getMockAuthData(delegate.id),
authData,
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand Down Expand Up @@ -107,7 +108,7 @@ describe("approve producer delegation", () => {
stamps: {
...delegation.stamps,
activation: {
who: delegate.id,
who: authData.userId,
when: currentExecutionTime,
},
},
Expand Down Expand Up @@ -163,7 +164,7 @@ describe("approve producer delegation", () => {
delegationProducerService.approveProducerDelegation(
nonExistentDelegationId,
{
authData: getMockAuthData(delegateId),
authData: getRandomAuthData(delegateId),
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand All @@ -186,7 +187,7 @@ describe("approve producer delegation", () => {

await expect(
delegationProducerService.approveProducerDelegation(delegation.id, {
authData: getMockAuthData(wrongDelegate.id),
authData: getRandomAuthData(wrongDelegate.id),
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand All @@ -208,7 +209,7 @@ describe("approve producer delegation", () => {

await expect(
delegationProducerService.approveProducerDelegation(delegation.id, {
authData: getMockAuthData(delegate.id),
authData: getRandomAuthData(delegate.id),
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand All @@ -235,7 +236,7 @@ describe("approve producer delegation", () => {
expect(version).toBe("0");

await delegationProducerService.approveProducerDelegation(delegation.id, {
authData: getMockAuthData(delegate.id),
authData: getRandomAuthData(delegate.id),
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe("create producer delegation", () => {
submittedAt: currentExecutionTime,
stamps: {
submission: {
who: delegatorId,
who: authData.userId,
when: currentExecutionTime,
},
},
Expand Down Expand Up @@ -216,7 +216,7 @@ describe("create producer delegation", () => {
submittedAt: currentExecutionTime,
stamps: {
submission: {
who: delegatorId,
who: authData.userId,
when: currentExecutionTime,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable functional/no-let */
import {
decodeProtobufPayload,
getMockAuthData,
getMockDelegation,
getMockTenant,
getRandomAuthData,
} from "pagopa-interop-commons-test/index.js";
import { describe, expect, it, vi } from "vitest";
import {
Expand Down Expand Up @@ -34,6 +34,7 @@ describe("reject producer delegation", () => {
vi.setSystemTime(currentExecutionTime);

const delegate = getMockTenant();
const authData = getRandomAuthData(delegate.id);
const delegation = getMockDelegation({
kind: delegationKind.delegatedProducer,
state: "WaitingForApproval",
Expand All @@ -47,7 +48,7 @@ describe("reject producer delegation", () => {
delegation.id,
rejectionReason,
{
authData: getMockAuthData(delegate.id),
authData,
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand All @@ -67,7 +68,7 @@ describe("reject producer delegation", () => {
rejectionReason,
stamps: {
...delegation.stamps,
rejection: { who: delegate.id, when: currentExecutionTime },
rejection: { who: authData.userId, when: currentExecutionTime },
},
});
expect(actualDelegation).toEqual(expectedDelegation);
Expand All @@ -83,7 +84,7 @@ describe("reject producer delegation", () => {
nonExistentDelegationId,
"",
{
authData: getMockAuthData(delegateId),
authData: getRandomAuthData(delegateId),
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand All @@ -104,7 +105,7 @@ describe("reject producer delegation", () => {

await expect(
delegationProducerService.rejectProducerDelegation(delegation.id, "", {
authData: getMockAuthData(wrongDelegate.id),
authData: getRandomAuthData(wrongDelegate.id),
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand All @@ -125,7 +126,7 @@ describe("reject producer delegation", () => {

await expect(
delegationProducerService.rejectProducerDelegation(delegation.id, "", {
authData: getMockAuthData(delegate.id),
authData: getRandomAuthData(delegate.id),
serviceName: "",
correlationId: generateId(),
logger: genericLogger,
Expand Down
27 changes: 14 additions & 13 deletions packages/delegation-process/test/revokeProducerDelegation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
unsafeBrandId,
DelegationContractId,
delegationKind,
UserId,
} from "pagopa-interop-models";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import {
Expand Down Expand Up @@ -51,7 +52,7 @@ type DelegationStateSeed =
};
stamps: {
rejection: {
who: TenantId;
who: UserId;
when: Date;
};
};
Expand All @@ -63,7 +64,7 @@ type DelegationStateSeed =
};
stamps: {
revocation: {
who: TenantId;
who: UserId;
when: Date;
};
};
Expand All @@ -83,7 +84,7 @@ const getNotRevocableStateSeeds = (): DelegationStateSeed[] => {
},
stamps: {
rejection: {
who: generateId<TenantId>(),
who: generateId<UserId>(),
when: rejectionOrRevokeDate,
},
},
Expand All @@ -95,7 +96,7 @@ const getNotRevocableStateSeeds = (): DelegationStateSeed[] => {
},
stamps: {
revocation: {
who: generateId<TenantId>(),
who: generateId<UserId>(),
when: rejectionOrRevokeDate,
},
},
Expand Down Expand Up @@ -149,11 +150,11 @@ describe("revoke producer delegation", () => {
submittedAt: delegationCreationDate,
stamps: {
submission: {
who: delegatorId,
who: generateId<UserId>(),
when: delegationCreationDate,
},
activation: {
who: delegateId,
who: generateId<UserId>(),
when: delegationActivationDate,
},
},
Expand Down Expand Up @@ -186,15 +187,15 @@ describe("revoke producer delegation", () => {
revokedAt: currentExecutionTime,
stamps: {
submission: {
who: delegatorId,
who: existentDelegation.stamps.submission.who,
when: delegationCreationDate,
},
activation: {
who: delegateId,
who: existentDelegation.stamps.activation!.who,
when: delegationActivationDate,
},
revocation: {
who: delegatorId,
who: authData.userId,
when: currentExecutionTime,
},
},
Expand Down Expand Up @@ -297,11 +298,11 @@ describe("revoke producer delegation", () => {
submittedAt: delegationCreationDate,
stamps: {
submission: {
who: delegatorId,
who: generateId<UserId>(),
when: delegationCreationDate,
},
approval: {
who: delegateId,
who: generateId<UserId>(),
when: delegationApprovalDate,
},
},
Expand Down Expand Up @@ -345,11 +346,11 @@ describe("revoke producer delegation", () => {
submittedAt: delegationCreationDate,
stamps: {
submission: {
who: delegatorId,
who: generateId<UserId>(),
when: delegationCreationDate,
},
activation: {
who: delegateId,
who: generateId<UserId>(),
when: delegationActivationDate,
},
...notRevocableDelegationState.stamps,
Expand Down

0 comments on commit 9f4c5c9

Please sign in to comment.