Skip to content

Commit

Permalink
MOL-536/MOL-566: add google pay method
Browse files Browse the repository at this point in the history
  • Loading branch information
tdang1-shopmacher committed Nov 21, 2024
1 parent 91d5c7a commit 76c4918
Show file tree
Hide file tree
Showing 6 changed files with 525 additions and 3 deletions.
14 changes: 14 additions & 0 deletions processor/tests/commercetools/action.commercetools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
changeTransactionTimestamp,
removeCustomLineItem,
setCustomFields,
setTransactionCustomField,
setTransactionCustomType,
} from '../../src/commercetools/action.commercetools';
import { CTTransactionState, CreateInterfaceInteractionParams } from '../../src/types/commercetools.types';
Expand Down Expand Up @@ -182,4 +183,17 @@ describe('Test actions.utils.ts', () => {
slug,
});
});

test('should return a action for adding transaction custom fields', () => {
const name = 'customFieldName';
const value = 'customFieldValue';
const transactionId = 'transactionId';

expect(setTransactionCustomField(name, value, transactionId)).toStrictEqual({
action: 'setTransactionCustomField',
name,
value,
transactionId,
});
});
});
63 changes: 62 additions & 1 deletion processor/tests/mollie/payment.mollie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
getPaymentById,
listPaymentMethods,
getApplePaySession,
getAllPaymentMethods,
} from '../../src/mollie/payment.mollie';
import { MollieApiError, PaymentCreateParams } from '@mollie/api-client';
import { Locale, MethodInclude, MethodsListParams, MollieApiError, PaymentCreateParams } from '@mollie/api-client';
import { logger } from '../../src/utils/logger.utils';
import CustomError from '../../src/errors/custom.error';
import { MOLLIE_VERSION_STRINGS } from '../../src/utils/constant.utils';
Expand Down Expand Up @@ -543,3 +544,63 @@ describe('getApplePaySession', () => {
}
});
});

describe('getAllPaymentMethods', () => {
it('should call getAllPaymentMethods with the correct parameters', async () => {
const options: MethodsListParams = {
locale: Locale.de_DE,
include: MethodInclude.pricing,
};

const queryParams = new URLSearchParams(options as any).toString();

const getAllPaymentMethodsEndpoint = `https://api.mollie.com/v2/methods/all?${queryParams as any}`;
const headers = {
'Content-Type': 'application/json',
Authorization: `Bearer ${getApiKey()}`,
versionStrings: MOLLIE_VERSION_STRINGS,
};

(fetch as unknown as jest.Mock).mockImplementation(async () =>
Promise.resolve({
json: () => Promise.resolve({ data: [] }),
headers: new Headers(),
ok: true,
redirected: false,
status: 201,
statusText: 'OK',
url: '',
}),
);

await getAllPaymentMethods(options);

expect(fetch).toHaveBeenCalledTimes(1);
expect(fetch).toHaveBeenCalledWith(getAllPaymentMethodsEndpoint, {
method: 'GET',
headers,
});
});

it('should be able to return a proper error message when error which is an instance of MollieApiError occurred', async () => {
const errorMessage = 'Something wrong happened';
const mollieApiError = new MollieApiError(errorMessage, { field: 'validationUrl' });

(fetch as unknown as jest.Mock).mockImplementation(async () => {
throw mollieApiError;
});

try {
await getAllPaymentMethods({});
} catch (error: unknown) {
expect(error).toBeInstanceOf(CustomError);
expect(logger.error).toBeCalledTimes(1);
expect(logger.error).toBeCalledWith(
`SCTM - getAllPaymentMethods - Failed to get all payment methods with unknown errors`,
{
error: mollieApiError,
},
);
}
});
});
26 changes: 26 additions & 0 deletions processor/tests/mollie/profile.mollie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,30 @@ describe('Test profile.mollie.ts', () => {

await expect(getProfile()).resolves.toThrow(errorMessage);
});

it('should return unknown errors when fetching the profile', async () => {
const errorMessage = 'SCTM - getProfile - Failed to get Mollie profile with unknown errors';
(initMollieClient as jest.Mock).mockReturnValue({
profiles: {
getCurrent: jest.fn().mockReturnValue(new Error(errorMessage)),
},
});

await expect(getProfile()).resolves.toThrow(errorMessage);
});

it('should return MollieApi errors when fetching the profile', async () => {
const errorMessage = `SCTM - getProfile - error: error, field: validationUrl`;
(initMollieClient as jest.Mock).mockReturnValue({
profiles: {
getCurrent: jest
.fn()
.mockReturnValue(
new MollieApiError('SCTM - getProfile - error: error, field: validationUrl', { field: 'validationUrl' }),
),
},
});

await expect(getProfile()).resolves.toThrow(errorMessage);
});
});
Loading

0 comments on commit 76c4918

Please sign in to comment.