forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayments-id-generation.test.ts
More file actions
69 lines (55 loc) · 2.03 KB
/
Copy pathpayments-id-generation.test.ts
File metadata and controls
69 lines (55 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { describe, expect, it } from "vitest";
import {
generatePaymentId,
generateQuoteId,
paymentsService,
} from "../src/modules/payments/payments.service";
describe("Quote and payment ID generation (issue #290)", () => {
const UUID_REGEX =
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
it("generateQuoteId retains quote_ prefix and follows UUID v4 format", () => {
const id = generateQuoteId();
expect(id.startsWith("quote_")).toBe(true);
const uuidPart = id.slice("quote_".length);
expect(uuidPart).toMatch(UUID_REGEX);
});
it("generatePaymentId retains pay_ prefix and follows UUID v4 format", () => {
const id = generatePaymentId();
expect(id.startsWith("pay_")).toBe(true);
const uuidPart = id.slice("pay_".length);
expect(uuidPart).toMatch(UUID_REGEX);
});
it("consecutive rapid ID generations produce strictly unique IDs", () => {
const quoteIds = new Set<string>();
const paymentIds = new Set<string>();
const count = 1000;
for (let i = 0; i < count; i++) {
quoteIds.add(generateQuoteId());
paymentIds.add(generatePaymentId());
}
expect(quoteIds.size).toBe(count);
expect(paymentIds.size).toBe(count);
});
it("paymentsService.createQuote produces UUID-backed quote ID", () => {
const { quote } = paymentsService.createQuote({
sourceAsset: "XLM",
destinationAsset: "USDC",
sourceAmount: "100.00",
});
expect(quote.id.startsWith("quote_")).toBe(true);
expect(quote.id.slice("quote_".length)).toMatch(UUID_REGEX);
});
it("paymentsService.executePayment produces UUID-backed payment ID", () => {
const { quote } = paymentsService.createQuote({
sourceAsset: "XLM",
destinationAsset: "USDC",
sourceAmount: "50.00",
});
const { payment } = paymentsService.executePayment({
quoteId: quote.id,
confirmed: true,
});
expect(payment.id.startsWith("pay_")).toBe(true);
expect(payment.id.slice("pay_".length)).toMatch(UUID_REGEX);
});
});