@cedarjs/testing 8.0.0-canary.3557 → 8.0.0-canary.3560

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.
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ children: React.ReactNode;
4
+ }
5
+ /**
6
+ * Does what the router does on a `PrivateSet` whose route is in an
7
+ * organization, with the app's own `tenancy`: its `useOrg` finds the
8
+ * organization from the mocked user and route params, and its `OrgProvider`
9
+ * provides it. So `useCurrentOrg()` and `useAuth().hasPermission` work in a
10
+ * test or story as they do on the app's organization routes, with
11
+ * `mockCurrentUser({ memberships })` and `mockRouteParams({ orgSlug })`.
12
+ *
13
+ * Without an organization (no `tenancy`, or a `useOrg` that finds none)
14
+ * `children` render without a provider, and `useCurrentOrg()` throws. A
15
+ * signed-in user who isn't a member gets the tenancy's `notAMember`.
16
+ */
17
+ export declare const MockOrgProvider: React.FC<Props>;
18
+ export {};
19
+ //# sourceMappingURL=MockOrgProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MockOrgProvider.d.ts","sourceRoot":"","sources":["../../src/web/MockOrgProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAQzB,UAAU,KAAK;IACb,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAQ3C,CAAA"}
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ import { useAuth } from "./mockAuth.js";
3
+ import { mockedRouteParamsMeta } from "./mockRequests.js";
4
+ import { mockedTenancyMeta } from "./mockTenancy.js";
5
+ const MockOrgProvider = ({ children }) => {
6
+ const tenancy = mockedTenancyMeta.tenancy;
7
+ if (!tenancy) {
8
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
9
+ }
10
+ return /* @__PURE__ */ React.createElement(TenancyOrgProvider, { tenancy }, children);
11
+ };
12
+ const TenancyOrgProvider = ({
13
+ tenancy,
14
+ children
15
+ }) => {
16
+ const org = tenancy.useOrg(useAuth, mockedRouteParamsMeta.params);
17
+ if (!org) {
18
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
19
+ }
20
+ const { membership, memberships } = org;
21
+ if (!membership) {
22
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, tenancy.notAMember ?? null);
23
+ }
24
+ return /* @__PURE__ */ React.createElement(
25
+ tenancy.OrgProvider,
26
+ {
27
+ key: membership.organizationId,
28
+ useAuth,
29
+ membership,
30
+ memberships
31
+ },
32
+ children
33
+ );
34
+ };
35
+ export {
36
+ MockOrgProvider
37
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"MockProviders.d.ts","sourceRoot":"","sources":["../../src/web/MockProviders.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AA+BzB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAClD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAYA,CAAA"}
1
+ {"version":3,"file":"MockProviders.d.ts","sourceRoot":"","sources":["../../src/web/MockProviders.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAgCzB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAClD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAcA,CAAA"}
@@ -4,6 +4,7 @@ import { CedarProvider } from "@cedarjs/web";
4
4
  import { CedarApolloProvider } from "@cedarjs/web/apollo/CedarApolloProvider";
5
5
  import { UserRoutes as VitestUserRoutes } from "./globRoutesImporter.js";
6
6
  import { useAuth } from "./mockAuth.js";
7
+ import { MockOrgProvider } from "./MockOrgProvider.js";
7
8
  import { MockParamsProvider } from "./MockParamsProvider.js";
8
9
  let UserRoutes;
9
10
  try {
@@ -16,7 +17,7 @@ try {
16
17
  UserRoutes = () => /* @__PURE__ */ React.createElement(React.Fragment, null);
17
18
  }
18
19
  const MockProviders = ({ children }) => {
19
- return /* @__PURE__ */ React.createElement(CedarProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ React.createElement(CedarApolloProvider, { useAuth }, /* @__PURE__ */ React.createElement(UserRoutes, null), /* @__PURE__ */ React.createElement(VitestUserRoutes, null), /* @__PURE__ */ React.createElement(LocationProvider, null, /* @__PURE__ */ React.createElement(MockParamsProvider, null, children))));
20
+ return /* @__PURE__ */ React.createElement(CedarProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ React.createElement(CedarApolloProvider, { useAuth }, /* @__PURE__ */ React.createElement(UserRoutes, null), /* @__PURE__ */ React.createElement(VitestUserRoutes, null), /* @__PURE__ */ React.createElement(LocationProvider, null, /* @__PURE__ */ React.createElement(MockParamsProvider, null, /* @__PURE__ */ React.createElement(MockOrgProvider, null, children)))));
20
21
  };
21
22
  function isModuleNotFoundError(error, module) {
22
23
  if (!error || typeof error !== "object" || !("code" in error) || error.code !== "MODULE_NOT_FOUND") {
@@ -4,8 +4,5 @@ export * from '@cedarjs/router/dist/index';
4
4
  export declare const routes: {
5
5
  [routeName: string]: () => string;
6
6
  };
7
- /**
8
- * This router populates the `routes.<pageName>()` utility object.
9
- */
10
7
  export declare const Router: React.FC<RouterProps>;
11
8
  //# sourceMappingURL=MockRouter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MockRouter.d.ts","sourceRoot":"","sources":["../../src/web/MockRouter.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAG9D,cAAc,4BAA4B,CAAA;AAE1C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,MAAM,CAAA;CAAO,CAAA;AAE/D;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAcxC,CAAA"}
1
+ {"version":3,"file":"MockRouter.d.ts","sourceRoot":"","sources":["../../src/web/MockRouter.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAM9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAM9D,cAAc,4BAA4B,CAAA;AAE1C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,MAAM,CAAA;CAAO,CAAA;AAiC/D,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAAc,CAAA"}
@@ -1,9 +1,11 @@
1
1
  import { flattenAll } from "@cedarjs/router/dist/react-util";
2
2
  import { isValidRoute } from "@cedarjs/router/dist/route-validators";
3
3
  import { replaceParams } from "@cedarjs/router/dist/util";
4
+ import { mockedTenancyMeta } from "./mockTenancy.js";
4
5
  export * from "@cedarjs/router/dist/index";
5
6
  const routes = {};
6
- const Router = ({ children }) => {
7
+ const MockRouter = ({ tenancy, children }) => {
8
+ mockedTenancyMeta.tenancy = tenancy;
7
9
  const flatChildArray = flattenAll(children);
8
10
  flatChildArray.forEach((child) => {
9
11
  if (isValidRoute(child)) {
@@ -15,6 +17,7 @@ const Router = ({ children }) => {
15
17
  });
16
18
  return null;
17
19
  };
20
+ const Router = MockRouter;
18
21
  export {
19
22
  Router,
20
23
  routes
@@ -1,6 +1,7 @@
1
1
  export * from '@testing-library/react';
2
2
  export { customRender as render, customRenderHook as renderHook, } from './customRender.js';
3
3
  export { MockProviders } from './MockProviders.js';
4
+ export { MockOrgProvider } from './MockOrgProvider.js';
4
5
  export { useAuth } from './mockAuth.js';
5
6
  export * from './mockRequests.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AAGtC,OAAO,EACL,YAAY,IAAI,MAAM,EACtB,gBAAgB,IAAI,UAAU,GAC/B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AAGtC,OAAO,EACL,YAAY,IAAI,MAAM,EACtB,gBAAgB,IAAI,UAAU,GAC/B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,cAAc,mBAAmB,CAAA"}
package/dist/web/index.js CHANGED
@@ -4,9 +4,11 @@ import {
4
4
  customRenderHook
5
5
  } from "./customRender.js";
6
6
  import { MockProviders } from "./MockProviders.js";
7
+ import { MockOrgProvider } from "./MockOrgProvider.js";
7
8
  import { useAuth } from "./mockAuth.js";
8
9
  export * from "./mockRequests.js";
9
10
  export {
11
+ MockOrgProvider,
10
12
  MockProviders,
11
13
  customRender as render,
12
14
  customRenderHook as renderHook,
@@ -0,0 +1,9 @@
1
+ import type { Tenancy } from '@cedarjs/router';
2
+ /**
3
+ * The `tenancy` passed to the app's `<Router>`. `MockRouter` records it when
4
+ * `MockProviders` renders the app's routes, and `MockOrgProvider` uses it.
5
+ */
6
+ export declare const mockedTenancyMeta: {
7
+ tenancy: Tenancy | undefined;
8
+ };
9
+ //# sourceMappingURL=mockTenancy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mockTenancy.d.ts","sourceRoot":"","sources":["../../src/web/mockTenancy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAE9C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE;IAAE,OAAO,EAAE,OAAO,GAAG,SAAS,CAAA;CAE7D,CAAA"}
@@ -0,0 +1,6 @@
1
+ const mockedTenancyMeta = {
2
+ tenancy: void 0
3
+ };
4
+ export {
5
+ mockedTenancyMeta
6
+ };
@@ -1,8 +1,18 @@
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
1
4
  import { afterAll, afterEach, beforeAll } from "vitest";
2
5
  import { getPaths } from "@cedarjs/project-config";
3
6
  import { findCellMocks } from "../findCellMocks.js";
4
- import { closeServer, setupRequestHandlers, startMSW } from "../mockRequests.js";
7
+ import {
8
+ closeServer,
9
+ mockRouteParams,
10
+ setupRequestHandlers,
11
+ startMSW
12
+ } from "../mockRequests.js";
13
+ let clearOrgClients;
5
14
  beforeAll(async () => {
15
+ clearOrgClients = await importClearOrgClients();
6
16
  const cellMocks = findCellMocks(getPaths().web.src);
7
17
  for (const m of cellMocks) {
8
18
  await import(m);
@@ -10,9 +20,29 @@ beforeAll(async () => {
10
20
  await startMSW("node");
11
21
  setupRequestHandlers();
12
22
  });
13
- afterEach(() => {
23
+ afterEach(async () => {
14
24
  setupRequestHandlers();
25
+ mockRouteParams({});
26
+ await clearOrgClients?.();
15
27
  });
16
28
  afterAll(() => {
17
29
  closeServer();
18
30
  });
31
+ async function importClearOrgClients() {
32
+ let tenancyWebPath;
33
+ try {
34
+ tenancyWebPath = createRequire(
35
+ path.join(getPaths().web.base, "package.json")
36
+ ).resolve("@cedarjs/tenancy/web");
37
+ } catch {
38
+ return void 0;
39
+ }
40
+ const tenancyWeb = await import(pathToFileURL(tenancyWebPath).href);
41
+ if (tenancyWeb && typeof tenancyWeb === "object" && "clearOrgClients" in tenancyWeb && typeof tenancyWeb.clearOrgClients === "function") {
42
+ const clear = tenancyWeb.clearOrgClients;
43
+ return async () => {
44
+ await clear();
45
+ };
46
+ }
47
+ return void 0;
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/testing",
3
- "version": "8.0.0-canary.3557",
3
+ "version": "8.0.0-canary.3560",
4
4
  "description": "Tools, wrappers and configuration for testing a Cedar project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,9 +54,9 @@
54
54
  "test:watch": "vitest watch"
55
55
  },
56
56
  "dependencies": {
57
- "@cedarjs/context": "8.0.0-canary.3557",
58
- "@cedarjs/graphql-server": "8.0.0-canary.3557",
59
- "@cedarjs/project-config": "8.0.0-canary.3557",
57
+ "@cedarjs/context": "8.0.0-canary.3560",
58
+ "@cedarjs/graphql-server": "8.0.0-canary.3560",
59
+ "@cedarjs/project-config": "8.0.0-canary.3560",
60
60
  "@prisma/internals": "7.10.1",
61
61
  "@testing-library/dom": "10.4.2",
62
62
  "@testing-library/jest-dom": "6.9.1",
@@ -64,7 +64,7 @@
64
64
  "@testing-library/user-event": "14.6.8",
65
65
  "@types/aws-lambda": "8.10.164",
66
66
  "@types/jest": "29.5.14",
67
- "@types/node": "24.10.4",
67
+ "@types/node": "24.19.2",
68
68
  "ansis": "4.4.0",
69
69
  "fast-glob": "3.3.3",
70
70
  "jsdom": "27.4.0",
@@ -74,19 +74,19 @@
74
74
  },
75
75
  "devDependencies": {
76
76
  "@arethetypeswrong/cli": "0.18.5",
77
- "@cedarjs/auth": "8.0.0-canary.3557",
78
- "@cedarjs/framework-tools": "8.0.0-canary.3557",
79
- "@cedarjs/router": "8.0.0-canary.3557",
80
- "@cedarjs/web": "8.0.0-canary.3557",
77
+ "@cedarjs/auth": "8.0.0-canary.3560",
78
+ "@cedarjs/framework-tools": "8.0.0-canary.3560",
79
+ "@cedarjs/router": "8.0.0-canary.3560",
80
+ "@cedarjs/web": "8.0.0-canary.3560",
81
81
  "concurrently": "9.2.5",
82
82
  "publint": "0.3.25",
83
83
  "typescript": "5.9.3",
84
84
  "vitest": "4.1.12"
85
85
  },
86
86
  "peerDependencies": {
87
- "@cedarjs/auth": "8.0.0-canary.3557",
88
- "@cedarjs/router": "8.0.0-canary.3557",
89
- "@cedarjs/web": "8.0.0-canary.3557",
87
+ "@cedarjs/auth": "8.0.0-canary.3560",
88
+ "@cedarjs/router": "8.0.0-canary.3560",
89
+ "@cedarjs/web": "8.0.0-canary.3560",
90
90
  "vitest": "4.1.12"
91
91
  },
92
92
  "peerDependenciesMeta": {