Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions web/app/stores/billing.test.ts
Original file line number Diff line number Diff line change
@@ -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<void>,
) {
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,
)
})
12 changes: 4 additions & 8 deletions web/app/stores/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ export const useBillingStore = defineStore('billing', () => {
return response.data
}

async function cancelSubscription(): Promise<string> {
const response = await apiFetch<{ message: string }>(
'/v1/users/subscription',
{
method: 'DELETE',
},
)
return response.message
async function cancelSubscription(): Promise<void> {
await apiFetch('/v1/users/subscription', {
method: 'DELETE',
})
}

async function indexSubscriptionPayments(): Promise<ResponsesUserSubscriptionPaymentsResponse> {
Expand Down
Loading