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

feat: [SIW-1697] Added wallet instance revoke endpoint #1154

Merged
merged 7 commits into from
Oct 3, 2024

Conversation

silvicir
Copy link
Contributor

@silvicir silvicir commented Oct 3, 2024

List of Changes

  1. Added PUT /wallet-instances/current/status endpoint for user wallet instance revoke
  2. Added unit tests
  3. Added 503 as response status in wallet endpoint

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Chore (nothing changes by a user perspective)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Copy link

github-actions bot commented Oct 3, 2024

Jira Pull Request Link

This Pull Request refers to the following Jira issue SIW-1697

req.body,
SetCurrentWalletInstanceStatusBody.decode,
E.mapLeft((errors) =>
ResponseErrorInternal(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about

Suggested change
ResponseErrorInternal(
ResponseErrorValidation(

@@ -183,4 +227,21 @@ export default class IoWalletController {
),
TE.map((response) => response.value.id)
);

// TODO SIW-1706
private readonly ensureFiscalCodeIsAllowed: (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding tests? ie.

import { FiscalCode, NonEmptyString } from "@pagopa/ts-commons/lib/strings";
import * as TE from "fp-ts/TaskEither";
import { getResponseErrorForbiddenNotAuthorized } from "@pagopa/ts-commons/lib/responses";
import IoWalletController from "../../src/controllers/ioWalletController";
import IoWalletService from "../../src/services/ioWalletService";

// Mock the IoWalletService
const ioWalletServiceMock = {
  getSubscription: jest.fn(),
} as unknown as IoWalletService;

const ioWalletController = new IoWalletController(ioWalletServiceMock);

describe("ensureFiscalCodeIsAllowed", () => {
  it("should return right when the fiscal code is allowed", async () => {
    // Mock successful response from getSubscription
    ioWalletServiceMock.getSubscription.mockReturnValueOnce(
      TE.right({
        kind: "IResponseSuccessJson",
        value: { state: "ACTIVE" },
      })
    );

    const fiscalCode: FiscalCode = "VALIDFISCALCODE" as FiscalCode;
    const result = await ioWalletController.ensureFiscalCodeIsAllowed(fiscalCode)();

    expect(result).toEqual(TE.right(undefined));
  });

  it("should return left when the fiscal code is not allowed", async () => {
    // Mock unsuccessful response from getSubscription
    ioWalletServiceMock.getSubscription.mockReturnValueOnce(TE.left(new Error()));

    const fiscalCode: FiscalCode = "INVALIDFISCALCODE" as FiscalCode;
    const result = await ioWalletController.ensureFiscalCodeIsAllowed(fiscalCode)();

    expect(result).toEqual(
      TE.left(getResponseErrorForbiddenNotAuthorized("Not authorized to perform this action"))
    );
  });

  it("should return left when the fiscal code is invalid", async () => {
    const fiscalCode: FiscalCode = "" as FiscalCode; // Empty fiscal code
    const result = await ioWalletController.ensureFiscalCodeIsAllowed(fiscalCode)();

    expect(result).toEqual(
      TE.left(getResponseErrorForbiddenNotAuthorized("Not authorized to perform this action"))
    );
  });
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensureFiscalCodeIsAllowed is a private method

Copy link

sonarcloud bot commented Oct 3, 2024

@silvicir silvicir merged commit 7bdec5c into master Oct 3, 2024
6 checks passed
@silvicir silvicir deleted the SIW-1697-add-wallet-instance-revoke-endpoint branch October 3, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants