@sprucelabs/spruce-image-utils 7.1.30 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,13 @@
1
1
  import { SpruceSchemas } from '@sprucelabs/spruce-test-fixtures';
2
2
  import { UploadedImage, ImageUploader, ImageUploadOptions } from '../../uploading/RemoteImageUploader';
3
3
  export default class FakeImageUploader implements ImageUploader {
4
- static lastUploadOptions: ImageUploadOptions;
4
+ private static _lastUploadOptions;
5
+ private static _isInitialized;
6
+ private static _shouldThrow;
7
+ static set lastUploadOptions(options: ImageUploadOptions);
8
+ static get lastUploadOptions(): ImageUploadOptions;
9
+ static beforeEach(): void;
10
+ static makeThrowWithInvalidImage(): void;
5
11
  private static fakeUploadedImage?;
6
12
  upload(options: ImageUploadOptions): Promise<SpruceSchemas.Images.v2022_05_31.UploadResponsePayload>;
7
13
  static setUploadResponse(image: UploadedImage): void;
@@ -1,10 +1,33 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.generateUploadedImageValues = void 0;
4
7
  const test_utils_1 = require("@sprucelabs/test-utils");
8
+ const SpruceError_1 = __importDefault(require("../../errors/SpruceError"));
5
9
  class FakeImageUploader {
10
+ static set lastUploadOptions(options) {
11
+ test_utils_1.assert.isTrue(this._isInitialized, `You gotta call FakeImageUploader.beforeEach() in your test!`);
12
+ this._lastUploadOptions = options;
13
+ }
14
+ static get lastUploadOptions() {
15
+ return this._lastUploadOptions;
16
+ }
17
+ static beforeEach() {
18
+ this._isInitialized = true;
19
+ this._shouldThrow = false;
20
+ }
21
+ static makeThrowWithInvalidImage() {
22
+ this._shouldThrow = true;
23
+ }
6
24
  async upload(options) {
7
25
  var _a;
26
+ if (FakeImageUploader._shouldThrow) {
27
+ throw new SpruceError_1.default({
28
+ code: 'INVALID_IMAGE',
29
+ });
30
+ }
8
31
  FakeImageUploader.lastUploadOptions = options;
9
32
  return (_a = FakeImageUploader.fakeUploadedImage) !== null && _a !== void 0 ? _a : generateUploadedImageValues();
10
33
  }
@@ -12,6 +35,8 @@ class FakeImageUploader {
12
35
  this.fakeUploadedImage = image;
13
36
  }
14
37
  }
38
+ FakeImageUploader._isInitialized = false;
39
+ FakeImageUploader._shouldThrow = false;
15
40
  exports.default = FakeImageUploader;
16
41
  function generateUploadedImageValues() {
17
42
  return {
@@ -1,7 +1,13 @@
1
1
  import { SpruceSchemas } from '@sprucelabs/spruce-test-fixtures';
2
2
  import { UploadedImage, ImageUploader, ImageUploadOptions } from '../../uploading/RemoteImageUploader';
3
3
  export default class FakeImageUploader implements ImageUploader {
4
- static lastUploadOptions: ImageUploadOptions;
4
+ private static _lastUploadOptions;
5
+ private static _isInitialized;
6
+ private static _shouldThrow;
7
+ static set lastUploadOptions(options: ImageUploadOptions);
8
+ static get lastUploadOptions(): ImageUploadOptions;
9
+ static beforeEach(): void;
10
+ static makeThrowWithInvalidImage(): void;
5
11
  private static fakeUploadedImage?;
6
12
  upload(options: ImageUploadOptions): Promise<SpruceSchemas.Images.v2022_05_31.UploadResponsePayload>;
7
13
  static setUploadResponse(image: UploadedImage): void;
@@ -7,11 +7,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { generateId } from '@sprucelabs/test-utils';
11
- export default class FakeImageUploader {
10
+ import { assert, generateId } from '@sprucelabs/test-utils';
11
+ import SpruceError from '../../errors/SpruceError.js';
12
+ class FakeImageUploader {
13
+ static set lastUploadOptions(options) {
14
+ assert.isTrue(this._isInitialized, `You gotta call FakeImageUploader.beforeEach() in your test!`);
15
+ this._lastUploadOptions = options;
16
+ }
17
+ static get lastUploadOptions() {
18
+ return this._lastUploadOptions;
19
+ }
20
+ static beforeEach() {
21
+ this._isInitialized = true;
22
+ this._shouldThrow = false;
23
+ }
24
+ static makeThrowWithInvalidImage() {
25
+ this._shouldThrow = true;
26
+ }
12
27
  upload(options) {
13
28
  var _a;
14
29
  return __awaiter(this, void 0, void 0, function* () {
30
+ if (FakeImageUploader._shouldThrow) {
31
+ throw new SpruceError({
32
+ code: 'INVALID_IMAGE',
33
+ });
34
+ }
15
35
  FakeImageUploader.lastUploadOptions = options;
16
36
  return (_a = FakeImageUploader.fakeUploadedImage) !== null && _a !== void 0 ? _a : generateUploadedImageValues();
17
37
  });
@@ -20,6 +40,9 @@ export default class FakeImageUploader {
20
40
  this.fakeUploadedImage = image;
21
41
  }
22
42
  }
43
+ FakeImageUploader._isInitialized = false;
44
+ FakeImageUploader._shouldThrow = false;
45
+ export default FakeImageUploader;
23
46
  export function generateUploadedImageValues() {
24
47
  return {
25
48
  id: generateId(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-image-utils",
3
3
  "description": "Support for working with images and Sprucebot. 📈",
4
- "version": "7.1.30",
4
+ "version": "7.2.0",
5
5
  "skill": {
6
6
  "namespace": "images"
7
7
  },