forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoney-amount-normalization.test.ts
More file actions
87 lines (76 loc) · 2.51 KB
/
Copy pathmoney-amount-normalization.test.ts
File metadata and controls
87 lines (76 loc) · 2.51 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { describe, expect, it, vi } from 'vitest';
const TEST_ISSUER = 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN';
import type { HttpRequest } from '../src/http/types';
import { LilySdk } from '../src/sdk';
import { createMockHttpClient } from './helpers/mock-http-client';
describe('MoneyAmount decimal normalization', () => {
const cases = ['1', '1.0', '01.5', '0.000001'] as const;
for (const amount of cases) {
it(`preserves amount "${amount}" unchanged in quote request`, async () => {
let capturedBody: unknown;
const requestSpy = vi.fn((req: HttpRequest) => {
capturedBody = req.body;
return Promise.resolve({
status: 200,
headers: new Headers(),
data: {
amount: { assetCode: 'BTC', amount },
estimatedFee: {
assetCode: 'USD',
amount: '0.5',
},
expiresAt: new Date(Date.now() + 60_000).toISOString(),
},
});
});
const sdk = new LilySdk(
{ baseUrl: 'https://api.lily.test' },
createMockHttpClient(requestSpy),
);
await sdk.payments.quote({
fromWalletId: 'wallet_test',
toAddress: 'addr_test',
amount: {
assetCode: 'BTC',
assetIssuer: TEST_ISSUER,
amount,
},
});
expect(requestSpy).toHaveBeenCalledOnce();
const body = capturedBody as { amount: { amount: string } };
expect(body.amount.amount).toBe(amount);
});
it(`preserves amount "${amount}" unchanged in execute request`, async () => {
let capturedBody: unknown;
const requestSpy = vi.fn((req: HttpRequest) => {
capturedBody = req.body;
return Promise.resolve({
status: 200,
headers: new Headers(),
data: {
id: 'pay_test',
status: 'pending',
amount: { assetCode: 'BTC', amount },
createdAt: new Date().toISOString(),
},
});
});
const sdk = new LilySdk(
{ baseUrl: 'https://api.lily.test' },
createMockHttpClient(requestSpy),
);
await sdk.payments.execute({
fromWalletId: 'wallet_test',
toAddress: 'addr_test',
amount: {
assetCode: 'BTC',
assetIssuer: TEST_ISSUER,
amount,
},
});
expect(requestSpy).toHaveBeenCalledOnce();
const body = capturedBody as { amount: { amount: string } };
expect(body.amount.amount).toBe(amount);
});
}
});