@sprucelabs/spruce-file-utils 15.1.16 → 15.1.18
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/esm/files.types.d.ts +1 -0
- package/build/esm/files.types.js +1 -1
- package/build/esm/uploading/MockChunkingUploader.d.ts +6 -2
- package/build/esm/uploading/MockChunkingUploader.js +21 -8
- package/build/files.types.d.ts +1 -0
- package/build/files.types.js +1 -0
- package/build/uploading/MockChunkingUploader.d.ts +6 -2
- package/build/uploading/MockChunkingUploader.js +20 -7
- package/package.json +1 -1
package/build/esm/files.types.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
import './.spruce/schemas/schemas.types';
|
@@ -5,13 +5,17 @@ export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingU
|
|
5
5
|
static instance?: MockChunkingUploader;
|
6
6
|
private lastUploadOptions?;
|
7
7
|
private lastUploadResponse?;
|
8
|
-
private
|
8
|
+
private fakedResponse?;
|
9
|
+
private fakedResponses;
|
10
|
+
private currentResponse;
|
9
11
|
constructor();
|
10
12
|
static assertWasCreated(): void;
|
11
13
|
assertFileEqualsLastReturnedFromUpload(file: UploadedFile): void;
|
12
14
|
assertUploadOptionsEqual(options: UploadOptions): void;
|
13
|
-
|
15
|
+
setUploadResponses(responses: UploadedFile[]): void;
|
16
|
+
setUploadResponse(options: UploadedFile): void;
|
14
17
|
upload(options: UploadOptions): Promise<{
|
15
18
|
file: UploadedFile;
|
16
19
|
}>;
|
20
|
+
private getCurrentResponse;
|
17
21
|
}
|
@@ -14,6 +14,8 @@ import { chunkingUploaderEventContract, } from './ChunkingUploader.js';
|
|
14
14
|
export default class MockChunkingUploader extends AbstractEventEmitter {
|
15
15
|
constructor() {
|
16
16
|
super(chunkingUploaderEventContract);
|
17
|
+
this.fakedResponses = [];
|
18
|
+
this.currentResponse = -1;
|
17
19
|
MockChunkingUploader.instance = this;
|
18
20
|
}
|
19
21
|
static assertWasCreated() {
|
@@ -27,22 +29,33 @@ export default class MockChunkingUploader extends AbstractEventEmitter {
|
|
27
29
|
assertOptions(options, ['fileName', 'base64']);
|
28
30
|
assert.isEqualDeep(options, this.lastUploadOptions, 'Upload options do not match the last upload options.');
|
29
31
|
}
|
30
|
-
|
32
|
+
setUploadResponses(responses) {
|
33
|
+
assertOptions({ responses }, ['responses']);
|
34
|
+
this.fakedResponses = responses;
|
35
|
+
}
|
36
|
+
setUploadResponse(options) {
|
31
37
|
assertOptions(options, ['id', 'type', 'uri']);
|
32
|
-
this.
|
38
|
+
this.fakedResponse = options;
|
33
39
|
}
|
34
40
|
upload(options) {
|
35
41
|
return __awaiter(this, void 0, void 0, function* () {
|
36
|
-
var _a;
|
37
42
|
this.lastUploadOptions = options;
|
38
|
-
this.
|
39
|
-
|
40
|
-
type: 'image/png',
|
41
|
-
uri: generateId(),
|
42
|
-
};
|
43
|
+
this.currentResponse++;
|
44
|
+
this.lastUploadResponse = this.getCurrentResponse();
|
43
45
|
return {
|
44
46
|
file: this.lastUploadResponse,
|
45
47
|
};
|
46
48
|
});
|
47
49
|
}
|
50
|
+
getCurrentResponse() {
|
51
|
+
var _a;
|
52
|
+
if (this.fakedResponses.length > 0) {
|
53
|
+
return this.fakedResponses[this.currentResponse];
|
54
|
+
}
|
55
|
+
return ((_a = this.fakedResponse) !== null && _a !== void 0 ? _a : {
|
56
|
+
id: generateId(),
|
57
|
+
type: 'image/png',
|
58
|
+
uri: generateId(),
|
59
|
+
});
|
60
|
+
}
|
48
61
|
}
|
package/build/files.types.d.ts
CHANGED
package/build/files.types.js
CHANGED
@@ -5,13 +5,17 @@ export default class MockChunkingUploader extends AbstractEventEmitter<ChunkingU
|
|
5
5
|
static instance?: MockChunkingUploader;
|
6
6
|
private lastUploadOptions?;
|
7
7
|
private lastUploadResponse?;
|
8
|
-
private
|
8
|
+
private fakedResponse?;
|
9
|
+
private fakedResponses;
|
10
|
+
private currentResponse;
|
9
11
|
constructor();
|
10
12
|
static assertWasCreated(): void;
|
11
13
|
assertFileEqualsLastReturnedFromUpload(file: UploadedFile): void;
|
12
14
|
assertUploadOptionsEqual(options: UploadOptions): void;
|
13
|
-
|
15
|
+
setUploadResponses(responses: UploadedFile[]): void;
|
16
|
+
setUploadResponse(options: UploadedFile): void;
|
14
17
|
upload(options: UploadOptions): Promise<{
|
15
18
|
file: UploadedFile;
|
16
19
|
}>;
|
20
|
+
private getCurrentResponse;
|
17
21
|
}
|
@@ -7,6 +7,8 @@ const ChunkingUploader_1 = require("./ChunkingUploader");
|
|
7
7
|
class MockChunkingUploader extends mercury_event_emitter_1.AbstractEventEmitter {
|
8
8
|
constructor() {
|
9
9
|
super(ChunkingUploader_1.chunkingUploaderEventContract);
|
10
|
+
this.fakedResponses = [];
|
11
|
+
this.currentResponse = -1;
|
10
12
|
MockChunkingUploader.instance = this;
|
11
13
|
}
|
12
14
|
static assertWasCreated() {
|
@@ -20,20 +22,31 @@ class MockChunkingUploader extends mercury_event_emitter_1.AbstractEventEmitter
|
|
20
22
|
(0, schema_1.assertOptions)(options, ['fileName', 'base64']);
|
21
23
|
test_utils_1.assert.isEqualDeep(options, this.lastUploadOptions, 'Upload options do not match the last upload options.');
|
22
24
|
}
|
23
|
-
|
25
|
+
setUploadResponses(responses) {
|
26
|
+
(0, schema_1.assertOptions)({ responses }, ['responses']);
|
27
|
+
this.fakedResponses = responses;
|
28
|
+
}
|
29
|
+
setUploadResponse(options) {
|
24
30
|
(0, schema_1.assertOptions)(options, ['id', 'type', 'uri']);
|
25
|
-
this.
|
31
|
+
this.fakedResponse = options;
|
26
32
|
}
|
27
33
|
async upload(options) {
|
28
34
|
this.lastUploadOptions = options;
|
29
|
-
this.
|
30
|
-
|
31
|
-
type: 'image/png',
|
32
|
-
uri: (0, test_utils_1.generateId)(),
|
33
|
-
};
|
35
|
+
this.currentResponse++;
|
36
|
+
this.lastUploadResponse = this.getCurrentResponse();
|
34
37
|
return {
|
35
38
|
file: this.lastUploadResponse,
|
36
39
|
};
|
37
40
|
}
|
41
|
+
getCurrentResponse() {
|
42
|
+
if (this.fakedResponses.length > 0) {
|
43
|
+
return this.fakedResponses[this.currentResponse];
|
44
|
+
}
|
45
|
+
return (this.fakedResponse ?? {
|
46
|
+
id: (0, test_utils_1.generateId)(),
|
47
|
+
type: 'image/png',
|
48
|
+
uri: (0, test_utils_1.generateId)(),
|
49
|
+
});
|
50
|
+
}
|
38
51
|
}
|
39
52
|
exports.default = MockChunkingUploader;
|