Skip to content
Open
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
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lucide-react": "^0.562.0",
"next": "16.1.4",
"next-mdx-remote": "^5.0.0",
"qrcode.react": "^4.2.0",
"react": "19.2.3",
"react-dom": "19.2.3",
"react-hook-form": "^7.71.1",
Expand Down
119 changes: 119 additions & 0 deletions src/__tests__/stellar-payment-instructions.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { StellarPaymentInstructions } from "@/features/orders/components/StellarPaymentInstructions";
import { toast } from "react-toastify";

const push = vi.fn();
const writeText = vi.fn();

vi.mock("next/navigation", () => ({
useRouter: () => ({ push }),
}));

vi.mock("react-toastify", () => ({
toast: {
success: vi.fn(),
error: vi.fn(),
},
}));

describe("StellarPaymentInstructions", () => {
beforeEach(() => {
vi.useRealTimers();
vi.clearAllMocks();
writeText.mockResolvedValue(undefined);
Object.defineProperty(navigator, "clipboard", {
configurable: true,
value: { writeText },
});
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ status: "PENDING" }),
}) as unknown as typeof fetch;
});

it("renders Stellar payment details and copy controls", async () => {
render(
<StellarPaymentInstructions
orderId="order-1"
destinationAddress="GABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
memo="MEMO-123"
amountXLM="25.5"
/>
);

expect(screen.getByText("Complete your ticket payment")).toBeInTheDocument();
expect(screen.getByText("Required — your payment will fail without the memo")).toBeInTheDocument();
expect(screen.getByText("25.5 XLM")).toBeInTheDocument();
expect(screen.getByRole("button", { name: /copy destination address/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /copy memo/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /copy amount/i })).toBeInTheDocument();
await waitFor(() => {
expect(fetch).toHaveBeenCalledWith("/api/orders/order-1", expect.any(Object));
});
});

it("redirects to tickets when polling returns PAID", async () => {
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ status: "PAID" }),
}) as unknown as typeof fetch;

render(
<StellarPaymentInstructions
orderId="order-paid"
destinationAddress="GABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
memo="MEMO-PAID"
amountXLM={12}
/>
);

await waitFor(() => {
expect(toast.success).toHaveBeenCalledWith("\uD83C\uDF89 Tickets issued! Check your email.");
expect(push).toHaveBeenCalledWith("/tickets");
});
});

it("retries an expired payment window", async () => {
const user = userEvent.setup();
global.fetch = vi
.fn()
.mockResolvedValueOnce({
ok: true,
json: async () => ({ status: "PENDING" }),
})
.mockResolvedValueOnce({
ok: true,
json: async () => ({
destinationAddress: "GNEWDESTINATION",
memo: "NEW-MEMO",
amountXLM: "30",
}),
})
.mockResolvedValueOnce({
ok: true,
json: async () => ({ status: "PENDING" }),
}) as unknown as typeof fetch;

render(
<StellarPaymentInstructions
orderId="order-expired"
destinationAddress="GOLDDESTINATION"
memo="OLD-MEMO"
amountXLM="20"
expiresAt={new Date(Date.now() - 1000)}
/>
);

await user.click(screen.getByRole("button", { name: /retry payment/i }));

await waitFor(() => {
expect(fetch).toHaveBeenCalledWith("/api/orders/order-expired/retry-payment", {
method: "POST",
});
expect(screen.getByText("NEW-MEMO")).toBeInTheDocument();
expect(toast.success).toHaveBeenCalledWith("Payment window refreshed.");
});
});
});
Loading