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

chore: update critical packages, fix tests, update error check #186

Merged
merged 4 commits into from Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1,836 changes: 393 additions & 1,443 deletions extension/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions extension/package.json
Expand Up @@ -42,7 +42,7 @@
"jest": "27.4.7",
"nock": "13.2.2",
"node-mocks-http": "1.11.0",
"nodemon": "2.0.15",
"nodemon": "2.0.20",
"prettier": "2.5.1",
"supertest": "6.2.1",
"ts-jest": "27.1.2",
Expand All @@ -58,7 +58,7 @@
"@commercetools/sdk-middleware-http": "6.1.0",
"@commercetools/sdk-middleware-user-agent": "2.1.5",
"@mollie/api-client": "3.6.0-beta.3",
"express": "4.17.2",
"express": "4.18.2",
"lodash": "4.17.21",
"morgan": "1.10.0",
"node-fetch-commonjs": "3.1.1",
Expand Down
4 changes: 2 additions & 2 deletions extension/tests/component/createOrder.test.ts
Expand Up @@ -2,7 +2,7 @@ import nock from 'nock';
import request from 'supertest';
import { v4 as uuid } from 'uuid';
import _ from 'lodash';
import { mocked } from 'ts-jest/utils';

import app from '../../src/app';
import config from '../../config/config';
import Logger from '../../src/logger/logger';
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('Create Order', () => {
beforeAll(() => {
// Ensure consistent uuid and datetime
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(() => '2021-11-10T14:02:45.858Z');
mocked(uuid).mockReturnValue('b2bd1698-9923-4704-9729-02db2de495d1');
jest.mocked(uuid).mockReturnValue('b2bd1698-9923-4704-9729-02db2de495d1');
// Credentials authentication flow is called first by commercetools client
authTokenScope = nock(`${authUrl}`).persist().post('/oauth/token').reply(200, {
access_token: 'vkFuQ6oTwj8_Ye4eiRSsqMeqLYNeQRJi',
Expand Down
4 changes: 2 additions & 2 deletions extension/tests/component/createOrderPayment.test.ts
Expand Up @@ -2,7 +2,7 @@ import nock from 'nock';
import request from 'supertest';
import { v4 as uuid } from 'uuid';
import _ from 'lodash';
import { mocked } from 'ts-jest/utils';

import app from '../../src/app';
import config from '../../config/config';
import Logger from '../../src/logger/logger';
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('Create Order Payment', () => {
beforeAll(() => {
// Ensure consistent uuid and datetime
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(() => '2021-11-10T14:02:45.858Z');
mocked(uuid).mockReturnValue('b2bd1698-9923-4704-9729-02db2de495d1');
jest.mocked(uuid).mockReturnValue('b2bd1698-9923-4704-9729-02db2de495d1');
// Credentials authentication flow is called first by commercetools client
authTokenScope = nock(`${authUrl}`).persist().post('/oauth/token').reply(200, {
access_token: 'vkFuQ6oTwj8_Ye4eiRSsqMeqLYNeQRJi',
Expand Down
4 changes: 2 additions & 2 deletions extension/tests/component/createRefund.test.ts
Expand Up @@ -3,7 +3,7 @@ import request from 'supertest';
import { v4 as uuid } from 'uuid';
import { CTTransactionState, CTTransactionType } from '../../src/types';
import _ from 'lodash';
import { mocked } from 'ts-jest/utils';

import app from '../../src/app';
import config from '../../config/config';
import Logger from '../../src/logger/logger';
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('Create Refund', () => {
beforeAll(() => {
// Ensure consistent uuid and datetime
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(() => '2021-11-10T14:02:45.858Z');
mocked(uuid).mockReturnValue('b2bd1698-9923-4704-9729-02db2de495d1');
jest.mocked(uuid).mockReturnValue('b2bd1698-9923-4704-9729-02db2de495d1');
// Credentials authentication flow is called first by commercetools client
authTokenScope = nock(`${authUrl}`).persist().post('/oauth/token').reply(200, {
access_token: 'vkFuQ6oTwj8_Ye4eiRSsqMeqLYNeQRJi',
Expand Down
4 changes: 2 additions & 2 deletions extension/tests/unit/app.test.ts
@@ -1,11 +1,11 @@
import request from 'supertest';
import app from '../../src/app';
import { mocked } from 'ts-jest/utils';

import { checkAuthorizationHeader } from '../../src/authentication/authenticationHandler';
jest.mock('../../src/authentication/authenticationHandler');

describe('App', () => {
mocked(checkAuthorizationHeader).mockImplementation(() => {
jest.mocked(checkAuthorizationHeader).mockImplementation(() => {
return {
isValid: true,
message: '',
Expand Down
6 changes: 3 additions & 3 deletions extension/tests/unit/makeActions.test.ts
@@ -1,5 +1,5 @@
import { v4 as uuid } from 'uuid';
import { mocked } from 'ts-jest/utils';

import { makeActions } from '../../src/makeActions';
import { ControllerAction } from '../../src/types';
import { createDateNowString } from '../../src/utils';
Expand All @@ -10,8 +10,8 @@ jest.mock('../../src/utils');
describe('makeActions', () => {
const mockUuid = 'f2e6db50-7bd8-4036-8e1f-9971b6226c62';
beforeAll(() => {
mocked(uuid).mockReturnValue(mockUuid);
mocked(createDateNowString).mockReturnValue('2021-10-08T12:12:02.625Z');
jest.mocked(uuid).mockReturnValue(mockUuid);
jest.mocked(createDateNowString).mockReturnValue('2021-10-08T12:12:02.625Z');
});
afterAll(() => {
jest.resetAllMocks();
Expand Down
25 changes: 12 additions & 13 deletions extension/tests/unit/requestHandlers/cancelOrder.test.ts
@@ -1,5 +1,4 @@
import { v4 as uuid } from 'uuid';
import { mocked } from 'ts-jest/utils';
import { Order } from '@mollie/api-client';
import { Action, CTPayment, CTTransaction } from '../../../src/types';
import cancelOrder, { getCancelOrderParams, createCtActions } from '../../../src/requestHandlers/cancelOrder';
Expand Down Expand Up @@ -29,8 +28,8 @@ describe('getCancelOrderParams', () => {
},
} as CTTransaction;
const mockMollieLines = [{ id: 'odl_1.tlaa3w' }, { id: 'odl_1.6997yo' }, { id: 'odl_1.cgark2' }];
mocked(findInitialTransaction).mockReturnValue(mockTransaction);
mocked(ctToMollieLines).mockReturnValue(mockMollieLines);
jest.mocked(findInitialTransaction).mockReturnValue(mockTransaction);
jest.mocked(ctToMollieLines).mockReturnValue(mockMollieLines);
const mockCtPayment = {
key: 'ord_3uwvfd',
transactions: [mockTransaction],
Expand Down Expand Up @@ -90,8 +89,8 @@ describe('getCancelOrderParams', () => {
},
} as CTTransaction;
const mockMollieLines = [{ id: 'odl_1.tlaa3w', quantity: 2, amount: { value: '5.00', currency: 'EUR' } }, { id: 'odl_1.cgark2' }];
mocked(findInitialTransaction).mockReturnValue(mockTransaction);
mocked(ctToMollieLines).mockReturnValue(mockMollieLines);
jest.mocked(findInitialTransaction).mockReturnValue(mockTransaction);
jest.mocked(ctToMollieLines).mockReturnValue(mockMollieLines);

const mockCtPayment = {
key: 'ord_3uwvfd',
Expand Down Expand Up @@ -133,8 +132,8 @@ describe('getCancelOrderParams', () => {
describe('createCtActions', () => {
beforeEach(() => {
const mockUuid = '3fea7470-5434-4056-a829-a187339e94d8';
mocked(uuid).mockReturnValue(mockUuid);
mocked(createDateNowString).mockReturnValue('2021-10-08T12:12:02.625Z');
jest.mocked(uuid).mockReturnValue(mockUuid);
jest.mocked(createDateNowString).mockReturnValue('2021-10-08T12:12:02.625Z');
});
afterEach(() => {
jest.clearAllMocks();
Expand All @@ -151,7 +150,7 @@ describe('createCtActions', () => {
},
},
} as CTTransaction;
mocked(findInitialTransaction).mockReturnValue(initialTransaction);
jest.mocked(findInitialTransaction).mockReturnValue(initialTransaction);
const mockCtPayment = {
key: 'ord_3uwvfd',
transactions: [initialTransaction],
Expand All @@ -170,8 +169,8 @@ describe('createCtActions', () => {
state: 'Initial',
custom: { fields: {} },
} as CTTransaction;
mocked(findInitialTransaction).mockReturnValue(initialTransaction);
mocked(mollieToCtLines).mockReturnValue('42c6d1fd-b942-433b-b6dd-41062c4b3a42');
jest.mocked(findInitialTransaction).mockReturnValue(initialTransaction);
jest.mocked(mollieToCtLines).mockReturnValue('42c6d1fd-b942-433b-b6dd-41062c4b3a42');
const mockCtPayment = {
key: 'ord_1wg40y',
transactions: [initialTransaction],
Expand Down Expand Up @@ -207,13 +206,13 @@ describe('cancelOrder', () => {
const mockLoggerError = jest.fn();
beforeEach(() => {
Logger.error = mockLoggerError;
mocked(createDateNowString).mockReturnValue('2021-10-08T12:12:02.625Z');
jest.mocked(createDateNowString).mockReturnValue('2021-10-08T12:12:02.625Z');
});
afterEach(() => {
jest.clearAllMocks();
});
it('Should call mollie, handle response and return actions when cancelling complete order', async () => {
mocked(isPartialTransaction).mockReturnValue(false);
jest.mocked(isPartialTransaction).mockReturnValue(false);
const mockedCtPayment: any = {
key: 'ord_jwtj05',
};
Expand Down Expand Up @@ -247,7 +246,7 @@ describe('cancelOrder', () => {
expect(cancelOrderRes.status).toBe(200);
});
it('Should call mollie, handle response and return actions when cancelling partial order', async () => {
mocked(isPartialTransaction).mockReturnValue(true);
jest.mocked(isPartialTransaction).mockReturnValue(true);
const mockedCtPayment: any = {
key: 'ord_jwtj05',
transactions: [
Expand Down
@@ -1,6 +1,5 @@
import { MollieClient, Refund } from '@mollie/api-client';
import _ from 'lodash';
import { mocked } from 'ts-jest/utils';
import PaymentRefundsBinder from '@mollie/api-client/dist/types/src/binders/payments/refunds/PaymentRefundsBinder';
import { ControllerAction, CTPayment, CTTransaction, CTTransactionState, CTTransactionType } from '../../../src/types';
import Logger from '../../../src/logger/logger';
Expand Down Expand Up @@ -59,10 +58,10 @@ describe('createCustomRefund', () => {
});

describe('201 - Success', () => {
mocked(makeActions.changeTransactionInteractionId).mockReturnValue({} as any);
mocked(makeActions.changeTransactionState).mockReturnValue({} as any);
mocked(makeActions.changeTransactionTimestamp).mockReturnValue({} as any);
mocked(makeActions.addInterfaceInteraction).mockReturnValue({} as any);
jest.mocked(makeActions.changeTransactionInteractionId).mockReturnValue({} as any);
jest.mocked(makeActions.changeTransactionState).mockReturnValue({} as any);
jest.mocked(makeActions.changeTransactionTimestamp).mockReturnValue({} as any);
jest.mocked(makeActions.addInterfaceInteraction).mockReturnValue({} as any);

it('should successfully call mollie create payment refund and return 201 response - pay now', async () => {
const ctPayment = _.cloneDeep(baseCTPayment);
Expand Down
29 changes: 19 additions & 10 deletions extension/tests/unit/requestHandlers/createOrder.test.ts
@@ -1,5 +1,4 @@
import { v4 as uuid } from 'uuid';
import { mocked } from 'ts-jest/utils';
import { Order, OrderLineType } from '@mollie/api-client';
import { cloneDeep, omit } from 'lodash';
import { makeMollieAmount } from '../../../src/utils';
Expand Down Expand Up @@ -81,7 +80,8 @@ describe('extractLocalizedName', () => {

describe('makeMollieLineCustom', () => {
it('Should make correct customLineItem parameters', () => {
mocked(makeMollieAmount)
jest
.mocked(makeMollieAmount)
.mockReturnValueOnce({ value: '-1.50', currency: 'EUR' }) // unitPrice
.mockReturnValueOnce({ value: '-1.50', currency: 'EUR' }) // totalAmount
.mockReturnValueOnce({ value: '-0.26', currency: 'EUR' }); // vatAmount
Expand All @@ -104,7 +104,8 @@ describe('makeMollieLineCustom', () => {

describe('makeMollieLine', () => {
it('Should make correct lineItem parameters', () => {
mocked(makeMollieAmount)
jest
.mocked(makeMollieAmount)
.mockReturnValueOnce({ value: '2.00', currency: 'EUR' }) // unitPrice
.mockReturnValueOnce({ value: '1.42', currency: 'EUR' }) // totalAmount
.mockReturnValueOnce({ value: '0.25', currency: 'EUR' }) // vatAmount
Expand Down Expand Up @@ -138,7 +139,8 @@ describe('getCreateOrderParams', () => {
jest.clearAllMocks();
});
it('Should make create order parameters', async () => {
mocked(makeMollieAmount)
jest
.mocked(makeMollieAmount)
.mockReturnValueOnce({ value: '7.04', currency: 'EUR' })
.mockReturnValueOnce({ value: '2.00', currency: 'EUR' })
.mockReturnValueOnce({ value: '1.42', currency: 'EUR' })
Expand All @@ -155,7 +157,8 @@ describe('getCreateOrderParams', () => {
await expect(getCreateOrderParams(ctPayment as CTPayment, ctCart as CTCart)).resolves.toMatchObject(mollieCreateOrderParams);
});
it('Should make create order parameters using customerEmail optional third argument', async () => {
mocked(makeMollieAmount)
jest
.mocked(makeMollieAmount)
.mockReturnValueOnce({ value: '7.04', currency: 'EUR' })
.mockReturnValueOnce({ value: '2.00', currency: 'EUR' })
.mockReturnValueOnce({ value: '1.42', currency: 'EUR' })
Expand Down Expand Up @@ -189,7 +192,8 @@ describe('getCreateOrderParams', () => {
expect(response).toMatchObject(mollieCreateOrderParams);
});
it('Should make create order parameters using cart.customerEmail field', async () => {
mocked(makeMollieAmount)
jest
.mocked(makeMollieAmount)
.mockReturnValueOnce({ value: '7.04', currency: 'EUR' })
.mockReturnValueOnce({ value: '2.00', currency: 'EUR' })
.mockReturnValueOnce({ value: '1.42', currency: 'EUR' })
Expand Down Expand Up @@ -243,8 +247,8 @@ describe('getCreateOrderParams', () => {
describe('createCTActions', () => {
beforeAll(() => {
const mockUuid = '3fea7470-5434-4056-a829-a187339e94d8';
mocked(uuid).mockReturnValue(mockUuid);
// mocked(createDateNowString).mockReturnValue('2021-12-15T08:21:15.495Z');
jest.mocked(uuid).mockReturnValue(mockUuid);
// jest.mocked(createDateNowString).mockReturnValue('2021-12-15T08:21:15.495Z');
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(() => '2021-12-15T08:21:15.495Z');
});

Expand Down Expand Up @@ -425,7 +429,11 @@ describe('makeMollieLines - shipping', () => {
};

it('should create mollie order line for shipping with correct amount', () => {
mocked(makeMollieAmount).mockReturnValueOnce({ value: '10.00', currency: 'EUR' }).mockReturnValueOnce({ value: '10.00', currency: 'EUR' }).mockReturnValueOnce({ value: '1.74', currency: 'EUR' });
jest
.mocked(makeMollieAmount)
.mockReturnValueOnce({ value: '10.00', currency: 'EUR' })
.mockReturnValueOnce({ value: '10.00', currency: 'EUR' })
.mockReturnValueOnce({ value: '1.74', currency: 'EUR' });
const orderLine = makeMollieLineShipping(shippingInfo);
expect(orderLine).toEqual({
type: OrderLineType.shipping_fee,
Expand All @@ -448,7 +456,8 @@ describe('makeMollieLines - shipping', () => {
});

it('should create mollie order line for shipping and handle discount amount', () => {
mocked(makeMollieAmount)
jest
.mocked(makeMollieAmount)
.mockReturnValueOnce({ value: '10.00', currency: 'EUR' })
.mockReturnValueOnce({ value: '0.00', currency: 'EUR' })
.mockReturnValueOnce({ value: '0.00', currency: 'EUR' })
Expand Down
@@ -1,6 +1,5 @@
import { Payment } from '@mollie/api-client';
import { v4 as uuid } from 'uuid';
import { mocked } from 'ts-jest/utils';
import createOrderPayment, { getOrdersPaymentsParams, createCtActions } from '../../../src/requestHandlers/createOrderPayment';
import { Action, CTPayment, CTTransactionState } from '../../../src/types';
import { makeActions } from '../../../src/makeActions';
Expand Down Expand Up @@ -140,7 +139,7 @@ describe('createCtActions', () => {
await expect(createCtActions({} as any as Payment, mockCtPayment)).rejects.toMatchObject(expectedError);
});
it('Should return an error when generating actions fails', async () => {
mocked(uuid).mockImplementationOnce(() => {
jest.mocked(uuid).mockImplementationOnce(() => {
throw new Error('Test error');
});
const mockCtPayment = {
Expand Down
3 changes: 1 addition & 2 deletions extension/tests/unit/requestHandlers/createShipment.test.ts
@@ -1,5 +1,4 @@
import { v4 as uuid } from 'uuid';
import { mocked } from 'ts-jest/utils';
import { CTPayment } from '../../../src/types';
import createShipment, { getShipmentParams, createCtActions } from '../../../src/requestHandlers/createShipment';
import Logger from '../../../src/logger/logger';
Expand Down Expand Up @@ -134,7 +133,7 @@ describe('getShipmentParams', () => {
describe('createCtActions', () => {
beforeAll(() => {
const mockUuid = '3fea7470-5434-4056-a829-a187339e94d8';
mocked(uuid).mockReturnValue(mockUuid);
jest.mocked(uuid).mockReturnValue(mockUuid);
});
afterAll(() => {
jest.clearAllMocks();
Expand Down
12 changes: 5 additions & 7 deletions extension/tests/unit/requestHandlers/getPaymentMethods.test.ts
@@ -1,7 +1,5 @@
import { mocked } from 'ts-jest/utils';
import { MollieClient } from '@mollie/api-client';
import MethodsBinder from '@mollie/api-client/dist/types/src/binders/methods/MethodsBinder';
// import MethodsResource from '@mollie/api-client/dist/types/src/resources/methods/MethodsResource';
import { CTPayment } from '../../../src/types/index';
import getPaymentMethods from '../../../src/requestHandlers/getPaymentMethods';
import { makeMollieAmount, createDateNowString } from '../../../src/utils';
Expand All @@ -24,11 +22,11 @@ describe('GetPaymentMethods', () => {

beforeAll(() => {
Logger.error = mockLogError;
mocked(createDateNowString).mockReturnValue('2021-10-08T12:12:02.625Z');
jest.mocked(createDateNowString).mockReturnValue('2021-10-08T12:12:02.625Z');
});
beforeEach(() => {
mockMethodsBinder.list = mockList;
mocked(makeMollieAmount).mockReturnValue({ value: '11.00', currency: 'EUR' });
jest.mocked(makeMollieAmount).mockReturnValue({ value: '11.00', currency: 'EUR' });
});

afterAll(() => {
Expand All @@ -43,7 +41,7 @@ describe('GetPaymentMethods', () => {
});

it('Should return status and one update action for commercetools', async () => {
mocked(makeActions.setCustomField).mockReturnValueOnce({
jest.mocked(makeActions.setCustomField).mockReturnValueOnce({
action: 'setCustomField',
name: 'paymentMethodsResponse',
value:
Expand Down Expand Up @@ -97,7 +95,7 @@ describe('GetPaymentMethods', () => {
});

it('Should return NO_PAYMENT_METHODS when methods returned are empty', async () => {
mocked(makeActions.setCustomField).mockReturnValueOnce({
jest.mocked(makeActions.setCustomField).mockReturnValueOnce({
action: 'setCustomField',
name: 'paymentMethodsResponse',
value: '{"count":0,"methods":"NO_AVAILABLE_PAYMENT_METHODS"}',
Expand Down Expand Up @@ -211,7 +209,7 @@ describe('Get Payment Methods - extractMethodListParameters', () => {

beforeEach(() => {
mockMethodsBinder.list = mockList;
mocked(makeMollieAmount).mockReturnValue({ value: '11.00', currency: 'EUR' });
jest.mocked(makeMollieAmount).mockReturnValue({ value: '11.00', currency: 'EUR' });
});

afterAll(() => {
Expand Down