@api-client/core 0.18.37 → 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 -175
- package/build/src/sdk/SdkMock.d.ts.map +1 -1
- package/build/src/sdk/SdkMock.js +774 -627
- 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 -689
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();
|
|
19
25
|
*
|
|
20
|
-
* //
|
|
21
|
-
*
|
|
26
|
+
* // Add intercept - returns random organizations
|
|
27
|
+
* await mocker.organizations.list();
|
|
28
|
+
*
|
|
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,35 +546,24 @@ 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
|
};
|
|
329
|
-
/**
|
|
330
|
-
* Auth API mocks.
|
|
331
|
-
*/
|
|
332
|
-
auth = {
|
|
333
|
-
/**
|
|
334
|
-
* Mocks the `auth.oauthRedirect()` method.
|
|
335
|
-
* This method returns `null` by default as it performs window navigation.
|
|
336
|
-
* @param options Optional response customization.
|
|
337
|
-
* @returns A stub reference that can be used to restore the original behavior.
|
|
338
|
-
*/
|
|
339
|
-
oauthRedirect: (options) => {
|
|
340
|
-
return this.createStub('auth', 'oauthRedirect', () => {
|
|
341
|
-
const defaultData = options?.data ?? null;
|
|
342
|
-
return defaultData;
|
|
343
|
-
}, true);
|
|
344
|
-
},
|
|
345
|
-
};
|
|
346
567
|
/**
|
|
347
568
|
* Files API mocks.
|
|
348
569
|
*/
|
|
@@ -350,216 +571,323 @@ export class SdkMock {
|
|
|
350
571
|
/**
|
|
351
572
|
* Mocks the `file.list()` method.
|
|
352
573
|
*/
|
|
353
|
-
list: (
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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),
|
|
357
588
|
};
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
589
|
+
return JSON.stringify(obj);
|
|
590
|
+
}, init);
|
|
591
|
+
await mock.add({
|
|
592
|
+
match: {
|
|
593
|
+
uri: RouteBuilder.files(':oid'),
|
|
594
|
+
methods: ['GET'],
|
|
595
|
+
},
|
|
596
|
+
respond,
|
|
362
597
|
});
|
|
363
598
|
},
|
|
364
599
|
/**
|
|
365
600
|
* Mocks the `file.createMeta()` method.
|
|
366
601
|
*/
|
|
367
|
-
createMeta: (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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,
|
|
375
616
|
});
|
|
376
617
|
},
|
|
377
618
|
/**
|
|
378
619
|
* Mocks the `file.createMedia()` method.
|
|
379
620
|
*/
|
|
380
|
-
createMedia: (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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,
|
|
387
633
|
});
|
|
388
634
|
},
|
|
389
635
|
/**
|
|
390
636
|
* Mocks the `file.create()` method.
|
|
391
637
|
*/
|
|
392
|
-
create: (
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const defaultData = this.generateFile();
|
|
399
|
-
return (options?.data ?? defaultData);
|
|
400
|
-
});
|
|
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();
|
|
401
644
|
},
|
|
402
645
|
/**
|
|
403
646
|
* Mocks the `file.createFolder()` method.
|
|
404
647
|
*/
|
|
405
|
-
createFolder: (
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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,
|
|
413
662
|
});
|
|
414
663
|
},
|
|
415
664
|
/**
|
|
416
665
|
* Mocks the `file.read()` method.
|
|
417
666
|
*/
|
|
418
|
-
read: (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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,
|
|
425
681
|
});
|
|
426
682
|
},
|
|
427
683
|
/**
|
|
428
684
|
* Mocks the `file.readMedia()` method.
|
|
429
685
|
*/
|
|
430
|
-
readMedia: (
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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,
|
|
437
706
|
});
|
|
438
707
|
},
|
|
439
708
|
/**
|
|
440
709
|
* Mocks the `file.readBulk()` method.
|
|
441
710
|
*/
|
|
442
|
-
readBulk: (
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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),
|
|
446
723
|
};
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
724
|
+
return JSON.stringify(obj);
|
|
725
|
+
}, init);
|
|
726
|
+
await mock.add({
|
|
727
|
+
match: {
|
|
728
|
+
uri: RouteBuilder.filesBatch(':oid'),
|
|
729
|
+
methods: ['POST'],
|
|
730
|
+
},
|
|
731
|
+
respond,
|
|
451
732
|
});
|
|
452
733
|
},
|
|
453
734
|
/**
|
|
454
735
|
* Mocks the `file.patch()` method.
|
|
455
736
|
*/
|
|
456
|
-
patch: (
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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,
|
|
463
751
|
});
|
|
464
752
|
},
|
|
465
753
|
/**
|
|
466
754
|
* Mocks the `file.patchMedia()` method.
|
|
467
755
|
*/
|
|
468
|
-
patchMedia: (
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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,
|
|
475
770
|
});
|
|
476
771
|
},
|
|
477
772
|
/**
|
|
478
773
|
* Mocks the `file.delete()` method.
|
|
479
774
|
*/
|
|
480
|
-
delete: (
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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,
|
|
487
787
|
});
|
|
488
788
|
},
|
|
489
789
|
/**
|
|
490
790
|
* Mocks the `file.deleteBulk()` method.
|
|
491
791
|
*/
|
|
492
|
-
deleteBulk: (
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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,
|
|
499
804
|
});
|
|
500
805
|
},
|
|
501
806
|
/**
|
|
502
807
|
* Mocks the `file.patchUsers()` method.
|
|
503
808
|
*/
|
|
504
|
-
patchUsers: (
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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,
|
|
511
823
|
});
|
|
512
824
|
},
|
|
513
825
|
/**
|
|
514
826
|
* Mocks the `file.addUser()` method.
|
|
515
827
|
*/
|
|
516
|
-
addUser: (
|
|
517
|
-
|
|
518
|
-
const defaultData = this.generateFile();
|
|
519
|
-
if (options?.status !== undefined && options.status !== 200) {
|
|
520
|
-
throw new Exception('Mocked error', { status: options.status });
|
|
521
|
-
}
|
|
522
|
-
return (options?.data ?? defaultData);
|
|
523
|
-
});
|
|
828
|
+
addUser: async (init) => {
|
|
829
|
+
await this.file.patchUsers(init);
|
|
524
830
|
},
|
|
525
831
|
/**
|
|
526
832
|
* Mocks the `file.removeUser()` method.
|
|
527
833
|
*/
|
|
528
|
-
removeUser: (
|
|
529
|
-
|
|
530
|
-
const defaultData = this.generateFile();
|
|
531
|
-
if (options?.status !== undefined && options.status !== 200) {
|
|
532
|
-
throw new Exception('Mocked error', { status: options.status });
|
|
533
|
-
}
|
|
534
|
-
return (options?.data ?? defaultData);
|
|
535
|
-
});
|
|
834
|
+
removeUser: async (init) => {
|
|
835
|
+
await this.file.patchUsers(init);
|
|
536
836
|
},
|
|
537
837
|
/**
|
|
538
838
|
* Mocks the `file.listUsers()` method.
|
|
539
839
|
*/
|
|
540
|
-
listUsers: (
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
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),
|
|
544
854
|
};
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
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,
|
|
549
863
|
});
|
|
550
864
|
},
|
|
551
865
|
/**
|
|
552
866
|
* Mocks the `file.breadcrumbs()` method.
|
|
553
867
|
*/
|
|
554
|
-
breadcrumbs: (
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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),
|
|
558
882
|
};
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
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,
|
|
563
891
|
});
|
|
564
892
|
},
|
|
565
893
|
};
|
|
@@ -567,15 +895,29 @@ export class SdkMock {
|
|
|
567
895
|
* Shared API mocks.
|
|
568
896
|
*/
|
|
569
897
|
shared = {
|
|
570
|
-
list: (
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
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),
|
|
574
912
|
};
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
913
|
+
return JSON.stringify(obj);
|
|
914
|
+
}, init);
|
|
915
|
+
await mock.add({
|
|
916
|
+
match: {
|
|
917
|
+
uri: RouteBuilder.shared(':oid'),
|
|
918
|
+
methods: ['GET'],
|
|
919
|
+
},
|
|
920
|
+
respond,
|
|
579
921
|
});
|
|
580
922
|
},
|
|
581
923
|
};
|
|
@@ -583,268 +925,73 @@ export class SdkMock {
|
|
|
583
925
|
* Trash API mocks.
|
|
584
926
|
*/
|
|
585
927
|
trash = {
|
|
586
|
-
list: (
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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),
|
|
590
942
|
};
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
});
|
|
614
|
-
},
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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,
|
|
622
993
|
});
|
|
623
994
|
},
|
|
624
995
|
};
|
|
625
|
-
/**
|
|
626
|
-
* Restores all stubs created by this mocker.
|
|
627
|
-
*/
|
|
628
|
-
restore() {
|
|
629
|
-
this.stubs.forEach((stub) => stub.restore());
|
|
630
|
-
this.stubs = [];
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Creates a stub for a specific SDK method.
|
|
634
|
-
* @param api The API name (e.g., 'organizations', 'groups', 'user', 'auth').
|
|
635
|
-
* @param method The method name to stub.
|
|
636
|
-
* @param implementation The stub implementation that returns the mocked data.
|
|
637
|
-
* @returns A stub reference.
|
|
638
|
-
*/
|
|
639
|
-
createStub(api, method, implementation, sync) {
|
|
640
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
641
|
-
let target = this.sdk;
|
|
642
|
-
const parts = api.split('.');
|
|
643
|
-
for (const part of parts) {
|
|
644
|
-
target = target[part];
|
|
645
|
-
if (!target) {
|
|
646
|
-
throw new Error(`API '${api}' not found in SDK`);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
const original = target[method];
|
|
650
|
-
if (typeof original !== 'function') {
|
|
651
|
-
throw new Error(`Method '${method}' not found in ${api} API`);
|
|
652
|
-
}
|
|
653
|
-
// Store original and create stub using sinon
|
|
654
|
-
const stub = sync
|
|
655
|
-
? sinon.stub(target, method).callsFake(() => implementation())
|
|
656
|
-
: sinon.stub(target, method).callsFake(async () => implementation());
|
|
657
|
-
const stubRef = {
|
|
658
|
-
restore: () => {
|
|
659
|
-
if (stub) {
|
|
660
|
-
stub.restore();
|
|
661
|
-
}
|
|
662
|
-
const index = this.stubs.indexOf(stubRef);
|
|
663
|
-
if (index > -1) {
|
|
664
|
-
this.stubs.splice(index, 1);
|
|
665
|
-
}
|
|
666
|
-
},
|
|
667
|
-
};
|
|
668
|
-
this.stubs.push(stubRef);
|
|
669
|
-
return stubRef;
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* Creates a response object from data and options.
|
|
673
|
-
* @param defaultData Default data to return if not overridden.
|
|
674
|
-
* @param options Response options.
|
|
675
|
-
* @returns The final data to return (for non-HTTP responses) or IStoreResponse (for HTTP responses).
|
|
676
|
-
*/
|
|
677
|
-
createResponse(defaultData, options) {
|
|
678
|
-
// For SDK-level stubs we return plain data. Status and headers are
|
|
679
|
-
// accepted but not propagated, since high-level SDK methods return data.
|
|
680
|
-
const data = options?.data !== undefined ? options.data : defaultData;
|
|
681
|
-
return data;
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* Generates a random organization object.
|
|
685
|
-
*/
|
|
686
|
-
generateOrganization() {
|
|
687
|
-
return {
|
|
688
|
-
kind: OrganizationKind,
|
|
689
|
-
key: nanoid(),
|
|
690
|
-
name: `Organization ${this.randomString()}`,
|
|
691
|
-
createdBy: nanoid(),
|
|
692
|
-
createdDate: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 30,
|
|
693
|
-
grantType: this.randomChoice(['owner', 'manager', 'editor', 'viewer']),
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
* Generates a random group object.
|
|
698
|
-
*/
|
|
699
|
-
generateGroup() {
|
|
700
|
-
return {
|
|
701
|
-
kind: GroupKind,
|
|
702
|
-
key: nanoid(),
|
|
703
|
-
name: `Group ${this.randomString()}`,
|
|
704
|
-
description: `Description for ${this.randomString()}`,
|
|
705
|
-
owner: nanoid(),
|
|
706
|
-
oid: nanoid(),
|
|
707
|
-
users: [],
|
|
708
|
-
createdAt: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 30,
|
|
709
|
-
updatedAt: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 7,
|
|
710
|
-
icon: `https://example.com/icon-${nanoid()}.png`,
|
|
711
|
-
color: this.randomColor(),
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
* Generates a random user object.
|
|
716
|
-
*/
|
|
717
|
-
generateUser() {
|
|
718
|
-
const firstName = this.randomString();
|
|
719
|
-
const lastName = this.randomString();
|
|
720
|
-
return {
|
|
721
|
-
kind: UserKind,
|
|
722
|
-
key: nanoid(),
|
|
723
|
-
name: `${firstName} ${lastName}`,
|
|
724
|
-
email: [
|
|
725
|
-
{
|
|
726
|
-
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`,
|
|
727
|
-
verified: true,
|
|
728
|
-
},
|
|
729
|
-
],
|
|
730
|
-
status: 'active',
|
|
731
|
-
created: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 365,
|
|
732
|
-
updated: Date.now() - Math.random() * 1000 * 60 * 60 * 24 * 7,
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* Generates a random file meta object.
|
|
737
|
-
*/
|
|
738
|
-
generateFile() {
|
|
739
|
-
const kind = this.randomChoice([ProjectKind, DomainFileKind, CertificateFileKind, FolderKind]);
|
|
740
|
-
const name = `File ${this.randomString()}`;
|
|
741
|
-
return File.createSchema({ kind, info: { name } });
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Generates a random folder meta object.
|
|
745
|
-
*/
|
|
746
|
-
generateFolder() {
|
|
747
|
-
const file = File.createSchema({ kind: FolderKind, info: { name: `Folder ${this.randomString()}` } });
|
|
748
|
-
return file;
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* Generates a random media patch revision object.
|
|
752
|
-
*/
|
|
753
|
-
generateMediaPatchRevision() {
|
|
754
|
-
const version = Math.floor(Math.random() * 10) + 1;
|
|
755
|
-
return {
|
|
756
|
-
id: nanoid(),
|
|
757
|
-
timestamp: Date.now(),
|
|
758
|
-
patch: [],
|
|
759
|
-
version,
|
|
760
|
-
revert: [],
|
|
761
|
-
newVersion: version + 1,
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* Generates a random breadcrumbs list.
|
|
766
|
-
*/
|
|
767
|
-
generateBreadcrumbs() {
|
|
768
|
-
const depth = 2 + Math.floor(Math.random() * 2); // 2-3
|
|
769
|
-
const items = [];
|
|
770
|
-
for (let i = 0; i < depth; i += 1) {
|
|
771
|
-
items.push({ key: nanoid(), kind: i === depth - 1 ? ProjectKind : FolderKind, name: this.randomString() });
|
|
772
|
-
}
|
|
773
|
-
return items;
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
* Generates a random invitation object.
|
|
777
|
-
*/
|
|
778
|
-
generateInvitation() {
|
|
779
|
-
const firstName = this.randomString();
|
|
780
|
-
const lastName = this.randomString();
|
|
781
|
-
const now = Date.now();
|
|
782
|
-
return {
|
|
783
|
-
kind: InvitationKind,
|
|
784
|
-
key: nanoid(),
|
|
785
|
-
uid: nanoid(),
|
|
786
|
-
oid: nanoid(),
|
|
787
|
-
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`,
|
|
788
|
-
name: `${firstName} ${lastName}`,
|
|
789
|
-
token: nanoid(),
|
|
790
|
-
expiresAt: now + 7 * 24 * 60 * 60 * 1000,
|
|
791
|
-
status: 'pending',
|
|
792
|
-
grantType: this.randomChoice(['owner', 'manager', 'editor', 'viewer']),
|
|
793
|
-
createdAt: now - Math.random() * 1000 * 60 * 60 * 24,
|
|
794
|
-
updatedAt: now - Math.random() * 1000 * 60 * 60,
|
|
795
|
-
resent: 0,
|
|
796
|
-
lastSentAt: now - Math.random() * 1000 * 60 * 60,
|
|
797
|
-
};
|
|
798
|
-
}
|
|
799
|
-
/**
|
|
800
|
-
* Generates a random trash entry.
|
|
801
|
-
*/
|
|
802
|
-
generateTrashEntry() {
|
|
803
|
-
return {
|
|
804
|
-
key: nanoid(),
|
|
805
|
-
refKey: nanoid(),
|
|
806
|
-
kind: this.randomChoice([ProjectKind, DomainFileKind, CertificateFileKind, FolderKind]),
|
|
807
|
-
name: `Deleted ${this.randomString()}`,
|
|
808
|
-
info: { byMe: false, time: Date.now() - Math.floor(Math.random() * 1000000), user: nanoid(), name: 'User' },
|
|
809
|
-
capabilities: { canDelete: true, canRestore: true },
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Generates a random string.
|
|
814
|
-
*/
|
|
815
|
-
randomString() {
|
|
816
|
-
const words = [
|
|
817
|
-
'Alpha',
|
|
818
|
-
'Beta',
|
|
819
|
-
'Gamma',
|
|
820
|
-
'Delta',
|
|
821
|
-
'Epsilon',
|
|
822
|
-
'Zeta',
|
|
823
|
-
'Theta',
|
|
824
|
-
'Lambda',
|
|
825
|
-
'Sigma',
|
|
826
|
-
'Omega',
|
|
827
|
-
'Phoenix',
|
|
828
|
-
'Dragon',
|
|
829
|
-
'Tiger',
|
|
830
|
-
'Eagle',
|
|
831
|
-
'Falcon',
|
|
832
|
-
];
|
|
833
|
-
return words[Math.floor(Math.random() * words.length)];
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* Returns a random choice from an array.
|
|
837
|
-
*/
|
|
838
|
-
randomChoice(choices) {
|
|
839
|
-
return choices[Math.floor(Math.random() * choices.length)];
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* Generates a random hex color.
|
|
843
|
-
*/
|
|
844
|
-
randomColor() {
|
|
845
|
-
return `#${Math.floor(Math.random() * 16777215)
|
|
846
|
-
.toString(16)
|
|
847
|
-
.padStart(6, '0')}`;
|
|
848
|
-
}
|
|
849
996
|
}
|
|
850
997
|
//# sourceMappingURL=SdkMock.js.map
|