Skip to content

Commit

Permalink
Add unit test for getPaymentMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
leungkinghin-ct committed Mar 18, 2024
1 parent cc9681f commit cef9f84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
run: npm run build

- name: Execute tests
run: npm run test
run: npm run test -- --coverage
23 changes: 22 additions & 1 deletion processor/test/services/adyen-payment.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: {},
Expand Down

0 comments on commit cef9f84

Please sign in to comment.