forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublic-api-types.test.ts
More file actions
197 lines (176 loc) · 6.33 KB
/
Copy pathpublic-api-types.test.ts
File metadata and controls
197 lines (176 loc) · 6.33 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import { describe, expectTypeOf, it } from 'vitest';
import type { LilySdkConfig, ResolvedLilySdkConfig } from '../src/config/types';
import type {
HttpRequest,
HttpResponse,
HttpClient,
RetryPolicy,
} from '../src/http/types';
import type {
MoneyAmount,
PaginationQuery,
ResourceStatus,
} from '../src/models/common';
import type {
ListAgentsQuery,
CreateAgentRequest,
Agent,
} from '../src/models/agent';
import type {
ExecutePaymentRequest,
PaymentQuoteRequest,
} from '../src/models/payment';
import type {
ResolveIdentityRequest,
IdentityProfile,
} from '../src/models/identity';
import type { LilySdk } from '../src/sdk';
describe('public API type-level tests', () => {
describe('LilySdkConfig', () => {
it('accepts string baseUrl', () => {
const config: LilySdkConfig = { baseUrl: 'https://api.test' };
expectTypeOf(config).toMatchTypeOf<LilySdkConfig>();
});
it('accepts optional retry policy', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.test',
retry: { retries: 3, retryDelayMs: 500 },
};
expectTypeOf(config).toMatchTypeOf<LilySdkConfig>();
});
it('accepts optional auth credentials', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.test',
apiKey: 'key',
authToken: 'token',
};
expectTypeOf(config).toMatchTypeOf<LilySdkConfig>();
});
});
describe('ResolvedLilySdkConfig', () => {
it('has readonly baseUrl as URL', () => {
expectTypeOf<ResolvedLilySdkConfig['baseUrl']>().toEqualTypeOf<URL>();
});
it('has required timeoutMs as number', () => {
expectTypeOf<
ResolvedLilySdkConfig['timeoutMs']
>().toEqualTypeOf<number>();
});
it('has required retry as RetryPolicy', () => {
expectTypeOf<
ResolvedLilySdkConfig['retry']
>().toEqualTypeOf<RetryPolicy>();
});
});
describe('HttpRequest and HttpResponse', () => {
it('HttpRequest accepts typed body generic', () => {
type Req = HttpRequest<{ name: string }>;
expectTypeOf<Req['body']>().toEqualTypeOf<{ name: string } | undefined>();
});
it('HttpResponse carries typed data generic', () => {
type Res = HttpResponse<{ id: string }>;
expectTypeOf<Res['data']>().toEqualTypeOf<{ id: string }>();
expectTypeOf<Res['status']>().toEqualTypeOf<number>();
expectTypeOf<Res['headers']>().toEqualTypeOf<Headers>();
});
it('HttpClient.request returns Promise of HttpResponse with matching generics', () => {
type Client = HttpClient;
expectTypeOf<Client['request']>()
.parameter(0)
.toMatchTypeOf<HttpRequest<unknown>>();
});
});
describe('Model shapes', () => {
it('MoneyAmount has required assetCode and amount strings', () => {
expectTypeOf<MoneyAmount['assetCode']>().toEqualTypeOf<string>();
expectTypeOf<MoneyAmount['amount']>().toEqualTypeOf<string>();
expectTypeOf<MoneyAmount['assetIssuer']>().toEqualTypeOf<
string | undefined
>();
});
it('PaginationQuery accepts optional limit and cursor', () => {
expectTypeOf<PaginationQuery['limit']>().toEqualTypeOf<
number | undefined
>();
expectTypeOf<PaginationQuery['cursor']>().toEqualTypeOf<
string | undefined
>();
});
it('ResourceStatus is a union of known literals', () => {
expectTypeOf<ResourceStatus>().toEqualTypeOf<
'pending' | 'active' | 'inactive' | 'failed'
>();
});
it('ListAgentsQuery extends PaginationQuery', () => {
expectTypeOf<ListAgentsQuery>().toMatchTypeOf<PaginationQuery>();
});
it('CreateAgentRequest requires name and network', () => {
expectTypeOf<CreateAgentRequest['name']>().toEqualTypeOf<string>();
expectTypeOf<CreateAgentRequest['network']>().toEqualTypeOf<
'stellar-testnet' | 'stellar-mainnet'
>();
});
it('Agent has required identity fields', () => {
expectTypeOf<Agent['id']>().toEqualTypeOf<string>();
expectTypeOf<Agent['name']>().toEqualTypeOf<string>();
expectTypeOf<Agent['status']>().toEqualTypeOf<ResourceStatus>();
});
it('ExecutePaymentRequest requires fromWalletId, toAddress, and amount', () => {
expectTypeOf<
ExecutePaymentRequest['fromWalletId']
>().toEqualTypeOf<string>();
expectTypeOf<
ExecutePaymentRequest['toAddress']
>().toEqualTypeOf<string>();
expectTypeOf<
ExecutePaymentRequest['amount']
>().toEqualTypeOf<MoneyAmount>();
expectTypeOf<ExecutePaymentRequest['memo']>().toEqualTypeOf<
string | undefined
>();
expectTypeOf<ExecutePaymentRequest['idempotencyKey']>().toEqualTypeOf<
string | undefined
>();
});
it('ResolveIdentityRequest has optional resolver keys', () => {
expectTypeOf<ResolveIdentityRequest['agentId']>().toEqualTypeOf<
string | undefined
>();
expectTypeOf<ResolveIdentityRequest['stellarAddress']>().toEqualTypeOf<
string | undefined
>();
expectTypeOf<ResolveIdentityRequest['domain']>().toEqualTypeOf<
string | undefined
>();
});
it('IdentityProfile has required audit metadata', () => {
expectTypeOf<IdentityProfile['createdAt']>().toEqualTypeOf<string>();
expectTypeOf<IdentityProfile['updatedAt']>().toEqualTypeOf<string>();
expectTypeOf<IdentityProfile['verificationLevel']>().toEqualTypeOf<
'none' | 'basic' | 'enhanced'
>();
});
});
describe('LilySdk client signatures', () => {
it('system.health returns Promise with status field', () => {
type Sdk = LilySdk;
type HealthResult = ReturnType<Sdk['system']['health']>;
expectTypeOf<HealthResult>().resolves.toMatchTypeOf<{ status: string }>();
});
it('payments.quote accepts PaymentQuoteRequest and returns PaymentQuote', () => {
type Sdk = LilySdk;
type QuoteResult = ReturnType<Sdk['payments']['quote']>;
expectTypeOf<QuoteResult>().resolves.toMatchTypeOf<{
amount: MoneyAmount;
}>();
});
it('payments.execute accepts ExecutePaymentRequest and returns Payment', () => {
type Sdk = LilySdk;
type ExecuteResult = ReturnType<Sdk['payments']['execute']>;
expectTypeOf<ExecuteResult>().resolves.toMatchTypeOf<{
id: string;
status: string;
}>();
});
});
});