From 6a6c567fd545021b0f33615e02f685dc726a5880 Mon Sep 17 00:00:00 2001 From: Jennie Robinson Faber Date: Mon, 20 Apr 2026 14:01:19 +0100 Subject: [PATCH] test(helcim): mock text() not json() to match helcimFetch contract --- tests/server/api/helcim-payment.test.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/server/api/helcim-payment.test.js b/tests/server/api/helcim-payment.test.js index 2423d9b..52e2342 100644 --- a/tests/server/api/helcim-payment.test.js +++ b/tests/server/api/helcim-payment.test.js @@ -1,15 +1,15 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' -vi.mock('../../../server/utils/auth.js', () => ({ requireAuth: vi.fn() })) -vi.mock('../../../server/utils/validateBody.js', () => ({ validateBody: vi.fn() })) -vi.mock('../../../server/utils/schemas.js', () => ({ paymentVerifySchema: {} })) - import { requireAuth } from '../../../server/utils/auth.js' import { validateBody as importedValidateBody } from '../../../server/utils/validateBody.js' import initPaymentHandler from '../../../server/api/helcim/initialize-payment.post.js' import verifyPaymentHandler from '../../../server/api/helcim/verify-payment.post.js' import { createMockEvent } from '../helpers/createMockEvent.js' +vi.mock('../../../server/utils/auth.js', () => ({ requireAuth: vi.fn() })) +vi.mock('../../../server/utils/validateBody.js', () => ({ validateBody: vi.fn() })) +vi.mock('../../../server/utils/schemas.js', () => ({ paymentVerifySchema: {} })) + // helcimInitializePaymentSchema is a Nitro auto-import used by validateBody vi.stubGlobal('helcimInitializePaymentSchema', {}) @@ -34,7 +34,7 @@ describe('initialize-payment endpoint', () => { mockFetch.mockResolvedValue({ ok: true, - json: async () => ({ checkoutToken: 'ct-123', secretToken: 'st-456' }) + text: async () => JSON.stringify({ checkoutToken: 'ct-123', secretToken: 'st-456' }) }) const event = createMockEvent({ @@ -55,7 +55,7 @@ describe('initialize-payment endpoint', () => { mockFetch.mockResolvedValue({ ok: true, - json: async () => ({ checkoutToken: 'ct-123', secretToken: 'st-456' }) + text: async () => JSON.stringify({ checkoutToken: 'ct-123', secretToken: 'st-456' }) }) const event = createMockEvent({ @@ -78,7 +78,7 @@ describe('initialize-payment endpoint', () => { mockFetch.mockResolvedValue({ ok: true, - json: async () => ({ checkoutToken: 'ct-abc', secretToken: 'st-xyz' }) + text: async () => JSON.stringify({ checkoutToken: 'ct-abc', secretToken: 'st-xyz' }) }) const event = createMockEvent({ @@ -132,7 +132,7 @@ describe('verify-payment endpoint', () => { mockFetch.mockResolvedValue({ ok: true, - json: async () => [{ cardToken: 'tok-1' }] + text: async () => JSON.stringify([{ cardToken: 'tok-1' }]) }) const event = createMockEvent({ @@ -153,10 +153,10 @@ describe('verify-payment endpoint', () => { mockFetch.mockResolvedValue({ ok: true, - json: async () => [ + text: async () => JSON.stringify([ { cardToken: 'tok-other' }, { cardToken: 'tok-match' } - ] + ]) }) const event = createMockEvent({ @@ -181,10 +181,10 @@ describe('verify-payment endpoint', () => { mockFetch.mockResolvedValue({ ok: true, - json: async () => [ + text: async () => JSON.stringify([ { cardToken: 'tok-aaa' }, { cardToken: 'tok-bbb' } - ] + ]) }) const event = createMockEvent({