@sprucelabs/spruce-test-fixtures 66.0.44 → 66.0.45

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,11 +1,11 @@
1
1
  import { Authorizer, AuthorizerCanOptions, AuthorizerDoesHonorOptions, SavePermissionsOptions } from '@sprucelabs/heartwood-view-controllers';
2
- import { PermissionContractId, PermissionId } from '@sprucelabs/mercury-types';
2
+ import { PermissionContractId, PermissionId, SpruceSchemas } from '@sprucelabs/mercury-types';
3
3
  export default class FakeAuthorizer implements Authorizer {
4
4
  private fakedContracts;
5
5
  private lastSavePermissionOptions?;
6
6
  private lastCanOptions?;
7
7
  private lastDoesHonorContractOptions?;
8
- fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakeOptions<ContractId>): void;
8
+ fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakePermissionOptions<ContractId>): void;
9
9
  can<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: AuthorizerCanOptions<ContractId, Ids>): Promise<Record<Ids, boolean>>;
10
10
  private getContractFromId;
11
11
  getLastCanOptions(): AuthorizerCanOptions<any> | undefined;
@@ -20,8 +20,10 @@ interface Perm<ContractId extends PermissionContractId> {
20
20
  id: PermissionId<ContractId>;
21
21
  can: boolean;
22
22
  }
23
- interface FakeOptions<ContractId extends PermissionContractId = PermissionContractId> {
23
+ export type PermissionContractTarget = SpruceSchemas.Mercury.v2020_12_25.DoesHonorPermissionContractEmitTarget;
24
+ export interface FakePermissionOptions<ContractId extends PermissionContractId = PermissionContractId> {
24
25
  contractId: ContractId;
25
26
  permissions: Perm<ContractId>[];
27
+ target?: PermissionContractTarget;
26
28
  }
27
29
  export {};
@@ -18,15 +18,20 @@ export default class FakeAuthorizer {
18
18
  }
19
19
  can(options) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
+ var _a, _b;
21
22
  this.lastCanOptions = options;
22
- const { contractId, permissionIds } = assertOptions(options, ['contractId', 'permissionIds']);
23
+ const { contractId, permissionIds, target } = assertOptions(options, ['contractId', 'permissionIds']);
23
24
  const fakedContract = this.getContractFromId(contractId);
24
25
  const results = {};
25
26
  permissionIds.reverse();
26
27
  for (const actual of permissionIds) {
27
28
  const fakedPerm = fakedContract.permissions.find((p) => p.id === actual);
28
29
  this.assertValidPermission(fakedPerm, actual, fakedContract);
29
- results[fakedPerm.id] = fakedPerm.can;
30
+ results[fakedPerm.id] =
31
+ fakedPerm.can &&
32
+ ((_a = fakedContract.target) === null || _a === void 0 ? void 0 : _a.organizationId) ===
33
+ (target === null || target === void 0 ? void 0 : target.organizationId) &&
34
+ ((_b = fakedContract.target) === null || _b === void 0 ? void 0 : _b.locationId) === (target === null || target === void 0 ? void 0 : target.locationId);
30
35
  }
31
36
  return results;
32
37
  });
@@ -61,6 +66,7 @@ Valid contracts are:
61
66
 
