Skip to content

Commit bf6b9c8

Browse files
fix(billing): send {} body on portal POST to satisfy Zod PortalRequest schema (#4137)
openPortal() was calling axios.post(url) with no body, causing Express/Zod strict() to reject with "expected object, received undefined" (422). Passing {} satisfies PortalRequest schema (returnUrl optional).
1 parent 50498ba commit bf6b9c8

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/modules/billing/stores/billing.store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export const useBillingStore = defineStore('billing', {
279279
this.loading = true;
280280
try {
281281
const api = apiBase();
282-
const res = await axios.post(`${api}/${config.api.endPoints.billing}/portal`);
282+
const res = await axios.post(`${api}/${config.api.endPoints.billing}/portal`, {});
283283
const url = res?.data?.data?.url;
284284
if (!url) {
285285
throw new Error('Billing portal URL is missing from the API response');

src/modules/billing/tests/billing.store.unit.tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ describe('Billing Store', () => {
258258
expect(store.loading).toBe(false);
259259
spy.mockRestore();
260260
});
261+
262+
it('sends an empty object body to POST /portal (not undefined)', async () => {
263+
const store = useBillingStore();
264+
const portalUrl = 'https://billing.stripe.com/session/test_123';
265+
axios.post.mockResolvedValueOnce({ data: { data: { url: portalUrl } } });
266+
const originalLocation = window.location;
267+
delete window.location;
268+
window.location = { ...originalLocation, href: '' };
269+
await store.openPortal();
270+
// Second argument must be {} (empty object), not undefined
271+
expect(axios.post).toHaveBeenCalledWith(
272+
expect.stringContaining('/portal'),
273+
{},
274+
);
275+
window.location = originalLocation;
276+
});
261277
});
262278

263279
describe('fetchUsageMeter', () => {

0 commit comments

Comments
 (0)