agenticpool-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,251 @@
1
+ import { NetworksNamespace } from '../src/networks';
2
+ import { ApiClient } from '../src/client';
3
+
4
+ jest.mock('../src/client');
5
+
6
+ describe('NetworksNamespace', () => {
7
+ let networksNamespace: NetworksNamespace;
8
+ let mockClient: jest.Mocked<ApiClient>;
9
+
10
+ beforeEach(() => {
11
+ mockClient = {
12
+ get: jest.fn(),
13
+ post: jest.fn(),
14
+ put: jest.fn(),
15
+ delete: jest.fn(),
16
+ setAuthToken: jest.fn(),
17
+ clearAuthToken: jest.fn(),
18
+ setFormat: jest.fn()
19
+ } as any;
20
+
21
+ networksNamespace = new NetworksNamespace(mockClient);
22
+ });
23
+
24
+ describe('list', () => {
25
+ it('should list networks without filters', async () => {
26
+ const mockNetworks = [
27
+ {
28
+ id: 'network-1',
29
+ name: 'Test Network',
30
+ description: 'Test Description',
31
+ status: 'live',
32
+ users: 10
33
+ }
34
+ ];
35
+
36
+ mockClient.get.mockResolvedValue({
37
+ success: true,
38
+ data: mockNetworks
39
+ });
40
+
41
+ const result = await networksNamespace.list();
42
+
43
+ expect(result).toEqual(mockNetworks);
44
+ expect(mockClient.get).toHaveBeenCalledWith('/v1/networks', {});
45
+ });
46
+
47
+ it('should list networks with filter', async () => {
48
+ const mockNetworks = [
49
+ {
50
+ id: 'network-1',
51
+ name: 'Popular Network',
52
+ description: 'Test Description',
53
+ status: 'live',
54
+ users: 100
55
+ }
56
+ ];
57
+
58
+ mockClient.get.mockResolvedValue({
59
+ success: true,
60
+ data: mockNetworks
61
+ });
62
+
63
+ const result = await networksNamespace.list({ filter: 'popular' });
64
+
65
+ expect(result).toEqual(mockNetworks);
66
+ expect(mockClient.get).toHaveBeenCalledWith('/v1/networks', { filter: 'popular' });
67
+ });
68
+
69
+ it('should list networks with short format', async () => {
70
+ const mockNetworks = [
71
+ {
72
+ id: 'network-1',
73
+ name: 'Test Network',
74
+ description: 'Test Description'
75
+ }
76
+ ];
77
+
78
+ mockClient.get.mockResolvedValue({
79
+ success: true,
80
+ data: mockNetworks
81
+ });
82
+
83
+ const result = await networksNamespace.list({ short: true });
84
+
85
+ expect(result).toEqual(mockNetworks);
86
+ expect(mockClient.get).toHaveBeenCalledWith('/v1/networks', { short: 'true' });
87
+ });
88
+
89
+ it('should throw error when listing fails', async () => {
90
+ mockClient.get.mockResolvedValue({
91
+ success: false,
92
+ error: { code: 'ERROR', message: 'Failed to list networks' }
93
+ });
94
+
95
+ await expect(networksNamespace.list()).rejects.toThrow('Failed to list networks');
96
+ });
97
+ });
98
+
99
+ describe('get', () => {
100
+ it('should get network by id', async () => {
101
+ const mockNetwork = {
102
+ id: 'network-1',
103
+ name: 'Test Network',
104
+ description: 'Test Description',
105
+ status: 'live',
106
+ users: 10
107
+ };
108
+
109
+ mockClient.get.mockResolvedValue({
110
+ success: true,
111
+ data: mockNetwork
112
+ });
113
+
114
+ const result = await networksNamespace.get('network-1');
115
+
116
+ expect(result).toEqual(mockNetwork);
117
+ expect(mockClient.get).toHaveBeenCalledWith('/v1/networks/network-1');
118
+ });
119
+
120
+ it('should throw error when network not found', async () => {
121
+ mockClient.get.mockResolvedValue({
122
+ success: false,
123
+ error: { code: 'NOT_FOUND', message: 'Network not found' }
124
+ });
125
+
126
+ await expect(networksNamespace.get('network-999')).rejects.toThrow('Network not found');
127
+ });
128
+ });
129
+
130
+ describe('create', () => {
131
+ it('should create network', async () => {
132
+ const mockNetwork = {
133
+ id: 'network-1',
134
+ name: 'New Network',
135
+ description: 'New Description',
136
+ status: 'testing',
137
+ users: 0
138
+ };
139
+
140
+ mockClient.post.mockResolvedValue({
141
+ success: true,
142
+ data: mockNetwork
143
+ });
144
+
145
+ const result = await networksNamespace.create({
146
+ name: 'New Network',
147
+ description: 'New Description'
148
+ });
149
+
150
+ expect(result).toEqual(mockNetwork);
151
+ expect(mockClient.post).toHaveBeenCalledWith('/v1/networks', {
152
+ name: 'New Network',
153
+ description: 'New Description',
154
+ longDescription: '',
155
+ logoUrl: '',
156
+ isPublic: true
157
+ });
158
+ });
159
+
160
+ it('should throw error when creation fails', async () => {
161
+ mockClient.post.mockResolvedValue({
162
+ success: false,
163
+ error: { code: 'ERROR', message: 'Failed to create network' }
164
+ });
165
+
166
+ await expect(networksNamespace.create({
167
+ name: 'New Network',
168
+ description: 'New Description'
169
+ })).rejects.toThrow('Failed to create network');
170
+ });
171
+ });
172
+
173
+ describe('mine', () => {
174
+ it('should get my networks', async () => {
175
+ const mockNetworks = [
176
+ {
177
+ id: 'network-1',
178
+ name: 'My Network',
179
+ description: 'My Description',
180
+ status: 'testing',
181
+ users: 1
182
+ }
183
+ ];
184
+
185
+ mockClient.get.mockResolvedValue({
186
+ success: true,
187
+ data: mockNetworks
188
+ });
189
+
190
+ const result = await networksNamespace.mine();
191
+
192
+ expect(result).toEqual(mockNetworks);
193
+ expect(mockClient.get).toHaveBeenCalledWith('/v1/networks/mine', {});
194
+ });
195
+
196
+ it('should throw error when getting my networks fails', async () => {
197
+ mockClient.get.mockResolvedValue({
198
+ success: false,
199
+ error: { code: 'ERROR', message: 'Failed to list networks' }
200
+ });
201
+
202
+ await expect(networksNamespace.mine()).rejects.toThrow('Failed to list networks');
203
+ });
204
+ });
205
+
206
+ describe('getMembers', () => {
207
+ it('should get network members', async () => {
208
+ const mockMembers = [
209
+ {
210
+ publicToken: 'token-1',
211
+ shortDescription: 'Member 1',
212
+ role: 'member'
213
+ }
214
+ ];
215
+
216
+ mockClient.get.mockResolvedValue({
217
+ success: true,
218
+ data: mockMembers
219
+ });
220
+
221
+ const result = await networksNamespace.getMembers('network-1');
222
+
223
+ expect(result).toEqual(mockMembers);
224
+ expect(mockClient.get).toHaveBeenCalledWith('/v1/networks/network-1/members');
225
+ });
226
+ });
227
+
228
+ describe('getQuestions', () => {
229
+ it('should get network questions', async () => {
230
+ const mockQuestions = [
231
+ {
232
+ id: 'question-1',
233
+ networkId: 'network-1',
234
+ question: 'What is your name?',
235
+ order: 1,
236
+ required: true
237
+ }
238
+ ];
239
+
240
+ mockClient.get.mockResolvedValue({
241
+ success: true,
242
+ data: mockQuestions
243
+ });
244
+
245
+ const result = await networksNamespace.getQuestions('network-1');
246
+
247
+ expect(result).toEqual(mockQuestions);
248
+ expect(mockClient.get).toHaveBeenCalledWith('/v1/networks/network-1/questions');
249
+ });
250
+ });
251
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "declaration": true,
7
+ "strict": true,
8
+ "noImplicitAny": true,
9
+ "strictNullChecks": true,
10
+ "noImplicitThis": true,
11
+ "alwaysStrict": true,
12
+ "noUnusedLocals": false,
13
+ "noUnusedParameters": false,
14
+ "noImplicitReturns": true,
15
+ "noFallthroughCasesInSwitch": false,
16
+ "inlineSourceMap": true,
17
+ "inlineSources": true,
18
+ "experimentalDecorators": true,
19
+ "strictPropertyInitialization": false,
20
+ "outDir": "./dist",
21
+ "rootDir": "./src",
22
+ "skipLibCheck": true,
23
+ "esModuleInterop": true,
24
+ "resolveJsonModule": true,
25
+ "moduleResolution": "node"
26
+ },
27
+ "include": ["src/**/*"],
28
+ "exclude": ["node_modules", "dist", "tests"]
29
+ }