62
67
  ${this.fakedContracts.map((p) => p.contractId).join('\n')}`);
63
68
  }
69
+ // WARNING - does not yet support targetting
64
70
  doesHonorPermissionContract(options) {
65
71
  return __awaiter(this, void 0, void 0, function* () {
66
72
  const { contractId } = assertOptions(options, ['contractId']);
@@ -1,11 +1,11 @@
1
1
  import { Authorizer, AuthorizerCanOptions, AuthorizerDoesHonorOptions, SavePermissionsOptions } from '@sprucelabs/heartwood-view-controllers';
2
- import { PermissionContractId, PermissionId } from '@sprucelabs/mercury-types';
2
+ import { PermissionContractId, PermissionId, SpruceSchemas } from '@sprucelabs/mercury-types';
3
3
  export default class FakeAuthorizer implements Authorizer {
4
4
  private fakedContracts;
5
5
  private lastSavePermissionOptions?;
6
6
  private lastCanOptions?;
7
7
  private lastDoesHonorContractOptions?;
8
- fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakeOptions<ContractId>): void;
8
+ fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakePermissionOptions<ContractId>): void;
9
9
  can<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: AuthorizerCanOptions<ContractId, Ids>): Promise<Record<Ids, boolean>>;
10
10
  private getContractFromId;
11
11
  getLastCanOptions(): AuthorizerCanOptions<any> | undefined;
@@ -20,8 +20,10 @@ interface Perm<ContractId extends PermissionContractId> {
20
20
  id: PermissionId<ContractId>;
21
21
  can: boolean;
22
22
  }
23
- interface FakeOptions<ContractId extends PermissionContractId = PermissionContractId> {
23
+ export type PermissionContractTarget = SpruceSchemas.Mercury.v2020_12_25.DoesHonorPermissionContractEmitTarget;
24
+ export interface FakePermissionOptions<ContractId extends PermissionContractId = PermissionContractId> {
24
25
  contractId: ContractId;
25
26
  permissions: Perm<ContractId>[];
27
+ target?: PermissionContractTarget;
26
28
  }
27
29
  export {};
@@ -11,14 +11,18 @@ class FakeAuthorizer {
11
11
  }
12
12
  async can(options) {
13
13
  this.lastCanOptions = options;
14
- const { contractId, permissionIds } = (0, schema_1.assertOptions)(options, ['contractId', 'permissionIds']);
14
+ const { contractId, permissionIds, target } = (0, schema_1.assertOptions)(options, ['contractId', 'permissionIds']);
15
15
  const fakedContract = this.getContractFromId(contractId);
16
16
  const results = {};
17
17
  permissionIds.reverse();
18
18
  for (const actual of permissionIds) {
19
19
  const fakedPerm = fakedContract.permissions.find((p) => p.id === actual);
20
20
  this.assertValidPermission(fakedPerm, actual, fakedContract);
21
- results[fakedPerm.id] = fakedPerm.can;
21
+ results[fakedPerm.id] =
22
+ fakedPerm.can &&
23
+ fakedContract.target?.organizationId ===
24
+ target?.organizationId &&
25
+ fakedContract.target?.locationId === target?.locationId;
22
26
  }
23
27
  return results;
24
28
  }
@@ -50,6 +54,7 @@ Valid contracts are:
50
54
 
51
55
  ${this.fakedContracts.map((p) => p.contractId).join('\n')}`);
52
56
  }
57
+ // WARNING - does not yet support targetting
53
58
  async doesHonorPermissionContract(options) {
54
59
  const { contractId } = (0, schema_1.assertOptions)(options, ['contractId']);
55
60
  this.lastDoesHonorContractOptions = options;
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "@sprucelabs/spruce-test-fixtures"
14
14
  ]
15
15
  },
16
- "version": "66.0.44",
16
+ "version": "66.0.45",
17
17
  "files": [
18
18
  "build/**/*",
19
19
  "!build/__tests__",
@@ -71,7 +71,7 @@
71
71
  "@sprucelabs/spruce-core-schemas": "^40.1.658",
72
72
  "@sprucelabs/spruce-event-utils": "^40.2.61",
73
73
  "@sprucelabs/spruce-permission-utils": "^12.0.62",
74
- "@sprucelabs/spruce-skill-booter": "^66.0.44",
74
+ "@sprucelabs/spruce-skill-booter": "^66.0.45",
75
75
  "@sprucelabs/spruce-skill-utils": "^31.2.73",
76
76
  "@sprucelabs/test-utils": "^5.5.27",
77
77
  "dotenv": "^16.4.7",
@@ -114,5 +114,5 @@
114
114
  "^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
115
115
  }
116
116
  },
117
- "gitHead": "ae9e2b9734348668ff3f4ef7297bd38f9cb5576c"
117
+ "gitHead": "ef8325143492f7b181d2d4e6b6affb405927d62c"
118
118
  }