@api-client/core 0.18.33 → 0.18.35
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.
- package/build/src/browser.d.ts +1 -0
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +1 -0
- package/build/src/browser.js.map +1 -1
- package/build/src/data/XmlReader.js +1 -1
- package/build/src/data/XmlReader.js.map +1 -1
- package/build/src/modeling/types.d.ts +7 -0
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/sdk/SdkMock.d.ts +301 -0
- package/build/src/sdk/SdkMock.d.ts.map +1 -0
- package/build/src/sdk/SdkMock.js +700 -0
- package/build/src/sdk/SdkMock.js.map +1 -0
- package/build/src/sdk/TrashSdk.d.ts +1 -1
- package/build/src/sdk/TrashSdk.d.ts.map +1 -1
- package/build/src/sdk/TrashSdk.js +1 -1
- package/build/src/sdk/TrashSdk.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/data/XmlReader.ts +1 -1
- package/src/modeling/types.ts +7 -0
- package/src/sdk/README-MOCK.md +40 -0
- package/src/sdk/SdkMock.ts +792 -0
- package/src/sdk/TrashSdk.ts +1 -1
- package/tests/unit/amf/schema_gen_xml.spec.ts +7 -8
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import type { StoreSdk } from './StoreSdkWeb.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for customizing mock responses.
|
|
4
|
+
*/
|
|
5
|
+
export interface MockResponseOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Custom response data to return instead of generated random data.
|
|
8
|
+
*/
|
|
9
|
+
data?: unknown;
|
|
10
|
+
/**
|
|
11
|
+
* HTTP status code to return. Defaults to 200.
|
|
12
|
+
*/
|
|
13
|
+
status?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Custom headers to include in the response.
|
|
16
|
+
*/
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A stub reference that can be used to restore the original behavior.
|
|
21
|
+
*/
|
|
22
|
+
export interface StubReference {
|
|
23
|
+
/**
|
|
24
|
+
* Restores the original behavior.
|
|
25
|
+
*/
|
|
26
|
+
restore: () => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* SDK mocking utility for testing. Provides simple API to mock SDK calls
|
|
30
|
+
* with random or custom responses.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { SdkMock } from '@api-client/core/sdk/SdkMock.js';
|
|
35
|
+
* import { StoreSdk } from '@api-client/core/sdk/StoreSdkWeb.js';
|
|
36
|
+
*
|
|
37
|
+
* const sdk = new StoreSdk('http://localhost:8080');
|
|
38
|
+
* const mocker = new SdkMock(sdk);
|
|
39
|
+
*
|
|
40
|
+
* // Simple usage - returns random valid organization
|
|
41
|
+
* const stub1 = mocker.organizations.list();
|
|
42
|
+
*
|
|
43
|
+
* // Custom response
|
|
44
|
+
* const stub2 = mocker.organizations.create({
|
|
45
|
+
* data: { key: 'org-1', name: 'Test Org', ... }
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Custom status and headers
|
|
49
|
+
* const stub3 = mocker.users.me({
|
|
50
|
+
* status: 404,
|
|
51
|
+
* headers: { 'X-Custom': 'value' }
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Restore all stubs
|
|
55
|
+
* mocker.restore();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare class SdkMock {
|
|
59
|
+
private sdk;
|
|
60
|
+
private stubs;
|
|
61
|
+
constructor(sdk: StoreSdk);
|
|
62
|
+
/**
|
|
63
|
+
* Organization API mocks.
|
|
64
|
+
*/
|
|
65
|
+
organizations: {
|
|
66
|
+
/**
|
|
67
|
+
* Mocks the `organizations.list()` method.
|
|
68
|
+
* @param options Optional response customization.
|
|
69
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
70
|
+
*/
|
|
71
|
+
list: (options?: MockResponseOptions) => StubReference;
|
|
72
|
+
/**
|
|
73
|
+
* Mocks the `organizations.create()` method.
|
|
74
|
+
* @param options Optional response customization.
|
|
75
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
76
|
+
*/
|
|
77
|
+
create: (options?: MockResponseOptions) => StubReference;
|
|
78
|
+
/**
|
|
79
|
+
* Mocks the `organizations.read()` method.
|
|
80
|
+
* @param options Optional response customization.
|
|
81
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
82
|
+
*/
|
|
83
|
+
read: (options?: MockResponseOptions) => StubReference;
|
|
84
|
+
/**
|
|
85
|
+
* Mocks the `organizations.delete()` method.
|
|
86
|
+
* @param options Optional response customization.
|
|
87
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
88
|
+
*/
|
|
89
|
+
delete: (options?: MockResponseOptions) => StubReference;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Group API mocks.
|
|
93
|
+
*/
|
|
94
|
+
groups: {
|
|
95
|
+
/**
|
|
96
|
+
* Mocks the `groups.list()` method.
|
|
97
|
+
* @param options Optional response customization.
|
|
98
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
99
|
+
*/
|
|
100
|
+
list: (options?: MockResponseOptions) => StubReference;
|
|
101
|
+
/**
|
|
102
|
+
* Mocks the `groups.create()` method.
|
|
103
|
+
* @param options Optional response customization.
|
|
104
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
105
|
+
*/
|
|
106
|
+
create: (options?: MockResponseOptions) => StubReference;
|
|
107
|
+
/**
|
|
108
|
+
* Mocks the `groups.read()` method.
|
|
109
|
+
* @param options Optional response customization.
|
|
110
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
111
|
+
*/
|
|
112
|
+
read: (options?: MockResponseOptions) => StubReference;
|
|
113
|
+
/**
|
|
114
|
+
* Mocks the `groups.update()` method.
|
|
115
|
+
* @param options Optional response customization.
|
|
116
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
117
|
+
*/
|
|
118
|
+
update: (options?: MockResponseOptions) => StubReference;
|
|
119
|
+
/**
|
|
120
|
+
* Mocks the `groups.delete()` method.
|
|
121
|
+
* @param options Optional response customization.
|
|
122
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
123
|
+
*/
|
|
124
|
+
delete: (options?: MockResponseOptions) => StubReference;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* User API mocks.
|
|
128
|
+
*/
|
|
129
|
+
users: {
|
|
130
|
+
/**
|
|
131
|
+
* Mocks the `user.me()` method.
|
|
132
|
+
* @param options Optional response customization.
|
|
133
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
134
|
+
*/
|
|
135
|
+
me: (options?: MockResponseOptions) => StubReference;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Auth API mocks.
|
|
139
|
+
*/
|
|
140
|
+
auth: {
|
|
141
|
+
/**
|
|
142
|
+
* Mocks the `auth.oauthRedirect()` method.
|
|
143
|
+
* This method returns `null` by default as it performs window navigation.
|
|
144
|
+
* @param options Optional response customization.
|
|
145
|
+
* @returns A stub reference that can be used to restore the original behavior.
|
|
146
|
+
*/
|
|
147
|
+
oauthRedirect: (options?: MockResponseOptions) => StubReference;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Files API mocks.
|
|
151
|
+
*/
|
|
152
|
+
file: {
|
|
153
|
+
/**
|
|
154
|
+
* Mocks the `file.list()` method.
|
|
155
|
+
*/
|
|
156
|
+
list: (options?: MockResponseOptions) => StubReference;
|
|
157
|
+
/**
|
|
158
|
+
* Mocks the `file.createMeta()` method.
|
|
159
|
+
*/
|
|
160
|
+
createMeta: (options?: MockResponseOptions) => StubReference;
|
|
161
|
+
/**
|
|
162
|
+
* Mocks the `file.createMedia()` method.
|
|
163
|
+
*/
|
|
164
|
+
createMedia: (options?: MockResponseOptions) => StubReference;
|
|
165
|
+
/**
|
|
166
|
+
* Mocks the `file.create()` method.
|
|
167
|
+
*/
|
|
168
|
+
create: (options?: MockResponseOptions) => StubReference;
|
|
169
|
+
/**
|
|
170
|
+
* Mocks the `file.createFolder()` method.
|
|
171
|
+
*/
|
|
172
|
+
createFolder: (options?: MockResponseOptions) => StubReference;
|
|
173
|
+
/**
|
|
174
|
+
* Mocks the `file.read()` method.
|
|
175
|
+
*/
|
|
176
|
+
read: (options?: MockResponseOptions) => StubReference;
|
|
177
|
+
/**
|
|
178
|
+
* Mocks the `file.readMedia()` method.
|
|
179
|
+
*/
|
|
180
|
+
readMedia: (options?: MockResponseOptions) => StubReference;
|
|
181
|
+
/**
|
|
182
|
+
* Mocks the `file.readBulk()` method.
|
|
183
|
+
*/
|
|
184
|
+
readBulk: (options?: MockResponseOptions) => StubReference;
|
|
185
|
+
/**
|
|
186
|
+
* Mocks the `file.patch()` method.
|
|
187
|
+
*/
|
|
188
|
+
patch: (options?: MockResponseOptions) => StubReference;
|
|
189
|
+
/**
|
|
190
|
+
* Mocks the `file.patchMedia()` method.
|
|
191
|
+
*/
|
|
192
|
+
patchMedia: (options?: MockResponseOptions) => StubReference;
|
|
193
|
+
/**
|
|
194
|
+
* Mocks the `file.delete()` method.
|
|
195
|
+
*/
|
|
196
|
+
delete: (options?: MockResponseOptions) => StubReference;
|
|
197
|
+
/**
|
|
198
|
+
* Mocks the `file.deleteBulk()` method.
|
|
199
|
+
*/
|
|
200
|
+
deleteBulk: (options?: MockResponseOptions) => StubReference;
|
|
201
|
+
/**
|
|
202
|
+
* Mocks the `file.patchUsers()` method.
|
|
203
|
+
*/
|
|
204
|
+
patchUsers: (options?: MockResponseOptions) => StubReference;
|
|
205
|
+
/**
|
|
206
|
+
* Mocks the `file.addUser()` method.
|
|
207
|
+
*/
|
|
208
|
+
addUser: (options?: MockResponseOptions) => StubReference;
|
|
209
|
+
/**
|
|
210
|
+
* Mocks the `file.removeUser()` method.
|
|
211
|
+
*/
|
|
212
|
+
removeUser: (options?: MockResponseOptions) => StubReference;
|
|
213
|
+
/**
|
|
214
|
+
* Mocks the `file.listUsers()` method.
|
|
215
|
+
*/
|
|
216
|
+
listUsers: (options?: MockResponseOptions) => StubReference;
|
|
217
|
+
/**
|
|
218
|
+
* Mocks the `file.breadcrumbs()` method.
|
|
219
|
+
*/
|
|
220
|
+
breadcrumbs: (options?: MockResponseOptions) => StubReference;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* Shared API mocks.
|
|
224
|
+
*/
|
|
225
|
+
shared: {
|
|
226
|
+
list: (options?: MockResponseOptions) => StubReference;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Trash API mocks.
|
|
230
|
+
*/
|
|
231
|
+
trash: {
|
|
232
|
+
list: (options?: MockResponseOptions) => StubReference;
|
|
233
|
+
delete: (options?: MockResponseOptions) => StubReference;
|
|
234
|
+
restore: (options?: MockResponseOptions) => StubReference;
|
|
235
|
+
empty: (options?: MockResponseOptions) => StubReference;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Restores all stubs created by this mocker.
|
|
239
|
+
*/
|
|
240
|
+
restore(): void;
|
|
241
|
+
/**
|
|
242
|
+
* Creates a stub for a specific SDK method.
|
|
243
|
+
* @param api The API name (e.g., 'organizations', 'groups', 'user', 'auth').
|
|
244
|
+
* @param method The method name to stub.
|
|
245
|
+
* @param implementation The stub implementation that returns the mocked data.
|
|
246
|
+
* @returns A stub reference.
|
|
247
|
+
*/
|
|
248
|
+
private createStub;
|
|
249
|
+
/**
|
|
250
|
+
* Creates a response object from data and options.
|
|
251
|
+
* @param defaultData Default data to return if not overridden.
|
|
252
|
+
* @param options Response options.
|
|
253
|
+
* @returns The final data to return (for non-HTTP responses) or IStoreResponse (for HTTP responses).
|
|
254
|
+
*/
|
|
255
|
+
private createResponse;
|
|
256
|
+
/**
|
|
257
|
+
* Generates a random organization object.
|
|
258
|
+
*/
|
|
259
|
+
private generateOrganization;
|
|
260
|
+
/**
|
|
261
|
+
* Generates a random group object.
|
|
262
|
+
*/
|
|
263
|
+
private generateGroup;
|
|
264
|
+
/**
|
|
265
|
+
* Generates a random user object.
|
|
266
|
+
*/
|
|
267
|
+
private generateUser;
|
|
268
|
+
/**
|
|
269
|
+
* Generates a random file meta object.
|
|
270
|
+
*/
|
|
271
|
+
private generateFile;
|
|
272
|
+
/**
|
|
273
|
+
* Generates a random folder meta object.
|
|
274
|
+
*/
|
|
275
|
+
private generateFolder;
|
|
276
|
+
/**
|
|
277
|
+
* Generates a random media patch revision object.
|
|
278
|
+
*/
|
|
279
|
+
private generateMediaPatchRevision;
|
|
280
|
+
/**
|
|
281
|
+
* Generates a random breadcrumbs list.
|
|
282
|
+
*/
|
|
283
|
+
private generateBreadcrumbs;
|
|
284
|
+
/**
|
|
285
|
+
* Generates a random trash entry.
|
|
286
|
+
*/
|
|
287
|
+
private generateTrashEntry;
|
|
288
|
+
/**
|
|
289
|
+
* Generates a random string.
|
|
290
|
+
*/
|
|
291
|
+
private randomString;
|
|
292
|
+
/**
|
|
293
|
+
* Returns a random choice from an array.
|
|
294
|
+
*/
|
|
295
|
+
private randomChoice;
|
|
296
|
+
/**
|
|
297
|
+
* Generates a random hex color.
|
|
298
|
+
*/
|
|
299
|
+
private randomColor;
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=SdkMock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SdkMock.d.ts","sourceRoot":"","sources":["../../../src/sdk/SdkMock.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAIhD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;C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