Files
co-lite/solvway-admin-portal/app/orders/refunds/refundSource.test.tsx
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

123 lines
4.5 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen } from "@testing-library/react";
import type { AdminRefundDetail, AdminRefundRequest } from "@/app/lib/types";
import { DEFAULT_MESSAGES } from "@/app/lib/i18n/defaultMessages";
// add-admin-initiated-refund: the queue shows who raised a refund and how it was paid out.
const svc = vi.hoisted(() => ({
getRefund: vi.fn(),
approveRefund: vi.fn(),
rejectRefund: vi.fn(),
retryRefundEmail: vi.fn(),
}));
vi.mock("@/app/lib/services/adminRefunds", () => svc);
import { RefundDrawer } from "./RefundDrawer";
import { payoutLabel } from "./refundLabels";
const t = (code: string, params?: Record<string, string | number>) => {
let s = DEFAULT_MESSAGES[code] ?? code;
for (const [k, v] of Object.entries(params ?? {})) s = s.replace(`{${k}}`, String(v));
return s;
};
function request(overrides: Partial<AdminRefundRequest> = {}): AdminRefundRequest {
return {
uuid: "U-41",
documentNo: "RR00000041",
orderUuid: "O-9",
orderDocumentNo: "IN00000080",
buyerCode: "",
status: "A",
reasonCode: "DAMAGED",
remark: null,
refundAmount: 35,
decisionReason: null,
decidedBy: "Ops Admin",
decidedAt: "2026-10-05T11:00:00",
walletTrxnRef: null,
stockDocumentNos: "AJI9",
lastError: null,
emailSentAt: null,
createDate: "2026-10-05T11:00:00",
lines: [{ orderDetailsId: 21, productName: "BA-001", qty: 1, netUnitPrice: 35, amount: 35 }],
source: "ADMIN",
payoutMethod: "MANUAL",
payoutChannel: "CASH",
payoutReference: null,
windowOverrideReason: null,
submittedBy: "Ops Admin",
...overrides,
};
}
function detail(req: AdminRefundRequest): AdminRefundDetail {
return {
request: req,
buyerName: null,
orderDate: "2026-10-02T10:00:00",
grandTotal: 70,
shippingCost: 0,
tenders: [{ paymentType: "PC", amount: 70, reference: null }],
stockEffects: [],
};
}
beforeEach(() => {
Object.values(svc).forEach(fn => fn.mockReset());
});
describe("payoutLabel", () => {
const base = request({ payoutMethod: "ACORNS", payoutChannel: null });
it("labels an Acorns payout", () => {
expect(payoutLabel(t, base)).toBe("Acorns wallet");
});
it("labels a manual bank transfer with its reference", () => {
expect(payoutLabel(t, { ...base, payoutMethod: "MANUAL", payoutChannel: "BANK_TRANSFER", payoutReference: "MBB-1" }))
.toBe("Manual · Bank transfer · MBB-1");
});
it("treats an old row without payoutMethod as Acorns", () => {
expect(payoutLabel(t, { ...base, payoutMethod: undefined })).toBe("Acorns wallet");
});
});
describe("RefundDrawer — admin-raised refunds", () => {
it("shows the Admin tag, the raiser and the manual payout record", async () => {
svc.getRefund.mockResolvedValue(detail(request()));
render(<RefundDrawer uuid="U-41" onClose={() => {}} onChanged={() => {}} />);
expect(await screen.findByText("Raised by Ops Admin")).toBeInTheDocument();
expect(screen.getByText("Admin")).toBeInTheDocument();
expect(screen.getByText("Returned manually RM 35.00 · Cash")).toBeInTheDocument();
expect(screen.queryByText(/Acorns credited/)).not.toBeInTheDocument();
});
it("shows a window override reason", async () => {
svc.getRefund.mockResolvedValue(detail(request({ windowOverrideReason: "Warranty goodwill" })));
render(<RefundDrawer uuid="U-41" onClose={() => {}} onChanged={() => {}} />);
expect(await screen.findByText("Warranty goodwill")).toBeInTheDocument();
});
it("previews a manual return instead of an Acorns credit while pending", async () => {
svc.getRefund.mockResolvedValue(detail(request({ status: "P", decidedBy: null, decidedAt: null, stockDocumentNos: null })));
render(<RefundDrawer uuid="U-41" onClose={() => {}} onChanged={() => {}} />);
expect(await screen.findByText("Return RM 35.00 to the buyer manually (Cash)")).toBeInTheDocument();
expect(screen.queryByText(/to Acorns/)).not.toBeInTheDocument();
});
it("keeps a member request's Acorns wording", async () => {
svc.getRefund.mockResolvedValue(detail(request({
source: undefined, payoutMethod: undefined, payoutChannel: undefined, submittedBy: "MY3619941",
buyerCode: "MY3619941", walletTrxnRef: "T-9",
})));
render(<RefundDrawer uuid="U-41" onClose={() => {}} onChanged={() => {}} />);
expect(await screen.findByText(/Acorns credited RM 35\.00/)).toBeInTheDocument();
expect(screen.queryByText("Raised by MY3619941")).not.toBeInTheDocument();
});
});