forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract.test.ts
More file actions
96 lines (80 loc) · 4 KB
/
Copy pathcontract.test.ts
File metadata and controls
96 lines (80 loc) · 4 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
92
93
94
95
96
import { describe, expect, it, vi } from 'vitest';
import type {
AgentClientContract,
IdentityClientContract,
PaymentClientContract,
SystemClientContract,
WalletClientContract,
} from '../src/types/contracts';
import { AgentClient } from '../src/clients/agent-client';
import { IdentityClient } from '../src/clients/identity-client';
import { PaymentClient } from '../src/clients/payment-client';
import { SystemClient } from '../src/clients/system-client';
import { WalletClient } from '../src/clients/wallet-client';
import { createMockHttpClient } from './helpers/mock-http-client';
describe('client contracts', () => {
it('AgentClient satisfies AgentClientContract', async () => {
const requestSpy = vi.fn(() => Promise.resolve({ status: 200, headers: new Headers(), data: [] }));
const client: AgentClientContract = new AgentClient(createMockHttpClient(requestSpy));
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.list).toBeDefined();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.get).toBeDefined();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.create).toBeDefined();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.update).toBeDefined();
await client.list();
expect(requestSpy).toHaveBeenCalledWith(
expect.objectContaining({ method: 'GET', path: '/v1/agents' }),
);
});
it('WalletClient satisfies WalletClientContract', async () => {
const requestSpy = vi.fn(() => Promise.resolve({ status: 200, headers: new Headers(), data: {} }));
const client: WalletClientContract = new WalletClient(createMockHttpClient(requestSpy));
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.provision).toBeDefined();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.get).toBeDefined();
await client.get('w-1');
expect(requestSpy).toHaveBeenCalledWith(
expect.objectContaining({ method: 'GET', path: '/v1/wallets/w-1' }),
);
});
it('PaymentClient satisfies PaymentClientContract', async () => {
const requestSpy = vi.fn(() => Promise.resolve({ status: 200, headers: new Headers(), data: {} }));
const client: PaymentClientContract = new PaymentClient(createMockHttpClient(requestSpy));
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.quote).toBeDefined();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.execute).toBeDefined();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.get).toBeDefined();
await client.get('p-1');
expect(requestSpy).toHaveBeenCalledWith(
expect.objectContaining({ method: 'GET', path: '/v1/payments/p-1' }),
);
});
it('IdentityClient satisfies IdentityClientContract', async () => {
const requestSpy = vi.fn(() => Promise.resolve({ status: 200, headers: new Headers(), data: {} }));
const client: IdentityClientContract = new IdentityClient(createMockHttpClient(requestSpy));
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.resolve).toBeDefined();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.verify).toBeDefined();
await client.resolve({ agentId: 'a-1' });
expect(requestSpy).toHaveBeenCalled();
});
it('SystemClient satisfies SystemClientContract', async () => {
const requestSpy = vi.fn(() => Promise.resolve({ status: 200, headers: new Headers(), data: {} }));
const client: SystemClientContract = new SystemClient(createMockHttpClient(requestSpy));
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.health).toBeDefined();
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(client.info).toBeDefined();
await client.health();
expect(requestSpy).toHaveBeenCalledWith(
expect.objectContaining({ method: 'GET', path: '/v1/system/health' }),
);
});
});