@sprucelabs/spruce-test-fixtures 52.7.14 → 52.8.0

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,3 +1,4 @@
1
+ import { AuthorizerCanOptions } from '@sprucelabs/heartwood-view-controllers';
1
2
  import AbstractSpruceFixtureTest from '../../../tests/AbstractSpruceFixtureTest';
2
3
  export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
3
4
  private static contractId;
@@ -19,6 +20,8 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
19
20
  protected static sameAuthorizerAsViews(): Promise<void>;
20
21
  protected static sameAuthenticatorAsViews(): Promise<void>;
21
22
  protected static canSpyOnSavePermissions(): Promise<void>;
23
+ protected static canSeeLastCanOptions(can: AuthorizerCanOptions<any>): Promise<void>;
24
+ private static assertCanOptionsMatch;
22
25
  private static assertSpysOnOptionsWhenSaving;
23
26
  private static assertPermNotFound;
24
27
  private static changeContractId;
@@ -136,6 +136,31 @@ class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
136
136
  ],
137
137
  });
138
138
  }
139
+ static async canSeeLastCanOptions(can) {
140
+ await this.assertCanOptionsMatch(can);
141
+ }
142
+ static async assertCanOptionsMatch(can) {
143
+ const { contractId } = can;
144
+ this.auth.fakePermissions({
145
+ contractId: contractId,
146
+ permissions: [
147
+ {
148
+ id: 'can-register-global-events',
149
+ can: true,
150
+ },
151
+ {
152
+ id: 'can-register-global-events-2',
153
+ can: true,
154
+ },
155
+ {
156
+ id: 'can-register-global-events-3',
157
+ can: true,
158
+ },
159
+ ],
160
+ });
161
+ await this.auth.can(can);
162
+ test_utils_1.assert.isEqualDeep(this.auth.getLastCanOptions(), can);
163
+ }
139
164
  static async assertSpysOnOptionsWhenSaving(options) {
140
165
  await this.auth.savePermissions(options);
141
166
  test_utils_1.assert.isEqualDeep(this.auth.getLastSavePermissionsOptions(), options);
@@ -227,4 +252,21 @@ __decorate([
227
252
  __decorate([
228
253
  (0, test_utils_1.test)()
229
254
  ], CheckingPermissionsTest, "canSpyOnSavePermissions", null);
255
+ __decorate([
256
+ (0, test_utils_1.test)('can see last can options 1', {
257
+ contractId: 'events-contract',
258
+ permissionIds: ['can-register-global-events'],
259
+ target: {},
260
+ }),
261
+ (0, test_utils_1.test)('can see last can options 2', {
262
+ contractId: 'events-contract-2',
263
+ permissionIds: [
264
+ 'can-register-global-events',
265
+ 'can-register-global-events-2',
266
+ ],
267
+ target: {
268
+ personId: (0, test_utils_2.generateId)(),
269
+ },
270
+ })
271
+ ], CheckingPermissionsTest, "canSeeLastCanOptions", null);
230
272
  exports.default = CheckingPermissionsTest;
@@ -1,3 +1,4 @@
1
+ import { AuthorizerCanOptions } from '@sprucelabs/heartwood-view-controllers';
1
2
  import AbstractSpruceFixtureTest from '../../../tests/AbstractSpruceFixtureTest';
2
3
  export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
3
4
  private static contractId;
@@ -19,6 +20,8 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
19
20
  protected static sameAuthorizerAsViews(): Promise<void>;
20
21
  protected static sameAuthenticatorAsViews(): Promise<void>;
21
22
  protected static canSpyOnSavePermissions(): Promise<void>;
23
+ protected static canSeeLastCanOptions(can: AuthorizerCanOptions<any>): Promise<void>;
24
+ private static assertCanOptionsMatch;
22
25
  private static assertSpysOnOptionsWhenSaving;
23
26
  private static assertPermNotFound;
24
27
  private static changeContractId;
@@ -179,6 +179,35 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
179
179
  });
180
180
  });
181
181
  }
