@cedarjs/testing 1.0.0-canary.12344 → 1.0.0-canary.12347

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.
Files changed (83) hide show
  1. package/config/jest/api/jest.setup.js +1 -1
  2. package/config/jest/package.json +3 -0
  3. package/config/jest/web/jest-preset.js +2 -2
  4. package/config/jest/web/jest.setup.js +2 -2
  5. package/dist/api/apiFunction.js +4 -30
  6. package/dist/api/directUrlHelpers.js +4 -39
  7. package/dist/api/directive.js +13 -38
  8. package/dist/api/index.d.ts +3 -3
  9. package/dist/api/index.d.ts.map +1 -1
  10. package/dist/api/index.js +3 -26
  11. package/dist/api/scenario.js +2 -26
  12. package/dist/cache/index.js +2 -26
  13. package/dist/cjs/api/apiFunction.d.ts +37 -0
  14. package/dist/cjs/api/apiFunction.d.ts.map +1 -0
  15. package/dist/cjs/api/apiFunction.js +89 -0
  16. package/dist/cjs/api/directUrlHelpers.d.ts +3 -0
  17. package/dist/cjs/api/directUrlHelpers.d.ts.map +1 -0
  18. package/dist/cjs/api/directUrlHelpers.js +60 -0
  19. package/dist/cjs/api/directive.d.ts +51 -0
  20. package/dist/cjs/api/directive.d.ts.map +1 -0
  21. package/dist/cjs/api/directive.js +77 -0
  22. package/dist/cjs/api/index.d.ts +4 -0
  23. package/dist/cjs/api/index.d.ts.map +1 -0
  24. package/dist/cjs/api/index.js +26 -0
  25. package/dist/cjs/api/scenario.d.ts +108 -0
  26. package/dist/cjs/api/scenario.d.ts.map +1 -0
  27. package/dist/cjs/api/scenario.js +30 -0
  28. package/dist/cjs/cache/index.d.ts +50 -0
  29. package/dist/cjs/cache/index.d.ts.map +1 -0
  30. package/dist/cjs/cache/index.js +104 -0
  31. package/dist/cjs/package.json +1 -0
  32. package/dist/cjs/web/MockParamsProvider.d.ts +7 -0
  33. package/dist/cjs/web/MockParamsProvider.d.ts.map +1 -0
  34. package/dist/cjs/web/MockParamsProvider.js +44 -0
  35. package/dist/cjs/web/MockProviders.d.ts +9 -0
  36. package/dist/cjs/web/MockProviders.d.ts.map +1 -0
  37. package/dist/cjs/web/MockProviders.js +53 -0
  38. package/dist/cjs/web/MockRouter.d.ts +14 -0
  39. package/dist/cjs/web/MockRouter.d.ts.map +1 -0
  40. package/dist/cjs/web/MockRouter.js +48 -0
  41. package/dist/cjs/web/customRender.d.ts +6 -0
  42. package/dist/cjs/web/customRender.d.ts.map +1 -0
  43. package/dist/cjs/web/customRender.js +54 -0
  44. package/dist/cjs/web/fileMock.d.ts +9 -0
  45. package/dist/cjs/web/fileMock.d.ts.map +1 -0
  46. package/dist/cjs/web/fileMock.js +24 -0
  47. package/dist/cjs/web/findCellMocks.d.ts +2 -0
  48. package/dist/cjs/web/findCellMocks.d.ts.map +1 -0
  49. package/dist/cjs/web/findCellMocks.js +45 -0
  50. package/dist/cjs/web/global.d.ts +6 -0
  51. package/dist/cjs/web/global.d.ts.map +1 -0
  52. package/dist/cjs/web/global.js +1 -0
  53. package/dist/cjs/web/index.d.ts +6 -0
  54. package/dist/cjs/web/index.d.ts.map +1 -0
  55. package/dist/cjs/web/index.js +41 -0
  56. package/dist/cjs/web/mockAuth.d.ts +29 -0
  57. package/dist/cjs/web/mockAuth.d.ts.map +1 -0
  58. package/dist/cjs/web/mockAuth.js +89 -0
  59. package/dist/cjs/web/mockRequests.d.ts +30 -0
  60. package/dist/cjs/web/mockRequests.d.ts.map +1 -0
  61. package/dist/cjs/web/mockRequests.js +139 -0
  62. package/dist/web/MockParamsProvider.js +7 -41
  63. package/dist/web/MockProviders.d.ts.map +1 -1
  64. package/dist/web/MockProviders.js +10 -44
  65. package/dist/web/MockRouter.js +10 -37
  66. package/dist/web/customRender.js +9 -44
  67. package/dist/web/fileMock.js +3 -23
  68. package/dist/web/findCellMocks.js +4 -38
  69. package/dist/web/global.d.ts +1 -1
  70. package/dist/web/global.d.ts.map +1 -1
  71. package/dist/web/global.js +0 -1
  72. package/dist/web/index.d.ts +4 -5
  73. package/dist/web/index.d.ts.map +1 -1
  74. package/dist/web/index.js +13 -41
  75. package/dist/web/mockAuth.js +12 -49
  76. package/dist/web/mockRequests.js +6 -37
  77. package/package.json +75 -11
  78. package/api/index.js +0 -2
  79. package/api/package.json +0 -4
  80. package/cache/index.js +0 -2
  81. package/cache/package.json +0 -4
  82. package/web/index.js +0 -2
  83. package/web/package.json +0 -4
