Skip to content

Commit a98b5a3

Browse files
fix(billing): add AdminOrgIdParam validation to adminDisputeCredit path param
Completes the Batch 4 admin endpoint param coverage — adminDisputeCredit /:orgId was missed in the initial pass. Now all 5 :orgId admin endpoints validate with AdminOrgIdParam.safeParse → 422 on invalid ObjectId.
1 parent c69a34a commit a98b5a3

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

modules/billing/controllers/billing.admin.controller.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,13 @@ const adminCancelSubscription = async (req, res) => {
248248
// biome-ignore lint/correctness/useQwikValidLexicalScope: false positive — Node.js controller, not Qwik
249249
const adminDisputeCredit = async (req, res) => {
250250
try {
251+
const parsedParams = AdminOrgIdParam.safeParse(req.params);
252+
if (!parsedParams.success) {
253+
return responses.error(res, 422, 'Unprocessable Entity', 'Invalid path parameters')(parsedParams.error);
254+
}
255+
const { orgId } = parsedParams.data;
256+
251257
const { chargeId, amountCents, reason, refundRequestId } = req.body;
252-
const { orgId } = req.params;
253258

254259
const rawAdminId = req.user?._id;
255260
if (!rawAdminId) {

modules/billing/tests/billing.admin.integration.tests.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,24 @@ describe('Billing admin integration tests:', () => {
548548

549549
expect(res.status).toHaveBeenCalledWith(200);
550550
});
551+
552+
test('invalid orgId on POST /dispute/credit/:orgId returns 422', async () => {
553+
const routes = await buildRoutes();
554+
const route = routes.get('/api/admin/billing/dispute/credit/:orgId');
555+
const res = { status: jest.fn().mockReturnThis(), json: jest.fn().mockReturnThis() };
556+
557+
await runHandlers(
558+
[...route.all, ...route.post],
559+
{
560+
method: 'POST',
561+
headers: { 'x-role': 'admin' },
562+
params: { orgId: 'not-objectid' },
563+
body: { chargeId: 'ch_abc', amountCents: 1000, reason: 'dispute won', refundRequestId: 'req-12345678' },
564+
user: { _id: '507f1f77bcf86cd799439022' },
565+
},
566+
res,
567+
);
568+
569+
expect(res.status).toHaveBeenCalledWith(422);
570+
});
551571
});

0 commit comments

Comments
 (0)