forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath-encoding-clients.test.ts
More file actions
91 lines (84 loc) · 3.01 KB
/
Copy pathpath-encoding-clients.test.ts
File metadata and controls
91 lines (84 loc) · 3.01 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
88
89
90
91
import { describe, it, expect } from 'vitest';
import { AgentClient } from '../src/clients/agent-client';
import { IdentityClient } from '../src/clients/identity-client';
import { WalletClient } from '../src/clients/wallet-client';
import { PaymentClient } from '../src/clients/payment-client';
import type { HttpClient } from '../src/http/types';
describe('Path parameter encoding in clients', () => {
const createMockHttpClient = (): HttpClient & { lastRequest?: unknown } => {
const state: { lastRequest?: unknown } = {};
return {
request: ((request: unknown) => {
state.lastRequest = request;
return Promise.resolve({
status: 200,
headers: new Headers(),
data: {},
});
}) as HttpClient['request'],
get lastRequest() {
return state.lastRequest;
},
};
};
it('AgentClient.get encodes special characters in agentId', async () => {
const mock = createMockHttpClient();
const client = new AgentClient(mock);
await client.get('agent/with?special#chars');
expect(mock.lastRequest).toEqual(
expect.objectContaining({
path: '/v1/agents/agent%2Fwith%3Fspecial%23chars',
}),
);
});
it('AgentClient.update encodes special characters in agentId', async () => {
const mock = createMockHttpClient();
const client = new AgentClient(mock);
await client.update('agent/id with spaces', { name: 'test' });
expect(mock.lastRequest).toEqual(
expect.objectContaining({
path: '/v1/agents/agent%2Fid%20with%20spaces',
}),
);
});
it('AgentClient.delete encodes special characters in agentId', async () => {
const mock = createMockHttpClient();
const client = new AgentClient(mock);
await client.delete('agent/with?special#chars and spaces');
expect(mock.lastRequest).toEqual(
expect.objectContaining({
path: '/v1/agents/agent%2Fwith%3Fspecial%23chars%20and%20spaces',
}),
);
});
it('IdentityClient.get uses the shared path encoder', async () => {
const mock = createMockHttpClient();
const client = new IdentityClient(mock);
await client.get('identity/with?special#chars and spaces');
expect(mock.lastRequest).toEqual(
expect.objectContaining({
path: '/v1/identity/identity%2Fwith%3Fspecial%23chars%20and%20spaces',
}),
);
});
it('WalletClient.get encodes special characters in walletId', async () => {
const mock = createMockHttpClient();
const client = new WalletClient(mock);
await client.get('wallet?id=test');
expect(mock.lastRequest).toEqual(
expect.objectContaining({
path: '/v1/wallets/wallet%3Fid%3Dtest',
}),
);
});
it('PaymentClient.get encodes special characters in paymentId', async () => {
const mock = createMockHttpClient();
const client = new PaymentClient(mock);
await client.get('payment#123/456');
expect(mock.lastRequest).toEqual(
expect.objectContaining({
path: '/v1/payments/payment%23123%2F456',
}),
);
});
});