From cef9f849ab3cee12a6aef833194d10536aa78c63 Mon Sep 17 00:00:00 2001 From: King-Hin Leung Date: Mon, 18 Mar 2024 15:29:40 +0100 Subject: [PATCH] Add unit test for getPaymentMethods --- .github/workflows/ci.yml | 2 +- .../services/adyen-payment.service.spec.ts | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ba80ba..cebe353 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,4 +53,4 @@ jobs: run: npm run build - name: Execute tests - run: npm run test \ No newline at end of file + run: npm run test -- --coverage \ No newline at end of file diff --git a/processor/test/services/adyen-payment.service.spec.ts b/processor/test/services/adyen-payment.service.spec.ts index 69edfc7..5bab259 100644 --- a/processor/test/services/adyen-payment.service.spec.ts +++ b/processor/test/services/adyen-payment.service.spec.ts @@ -29,7 +29,11 @@ import { HealthCheckResult, } from '@commercetools/connect-payments-sdk'; import { SupportedPaymentComponentsSchemaDTO } from '../../src/dtos/operations/payment-componets.dto'; -import { CreatePaymentRequestDTO, CreateSessionRequestDTO } from '../../src/dtos/adyen-payment.dto'; +import { + CreatePaymentRequestDTO, + CreateSessionRequestDTO, + PaymentMethodsRequestDTO +} from '../../src/dtos/adyen-payment.dto'; import * as FastifyContext from '../../src/libs/fastify/context/context'; import { PaymentResponse } from '@adyen/api-library/lib/src/typings/checkout/paymentResponse'; @@ -216,6 +220,23 @@ describe('adyen-payment.service', () => { expect(result?.paymentReference).toStrictEqual('123456'); }); + test('getPaymentMethods', async () => { + const getPaymentMethodsOpts: { data: PaymentMethodsRequestDTO } = { + data: {}, + }; + + jest.spyOn(DefaultCartService.prototype, 'getCart').mockResolvedValue(mockGetCartResult()); + jest.spyOn(DefaultCartService.prototype, 'getPaymentAmount').mockResolvedValue(mockGetPaymentAmount); + jest.spyOn(PaymentsApi.prototype, 'paymentMethods').mockResolvedValue(mockAdyenPaymentMethodsResponse); + jest.spyOn(FastifyContext, 'getAllowedPaymentMethodsFromContext').mockReturnValue(['card']); + + const adyenPaymentService: AdyenPaymentService = new AdyenPaymentService(opts); + const result = await adyenPaymentService.getPaymentMethods(getPaymentMethodsOpts); + + expect(result.paymentMethods).toBeDefined(); + expect(result.paymentMethods).toHaveLength(0); + }); + test('createSession', async () => { const createSessionOpts: { data: CreateSessionRequestDTO } = { data: {},