182
+ static canSeeLastCanOptions(can) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ yield this.assertCanOptionsMatch(can);
185
+ });
186
+ }
187
+ static assertCanOptionsMatch(can) {
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ const { contractId } = can;
190
+ this.auth.fakePermissions({
191
+ contractId: contractId,
192
+ permissions: [
193
+ {
194
+ id: 'can-register-global-events',
195
+ can: true,
196
+ },
197
+ {
198
+ id: 'can-register-global-events-2',
199
+ can: true,
200
+ },
201
+ {
202
+ id: 'can-register-global-events-3',
203
+ can: true,
204
+ },
205
+ ],
206
+ });
207
+ yield this.auth.can(can);
208
+ assert.isEqualDeep(this.auth.getLastCanOptions(), can);
209
+ });
210
+ }
182
211
  static assertSpysOnOptionsWhenSaving(options) {
183
212
  return __awaiter(this, void 0, void 0, function* () {
184
213
  yield this.auth.savePermissions(options);
@@ -276,3 +305,20 @@ __decorate([
276
305
  __decorate([
277
306
  test()
278
307
  ], CheckingPermissionsTest, "canSpyOnSavePermissions", null);
308
+ __decorate([
309
+ test('can see last can options 1', {
310
+ contractId: 'events-contract',
311
+ permissionIds: ['can-register-global-events'],
312
+ target: {},
313
+ }),
314
+ test('can see last can options 2', {
315
+ contractId: 'events-contract-2',
316
+ permissionIds: [
317
+ 'can-register-global-events',
318
+ 'can-register-global-events-2',
319
+ ],
320
+ target: {
321
+ personId: generateId(),
322
+ },
323
+ })
324
+ ], CheckingPermissionsTest, "canSeeLastCanOptions", null);
@@ -3,8 +3,10 @@ import { PermissionContractId, PermissionId } from '@sprucelabs/mercury-types';
3
3
  export default class FakeAuthorizer implements Authorizer {
4
4
  private fakedContracts;
5
5
  private lastSavePermissionOptions?;
6
+ private lastCanOptions?;
6
7
  fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakeOptions<ContractId>): void;
7
8
  can<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: AuthorizerCanOptions<ContractId, Ids>): Promise<Record<Ids, boolean>>;
9
+ getLastCanOptions(): AuthorizerCanOptions<any> | undefined;
8
10
  savePermissions<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: SavePermissionsOptions<ContractId, Ids>): Promise<void>;
9
11
  getLastSavePermissionsOptions<ContractId extends PermissionContractId = PermissionContractId, Ids extends PermissionId<ContractId> = PermissionId<ContractId>>(): SavePermissionsOptions<ContractId, Ids>;
10
12
  private assertValidPermission;
@@ -18,6 +18,7 @@ export default class FakeAuthorizer {
18
18
  }
19
19
  can(options) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
+ this.lastCanOptions = options;
21
22
  const { contractId, permissionIds } = assertOptions(options, ['contractId', 'permissionIds']);
22
23
  const fakedContract = this.fakedContracts.find((f) => f.contractId === contractId);
23
24
  this.assertValidContractId(fakedContract, contractId);
@@ -31,6 +32,9 @@ export default class FakeAuthorizer {
31
32
  return results;
32
33
  });
33
34
  }
35
+ getLastCanOptions() {
36
+ return this.lastCanOptions;
37
+ }
34
38
  savePermissions(options) {
35
39
  return __awaiter(this, void 0, void 0, function* () {
36
40
  this.lastSavePermissionOptions = options;
@@ -3,8 +3,10 @@ import { PermissionContractId, PermissionId } from '@sprucelabs/mercury-types';
3
3
  export default class FakeAuthorizer implements Authorizer {
4
4
  private fakedContracts;
5
5
  private lastSavePermissionOptions?;
6
+ private lastCanOptions?;
6
7
  fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakeOptions<ContractId>): void;
7
8
  can<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: AuthorizerCanOptions<ContractId, Ids>): Promise<Record<Ids, boolean>>;
9
+ getLastCanOptions(): AuthorizerCanOptions<any> | undefined;
8
10
  savePermissions<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: SavePermissionsOptions<ContractId, Ids>): Promise<void>;
9
11
  getLastSavePermissionsOptions<ContractId extends PermissionContractId = PermissionContractId, Ids extends PermissionId<ContractId> = PermissionId<ContractId>>(): SavePermissionsOptions<ContractId, Ids>;
10
12
  private assertValidPermission;
@@ -10,6 +10,7 @@ class FakeAuthorizer {
10
10
  this.fakedContracts.unshift(options);
11
11
  }
12
12
  async can(options) {
13
+ this.lastCanOptions = options;
13
14
  const { contractId, permissionIds } = (0, schema_1.assertOptions)(options, ['contractId', 'permissionIds']);
14
15
  const fakedContract = this.fakedContracts.find((f) => f.contractId === contractId);
15
16
  this.assertValidContractId(fakedContract, contractId);
@@ -22,6 +23,9 @@ class FakeAuthorizer {
22
23
  }
23
24
  return results;
24
25
  }
26
+ getLastCanOptions() {
27
+ return this.lastCanOptions;
28
+ }
25
29
  async savePermissions(options) {
26
30
  this.lastSavePermissionOptions = options;
27
31
  }
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "@sprucelabs/spruce-test-fixtures"
14
14
  ]
15
15
  },
16
- "version": "52.7.14",
16
+ "version": "52.8.0",
17
17
  "files": [
18
18
  "build/**/*",
19
19
  "!build/__tests__",
@@ -64,15 +64,15 @@
64
64
  "dependencies": {
65
65
  "@sprucelabs/data-stores": "^19.1.66",
66
66
  "@sprucelabs/error": "^5.0.580",
67
- "@sprucelabs/heartwood-view-controllers": "^100.8.13",
68
- "@sprucelabs/mercury-client": "^35.0.150",
69
- "@sprucelabs/mercury-core-events": "^15.3.10",
70
- "@sprucelabs/mercury-event-emitter": "^35.0.150",
67
+ "@sprucelabs/heartwood-view-controllers": "^100.8.14",
68
+ "@sprucelabs/mercury-client": "^35.0.151",
69
+ "@sprucelabs/mercury-core-events": "^15.3.11",
70
+ "@sprucelabs/mercury-event-emitter": "^35.0.151",
71
71
  "@sprucelabs/schema": "^28.5.127",
72
72
  "@sprucelabs/spruce-core-schemas": "^35.1.171",
73
73
  "@sprucelabs/spruce-event-utils": "^30.0.124",
74
- "@sprucelabs/spruce-permission-utils": "^1.2.35",
75
- "@sprucelabs/spruce-skill-booter": "^52.7.14",
74
+ "@sprucelabs/spruce-permission-utils": "^1.2.37",
75
+ "@sprucelabs/spruce-skill-booter": "^52.8.0",
76
76
  "@sprucelabs/spruce-skill-utils": "^28.1.78",
77
77
  "@sprucelabs/test-utils": "^3.3.9",
78
78
  "dotenv": "^16.0.3",
@@ -132,5 +132,5 @@
132
132
  ]
133
133
  ]
134
134
  },
135
- "gitHead": "e7d2f9208b08bc10e4c7595c1ad027d15417f445"
135
+ "gitHead": "db2a51377ffaad5681871b810003eac31fea62f5"
136
136
  }