@jaypie/testkit 1.0.27 → 1.0.29

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/README.md CHANGED
@@ -25,6 +25,23 @@ The testkit provides a complete mock for Jaypie including:
25
25
  vi.mock("jaypie", async () => vi.importActual("@jaypie/testkit/mock"));
26
26
  ```
27
27
 
28
+ #### Error Spying
29
+
30
+ ```javascript
31
+ import { ConfigurationError } from "@jaypie/core";
32
+
33
+ vi.mock("jaypie", async () => vi.importActual("@jaypie/testkit/mock"));
34
+
35
+ test("ConfigurationError", () => {
36
+ try {
37
+ throw new ConfigurationError("Sorpresa!");
38
+ } catch (error) {
39
+ expect(error).toBeJaypieError();
40
+ expect(ConfigurationError).toHaveBeenCalled();
41
+ }
42
+ });
43
+ ```
44
+
28
45
  #### Log Spying
29
46
 
30
47
  ```javascript
@@ -146,13 +163,16 @@ export default {
146
163
  toMatchUuid4,
147
164
  toMatchUuid5,
148
165
  toMatchUuid,
166
+ toThrowBadGatewayError,
149
167
  toThrowBadRequestError,
150
168
  toThrowConfigurationError,
151
169
  toThrowForbiddenError,
170
+ toThrowGatewayTimeoutError,
152
171
  toThrowInternalError,
153
172
  toThrowJaypieError,
154
173
  toThrowNotFoundError,
155
174
  toThrowUnauthorizedError,
175
+ toThrowUnavailableError,
156
176
  };
