|
|
@@ -23,7 +23,7 @@ import {
|
|
|
import nock from 'nock';
|
|
|
import fetch from 'node-fetch';
|
|
|
import path from 'path';
|
|
|
-import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
|
|
|
+import { afterAll, afterEach, beforeAll, describe, expect, it, onTestFinished, vi } from 'vitest';
|
|
|
|
|
|
import { initialData } from '../../../e2e-common/e2e-initial-data';
|
|
|
import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
|
|
|
@@ -582,6 +582,55 @@ describe('Mollie payments', () => {
|
|
|
expect(mollieRequest.captureMode).toBe('manual');
|
|
|
});
|
|
|
|
|
|
+ it('Should not allow setting immediateCapture=false via client input, when it is already set on the plugin level to true', async () => {
|
|
|
+ const originalImmediateCapture = MolliePlugin.options.immediateCapture;
|
|
|
+ MolliePlugin.options.immediateCapture = true;
|
|
|
+ const logSpy = vi.spyOn(Logger, 'warn');
|
|
|
+ onTestFinished(() => {
|
|
|
+ // Revert back to plugin setting for next test
|
|
|
+ MolliePlugin.options.immediateCapture = originalImmediateCapture;
|
|
|
+ logSpy.mockClear();
|
|
|
+ });
|
|
|
+ let mollieRequest: any;
|
|
|
+ nock('https://api.mollie.com/')
|
|
|
+ .post('/v2/payments', body => {
|
|
|
+ mollieRequest = body;
|
|
|
+ return true;
|
|
|
+ })
|
|
|
+ .reply(200, mollieMockData.molliePaymentResponse);
|
|
|
+ await shopClient.query(CREATE_MOLLIE_PAYMENT_INTENT, {
|
|
|
+ input: {
|
|
|
+ immediateCapture: false,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ expect(logSpy.mock.calls?.[0]?.[0]).toContain(
|
|
|
+ `'immediateCapture' is overridden by the plugin options to 'true'`,
|
|
|
+ );
|
|
|
+ expect(mollieRequest.captureMode).toBe('automatic');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Should not allow setting immediateCapture=true via client input, when it is already set on the plugin level to false', async () => {
|
|
|
+ MolliePlugin.options.immediateCapture = false;
|
|
|
+ const logSpy = vi.spyOn(Logger, 'warn');
|
|
|
+ let mollieRequest: any;
|
|
|
+ nock('https://api.mollie.com/')
|
|
|
+ .post('/v2/payments', body => {
|
|
|
+ mollieRequest = body;
|
|
|
+ return true;
|
|
|
+ })
|
|
|
+ .reply(200, mollieMockData.molliePaymentResponse);
|
|
|
+ await shopClient.query(CREATE_MOLLIE_PAYMENT_INTENT, {
|
|
|
+ input: {
|
|
|
+ immediateCapture: true,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ MolliePlugin.options.immediateCapture = undefined; // Reset again for next test
|
|
|
+ expect(logSpy.mock.calls?.[0]?.[0]).toContain(
|
|
|
+ `'immediateCapture' is overridden by the plugin options to 'false'`,
|
|
|
+ );
|
|
|
+ expect(mollieRequest.captureMode).toBe('manual');
|
|
|
+ });
|
|
|
+
|
|
|
it('Should authorize payment with immediateCapture = false', async () => {
|
|
|
nock('https://api.mollie.com/')
|
|
|
.get(`/v2/payments/${mollieMockData.molliePaymentResponse.id}`)
|