From 3b04ba40451536fae58f1ae8bd514fa1c2f65e2f Mon Sep 17 00:00:00 2001 From: Acho Arnold Ewin Date: Tue, 24 Nov 2026 19:29:47 +0200 Subject: [PATCH] fix(web): handle empty subscription cancellation response Treat the cancellation endpoint's 204 response as a successful void result. Do not read a missing message after cancellation succeeds. Add regression coverage for bodyless success and API failures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ed7b2928-caae-4667-8285-9b3c3f31bca4 --- web/app/stores/billing.test.ts | 43 ++++++++++++++++++++++++++++++++++ web/app/stores/billing.ts | 12 ++++------ 2 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 web/app/stores/billing.test.ts diff --git a/web/app/stores/billing.test.ts b/web/app/stores/billing.test.ts new file mode 100644 index 000000000..f17e82984 --- /dev/null +++ b/web/app/stores/billing.test.ts @@ -0,0 +1,43 @@ +import assert from 'node:assert/strict' +import { test } from 'node:test' +import { createPinia, setActivePinia } from 'pinia' +import { ref } from 'vue' +import { useBillingStore } from './billing' + +function setupStore( + apiFetch: (path: string, options: { method: string }) => Promise, +) { + Object.assign(globalThis, { + ref, + useApi: () => ({ apiFetch }), + useNotificationsStore: () => ({ addNotification: () => {} }), + }) + setActivePinia(createPinia()) + return useBillingStore() +} + +test('subscription cancellation succeeds with an empty 204 response', async () => { + const calls: { path: string; method: string }[] = [] + const store = setupStore(async (path, options) => { + calls.push({ path, method: options.method }) + }) + + await assert.doesNotReject(() => store.cancelSubscription()) + assert.deepEqual(calls, [ + { path: '/v1/users/subscription', method: 'DELETE' }, + ]) +}) + +test('subscription cancellation propagates API failures', async () => { + const error = Object.assign(new Error('Cancellation failed'), { + statusCode: 500, + }) + const store = setupStore(async () => { + throw error + }) + + await assert.rejects( + () => store.cancelSubscription(), + (caught) => caught === error, + ) +}) diff --git a/web/app/stores/billing.ts b/web/app/stores/billing.ts index 6d5db82e5..5d75f1061 100644 --- a/web/app/stores/billing.ts +++ b/web/app/stores/billing.ts @@ -43,14 +43,10 @@ export const useBillingStore = defineStore('billing', () => { return response.data } - async function cancelSubscription(): Promise { - const response = await apiFetch<{ message: string }>( - '/v1/users/subscription', - { - method: 'DELETE', - }, - ) - return response.message + async function cancelSubscription(): Promise { + await apiFetch('/v1/users/subscription', { + method: 'DELETE', + }) } async function indexSubscriptionPayments(): Promise {