@jaypie/testkit 1.0.3 → 1.0.5

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
@@ -214,6 +214,19 @@ test("log", () => {
214
214
  });
215
215
  ```
216
216
 
217
+ ### `sqsTestRecords(message, message, ...)` or `sqsTestRecords([...])`
218
+
219
+ Generates an event object for testing SQS Lambda functions with as many messages as provided. Note, test will accept more than ten messages, but AWS will only send ten at a time.
220
+
221
+ ```javascript
222
+ import { sqsTestRecords } from "@jaypie/testkit";
223
+
224
+ const event = sqsTestRecords(
225
+ { MessageId: "1", Body: "Hello, World!" },
226
+ { MessageId: "2", Body: "Goodbye, World!" }
227
+ );
228
+ ```
229
+
217
230
  ## 🌠 Wishlist
218
231
 
219
232
  * matcher toBeHttpStatus
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/testkit",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "author": "Finlayson Studio",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -16,10 +16,12 @@
16
16
  "test:spec:jsonApiSchema.module": "vitest run ./src/__tests__/jsonApiSchema.module.spec.js",
17
17
  "test:spec:matchers.module": "vitest run ./src/__tests__/matchers.module.spec.js",
18
18
  "test:spec:mockLog.module": "vitest run ./src/__tests__/mockLog.module.spec.js",
19
+ "test:spec:sqsTestRecords.function": "vitest run ./src/__tests__/sqsTestRecords.function.spec.js",
20
+ "test:spec:toBeClass.matcher": "vitest run ./src/matchers/__tests__/toBeClass.matcher.spec.js",
19
21
  "test:spec:toBeJaypieError.matcher": "vitest run ./src/matchers/__tests__/toBeJaypieError.matcher.spec.js"
20
22
  },
21
23
  "dependencies": {
22
- "@jaypie/core": "^1.0.0",
24
+ "@jaypie/core": "^1.0.2",
23
25
  "jest-json-schema": "^6.1.0"
24
26
  },
25
27
  "devDependencies": {
package/src/index.js CHANGED
@@ -8,3 +8,4 @@ export { LOG } from "@jaypie/core";
8
8
  export { jsonApiErrorSchema, jsonApiSchema } from "./jsonApiSchema.module.js";
9
9
  export { default as matchers } from "./matchers.module.js";
10
10
  export { mockLogFactory, restoreLog, spyLog } from "./mockLog.module.js";
11
+ export { default as sqsTestRecords } from "./sqsTestRecords.function.js";
@@ -0,0 +1,44 @@
1
+ //
2
+ //
3
+ // Constants
4
+ //
5
+
6
+ //
7
+ //
8
+ // Helper Functions
9
+ //
10
+
11
+ //
12
+ //
13
+ // Main
14
+ //
15
+
16
+ const toBeClass = (received) => {
17
+ let pass = false;
18
+ if (typeof received === "function") {
19
+ try {
20
+ // eslint-disable-next-line new-cap, no-new
21
+ new received();
22
+ pass = true;
23
+ } catch (e) {
24
+ pass = false;
25
+ }
26
+ }
27
+ if (pass) {
28
+ return {
29
+ message: () => `expected ${received} not to be a class`,
30
+ pass: true,
31
+ };
32
+ }
33
+ return {
34
+ message: () => `expected ${received} to be a class`,
35
+ pass: false,
36
+ };
37
+ };
38
+
39
+ //
40
+ //
41
+ // Export
42
+ //
43
+
44
+ export default toBeClass;
@@ -1,5 +1,6 @@
1
1
  import { matchers as jsonSchemaMatchers } from "jest-json-schema";
2
2
 
3
+ import toBeClass from "./matchers/toBeClass.matcher.js";
3
4
  import toBeJaypieError from "./matchers/toBeJaypieError.matcher.js";
4
5
 
5
6
  //
@@ -8,6 +9,7 @@ import toBeJaypieError from "./matchers/toBeJaypieError.matcher.js";
8
9
  //
9
10
 
10
11
  export default {
12
+ toBeClass,
11
13
  toBeJaypieError,
12
14
  toBeValidSchema: jsonSchemaMatchers.toBeValidSchema,
13
15
  toMatchSchema: jsonSchemaMatchers.toMatchSchema,
@@ -0,0 +1,53 @@
1
+ import { uuid } from "@jaypie/core";
2
+
3
+ //
4
+ //
5
+ // Constants
6
+ //
7
+
8
+ //
9
+ //
10
+ // Helper Functions
11
+ //
12
+
13
+ //
14
+ //
15
+ // Main
16
+ //
17
+
18
+ const sqsTestRecords = (...args) => {
19
+ const records = [];
20
+
21
+ // See if only a single array was passed in and spread it
22
+ if (args.length === 1 && Array.isArray(args[0])) {
23
+ // eslint-disable-next-line no-param-reassign
24
+ [args] = args;
25
+ }
26
+
27
+ for (let i = 0; i < args.length; i += 1) {
28
+ const item = args[i];
29
+ let body;
30
+ if (item && typeof item === "object") {
31
+ body = JSON.stringify(item);
32
+ } else {
33
+ // Cast item to string
34
+ body = String(item);
35
+ }
36
+ const record = {
37
+ messageId: uuid(),
38
+ body,
39
+ };
40
+ records.push(record);
41
+ }
42
+
43
+ return {
44
+ Records: records,
45
+ };
46
+ };
47
+
48
+ //
49
+ //
50
+ // Export
51
+ //
52
+
53
+ export default sqsTestRecords;