@@ -4,7 +4,7 @@
4
4
  // @NOTE without these imports in the setup file, mockCurrentUser
5
5
  // will remain undefined in the user's tests
6
6
  // Remember to use specific imports
7
- const { defineScenario } = require('@cedarjs/testing/dist/api/scenario')
7
+ const { defineScenario } = require('@cedarjs/testing/dist/cjs/api/scenario')
8
8
 
9
9
  // @NOTE we do this because jest.setup.js runs every time in each context
10
10
  // while jest-preset runs once. This significantly reduces memory footprint, and testing time
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -52,7 +52,7 @@ module.exports = {
52
52
  // We replace imports to "@cedarjs/router" with our own "mock" implementation.
53
53
  '^@cedarjs/router$': path.join(
54
54
  NODE_MODULES_PATH,
55
- '@cedarjs/testing/dist/web/MockRouter.js',
55
+ '@cedarjs/testing/dist/cjs/web/MockRouter.js',
56
56
  ),
57
57
  '^@cedarjs/web$': path.join(NODE_MODULES_PATH, '@cedarjs/web/dist/cjs'),
58
58
 
@@ -60,7 +60,7 @@ module.exports = {
60
60
  // clients, which in turn lets us mock `useAuth` in tests
61
61
  '^@cedarjs/auth$': path.join(
62
62
  NODE_MODULES_PATH,
63
- '@cedarjs/testing/dist/web/mockAuth.js',
63
+ '@cedarjs/testing/dist/cjs/web/mockAuth.js',
64
64
  ),
65
65
 
66
66
  // @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
@@ -3,7 +3,7 @@
3
3
  require('@testing-library/jest-dom')
4
4
  require('whatwg-fetch')
5
5
 
6
- const { findCellMocks } = require('@cedarjs/testing/dist/web/findCellMocks')
6
+ const { findCellMocks } = require('@cedarjs/testing/dist/cjs/web/findCellMocks')
7
7
  const {
8
8
  startMSW,
9
9
  setupRequestHandlers,
@@ -11,7 +11,7 @@ const {
11
11
  mockGraphQLMutation,
12
12
  mockGraphQLQuery,
13
13
  mockCurrentUser,
14
- } = require('@cedarjs/testing/dist/web/mockRequests')
14
+ } = require('@cedarjs/testing/dist/cjs/web/mockRequests')
15
15
 
16
16
  global.mockGraphQLQuery = mockGraphQLQuery
17
17
  global.mockGraphQLMutation = mockGraphQLMutation
@@ -1,29 +1,4 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var apiFunction_exports = {};
20
- __export(apiFunction_exports, {
21
- mockContext: () => mockContext,
22
- mockHttpEvent: () => mockHttpEvent,
23
- mockSignedWebhook: () => mockSignedWebhook
24
- });
25
- module.exports = __toCommonJS(apiFunction_exports);
26
- var import_webhooks = require("@cedarjs/api/webhooks");
1
+ import { signPayload } from "@cedarjs/api/webhooks";
27
2
  const mockHttpEvent = ({
28
3
  payload = null,
29
4
  signature,
@@ -70,7 +45,7 @@ const mockSignedWebhook = ({
70
45
  ...others
71
46
  }) => {
72
47
  const payloadAsString = typeof payload === "string" ? payload : JSON.stringify(payload);
73
- const signature = (0, import_webhooks.signPayload)(signatureType, {
48
+ const signature = signPayload(signatureType, {
74
49
  payload: payloadAsString,
75
50
  secret
76
51
  });
@@ -81,9 +56,8 @@ const mockSignedWebhook = ({
81
56
  ...others
82
57
  });
83
58
  };
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {
59
+ export {
86
60
  mockContext,
87
61
  mockHttpEvent,
88
62
  mockSignedWebhook
89
- });
63
+ };
@@ -1,40 +1,6 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var directUrlHelpers_exports = {};
30
- __export(directUrlHelpers_exports, {
31
- checkAndReplaceDirectUrl: () => checkAndReplaceDirectUrl,
32
- getDefaultDb: () => getDefaultDb
33
- });
34
- module.exports = __toCommonJS(directUrlHelpers_exports);
35
- var import_path = __toESM(require("path"));
1
+ import path from "path";
36
2
  function getDefaultDb(rwjsCwd) {
37
- return `file:${import_path.default.join(rwjsCwd, ".redwood", "test.db")}`;
3
+ return `file:${path.join(rwjsCwd, ".redwood", "test.db")}`;
38
4
  }
39
5
  function checkAndReplaceDirectUrl(prismaSchema, defaultDb) {
40
6
  const directUrl = prismaSchema.match(PRISMA_DIRECT_URL_REGEXP);
@@ -53,8 +19,7 @@ function checkAndReplaceDirectUrl(prismaSchema, defaultDb) {
53
19
  }
54
20
  const PRISMA_DIRECT_URL_REGEXP = /directUrl(\s*)=(\s*)env\(('|")(.*)('|")\)/g;
55
21
  const BETWEEN_PARENTHESES_REGEXP = /\(('|")([^)]+)('|")\)/;
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
22
+ export {
58
23
  checkAndReplaceDirectUrl,
59
24
  getDefaultDb
60
- });
25
+ };
@@ -1,49 +1,25 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var directive_exports = {};
20
- __export(directive_exports, {
21
- getDirectiveName: () => import_graphql_server2.getDirectiveName,
22
- mockRedwoodDirective: () => mockRedwoodDirective
23
- });
24
- module.exports = __toCommonJS(directive_exports);
25
- var import_context = require("@cedarjs/context");
26
- var import_graphql_server = require("@cedarjs/graphql-server");
27
- var import_graphql_server2 = require("@cedarjs/graphql-server");
1
+ import { setContext, context as globalContext } from "@cedarjs/context";
2
+ import { DirectiveType } from "@cedarjs/graphql-server";
3
+ import { getDirectiveName } from "@cedarjs/graphql-server";
28
4
  const mockRedwoodDirective = (directive, executionMock) => {
29
5
  const { directiveArgs, context, ...others } = executionMock;
30
6
  if (directive.onResolvedValue.constructor.name === "AsyncFunction") {
31
7
  return async () => {
32
8
  if (context !== void 0) {
33
- (0, import_context.setContext)(context);
9
+ setContext(context);
34
10
  }
35
- if (directive.type === import_graphql_server.DirectiveType.TRANSFORMER) {
11
+ if (directive.type === DirectiveType.TRANSFORMER) {
36
12
  const { mockedResolvedValue } = others;
37
13
  return directive.onResolvedValue({
38
14
  resolvedValue: mockedResolvedValue,
39
15
  directiveArgs: directiveArgs ?? {},
40
- context: import_context.context,
16
+ context: globalContext,
41
17
  ...others
42
18
  });
43
19
  } else {
44
20
  await directive.onResolvedValue({
45
21
  directiveArgs: directiveArgs ?? {},
46
- context: import_context.context,
22
+ context: globalContext,
47
23
  ...others
48
24
  });
49
25
  }
@@ -51,27 +27,26 @@ const mockRedwoodDirective = (directive, executionMock) => {
51
27
  }
52
28
  return () => {
53
29
  if (context !== void 0) {
54
- (0, import_context.setContext)(context);
30
+ setContext(context);
55
31
  }
56
- if (directive.type === import_graphql_server.DirectiveType.TRANSFORMER) {
32
+ if (directive.type === DirectiveType.TRANSFORMER) {
57
33
  const { mockedResolvedValue } = others;
58
34
  return directive.onResolvedValue({
59
35
  resolvedValue: mockedResolvedValue,
60
36
  directiveArgs: directiveArgs ?? {},
61
- context: import_context.context,
37
+ context: globalContext,
62
38
  ...others
63
39
  });
64
40
  } else {
65
41
  directive.onResolvedValue({
66
42
  directiveArgs: directiveArgs ?? {},
67
- context: import_context.context,
43
+ context: globalContext,
68
44
  ...others
69
45
  });
70
46
  }
71
47
  };
72
48
  };
73
- // Annotate the CommonJS export names for ESM import in node:
74
- 0 && (module.exports = {
49
+ export {
75
50
  getDirectiveName,
76
51
  mockRedwoodDirective
77
- });
52
+ };
@@ -1,4 +1,4 @@
1
- export * from './apiFunction';
2
- export * from './scenario';
3
- export * from './directive';
1
+ export * from './apiFunction.js';
2
+ export * from './scenario.js';
3
+ export * from './directive.js';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
package/dist/api/index.js CHANGED
@@ -1,26 +1,3 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var api_exports = {};
17
- module.exports = __toCommonJS(api_exports);
18
- __reExport(api_exports, require("./apiFunction"), module.exports);
19
- __reExport(api_exports, require("./scenario"), module.exports);
20
- __reExport(api_exports, require("./directive"), module.exports);
21
- // Annotate the CommonJS export names for ESM import in node:
22
- 0 && (module.exports = {
23
- ...require("./apiFunction"),
24
- ...require("./scenario"),
25
- ...require("./directive")
26
- });
1
+ export * from "./apiFunction.js";
2
+ export * from "./scenario.js";
3
+ export * from "./directive.js";
@@ -1,30 +1,6 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var scenario_exports = {};
20
- __export(scenario_exports, {
21
- defineScenario: () => defineScenario
22
- });
23
- module.exports = __toCommonJS(scenario_exports);
24
1
  const defineScenario = (data) => {
25
2
  return data;
26
3
  };
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
4
+ export {
29
5
  defineScenario
30
- });
6
+ };
@@ -1,26 +1,3 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var cache_exports = {};
20
- __export(cache_exports, {
21
- partialMatch: () => partialMatch
22
- });
23
- module.exports = __toCommonJS(cache_exports);
24
1
  expect.extend({
25
2
  toHaveCached(cacheClient, keyOrExpectedValue, expectedValue) {
26
3
  let value;
@@ -98,7 +75,6 @@ const _checkValueForKey = (cacheClient, cacheKey, expectedValue) => {
98
75
  const partialMatch = (value) => {
99
76
  return Array.isArray(value) ? expect.arrayContaining(value.map((v) => expect.objectContaining(v))) : expect.objectContaining(value);
100
77
  };
101
- // Annotate the CommonJS export names for ESM import in node:
102
- 0 && (module.exports = {
78
+ export {
103
79
  partialMatch
104
- });
80
+ };
@@ -0,0 +1,37 @@
1
+ import type { APIGatewayProxyEvent, APIGatewayProxyEventHeaders, Context } from 'aws-lambda';
2
+ import type { SupportedVerifierTypes } from '@cedarjs/api/webhooks';
3
+ interface BuildEventParams extends Partial<APIGatewayProxyEvent> {
4
+ payload?: string | null | Record<any, any>;
5
+ signature?: string;
6
+ signatureHeader?: string;
7
+ headers?: APIGatewayProxyEventHeaders;
8
+ }
9
+ /**
10
+ * @description Use this to mock out the http request event that is received by your function in unit tests
11
+ *
12
+ * @example Mocking sending headers
13
+ * mockHttpEvent({header: {'X-Custom-Header': 'bazinga'}})
14
+ *
15
+ * @example Adding a JSON payload
16
+ * mockHttpEvent({payload: JSON.stringify(mockedRequestBody)})
17
+ *
18
+ * @returns APIGatewayProxyEvent
19
+ */
20
+ export declare const mockHttpEvent: ({ payload, signature, signatureHeader, queryStringParameters, httpMethod, headers, path, isBase64Encoded, ...others }: BuildEventParams) => APIGatewayProxyEvent;
21
+ /**
22
+ * @description Use this function to mock the http event's context
23
+ * @see: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html
24
+ **/
25
+ export declare const mockContext: () => Context;
26
+ interface MockedSignedWebhookParams extends Omit<BuildEventParams, 'signature' | 'signatureHeader'> {
27
+ signatureType: Exclude<SupportedVerifierTypes, 'skipVerifier'>;
28
+ signatureHeader: string;
29
+ secret: string;
30
+ }
31
+ /**
32
+ * @description Use this function to mock a signed webhook
33
+ * @see https://redwoodjs.com/docs/webhooks#webhooks
34
+ **/
35
+ export declare const mockSignedWebhook: ({ payload, signatureType, signatureHeader, secret, ...others }: MockedSignedWebhookParams) => APIGatewayProxyEvent;
36
+ export {};
37
+ //# sourceMappingURL=apiFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiFunction.d.ts","sourceRoot":"","sources":["../../../src/api/apiFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,2BAA2B,EAC3B,OAAO,EACR,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAGnE,UAAU,gBAAiB,SAAQ,OAAO,CAAC,oBAAoB,CAAC;IAC9D,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,2BAA2B,CAAA;CACtC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,0HAUvB,gBAAgB,KAAG,oBAgCrB,CAAA;AAED;;;IAGI;AACJ,eAAO,MAAM,WAAW,QAAO,OAI9B,CAAA;AAED,UAAU,yBACR,SAAQ,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,iBAAiB,CAAC;IAC/D,aAAa,EAAE,OAAO,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAA;IAC9D,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;IAGI;AACJ,eAAO,MAAM,iBAAiB,mEAM3B,yBAAyB,yBAe3B,CAAA"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var apiFunction_exports = {};
20
+ __export(apiFunction_exports, {
21
+ mockContext: () => mockContext,
22
+ mockHttpEvent: () => mockHttpEvent,
23
+ mockSignedWebhook: () => mockSignedWebhook
24
+ });
25
+ module.exports = __toCommonJS(apiFunction_exports);
26
+ var import_webhooks = require("@cedarjs/api/webhooks");
27
+ const mockHttpEvent = ({
28
+ payload = null,
29
+ signature,
30
+ signatureHeader,
31
+ queryStringParameters = null,
32
+ httpMethod = "GET",
33
+ headers = {},
34
+ path = "",
35
+ isBase64Encoded = false,
36
+ ...others
37
+ }) => {
38
+ if (signature && signatureHeader) {
39
+ headers[signatureHeader.toLocaleLowerCase()] = signature;
40
+ }
41
+ const payloadAsString = typeof payload === "string" ? payload : JSON.stringify(payload);
42
+ const body = payload === null ? null : isBase64Encoded ? Buffer.from(payloadAsString || "").toString("base64") : payloadAsString;
43
+ return {
44
+ body,
45
+ headers,
46
+ multiValueHeaders: {},
47
+ isBase64Encoded,
48
+ path,
49
+ pathParameters: null,
50
+ stageVariables: null,
51
+ httpMethod,
52
+ queryStringParameters,
53
+ // @ts-expect-error not required for mocks
54
+ requestContext: null,
55
+ // @ts-expect-error not required for mocks
56
+ resource: null,
57
+ multiValueQueryStringParameters: null,
58
+ ...others
59
+ };
60
+ };
61
+ const mockContext = () => {
62
+ const context = {};
63
+ return context;
64
+ };
65
+ const mockSignedWebhook = ({
66
+ payload = null,
67
+ signatureType,
68
+ signatureHeader,
69
+ secret,
70
+ ...others
71
+ }) => {
72
+ const payloadAsString = typeof payload === "string" ? payload : JSON.stringify(payload);
73
+ const signature = (0, import_webhooks.signPayload)(signatureType, {
74
+ payload: payloadAsString,
75
+ secret
76
+ });
77
+ return mockHttpEvent({
78
+ payload,
79
+ signature,
80
+ signatureHeader,
81
+ ...others
82
+ });
83
+ };
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ mockContext,
87
+ mockHttpEvent,
88
+ mockSignedWebhook
89
+ });
@@ -0,0 +1,3 @@
1
+ export declare function getDefaultDb(rwjsCwd: string): string;
2
+ export declare function checkAndReplaceDirectUrl(prismaSchema: string, defaultDb: string): string | undefined;
3
+ //# sourceMappingURL=directUrlHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directUrlHelpers.d.ts","sourceRoot":"","sources":["../../../src/api/directUrlHelpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,UAE3C;AAED,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,sBA2BlB"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var directUrlHelpers_exports = {};
30
+ __export(directUrlHelpers_exports, {
31
+ checkAndReplaceDirectUrl: () => checkAndReplaceDirectUrl,
32
+ getDefaultDb: () => getDefaultDb
33
+ });
34
+ module.exports = __toCommonJS(directUrlHelpers_exports);
35
+ var import_path = __toESM(require("path"), 1);
36
+ function getDefaultDb(rwjsCwd) {
37
+ return `file:${import_path.default.join(rwjsCwd, ".redwood", "test.db")}`;
38
+ }
39
+ function checkAndReplaceDirectUrl(prismaSchema, defaultDb) {
40
+ const directUrl = prismaSchema.match(PRISMA_DIRECT_URL_REGEXP);
41
+ if (!directUrl) {
42
+ return;
43
+ }
44
+ const directUrlEnvMatch = directUrl[0].match(BETWEEN_PARENTHESES_REGEXP);
45
+ if (!directUrlEnvMatch) {
46
+ throw new Error(
47
+ "Error parsing `directUrl` from schema.prisma. Proceeding with this env var could be dangerous. Please check your schema.prisma file; if everything looks ok, file an issue."
48
+ );
49
+ }
50
+ const directUrlEnv = directUrlEnvMatch[2];
51
+ process.env[directUrlEnv] = process.env.TEST_DIRECT_URL || process.env.TEST_DATABASE_URL || defaultDb;
52
+ return directUrlEnv;
53
+ }
54
+ const PRISMA_DIRECT_URL_REGEXP = /directUrl(\s*)=(\s*)env\(('|")(.*)('|")\)/g;
55
+ const BETWEEN_PARENTHESES_REGEXP = /\(('|")([^)]+)('|")\)/;
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ checkAndReplaceDirectUrl,
59
+ getDefaultDb
60
+ });
@@ -0,0 +1,51 @@
1
+ import type { A } from 'ts-toolbelt';
2
+ import type { DirectiveParams, ValidatorDirective, TransformerDirective } from '@cedarjs/graphql-server';
3
+ export { getDirectiveName } from '@cedarjs/graphql-server';
4
+ interface DirectiveMocker {
5
+ (directive: ValidatorDirective, executionMock: A.Compute<Omit<Partial<DirectiveParams>, 'resolvedValue'>>): any;
6
+ }
7
+ type TransformerMock = A.Compute<Omit<Partial<DirectiveParams>, 'resolvedValue'>> & {
8
+ mockedResolvedValue: any;
9
+ };
10
+ interface DirectiveMocker {
11
+ (directive: TransformerDirective, executionMock: TransformerMock): any;
12
+ }
13
+ /**
14
+ * @description
15
+ *
16
+ * Used for writing both synchronous and asynchronous directive tests e.g.
17
+ *
18
+ * - Transformer directives can be passed mockedResolvedValue
19
+ * - Validator directives should check for errors thrown in certain situations
20
+ * - Can provide args, directiveArgs and context to mock directive execution
21
+ *
22
+ * @example
23
+ *
24
+ * Synchronous transformer directive:
25
+ *
26
+ * ```ts
27
+ * const mockExecution = mockRedwoodDirective(myTransformer, {
28
+ * context: currentUser,
29
+ * mockedResolvedValue: 'Original Value',
30
+ * })
31
+ *
32
+ * expect(mockExecution).not.toThrow()
33
+ * expect(mockExecution()).toEqual('Transformed Value')
34
+ * ```ts
35
+ *
36
+ * @example
37
+ *
38
+ * Asynchronous transformer directive:
39
+ *
40
+ * ```ts
41
+ * const mockExecution = mockRedwoodDirective(myTransformer, {
42
+ * context: currentUser,
43
+ * mockedResolvedValue: 'Original Value',
44
+ * })
45
+ *
46
+ * await expect(mockExecution).resolves.not.toThrow()
47
+ * await expect(mockExecution()).resolves.toEqual('Transformed Value')
48
+ * ```
49
+ */
50
+ export declare const mockRedwoodDirective: DirectiveMocker;
51
+ //# sourceMappingURL=directive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directive.d.ts","sourceRoot":"","sources":["../../../src/api/directive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,aAAa,CAAA;AAGpC,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAG1D,UAAU,eAAe;IACvB,CACE,SAAS,EAAE,kBAAkB,EAC7B,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC,CAAC,GACxE,GAAG,CAAA;CACP;AAED,KAAK,eAAe,GAAG,CAAC,CAAC,OAAO,CAC9B,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC,CAChD,GAAG;IACF,mBAAmB,EAAE,GAAG,CAAA;CACzB,CAAA;AAGD,UAAU,eAAe;IACvB,CAAC,SAAS,EAAE,oBAAoB,EAAE,aAAa,EAAE,eAAe,GAAG,GAAG,CAAA;CACvE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,oBAAoB,EAAE,eAmDlC,CAAA"}