@api-client/core 0.18.38 → 0.18.39
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 -1
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js.map +1 -1
- package/build/src/mocking/ModelingMock.d.ts +19 -0
- package/build/src/mocking/ModelingMock.d.ts.map +1 -0
- package/build/src/mocking/ModelingMock.js +19 -0
- package/build/src/mocking/ModelingMock.js.map +1 -0
- package/build/src/mocking/ProjectMock.js +1 -1
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/File.d.ts +34 -0
- package/build/src/mocking/lib/File.d.ts.map +1 -0
- package/build/src/mocking/lib/File.js +64 -0
- package/build/src/mocking/lib/File.js.map +1 -0
- package/build/src/mocking/lib/Group.d.ts +16 -0
- package/build/src/mocking/lib/Group.d.ts.map +1 -0
- package/build/src/mocking/lib/Group.js +39 -0
- package/build/src/mocking/lib/Group.js.map +1 -0
- package/build/src/mocking/lib/Invitation.d.ts +16 -0
- package/build/src/mocking/lib/Invitation.d.ts.map +1 -0
- package/build/src/mocking/lib/Invitation.js +42 -0
- package/build/src/mocking/lib/Invitation.js.map +1 -0
- package/build/src/mocking/lib/Organization.d.ts +16 -0
- package/build/src/mocking/lib/Organization.d.ts.map +1 -0
- package/build/src/mocking/lib/Organization.js +34 -0
- package/build/src/mocking/lib/Organization.js.map +1 -0
- package/build/src/mocking/lib/Patch.d.ts +29 -0
- package/build/src/mocking/lib/Patch.d.ts.map +1 -0
- package/build/src/mocking/lib/Patch.js +102 -0
- package/build/src/mocking/lib/Patch.js.map +1 -0
- package/build/src/mocking/lib/Trash.d.ts +16 -0
- package/build/src/mocking/lib/Trash.d.ts.map +1 -0
- package/build/src/mocking/lib/Trash.js +39 -0
- package/build/src/mocking/lib/Trash.js.map +1 -0
- package/build/src/mocking/lib/User.d.ts +12 -12
- package/build/src/mocking/lib/User.d.ts.map +1 -1
- package/build/src/mocking/lib/User.js +29 -26
- package/build/src/mocking/lib/User.js.map +1 -1
- package/build/src/sdk/SdkMock.d.ts +125 -156
- package/build/src/sdk/SdkMock.d.ts.map +1 -1
- package/build/src/sdk/SdkMock.js +774 -596
- package/build/src/sdk/SdkMock.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +9 -9
- package/package.json +5 -3
- package/src/mocking/ModelingMock.ts +19 -0
- package/src/mocking/ProjectMock.ts +1 -1
- package/src/mocking/lib/File.ts +72 -0
- package/src/mocking/lib/Group.ts +52 -0
- package/src/mocking/lib/Invitation.ts +58 -0
- package/src/mocking/lib/Organization.ts +42 -0
- package/src/mocking/lib/Patch.ts +128 -0
- package/src/mocking/lib/Trash.ts +47 -0
- package/src/mocking/lib/User.ts +30 -29
- package/src/sdk/SdkMock.ts +966 -650
package/build/src/sdk/SdkMock.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { File } from '../models/store/File.js';
|
|
5
|
-
import { CertificateFileKind, DomainFileKind, FolderKind, ProjectKind } from '../models/kinds.js';
|
|
6
|
-
import * as sinon from 'sinon';
|
|
7
|
-
import { Exception } from '../exceptions/exception.js';
|
|
1
|
+
import { setupWorker } from '@jarrodek/amw';
|
|
2
|
+
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
+
import { ModelingMock } from '../mocking/ModelingMock.js';
|
|
8
4
|
/**
|
|
9
|
-
* SDK mocking utility for testing.
|
|
10
|
-
*
|
|
5
|
+
* SDK mocking utility for testing. Uses Service Workers to intercept HTTP requests
|
|
6
|
+
* and provide mock responses for API calls.
|
|
7
|
+
*
|
|
8
|
+
* This class uses the `@jarrodek/amw` library to set up a Service Worker that intercepts
|
|
9
|
+
* fetch requests matching the configured routes. Each method adds an intercept for a specific
|
|
10
|
+
* API endpoint, returning either random generated data or custom responses.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
|
@@ -15,191 +15,396 @@ import { Exception } from '../exceptions/exception.js';
|
|
|
15
15
|
* import { StoreSdk } from '@api-client/core/sdk/StoreSdkWeb.js';
|
|
16
16
|
*
|
|
17
17
|
* const sdk = new StoreSdk('http://localhost:8080');
|
|
18
|
-
* const mocker = new SdkMock(
|
|
18
|
+
* const mocker = new SdkMock({
|
|
19
|
+
* swPath: '/mockServiceWorker.js', // Path to the Service Worker script
|
|
20
|
+
* base: 'http://localhost:8080' // Base URL matching the SDK
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Initialize the Service Worker
|
|
24
|
+
* await mocker.setup();
|
|
25
|
+
*
|
|
26
|
+
* // Add intercept - returns random organizations
|
|
27
|
+
* await mocker.organizations.list();
|
|
19
28
|
*
|
|
20
|
-
* //
|
|
21
|
-
*
|
|
29
|
+
* // Custom response with specific data
|
|
30
|
+
* await mocker.organizations.create({
|
|
31
|
+
* response: {
|
|
32
|
+
* status: 201,
|
|
33
|
+
* headers: { 'Content-Type': 'application/json', 'X-Custom-Header': 'value' },
|
|
34
|
+
* body: JSON.stringify({ key: 'custom-id', name: 'Custom Org' })
|
|
35
|
+
* }
|
|
36
|
+
* });
|
|
22
37
|
*
|
|
23
|
-
* //
|
|
24
|
-
*
|
|
25
|
-
*
|
|
38
|
+
* // Control pagination in list responses
|
|
39
|
+
* await mocker.groups.list({
|
|
40
|
+
* size: 10, // Number of items to generate
|
|
41
|
+
* cursor: true // Include pagination cursor
|
|
26
42
|
* });
|
|
27
43
|
*
|
|
28
|
-
* //
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
44
|
+
* // Error simulation
|
|
45
|
+
* await mocker.users.me({
|
|
46
|
+
* response: {
|
|
47
|
+
* status: 404,
|
|
48
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
49
|
+
* body: JSON.stringify({ error: 'Not found' })
|
|
50
|
+
* }
|
|
32
51
|
* });
|
|
33
52
|
*
|
|
34
|
-
* //
|
|
35
|
-
* mocker.
|
|
53
|
+
* // Remove all intercepts (keep Service Worker active)
|
|
54
|
+
* await mocker.reset();
|
|
55
|
+
*
|
|
56
|
+
* // Stop and remove the Service Worker
|
|
57
|
+
* await mocker.teardown();
|
|
36
58
|
* ```
|
|
37
59
|
*/
|
|
38
60
|
export class SdkMock {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
61
|
+
options;
|
|
62
|
+
handler;
|
|
63
|
+
gen = new ModelingMock();
|
|
64
|
+
constructor(options) {
|
|
65
|
+
this.options = options;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Initializes the mock handler. It uses options provided in the constructor.
|
|
69
|
+
* It has to be called before using any of the mock methods.
|
|
70
|
+
*/
|
|
71
|
+
async setup() {
|
|
72
|
+
this.handler = await setupWorker(this.options);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Removes the mock worker and all intercepts.
|
|
76
|
+
*/
|
|
77
|
+
async teardown() {
|
|
78
|
+
await this.mock.stop();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Removes all added intercepts.
|
|
82
|
+
*/
|
|
83
|
+
async reset() {
|
|
84
|
+
await this.mock.reset();
|
|
85
|
+
}
|
|
86
|
+
get mock() {
|
|
87
|
+
if (!this.handler) {
|
|
88
|
+
throw new Error('Mock handler not initialized. Call setup() first.');
|
|
89
|
+
}
|
|
90
|
+
return this.handler;
|
|
91
|
+
}
|
|
92
|
+
createCursorOption(init = {}) {
|
|
93
|
+
if (init.cursor === false) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const hasCursor = init.cursor === true ? true : this.gen.faker.datatype.boolean();
|
|
97
|
+
if (!hasCursor) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
return this.gen.faker.internet.jwt();
|
|
101
|
+
}
|
|
102
|
+
createDefaultResponse(status, headers, body, userConfig) {
|
|
103
|
+
let respond;
|
|
104
|
+
if (userConfig?.response) {
|
|
105
|
+
// user config takes precedence
|
|
106
|
+
respond = userConfig.response;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
respond = {};
|
|
110
|
+
}
|
|
111
|
+
// Set defaults if not provided in user config
|
|
112
|
+
if (!respond.status) {
|
|
113
|
+
respond.status = status;
|
|
114
|
+
}
|
|
115
|
+
// only set headers if the user didn't configure the response only.
|
|
116
|
+
// The user may want to remove default headers.
|
|
117
|
+
if (!userConfig || !userConfig.response) {
|
|
118
|
+
respond.headers = headers;
|
|
119
|
+
}
|
|
120
|
+
if (!respond.body && userConfig?.forceBody && body) {
|
|
121
|
+
// when body is missing and forceBody is set, generate the body
|
|
122
|
+
respond.body = body();
|
|
123
|
+
}
|
|
124
|
+
else if (body && (!userConfig || !userConfig.response)) {
|
|
125
|
+
// we set the body by default when the user config is missing
|
|
126
|
+
respond.body = body();
|
|
127
|
+
}
|
|
128
|
+
return respond;
|
|
43
129
|
}
|
|
44
130
|
/**
|
|
45
131
|
* Organization API mocks.
|
|
46
132
|
*/
|
|
47
133
|
organizations = {
|
|
48
134
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param options Optional response
|
|
51
|
-
* @returns A stub reference that can be used to restore the original behavior.
|
|
135
|
+
* Adds an intercept to mock the `organizations.list()` method.
|
|
136
|
+
* @param options Optional response configuration
|
|
52
137
|
*/
|
|
53
|
-
list: (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
138
|
+
list: async (init) => {
|
|
139
|
+
const { mock } = this;
|
|
140
|
+
// const respond = init?.response ?? {
|
|
141
|
+
// status: 200,
|
|
142
|
+
// headers: { 'content-type': 'application/json' },
|
|
143
|
+
// body: JSON.stringify({
|
|
144
|
+
// items: this.gen.organization.organizations(init?.size ?? 5),
|
|
145
|
+
// cursor: this.createCursorOption(init),
|
|
146
|
+
// } as ContextListResult<IOrganization>),
|
|
147
|
+
// }
|
|
148
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify({
|
|
149
|
+
items: this.gen.organization.organizations(init?.size ?? 5),
|
|
150
|
+
cursor: this.createCursorOption(init),
|
|
151
|
+
}), init);
|
|
152
|
+
await mock.add({
|
|
153
|
+
match: {
|
|
154
|
+
uri: RouteBuilder.organizations(),
|
|
155
|
+
methods: ['GET'],
|
|
156
|
+
},
|
|
157
|
+
respond,
|
|
63
158
|
});
|
|
64
159
|
},
|
|
65
160
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param options Optional response
|
|
68
|
-
* @returns A stub reference that can be used to restore the original behavior.
|
|
161
|
+
* Adds an intercept to mock the `organizations.create()` method.
|
|
162
|
+
* @param options Optional response configuration
|
|
69
163
|
*/
|
|
70
|
-
create: (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
164
|
+
create: async (init) => {
|
|
165
|
+
const { mock } = this;
|
|
166
|
+
// const respond = init?.response ?? {
|
|
167
|
+
// status: 200,
|
|
168
|
+
// headers: { 'content-type': 'application/json' },
|
|
169
|
+
// body: JSON.stringify(this.gen.organization.organization()),
|
|
170
|
+
// }
|
|
171
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.organization.organization()), init);
|
|
172
|
+
await mock.add({
|
|
173
|
+
match: {
|
|
174
|
+
uri: RouteBuilder.organizations(),
|
|
175
|
+
methods: ['POST'],
|
|
176
|
+
},
|
|
177
|
+
respond,
|
|
77
178
|
});
|
|
78
179
|
},
|
|
79
180
|
invitations: {
|
|
80
|
-
list: (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
181
|
+
list: async (init) => {
|
|
182
|
+
const { mock } = this;
|
|
183
|
+
// const respond = init?.response ?? {
|
|
184
|
+
// status: 200,
|
|
185
|
+
// headers: { 'content-type': 'application/json' },
|
|
186
|
+
// body: JSON.stringify({
|
|
187
|
+
// items: this.gen.invitation.invitations(init?.size ?? 5),
|
|
188
|
+
// cursor: this.createCursorOption(init),
|
|
189
|
+
// } as ContextListResult<InvitationSchema>),
|
|
190
|
+
// }
|
|
191
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
192
|
+
const obj = {
|
|
193
|
+
items: this.gen.invitation.invitations(init?.size ?? 5),
|
|
194
|
+
cursor: this.createCursorOption(init),
|
|
84
195
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
196
|
+
return JSON.stringify(obj);
|
|
197
|
+
}, init);
|
|
198
|
+
await mock.add({
|
|
199
|
+
match: {
|
|
200
|
+
uri: RouteBuilder.invitations(':oid'),
|
|
201
|
+
methods: ['GET'],
|
|
202
|
+
},
|
|
203
|
+
respond,
|
|
89
204
|
});
|
|
90
205
|
},
|
|
91
|
-
create: (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
206
|
+
create: async (init) => {
|
|
207
|
+
const { mock } = this;
|
|
208
|
+
// const respond = init?.response ?? {
|
|
209
|
+
// status: 200,
|
|
210
|
+
// headers: { 'content-type': 'application/json' },
|
|
211
|
+
// body: JSON.stringify(this.gen.invitation.invitation()),
|
|
212
|
+
// }
|
|
213
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.invitation.invitation()), init);
|
|
214
|
+
await mock.add({
|
|
215
|
+
match: {
|
|
216
|
+
uri: RouteBuilder.invitations(':oid'),
|
|
217
|
+
methods: ['POST'],
|
|
218
|
+
},
|
|
219
|
+
respond,
|
|
98
220
|
});
|
|
99
221
|
},
|
|
100
|
-
findByToken: (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
222
|
+
findByToken: async (init) => {
|
|
223
|
+
const { mock } = this;
|
|
224
|
+
// const respond = init?.response ?? {
|
|
225
|
+
// status: 200,
|
|
226
|
+
// headers: { 'content-type': 'application/json' },
|
|
227
|
+
// body: JSON.stringify(this.gen.invitation.invitation()),
|
|
228
|
+
// }
|
|
229
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.invitation.invitation()), init);
|
|
230
|
+
await mock.add({
|
|
231
|
+
match: {
|
|
232
|
+
uri: RouteBuilder.findInvitation(),
|
|
233
|
+
methods: ['GET'],
|
|
234
|
+
},
|
|
235
|
+
respond,
|
|
107
236
|
});
|
|
108
237
|
},
|
|
109
|
-
decline: (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
238
|
+
decline: async (init) => {
|
|
239
|
+
const { mock } = this;
|
|
240
|
+
// const respond = init?.response ?? {
|
|
241
|
+
// status: 200,
|
|
242
|
+
// headers: { 'content-type': 'application/json' },
|
|
243
|
+
// body: JSON.stringify(this.gen.invitation.invitation()),
|
|
244
|
+
// }
|
|
245
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.invitation.invitation()), init);
|
|
246
|
+
await mock.add({
|
|
247
|
+
match: {
|
|
248
|
+
uri: RouteBuilder.declineInvitation(':oid', ':id'),
|
|
249
|
+
methods: ['POST'],
|
|
250
|
+
},
|
|
251
|
+
respond,
|
|
116
252
|
});
|
|
117
253
|
},
|
|
118
|
-
delete: (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
254
|
+
delete: async (init) => {
|
|
255
|
+
const { mock } = this;
|
|
256
|
+
// const respond = init?.response ?? {
|
|
257
|
+
// status: 200,
|
|
258
|
+
// headers: { 'content-type': 'application/json' },
|
|
259
|
+
// body: JSON.stringify(this.gen.invitation.invitation()),
|
|
260
|
+
// }
|
|
261
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.invitation.invitation()), init);
|
|
262
|
+
await mock.add({
|
|
263
|
+
match: {
|
|
264
|
+
uri: RouteBuilder.invitation(':oid', ':id'),
|
|
265
|
+
methods: ['DELETE'],
|
|
266
|
+
},
|
|
267
|
+
respond,
|
|
125
268
|
});
|
|
126
269
|
},
|
|
127
|
-
patch: (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
270
|
+
patch: async (init) => {
|
|
271
|
+
const { mock } = this;
|
|
272
|
+
// const respond = init?.response ?? {
|
|
273
|
+
// status: 200,
|
|
274
|
+
// headers: { 'content-type': 'application/json' },
|
|
275
|
+
// body: JSON.stringify(this.gen.invitation.invitation()),
|
|
276
|
+
// }
|
|
277
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.invitation.invitation()), init);
|
|
278
|
+
await mock.add({
|
|
279
|
+
match: {
|
|
280
|
+
uri: RouteBuilder.invitation(':oid', ':id'),
|
|
281
|
+
methods: ['PATCH'],
|
|
282
|
+
},
|
|
283
|
+
respond,
|
|
134
284
|
});
|
|
135
285
|
},
|
|
136
|
-
resend: (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
286
|
+
resend: async (init) => {
|
|
287
|
+
const { mock } = this;
|
|
288
|
+
// const respond = init?.response ?? {
|
|
289
|
+
// status: 200,
|
|
290
|
+
// headers: { 'content-type': 'application/json' },
|
|
291
|
+
// body: JSON.stringify(this.gen.invitation.invitation()),
|
|
292
|
+
// }
|
|
293
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.invitation.invitation()), init);
|
|
294
|
+
await mock.add({
|
|
295
|
+
match: {
|
|
296
|
+
uri: RouteBuilder.resendInvitation(':oid', ':id'),
|
|
297
|
+
methods: ['PUT'],
|
|
298
|
+
},
|
|
299
|
+
respond,
|
|
143
300
|
});
|
|
144
301
|
},
|
|
145
302
|
},
|
|
146
303
|
users: {
|
|
147
|
-
list: (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
304
|
+
list: async (init) => {
|
|
305
|
+
const { mock } = this;
|
|
306
|
+
// const respond = init?.response ?? {
|
|
307
|
+
// status: 200,
|
|
308
|
+
// headers: { 'content-type': 'application/json' },
|
|
309
|
+
// body: JSON.stringify({
|
|
310
|
+
// items: this.gen.user.users(init?.size ?? 5),
|
|
311
|
+
// cursor: this.createCursorOption(init),
|
|
312
|
+
// } as ContextListResult<IUser>),
|
|
313
|
+
// }
|
|
314
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
315
|
+
const obj = {
|
|
316
|
+
items: this.gen.user.users(init?.size ?? 5),
|
|
317
|
+
cursor: this.createCursorOption(init),
|
|
151
318
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
319
|
+
return JSON.stringify(obj);
|
|
320
|
+
}, init);
|
|
321
|
+
await mock.add({
|
|
322
|
+
match: {
|
|
323
|
+
uri: RouteBuilder.organizationUsers(':oid'),
|
|
324
|
+
methods: ['GET'],
|
|
325
|
+
},
|
|
326
|
+
respond,
|
|
156
327
|
});
|
|
157
328
|
},
|
|
158
|
-
read: (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
329
|
+
read: async (init) => {
|
|
330
|
+
const { mock } = this;
|
|
331
|
+
// const respond = init?.response ?? {
|
|
332
|
+
// status: 200,
|
|
333
|
+
// headers: { 'content-type': 'application/json' },
|
|
334
|
+
// body: JSON.stringify(this.gen.user.user()),
|
|
335
|
+
// }
|
|
336
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.user.user()), init);
|
|
337
|
+
await mock.add({
|
|
338
|
+
match: {
|
|
339
|
+
uri: RouteBuilder.organizationUser(':oid', ':id'),
|
|
340
|
+
methods: ['GET'],
|
|
341
|
+
},
|
|
342
|
+
respond,
|
|
165
343
|
});
|
|
166
344
|
},
|
|
167
|
-
readBatch: (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
345
|
+
readBatch: async (init) => {
|
|
346
|
+
const { mock } = this;
|
|
347
|
+
const path = RouteBuilder.organizationUserBatch(':oid');
|
|
348
|
+
const respond = init?.response ?? {
|
|
349
|
+
status: 200,
|
|
350
|
+
headers: { 'content-type': 'application/json' },
|
|
351
|
+
body: JSON.stringify({
|
|
352
|
+
items: this.gen.user.users(init?.size ?? 5),
|
|
353
|
+
cursor: this.createCursorOption(init),
|
|
354
|
+
}),
|
|
355
|
+
};
|
|
356
|
+
await mock.add({
|
|
357
|
+
match: {
|
|
358
|
+
uri: path,
|
|
359
|
+
methods: ['POST'],
|
|
360
|
+
},
|
|
361
|
+
respond,
|
|
176
362
|
});
|
|
177
363
|
},
|
|
178
|
-
activate: (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
364
|
+
activate: async (init) => {
|
|
365
|
+
const { mock } = this;
|
|
366
|
+
// const respond = init?.response ?? {
|
|
367
|
+
// status: 200,
|
|
368
|
+
// headers: { 'content-type': 'application/json' },
|
|
369
|
+
// body: JSON.stringify(this.gen.user.user()),
|
|
370
|
+
// }
|
|
371
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.user.user()), init);
|
|
372
|
+
await mock.add({
|
|
373
|
+
match: {
|
|
374
|
+
uri: RouteBuilder.organizationUserActivate(':oid', ':id'),
|
|
375
|
+
methods: ['POST'],
|
|
376
|
+
},
|
|
377
|
+
respond,
|
|
185
378
|
});
|
|
186
379
|
},
|
|
187
|
-
deactivate: (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
380
|
+
deactivate: async (init) => {
|
|
381
|
+
const { mock } = this;
|
|
382
|
+
// const respond = init?.response ?? {
|
|
383
|
+
// status: 200,
|
|
384
|
+
// headers: { 'content-type': 'application/json' },
|
|
385
|
+
// body: JSON.stringify(this.gen.user.user()),
|
|
386
|
+
// }
|
|
387
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.user.user()), init);
|
|
388
|
+
await mock.add({
|
|
389
|
+
match: {
|
|
390
|
+
uri: RouteBuilder.organizationUserDeactivate(':oid', ':id'),
|
|
391
|
+
methods: ['POST'],
|
|
392
|
+
},
|
|
393
|
+
respond,
|
|
194
394
|
});
|
|
195
395
|
},
|
|
196
|
-
delete: (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
396
|
+
delete: async (init) => {
|
|
397
|
+
const { mock } = this;
|
|
398
|
+
// const respond = init?.response ?? {
|
|
399
|
+
// status: 204,
|
|
400
|
+
// }
|
|
401
|
+
const respond = this.createDefaultResponse(204, undefined, undefined, init);
|
|
402
|
+
await mock.add({
|
|
403
|
+
match: {
|
|
404
|
+
uri: RouteBuilder.organizationUser(':oid', ':id'),
|
|
405
|
+
methods: ['DELETE'],
|
|
406
|
+
},
|
|
407
|
+
respond,
|
|
203
408
|
});
|
|
204
409
|
},
|
|
205
410
|
},
|
|
@@ -211,99 +416,126 @@ export class SdkMock {
|
|
|
211
416
|
/**
|
|
212
417
|
* Mocks the `groups.list()` method.
|
|
213
418
|
* @param options Optional response customization.
|
|
214
|
-
* @returns A stub reference that can be used to restore the original behavior.
|
|
215
419
|
*/
|
|
216
|
-
list: (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
420
|
+
list: async (init) => {
|
|
421
|
+
const { mock } = this;
|
|
422
|
+
// const respond = init?.response ?? {
|
|
423
|
+
// status: 200,
|
|
424
|
+
// headers: { 'content-type': 'application/json' },
|
|
425
|
+
// body: JSON.stringify({
|
|
426
|
+
// items: this.gen.group.groups(init?.size ?? 5),
|
|
427
|
+
// cursor: this.createCursorOption(init),
|
|
428
|
+
// } as ContextListResult<GroupSchema>),
|
|
429
|
+
// }
|
|
430
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
431
|
+
const obj = {
|
|
432
|
+
items: this.gen.group.groups(init?.size ?? 5),
|
|
433
|
+
cursor: this.createCursorOption(init),
|
|
221
434
|
};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
435
|
+
return JSON.stringify(obj);
|
|
436
|
+
}, init);
|
|
437
|
+
await mock.add({
|
|
438
|
+
match: {
|
|
439
|
+
uri: RouteBuilder.groups(':oid'),
|
|
440
|
+
methods: ['GET'],
|
|
441
|
+
},
|
|
442
|
+
respond,
|
|
226
443
|
});
|
|
227
444
|
},
|
|
228
445
|
/**
|
|
229
446
|
* Mocks the `groups.create()` method.
|
|
230
447
|
* @param options Optional response customization.
|
|
231
|
-
* @returns A stub reference that can be used to restore the original behavior.
|
|
232
448
|
*/
|
|
233
|
-
create: (
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
*/
|
|
248
|
-
read: (options) => {
|
|
249
|
-
return this.createStub('groups', 'read', () => {
|
|
250
|
-
const defaultData = this.generateGroup();
|
|
251
|
-
if (options?.status !== undefined && options.status !== 200) {
|
|
252
|
-
throw new Exception('Mocked error', { status: options.status });
|
|
253
|
-
}
|
|
254
|
-
return (options?.data ?? defaultData);
|
|
449
|
+
create: async (init) => {
|
|
450
|
+
const { mock } = this;
|
|
451
|
+
// const respond = init?.response ?? {
|
|
452
|
+
// status: 201,
|
|
453
|
+
// headers: { 'content-type': 'application/json' },
|
|
454
|
+
// body: JSON.stringify(this.gen.group.group()),
|
|
455
|
+
// }
|
|
456
|
+
const respond = this.createDefaultResponse(201, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.group.group()), init);
|
|
457
|
+
await mock.add({
|
|
458
|
+
match: {
|
|
459
|
+
uri: RouteBuilder.groups(':oid'),
|
|
460
|
+
methods: ['POST'],
|
|
461
|
+
},
|
|
462
|
+
respond,
|
|
255
463
|
});
|
|
256
464
|
},
|
|
257
465
|
/**
|
|
258
466
|
* Mocks the `groups.update()` method.
|
|
259
467
|
* @param options Optional response customization.
|
|
260
|
-
* @returns A stub reference that can be used to restore the original behavior.
|
|
261
468
|
*/
|
|
262
|
-
update: (
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
469
|
+
update: async (init) => {
|
|
470
|
+
const { mock } = this;
|
|
471
|
+
// const respond = init?.response ?? {
|
|
472
|
+
// status: 200,
|
|
473
|
+
// headers: { 'content-type': 'application/json' },
|
|
474
|
+
// body: JSON.stringify(this.gen.group.group()),
|
|
475
|
+
// }
|
|
476
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.group.group()), init);
|
|
477
|
+
await mock.add({
|
|
478
|
+
match: {
|
|
479
|
+
uri: RouteBuilder.group(':oid', ':key'),
|
|
480
|
+
methods: ['PATCH'],
|
|
481
|
+
},
|
|
482
|
+
respond,
|
|
269
483
|
});
|
|
270
484
|
},
|
|
271
485
|
/**
|
|
272
486
|
* Mocks the `groups.delete()` method.
|
|
273
487
|
* @param options Optional response customization.
|
|
274
|
-
* @returns A stub reference that can be used to restore the original behavior.
|
|
275
488
|
*/
|
|
276
|
-
delete: (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
489
|
+
delete: async (init) => {
|
|
490
|
+
const { mock } = this;
|
|
491
|
+
// const respond = init?.response ?? {
|
|
492
|
+
// status: 204,
|
|
493
|
+
// }
|
|
494
|
+
const respond = this.createDefaultResponse(204, undefined, undefined, init);
|
|
495
|
+
await mock.add({
|
|
496
|
+
match: {
|
|
497
|
+
uri: RouteBuilder.group(':oid', ':key'),
|
|
498
|
+
methods: ['DELETE'],
|
|
499
|
+
},
|
|
500
|
+
respond,
|
|
283
501
|
});
|
|
284
502
|
},
|
|
285
503
|
/**
|
|
286
504
|
* Mocks the `groups.addUsers()` method.
|
|
287
505
|
*/
|
|
288
|
-
addUsers: (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
506
|
+
addUsers: async (init) => {
|
|
507
|
+
const { mock } = this;
|
|
508
|
+
// const respond = init?.response ?? {
|
|
509
|
+
// status: 200,
|
|
510
|
+
// headers: { 'content-type': 'application/json' },
|
|
511
|
+
// body: JSON.stringify(this.gen.group.group()),
|
|
512
|
+
// }
|
|
513
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.group.group()), init);
|
|
514
|
+
await mock.add({
|
|
515
|
+
match: {
|
|
516
|
+
uri: RouteBuilder.groupUsers(':oid', ':key'),
|
|
517
|
+
methods: ['POST'],
|
|
518
|
+
},
|
|
519
|
+
respond,
|
|
295
520
|
});
|
|
296
521
|
},
|
|
297
522
|
/**
|
|
298
523
|
* Mocks the `groups.removeUsers()` method.
|
|
299
524
|
*/
|
|
300
|
-
removeUsers: (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
525
|
+
removeUsers: async (init) => {
|
|
526
|
+
const { mock } = this;
|
|
527
|
+
// const respond = init?.response ?? {
|
|
528
|
+
// status: 200,
|
|
529
|
+
// headers: { 'content-type': 'application/json' },
|
|
530
|
+
// body: JSON.stringify(this.gen.group.group()),
|
|
531
|
+
// }
|
|
532
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.group.group()), init);
|
|
533
|
+
await mock.add({
|
|
534
|
+
match: {
|
|
535
|
+
uri: RouteBuilder.groupUsers(':oid', ':key'),
|
|
536
|
+
methods: ['DELETE'],
|
|
537
|
+
},
|
|
538
|
+
respond,
|
|
307
539
|
});
|
|
308
540
|
},
|
|
309
541
|
};
|
|
@@ -314,15 +546,21 @@ export class SdkMock {
|
|
|
314
546
|
/**
|
|
315
547
|
* Mocks the `user.me()` method.
|
|
316
548
|
* @param options Optional response customization.
|
|
317
|
-
* @returns A stub reference that can be used to restore the original behavior.
|
|
318
549
|
*/
|
|
319
|
-
me: (
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
550
|
+
me: async (init) => {
|
|
551
|
+
const { mock } = this;
|
|
552
|
+
// const respond = init?.response ?? {
|
|
553
|
+
// status: 200,
|
|
554
|
+
// headers: { 'content-type': 'application/json' },
|
|
555
|
+
// body: JSON.stringify(this.gen.user.user()),
|
|
556
|
+
// }
|
|
557
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.user.user()), init);
|
|
558
|
+
await mock.add({
|
|
559
|
+
match: {
|
|
560
|
+
uri: RouteBuilder.usersMe(),
|
|
561
|
+
methods: ['GET'],
|
|
562
|
+
},
|
|
563
|
+
respond,
|
|
326
564
|
});
|
|
327
565
|
},
|
|
328
566
|
};
|
|
@@ -333,216 +571,323 @@ export class SdkMock {
|
|
|
333
571
|
/**
|
|
334
572
|
* Mocks the `file.list()` method.
|
|
335
573
|
*/
|
|
336
|
-
list: (
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
574
|
+
list: async (init) => {
|
|
575
|
+
const { mock } = this;
|
|
576
|
+
// const respond = init?.response ?? {
|
|
577
|
+
// status: 200,
|
|
578
|
+
// headers: { 'content-type': 'application/json' },
|
|
579
|
+
// body: JSON.stringify({
|
|
580
|
+
// items: this.gen.file.files(init?.size ?? 5),
|
|
581
|
+
// cursor: this.createCursorOption(init),
|
|
582
|
+
// } as ContextListResult<IFile>),
|
|
583
|
+
// }
|
|
584
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
585
|
+
const obj = {
|
|
586
|
+
items: this.gen.file.files(init?.size ?? 5),
|
|
587
|
+
cursor: this.createCursorOption(init),
|
|
340
588
|
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
589
|
+
return JSON.stringify(obj);
|
|
590
|
+
}, init);
|
|
591
|
+
await mock.add({
|
|
592
|
+
match: {
|
|
593
|
+
uri: RouteBuilder.files(':oid'),
|
|
594
|
+
methods: ['GET'],
|
|
595
|
+
},
|
|
596
|
+
respond,
|
|
345
597
|
});
|
|
346
598
|
},
|
|
347
599
|
/**
|
|
348
600
|
* Mocks the `file.createMeta()` method.
|
|
349
601
|
*/
|
|
350
|
-
createMeta: (
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
602
|
+
createMeta: async (init) => {
|
|
603
|
+
const { mock } = this;
|
|
604
|
+
// const respond = init?.response ?? {
|
|
605
|
+
// status: 201,
|
|
606
|
+
// headers: { 'content-type': 'application/json' },
|
|
607
|
+
// body: JSON.stringify(this.gen.file.file()),
|
|
608
|
+
// }
|
|
609
|
+
const respond = this.createDefaultResponse(201, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.file.file()), init);
|
|
610
|
+
await mock.add({
|
|
611
|
+
match: {
|
|
612
|
+
uri: RouteBuilder.files(':oid'),
|
|
613
|
+
methods: ['POST'],
|
|
614
|
+
},
|
|
615
|
+
respond,
|
|
358
616
|
});
|
|
359
617
|
},
|
|
360
618
|
/**
|
|
361
619
|
* Mocks the `file.createMedia()` method.
|
|
362
620
|
*/
|
|
363
|
-
createMedia: (
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
621
|
+
createMedia: async (init) => {
|
|
622
|
+
const { mock } = this;
|
|
623
|
+
// const respond = init?.response ?? {
|
|
624
|
+
// status: 200,
|
|
625
|
+
// }
|
|
626
|
+
const respond = this.createDefaultResponse(200, undefined, undefined, init);
|
|
627
|
+
await mock.add({
|
|
628
|
+
match: {
|
|
629
|
+
uri: RouteBuilder.fileMedia(':oid', ':id'),
|
|
630
|
+
methods: ['PUT'],
|
|
631
|
+
},
|
|
632
|
+
respond,
|
|
370
633
|
});
|
|
371
634
|
},
|
|
372
635
|
/**
|
|
373
636
|
* Mocks the `file.create()` method.
|
|
374
637
|
*/
|
|
375
|
-
create: (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const defaultData = this.generateFile();
|
|
382
|
-
return (options?.data ?? defaultData);
|
|
383
|
-
});
|
|
638
|
+
create: async (init) => {
|
|
639
|
+
await this.file.createMeta(init);
|
|
640
|
+
// When SDK's file.create() is called, it responds with
|
|
641
|
+
// what the result of file.createMeta() would be.
|
|
642
|
+
// Because of that, we don't need to configure the media request.
|
|
643
|
+
await this.file.createMedia();
|
|
384
644
|
},
|
|
385
645
|
/**
|
|
386
646
|
* Mocks the `file.createFolder()` method.
|
|
387
647
|
*/
|
|
388
|
-
createFolder: (
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
648
|
+
createFolder: async (init) => {
|
|
649
|
+
const { mock } = this;
|
|
650
|
+
// const respond = init?.response ?? {
|
|
651
|
+
// status: 201,
|
|
652
|
+
// headers: { 'content-type': 'application/json' },
|
|
653
|
+
// body: JSON.stringify(this.gen.file.folder()),
|
|
654
|
+
// }
|
|
655
|
+
const respond = this.createDefaultResponse(201, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.file.folder()), init);
|
|
656
|
+
await mock.add({
|
|
657
|
+
match: {
|
|
658
|
+
uri: RouteBuilder.files(':oid'),
|
|
659
|
+
methods: ['POST'],
|
|
660
|
+
},
|
|
661
|
+
respond,
|
|
396
662
|
});
|
|
397
663
|
},
|
|
398
664
|
/**
|
|
399
665
|
* Mocks the `file.read()` method.
|
|
400
666
|
*/
|
|
401
|
-
read: (
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
667
|
+
read: async (init) => {
|
|
668
|
+
const { mock } = this;
|
|
669
|
+
// const respond = init?.response ?? {
|
|
670
|
+
// status: 200,
|
|
671
|
+
// headers: { 'content-type': 'application/json' },
|
|
672
|
+
// body: JSON.stringify(this.gen.file.file()),
|
|
673
|
+
// }
|
|
674
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.file.file()), init);
|
|
675
|
+
await mock.add({
|
|
676
|
+
match: {
|
|
677
|
+
uri: RouteBuilder.file(':oid', ':id'),
|
|
678
|
+
methods: ['GET'],
|
|
679
|
+
},
|
|
680
|
+
respond,
|
|
408
681
|
});
|
|
409
682
|
},
|
|
410
683
|
/**
|
|
411
684
|
* Mocks the `file.readMedia()` method.
|
|
412
685
|
*/
|
|
413
|
-
readMedia: (
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
686
|
+
readMedia: async (init) => {
|
|
687
|
+
const { mock } = this;
|
|
688
|
+
// const respond = init?.response ?? {
|
|
689
|
+
// status: 200,
|
|
690
|
+
// headers: {
|
|
691
|
+
// 'content-type': 'application/json',
|
|
692
|
+
// 'x-version': `${this.gen.faker.number.int({ min: 1, max: 100 })}`,
|
|
693
|
+
// },
|
|
694
|
+
// body: JSON.stringify({ data: this.gen.faker.lorem.sentences() }),
|
|
695
|
+
// }
|
|
696
|
+
const respond = this.createDefaultResponse(200, {
|
|
697
|
+
'content-type': 'application/json',
|
|
698
|
+
'x-version': `${this.gen.faker.number.int({ min: 1, max: 100 })}`,
|
|
699
|
+
}, () => JSON.stringify({ data: this.gen.faker.lorem.sentences() }), init);
|
|
700
|
+
await mock.add({
|
|
701
|
+
match: {
|
|
702
|
+
uri: RouteBuilder.fileMedia(':oid', ':id'),
|
|
703
|
+
methods: ['GET'],
|
|
704
|
+
},
|
|
705
|
+
respond,
|
|
420
706
|
});
|
|
421
707
|
},
|
|
422
708
|
/**
|
|
423
709
|
* Mocks the `file.readBulk()` method.
|
|
424
710
|
*/
|
|
425
|
-
readBulk: (
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
711
|
+
readBulk: async (init) => {
|
|
712
|
+
const { mock } = this;
|
|
713
|
+
// const respond = init?.response ?? {
|
|
714
|
+
// status: 200,
|
|
715
|
+
// headers: { 'content-type': 'application/json' },
|
|
716
|
+
// body: JSON.stringify({
|
|
717
|
+
// items: this.gen.file.files(init?.size ?? 5),
|
|
718
|
+
// } as IBulkOperationResult<IFile>),
|
|
719
|
+
// }
|
|
720
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
721
|
+
const obj = {
|
|
722
|
+
items: this.gen.file.files(init?.size ?? 5),
|
|
429
723
|
};
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
724
|
+
return JSON.stringify(obj);
|
|
725
|
+
}, init);
|
|
726
|
+
await mock.add({
|
|
727
|
+
match: {
|
|
728
|
+
uri: RouteBuilder.filesBatch(':oid'),
|
|
729
|
+
methods: ['POST'],
|
|
730
|
+
},
|
|
731
|
+
respond,
|
|
434
732
|
});
|
|
435
733
|
},
|
|
436
734
|
/**
|
|
437
735
|
* Mocks the `file.patch()` method.
|
|
438
736
|
*/
|
|
439
|
-
patch: (
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
737
|
+
patch: async (init) => {
|
|
738
|
+
const { mock } = this;
|
|
739
|
+
// const respond = init?.response ?? {
|
|
740
|
+
// status: 200,
|
|
741
|
+
// headers: { 'content-type': 'application/json' },
|
|
742
|
+
// body: JSON.stringify(this.gen.file.file()),
|
|
743
|
+
// }
|
|
744
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.file.file()), init);
|
|
745
|
+
await mock.add({
|
|
746
|
+
match: {
|
|
747
|
+
uri: RouteBuilder.file(':oid', ':id'),
|
|
748
|
+
methods: ['PATCH'],
|
|
749
|
+
},
|
|
750
|
+
respond,
|
|
446
751
|
});
|
|
447
752
|
},
|
|
448
753
|
/**
|
|
449
754
|
* Mocks the `file.patchMedia()` method.
|
|
450
755
|
*/
|
|
451
|
-
patchMedia: (
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
756
|
+
patchMedia: async (init) => {
|
|
757
|
+
const { mock } = this;
|
|
758
|
+
// const respond = init?.response ?? {
|
|
759
|
+
// status: 200,
|
|
760
|
+
// headers: { 'content-type': 'application/json' },
|
|
761
|
+
// body: JSON.stringify(this.gen.patch.mediaPatchRevision()),
|
|
762
|
+
// }
|
|
763
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.patch.mediaPatchRevision()), init);
|
|
764
|
+
await mock.add({
|
|
765
|
+
match: {
|
|
766
|
+
uri: RouteBuilder.fileMedia(':oid', ':id'),
|
|
767
|
+
methods: ['PATCH'],
|
|
768
|
+
},
|
|
769
|
+
respond,
|
|
458
770
|
});
|
|
459
771
|
},
|
|
460
772
|
/**
|
|
461
773
|
* Mocks the `file.delete()` method.
|
|
462
774
|
*/
|
|
463
|
-
delete: (
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
775
|
+
delete: async (init) => {
|
|
776
|
+
const { mock } = this;
|
|
777
|
+
// const respond = init?.response ?? {
|
|
778
|
+
// status: 204,
|
|
779
|
+
// }
|
|
780
|
+
const respond = this.createDefaultResponse(204, undefined, undefined, init);
|
|
781
|
+
await mock.add({
|
|
782
|
+
match: {
|
|
783
|
+
uri: RouteBuilder.file(':oid', ':id'),
|
|
784
|
+
methods: ['DELETE'],
|
|
785
|
+
},
|
|
786
|
+
respond,
|
|
470
787
|
});
|
|
471
788
|
},
|
|
472
789
|
/**
|
|
473
790
|
* Mocks the `file.deleteBulk()` method.
|
|
474
791
|
*/
|
|
475
|
-
deleteBulk: (
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
792
|
+
deleteBulk: async (init) => {
|
|
793
|
+
const { mock } = this;
|
|
794
|
+
// const respond = init?.response ?? {
|
|
795
|
+
// status: 204,
|
|
796
|
+
// }
|
|
797
|
+
const respond = this.createDefaultResponse(204, undefined, undefined, init);
|
|
798
|
+
await mock.add({
|
|
799
|
+
match: {
|
|
800
|
+
uri: RouteBuilder.files(':oid'),
|
|
801
|
+
methods: ['DELETE'],
|
|
802
|
+
},
|
|
803
|
+
respond,
|
|
482
804
|
});
|
|
483
805
|
},
|
|
484
806
|
/**
|
|
485
807
|
* Mocks the `file.patchUsers()` method.
|
|
486
808
|
*/
|
|
487
|
-
patchUsers: (
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
809
|
+
patchUsers: async (init) => {
|
|
810
|
+
const { mock } = this;
|
|
811
|
+
// const respond = init?.response ?? {
|
|
812
|
+
// status: 200,
|
|
813
|
+
// headers: { 'content-type': 'application/json' },
|
|
814
|
+
// body: JSON.stringify(this.gen.file.file()),
|
|
815
|
+
// }
|
|
816
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => JSON.stringify(this.gen.file.file()), init);
|
|
817
|
+
await mock.add({
|
|
818
|
+
match: {
|
|
819
|
+
uri: RouteBuilder.filesAccess(':oid', ':id'),
|
|
820
|
+
methods: ['PATCH'],
|
|
821
|
+
},
|
|
822
|
+
respond,
|
|
494
823
|
});
|
|
495
824
|
},
|
|
496
825
|
/**
|
|
497
826
|
* Mocks the `file.addUser()` method.
|
|
498
827
|
*/
|
|
499
|
-
addUser: (
|
|
500
|
-
|
|
501
|
-
const defaultData = this.generateFile();
|
|
502
|
-
if (options?.status !== undefined && options.status !== 200) {
|
|
503
|
-
throw new Exception('Mocked error', { status: options.status });
|
|
504
|
-
}
|
|
505
|
-
return (options?.data ?? defaultData);
|
|
506
|
-
});
|
|
828
|
+
addUser: async (init) => {
|
|
829
|
+
await this.file.patchUsers(init);
|
|
507
830
|
},
|
|
508
831
|
/**
|
|
509
832
|
* Mocks the `file.removeUser()` method.
|
|
510
833
|
*/
|
|
511
|
-
removeUser: (
|
|
512
|
-
|
|
513
|
-
const defaultData = this.generateFile();
|
|
514
|
-
if (options?.status !== undefined && options.status !== 200) {
|
|
515
|
-
throw new Exception('Mocked error', { status: options.status });
|
|
516
|
-
}
|
|
517
|
-
return (options?.data ?? defaultData);
|
|
518
|
-
});
|
|
834
|
+
removeUser: async (init) => {
|
|
835
|
+
await this.file.patchUsers(init);
|
|
519
836
|
},
|
|
520
837
|
/**
|
|
521
838
|
* Mocks the `file.listUsers()` method.
|
|
522
839
|
*/
|
|
523
|
-
listUsers: (
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
840
|
+
listUsers: async (init) => {
|
|
841
|
+
const { mock } = this;
|
|
842
|
+
// const respond = init?.response ?? {
|
|
843
|
+
// status: 200,
|
|
844
|
+
// headers: { 'content-type': 'application/json' },
|
|
845
|
+
// body: JSON.stringify({
|
|
846
|
+
// items: this.gen.user.users(init?.size ?? 5),
|
|
847
|
+
// cursor: this.createCursorOption(init),
|
|
848
|
+
// } as ContextListResult<IUser>),
|
|
849
|
+
// }
|
|
850
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
851
|
+
const obj = {
|
|
852
|
+
items: this.gen.user.users(init?.size ?? 5),
|
|
853
|
+
cursor: this.createCursorOption(init),
|
|
527
854
|
};
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
855
|
+
return JSON.stringify(obj);
|
|
856
|
+
}, init);
|
|
857
|
+
await mock.add({
|
|
858
|
+
match: {
|
|
859
|
+
uri: RouteBuilder.fileUsers(':oid', ':id'),
|
|
860
|
+
methods: ['GET'],
|
|
861
|
+
},
|
|
862
|
+
respond,
|
|
532
863
|
});
|
|
533
864
|
},
|
|
534
865
|
/**
|
|
535
866
|
* Mocks the `file.breadcrumbs()` method.
|
|
536
867
|
*/
|
|
537
|
-
breadcrumbs: (
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
868
|
+
breadcrumbs: async (init) => {
|
|
869
|
+
const { mock } = this;
|
|
870
|
+
// const respond = init?.response ?? {
|
|
871
|
+
// status: 200,
|
|
872
|
+
// headers: { 'content-type': 'application/json' },
|
|
873
|
+
// body: JSON.stringify({
|
|
874
|
+
// items: this.gen.file.fileBreadcrumbs(init?.size ?? 5),
|
|
875
|
+
// cursor: this.createCursorOption(init),
|
|
876
|
+
// } as ContextListResult<FileBreadcrumb>),
|
|
877
|
+
// }
|
|
878
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
879
|
+
const obj = {
|
|
880
|
+
items: this.gen.file.fileBreadcrumbs(init?.size ?? 5),
|
|
881
|
+
cursor: this.createCursorOption(init),
|
|
541
882
|
};
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
883
|
+
return JSON.stringify(obj);
|
|
884
|
+
}, init);
|
|
885
|
+
await mock.add({
|
|
886
|
+
match: {
|
|
887
|
+
uri: RouteBuilder.fileBreadcrumbs(':oid', ':id'),
|
|
888
|
+
methods: ['GET'],
|
|
889
|
+
},
|
|
890
|
+
respond,
|
|
546
891
|
});
|
|
547
892
|
},
|
|
548
893
|
};
|
|
@@ -550,15 +895,29 @@ export class SdkMock {
|
|
|
550
895
|
* Shared API mocks.
|
|
551
896
|
*/
|
|
552
897
|
shared = {
|
|
553
|
-
list: (
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
898
|
+
list: async (init) => {
|
|
899
|
+
const { mock } = this;
|
|
900
|
+
// const respond = init?.response ?? {
|
|
901
|
+
// status: 200,
|
|
902
|
+
// headers: { 'content-type': 'application/json' },
|
|
903
|
+
// body: JSON.stringify({
|
|
904
|
+
// items: this.gen.file.files(init?.size ?? 5),
|
|
905
|
+
// cursor: this.createCursorOption(init),
|
|
906
|
+
// } as ContextListResult<IFile>),
|
|
907
|
+
// }
|
|
908
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
909
|
+
const obj = {
|
|
910
|
+
items: this.gen.file.files(init?.size ?? 5),
|
|
911
|
+
cursor: this.createCursorOption(init),
|
|
557
912
|
};
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
913
|
+
return JSON.stringify(obj);
|
|
914
|
+
}, init);
|
|
915
|
+
await mock.add({
|
|
916
|
+
match: {
|
|
917
|
+
uri: RouteBuilder.shared(':oid'),
|
|
918
|
+
methods: ['GET'],
|
|
919
|
+
},
|
|
920
|
+
respond,
|
|
562
921
|
});
|
|
563
922
|
},
|
|
564
923
|
};
|
|
@@ -566,254 +925,73 @@ export class SdkMock {
|
|
|
566
925
|
* Trash API mocks.
|
|
567
926
|
*/
|
|
568
927
|
trash = {
|
|
569
|
-
list: (
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
928
|
+
list: async (init) => {
|
|
929
|
+
const { mock } = this;
|
|
930
|
+
// const respond = init?.response ?? {
|
|
931
|
+
// status: 200,
|
|
932
|
+
// headers: { 'content-type': 'application/json' },
|
|
933
|
+
// body: JSON.stringify({
|
|
934
|
+
// items: this.gen.trash.trashEntries(init?.size ?? 5),
|
|
935
|
+
// cursor: this.createCursorOption(init),
|
|
936
|
+
// } as ContextListResult<TrashEntry>),
|
|
937
|
+
// }
|
|
938
|
+
const respond = this.createDefaultResponse(200, { 'content-type': 'application/json' }, () => {
|
|
939
|
+
const obj = {
|
|
940
|
+
items: this.gen.trash.trashEntries(init?.size ?? 5),
|
|
941
|
+
cursor: this.createCursorOption(init),
|
|
573
942
|
};
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
});
|
|
597
|
-
},
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
943
|
+
return JSON.stringify(obj);
|
|
944
|
+
}, init);
|
|
945
|
+
await mock.add({
|
|
946
|
+
match: {
|
|
947
|
+
uri: RouteBuilder.trash(':oid'),
|
|
948
|
+
methods: ['GET'],
|
|
949
|
+
},
|
|
950
|
+
respond,
|
|
951
|
+
});
|
|
952
|
+
},
|
|
953
|
+
delete: async (init) => {
|
|
954
|
+
const { mock } = this;
|
|
955
|
+
// const respond = init?.response ?? {
|
|
956
|
+
// status: 204,
|
|
957
|
+
// }
|
|
958
|
+
const respond = this.createDefaultResponse(204, undefined, undefined, init);
|
|
959
|
+
await mock.add({
|
|
960
|
+
match: {
|
|
961
|
+
uri: RouteBuilder.trashBatchDelete(':oid'),
|
|
962
|
+
methods: ['DELETE'],
|
|
963
|
+
},
|
|
964
|
+
respond,
|
|
965
|
+
});
|
|
966
|
+
},
|
|
967
|
+
restore: async (init) => {
|
|
968
|
+
const { mock } = this;
|
|
969
|
+
// const respond = init?.response ?? {
|
|
970
|
+
// status: 204,
|
|
971
|
+
// }
|
|
972
|
+
const respond = this.createDefaultResponse(204, undefined, undefined, init);
|
|
973
|
+
await mock.add({
|
|
974
|
+
match: {
|
|
975
|
+
uri: RouteBuilder.trashBatchRestore(':oid'),
|
|
976
|
+
methods: ['POST'],
|
|
977
|
+
},
|
|
978
|
+
respond,
|
|
979
|
+
});
|
|
980
|
+
},
|
|
981
|
+
empty: async (init) => {
|
|
982
|
+
const { mock } = this;
|
|
983
|
+
// const respond = init?.response ?? {
|
|
984
|
+
// status: 204,
|
|
985
|
+
// }
|
|
986
|
+
const respond = this.createDefaultResponse(204, undefined, undefined, init);
|
|
987
|
+
await mock.add({
|
|
988
|
+
match: {
|
|
989
|
+
uri: RouteBuilder.trashEmpty(':oid'),
|
|
990
|
+
methods: ['DELETE'],
|
|
991
|
+
},
|
|
992
|
+
respond,
|
|
605
993
|
});
|
|
606
994
|
},
|
|
607
995
|
};
|
|
608
|
-
/**
|
|
609
|
-
* Restores all stubs created by this mocker.
|
|
610
|
-
*/
|
|
611
|
-
restore() {
|
|
612
|
-
this.stubs.forEach((stub) => stub.restore());
|
|
613
|
-
this.stubs = [];
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Creates a stub for a specific SDK method.
|
|
617
|
-
* @param api The API name (e.g., 'organizations', 'groups', 'user', 'auth').
|
|
618
|
-
* @param method The method name to stub.
|
|
619
|
-
* @param implementation The stub implementation that returns the mocked data.
|
|
620
|
-
* @returns A stub reference.
|
|
621
|
-
*/
|
|
622
|
-
createStub(api, method, implementation) {
|
|
623
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
624
|
-
let target = this.sdk;
|
|
625
|
-
const parts = api.split('.');
|
|
626
|
-
for (const part of parts) {
|
|
627
|
-
target = target[part];
|
|
628
|
-
if (!target) {
|
|
629
|
-
throw new Error(`API '${api}' not found in SDK`);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
const original = target[method];
|
|
633
|
-
if (typeof original !== 'function') {
|
|
634
|
-
throw new Error(`Method '${method}' not found in ${api} API`);
|
|
635
|
-
}
|
|
636
|
-
// Create stub using sinon
|
|
637
|
-
const stub = sinon.stub(target, method).callsFake(async () => implementation());
|
|
638
|
-
const stubRef = {
|
|
639
|
-
restore: () => {
|
|
640
|
-
if (stub) {
|
|
641
|
-
stub.restore();
|
|
642
|
-
}
|
|
643
|
-
const index = this.stubs.indexOf(stubRef);
|
|
644
|
-
if (index > -1) {
|
|
645
|
-
this.stubs.splice(index, 1);
|
|
646
|
-
}
|
|
647
|
-
},
|
|
648
|
-
};
|
|
649
|
-
this.stubs.push(stubRef);
|
|
650
|
-
return stubRef;
|
|
651
|
-
}
|
|
652
|
-
/**
|
|
653
|
-
* Generates a random organization object.
|
|
654
|
-
*/
|
|
655
|
-
generateOrganization() {
|
|
656
|
-
return {
|
|
657
|
-
kind: OrganizationKind,
|
|
658
|
-
key: nanoid(),
|
|
659
|
-
name: `Organization ${this.randomString()}`,
|
|
660
|
-
createdBy: nanoid(),
|
|
661
|
-
createdDate: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 30,
|
|
662
|
-
grantType: this.randomChoice(['owner', 'manager', 'editor', 'viewer']),
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Generates a random group object.
|
|
667
|
-
*/
|
|
668
|
-
generateGroup() {
|
|
669
|
-
return {
|
|
670
|
-
kind: GroupKind,
|
|
671
|
-
key: nanoid(),
|
|
672
|
-
name: `Group ${this.randomString()}`,
|
|
673
|
-
description: `Description for ${this.randomString()}`,
|
|
674
|
-
owner: nanoid(),
|
|
675
|
-
oid: nanoid(),
|
|
676
|
-
users: [],
|
|
677
|
-
createdAt: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 30,
|
|
678
|
-
updatedAt: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 7,
|
|
679
|
-
icon: `https://example.com/icon-${nanoid()}.png`,
|
|
680
|
-
color: this.randomColor(),
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* Generates a random user object.
|
|
685
|
-
*/
|
|
686
|
-
generateUser() {
|
|
687
|
-
const firstName = this.randomString();
|
|
688
|
-
const lastName = this.randomString();
|
|
689
|
-
return {
|
|
690
|
-
kind: UserKind,
|
|
691
|
-
key: nanoid(),
|
|
692
|
-
name: `${firstName} ${lastName}`,
|
|
693
|
-
email: [
|
|
694
|
-
{
|
|
695
|
-
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`,
|
|
696
|
-
verified: true,
|
|
697
|
-
},
|
|
698
|
-
],
|
|
699
|
-
status: 'active',
|
|
700
|
-
created: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 365,
|
|
701
|
-
updated: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 7,
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Generates a random file meta object.
|
|
706
|
-
*/
|
|
707
|
-
generateFile() {
|
|
708
|
-
const kind = this.randomChoice([ProjectKind, DomainFileKind, CertificateFileKind, FolderKind]);
|
|
709
|
-
const name = `File ${this.randomString()}`;
|
|
710
|
-
return File.createSchema({ kind, info: { name } });
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Generates a random folder meta object.
|
|
714
|
-
*/
|
|
715
|
-
generateFolder() {
|
|
716
|
-
const file = File.createSchema({ kind: FolderKind, info: { name: `Folder ${this.randomString()}` } });
|
|
717
|
-
return file;
|
|
718
|
-
}
|
|
719
|
-
/**
|
|
720
|
-
* Generates a random media patch revision object.
|
|
721
|
-
*/
|
|
722
|
-
generateMediaPatchRevision() {
|
|
723
|
-
const version = Math.floor(Math.random() * 10) + 1;
|
|
724
|
-
return {
|
|
725
|
-
id: nanoid(),
|
|
726
|
-
timestamp: Date.now(),
|
|
727
|
-
patch: [],
|
|
728
|
-
version,
|
|
729
|
-
revert: [],
|
|
730
|
-
newVersion: version + 1,
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
/**
|
|
734
|
-
* Generates a random breadcrumbs list.
|
|
735
|
-
*/
|
|
736
|
-
generateBreadcrumbs() {
|
|
737
|
-
const depth = 2 + Math.floor(Math.random() * 2); // 2-3
|
|
738
|
-
const items = [];
|
|
739
|
-
for (let i = 0; i < depth; i += 1) {
|
|
740
|
-
items.push({ key: nanoid(), kind: i === depth - 1 ? ProjectKind : FolderKind, name: this.randomString() });
|
|
741
|
-
}
|
|
742
|
-
return items;
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Generates a random invitation object.
|
|
746
|
-
*/
|
|
747
|
-
generateInvitation() {
|
|
748
|
-
const firstName = this.randomString();
|
|
749
|
-
const lastName = this.randomString();
|
|
750
|
-
const now = Date.now();
|
|
751
|
-
return {
|
|
752
|
-
kind: InvitationKind,
|
|
753
|
-
key: nanoid(),
|
|
754
|
-
uid: nanoid(),
|
|
755
|
-
oid: nanoid(),
|
|
756
|
-
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`,
|
|
757
|
-
name: `${firstName} ${lastName}`,
|
|
758
|
-
token: nanoid(),
|
|
759
|
-
expiresAt: now + 7 * 24 * 60 * 60 * 1000,
|
|
760
|
-
status: 'pending',
|
|
761
|
-
grantType: this.randomChoice(['owner', 'manager', 'editor', 'viewer']),
|
|
762
|
-
createdAt: now - Math.random() * 1000 * 60 * 60 * 24,
|
|
763
|
-
updatedAt: now - Math.random() * 1000 * 60 * 60,
|
|
764
|
-
resent: 0,
|
|
765
|
-
lastSentAt: now - Math.random() * 1000 * 60 * 60,
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Generates a random trash entry.
|
|
770
|
-
*/
|
|
771
|
-
generateTrashEntry() {
|
|
772
|
-
return {
|
|
773
|
-
key: nanoid(),
|
|
774
|
-
refKey: nanoid(),
|
|
775
|
-
kind: this.randomChoice([ProjectKind, DomainFileKind, CertificateFileKind, FolderKind]),
|
|
776
|
-
name: `Deleted ${this.randomString()}`,
|
|
777
|
-
info: { byMe: false, time: Date.now() - Math.floor(Math.random() * 1000000), user: nanoid(), name: 'User' },
|
|
778
|
-
capabilities: { canDelete: true, canRestore: true },
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
/**
|
|
782
|
-
* Generates a random string.
|
|
783
|
-
*/
|
|
784
|
-
randomString() {
|
|
785
|
-
const words = [
|
|
786
|
-
'Alpha',
|
|
787
|
-
'Beta',
|
|
788
|
-
'Gamma',
|
|
789
|
-
'Delta',
|
|
790
|
-
'Epsilon',
|
|
791
|
-
'Zeta',
|
|
792
|
-
'Theta',
|
|
793
|
-
'Lambda',
|
|
794
|
-
'Sigma',
|
|
795
|
-
'Omega',
|
|
796
|
-
'Phoenix',
|
|
797
|
-
'Dragon',
|
|
798
|
-
'Tiger',
|
|
799
|
-
'Eagle',
|
|
800
|
-
'Falcon',
|
|
801
|
-
];
|
|
802
|
-
return words[Math.floor(Math.random() * words.length)];
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* Returns a random choice from an array.
|
|
806
|
-
*/
|
|
807
|
-
randomChoice(choices) {
|
|
808
|
-
return choices[Math.floor(Math.random() * choices.length)];
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* Generates a random hex color.
|
|
812
|
-
*/
|
|
813
|
-
randomColor() {
|
|
814
|
-
return `#${Math.floor(Math.random() * 16777215)
|
|
815
|
-
.toString(16)
|
|
816
|
-
.padStart(6, '0')}`;
|
|
817
|
-
}
|
|
818
996
|
}
|
|
819
997
|
//# sourceMappingURL=SdkMock.js.map
|