157
177
  ```
158
178
 
@@ -330,6 +350,8 @@ const event = sqsTestRecords(
330
350
 
331
351
  | Date | Version | Summary |
332
352
  | ---------- | ------- | -------------- |
353
+ | 9/15/2024 | 1.0.29 | All errors exported as mocks |
354
+ | 9/14/2024 | 1.0.28 | Matchers `toThrowBadGatewayError`, `toThrowGatewayTimeoutError`, `toThrowUnavailableError` |
333
355
  | 9/13/2024 | 1.0.27 | Matcher `toBeCalledAboveTrace` |
334
356
  | 7/16/2024 | 1.0.21 | Export Jaypie mock as default |
335
357
  | 3/20/2024 | 1.0.2 | Export `LOG` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/testkit",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "author": "Finlayson Studio",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,12 +1,31 @@
1
1
  import { getMessages as originalGetMessages } from "@jaypie/aws";
2
2
  import { force, uuid as originalUuid } from "@jaypie/core";
3
3
  import {
4
- BadRequestError,
4
+ // Core utilities
5
5
  HTTP,
6
6
  JAYPIE,
7
7
  log,
8
- UnavailableError,
9
- UnhandledError,
8
+ // Errors
9
+ BadGatewayError as BadGatewayErrorOriginal,
10
+ BadRequestError as BadRequestErrorOriginal,
11
+ ConfigurationError as ConfigurationErrorOriginal,
12
+ ForbiddenError as ForbiddenErrorOriginal,
13
+ GatewayTimeoutError as GatewayTimeoutErrorOriginal,
14
+ GoneError as GoneErrorOriginal,
15
+ IllogicalError as IllogicalErrorOriginal,
16
+ InternalError as InternalErrorOriginal,
17
+ MethodNotAllowedError as MethodNotAllowedErrorOriginal,
18
+ MultiError as MultiErrorOriginal,
19
+ NotFoundError as NotFoundErrorOriginal,
20
+ NotImplementedError as NotImplementedErrorOriginal,
21
+ ProjectError as ProjectErrorOriginal,
22
+ ProjectMultiError as ProjectMultiErrorOriginal,
23
+ RejectedError as RejectedErrorOriginal,
24
+ TeapotError as TeapotErrorOriginal,
25
+ UnauthorizedError as UnauthorizedErrorOriginal,
26
+ UnavailableError as UnavailableErrorOriginal,
27
+ UnhandledError as UnhandledErrorOriginal,
28
+ UnreachableCodeError as UnreachableCodeErrorOriginal,
10
29
  } from "@jaypie/core";
11
30
  import { beforeAll, vi } from "vitest";
12
31
 
@@ -64,6 +83,69 @@ export const sendMessage = vi.fn(() => {
64
83
  return { value: `_MOCK_MESSAGE_[${TAG}]` };
65
84
  });
66
85
 
86
+ // @jaypie/core Errors
87
+
88
+ export const BadGatewayError = vi.fn((...params) => {
89
+ return BadGatewayErrorOriginal(...params);
90
+ });
91
+ export const BadRequestError = vi.fn((...params) => {
92
+ return BadRequestErrorOriginal(...params);
93
+ });
94
+ export const ConfigurationError = vi.fn((...params) => {
95
+ return ConfigurationErrorOriginal(...params);
96
+ });
97
+ export const ForbiddenError = vi.fn((...params) => {
98
+ return ForbiddenErrorOriginal(...params);
99
+ });
100
+ export const GatewayTimeoutError = vi.fn((...params) => {
101
+ return GatewayTimeoutErrorOriginal(...params);
102
+ });
103
+ export const GoneError = vi.fn((...params) => {
104
+ return GoneErrorOriginal(...params);
105
+ });
106
+ export const IllogicalError = vi.fn((...params) => {
107
+ return IllogicalErrorOriginal(...params);
108
+ });
109
+ export const InternalError = vi.fn((...params) => {
110
+ return InternalErrorOriginal(...params);
111
+ });
112
+ export const MethodNotAllowedError = vi.fn((...params) => {
113
+ return MethodNotAllowedErrorOriginal(...params);
114
+ });
115
+ export const MultiError = vi.fn((...params) => {
116
+ return MultiErrorOriginal(...params);
117
+ });
118
+ export const NotFoundError = vi.fn((...params) => {
119
+ return NotFoundErrorOriginal(...params);
120
+ });
121
+ export const NotImplementedError = vi.fn((...params) => {
122
+ return NotImplementedErrorOriginal(...params);
123
+ });
124
+ export const ProjectError = vi.fn((...params) => {
125
+ return ProjectErrorOriginal(...params);
126
+ });
127
+ export const ProjectMultiError = vi.fn((...params) => {
128
+ return ProjectMultiErrorOriginal(...params);
129
+ });
130
+ export const RejectedError = vi.fn((...params) => {
131
+ return RejectedErrorOriginal(...params);
132
+ });
133
+ export const TeapotError = vi.fn((...params) => {
134
+ return TeapotErrorOriginal(...params);
135
+ });
136
+ export const UnauthorizedError = vi.fn((...params) => {
137
+ return UnauthorizedErrorOriginal(...params);
138
+ });
139
+ export const UnavailableError = vi.fn((...params) => {
140
+ return UnavailableErrorOriginal(...params);
141
+ });
142
+ export const UnhandledError = vi.fn((...params) => {
143
+ return UnhandledErrorOriginal(...params);
144
+ });
145
+ export const UnreachableCodeError = vi.fn((...params) => {
146
+ return UnreachableCodeErrorOriginal(...params);
147
+ });
148
+
67
149
  // @jaypie/core Functions
68
150
 
69
151
  export const envBoolean = vi.fn(() => {
@@ -263,6 +345,12 @@ export const expressHandler = vi.fn((handler, props = {}) => {
263
345
 
264
346
  // For testing, this is the same as the jaypieHandler
265
347
  export const lambdaHandler = vi.fn((handler, props = {}) => {
348
+ // If handler is an object and options is a function, swap them
349
+ if (typeof handler === "object" && typeof props === "function") {
350
+ const temp = handler;
351
+ handler = props;
352
+ props = temp;
353
+ }
266
354
  return async (event, context, ...extra) => {
267
355
  return jaypieHandler(handler, props)(event, context, ...extra);
268
356
  };
@@ -1,11 +1,14 @@
1
1
  import {
2
+ BadGatewayError,
2
3
  BadRequestError,
3
4
  ConfigurationError,
4
5
  ForbiddenError,
6
+ GatewayTimeoutError,
5
7
  InternalError,
6
8
  isJaypieError,
7
9
  NotFoundError,
8
10
  UnauthorizedError,
11
+ UnavailableError,
9
12
  } from "@jaypie/core";
10
13
 
11
14
  //
@@ -69,18 +72,24 @@ const toThrowJaypieError = async (received, expected) => {
69
72
  // Convenience Methods
70
73
  //
71
74
 
75
+ const toThrowBadGatewayError = (received) =>
76
+ toThrowJaypieError(received, BadGatewayError);
72
77
  const toThrowBadRequestError = (received) =>
73
78
  toThrowJaypieError(received, BadRequestError);
74
79
  const toThrowConfigurationError = (received) =>
75
80
  toThrowJaypieError(received, ConfigurationError);
76
81
  const toThrowForbiddenError = (received) =>
77
82
  toThrowJaypieError(received, ForbiddenError);
83
+ const toThrowGatewayTimeoutError = (received) =>
84
+ toThrowJaypieError(received, GatewayTimeoutError);
78
85
  const toThrowInternalError = (received) =>
79
86
  toThrowJaypieError(received, InternalError);
80
87
  const toThrowNotFoundError = (received) =>
81
88
  toThrowJaypieError(received, NotFoundError);
82
89
  const toThrowUnauthorizedError = (received) =>
83
90
  toThrowJaypieError(received, UnauthorizedError);
91
+ const toThrowUnavailableError = (received) =>
92
+ toThrowJaypieError(received, UnavailableError);
84
93
 
85
94
  //
86
95
  //
@@ -90,10 +99,13 @@ const toThrowUnauthorizedError = (received) =>
90
99
  export default toThrowJaypieError;
91
100
 
92
101
  export {
102
+ toThrowBadGatewayError,
93
103
  toThrowBadRequestError,
94
104
  toThrowConfigurationError,
95
105
  toThrowForbiddenError,
106
+ toThrowGatewayTimeoutError,
96
107
  toThrowInternalError,
97
108
  toThrowNotFoundError,
98
109
  toThrowUnauthorizedError,
110
+ toThrowUnavailableError,
99
111
  };
@@ -5,12 +5,15 @@ import toBeCalledWithInitialParams from "./matchers/toBeCalledWithInitialParams.
5
5
  import toBeClass from "./matchers/toBeClass.matcher.js";
6
6
  import toBeJaypieError from "./matchers/toBeJaypieError.matcher.js";
7
7
  import toThrowJaypieError, {
8
+ toThrowBadGatewayError,
8
9
  toThrowBadRequestError,
9
10
  toThrowConfigurationError,
10
11
  toThrowForbiddenError,
12
+ toThrowGatewayTimeoutError,
11
13
  toThrowInternalError,
12
14
  toThrowNotFoundError,
13
15
  toThrowUnauthorizedError,
16
+ toThrowUnavailableError,
14
17
  } from "./matchers/toThrowJaypieError.matcher.js";
15
18
 
16
19
  import {
@@ -42,11 +45,14 @@ export default {
42
45
  toMatchUuid4,
43
46
  toMatchUuid5,
44
47
  toMatchUuid,
48
+ toThrowBadGatewayError,
45
49
  toThrowBadRequestError,
46
50
  toThrowConfigurationError,
47
51
  toThrowForbiddenError,
52
+ toThrowGatewayTimeoutError,
48
53
  toThrowInternalError,
49
54
  toThrowJaypieError,
50
55
  toThrowNotFoundError,
51
56
  toThrowUnauthorizedError,
57
+ toThrowUnavailableError,
52
58
  };