Skip to content
Open
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
30 changes: 29 additions & 1 deletion agent/__tests__/pay-for-medication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ vi.mock("fs", () => ({
writeFileSync: vi.fn((filePath: string, data: string) => {
mockFiles.set(String(filePath), String(data));
}),
appendFileSync: vi.fn(),
appendFileSync: vi.fn((filePath: string, data: string) => {
const key = String(filePath);
mockFiles.set(key, (mockFiles.get(key) ?? "") + String(data));
}),
unlinkSync: vi.fn(),
existsSync: vi.fn((filePath: string) => mockFiles.has(String(filePath))),
mkdirSync: vi.fn(),
Expand Down Expand Up @@ -77,6 +80,17 @@ const DEFAULT_POLICY = {
approvalThreshold: 75,
};

function getPersistedTransactions() {
const jsonl = [...mockFiles.entries()].find(([filePath]) =>
filePath.endsWith("transactions.jsonl"),
)?.[1] ?? "";

return jsonl
.split("\n")
.filter(Boolean)
.map((line) => JSON.parse(line));
}

beforeEach(() => {
mockFiles.clear();
mockMppFetch.mockReset();
Expand Down Expand Up @@ -211,6 +225,20 @@ describe("payForMedication — success path (Issue #35)", () => {
expect(tx.stellarTxHash).toBeUndefined();
});

it("persists mppOrderId separately from stellarTxHash in the transaction log", async () => {
mockMppFetch.mockResolvedValueOnce({
json: async () => ({ success: true, order: { id: "order-persisted" } }),
headers: { get: () => null },
});

const r = await payForMedication("p1", "Pharma", "Drug", 50);
expect(r.success).toBe(true);

const [persistedTx] = getPersistedTransactions();
expect(persistedTx.mppOrderId).toBe("order-persisted");
expect(persistedTx).not.toHaveProperty("stellarTxHash");
});

it("sets stellarTxHash from Payment-Receipt header when no progress event fired", async () => {
const validHash = "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
const encodedReceipt = Buffer.from(
Expand Down