@sprucelabs/spruce-test-fixtures 52.5.5 → 52.5.7

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 (37) hide show
  1. package/build/__tests__/behavioral/ResettingFixtureFieldsBeforeEach.test.js +7 -0
  2. package/build/__tests__/behavioral/permissions/FakeAuthorizer.test.d.ts +1 -1
  3. package/build/__tests__/behavioral/permissions/FakeAuthorizer.test.js +7 -7
  4. package/build/__tests__/behavioral/permissions/PermissionFixture.test.d.ts +5 -0
  5. package/build/__tests__/behavioral/permissions/{TestingWithPermissions.test.js → PermissionFixture.test.js} +14 -5
  6. package/build/esm/__tests__/behavioral/ResettingFixtureFieldsBeforeEach.test.js +7 -0
  7. package/build/esm/__tests__/behavioral/permissions/FakeAuthorizer.test.d.ts +1 -1
  8. package/build/esm/__tests__/behavioral/permissions/FakeAuthorizer.test.js +7 -7
  9. package/build/esm/__tests__/behavioral/permissions/PermissionFixture.test.d.ts +5 -0
  10. package/build/esm/__tests__/behavioral/permissions/{TestingWithPermissions.test.js → PermissionFixture.test.js} +16 -5
  11. package/build/esm/tests/AbstractSpruceFixtureTest.d.ts +33 -30
  12. package/build/esm/tests/AbstractSpruceFixtureTest.js +102 -84
  13. package/build/esm/tests/FakeAuthorizer.d.ts +0 -3
  14. package/build/esm/tests/FakeAuthorizer.js +1 -10
  15. package/build/esm/tests/fixtures/FixtureFactory.d.ts +2 -0
  16. package/build/esm/tests/fixtures/FixtureFactory.js +8 -2
  17. package/build/esm/tests/fixtures/PermissionFixture.d.ts +3 -0
  18. package/build/esm/tests/fixtures/PermissionFixture.js +8 -1
  19. package/build/esm/tests/fixtures/ViewFixture.d.ts +4 -2
  20. package/build/esm/tests/fixtures/ViewFixture.js +5 -5
  21. package/build/esm/tests/routers/TestRouter.d.ts +4 -1
  22. package/build/esm/tests/routers/TestRouter.js +4 -2
  23. package/build/tests/AbstractSpruceFixtureTest.d.ts +33 -30
  24. package/build/tests/AbstractSpruceFixtureTest.js +73 -60
  25. package/build/tests/FakeAuthorizer.d.ts +0 -3
  26. package/build/tests/FakeAuthorizer.js +1 -10
  27. package/build/tests/fixtures/FixtureFactory.d.ts +2 -0
  28. package/build/tests/fixtures/FixtureFactory.js +8 -2
  29. package/build/tests/fixtures/PermissionFixture.d.ts +3 -0
  30. package/build/tests/fixtures/PermissionFixture.js +8 -1
  31. package/build/tests/fixtures/ViewFixture.d.ts +4 -2
  32. package/build/tests/fixtures/ViewFixture.js +5 -5
  33. package/build/tests/routers/TestRouter.d.ts +4 -1
  34. package/build/tests/routers/TestRouter.js +4 -2
  35. package/package.json +5 -4
  36. package/build/__tests__/behavioral/permissions/TestingWithPermissions.test.d.ts +0 -4
  37. package/build/esm/__tests__/behavioral/permissions/TestingWithPermissions.test.d.ts +0 -4
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const data_stores_1 = require("@sprucelabs/data-stores");
13
13
  const test_utils_1 = require("@sprucelabs/test-utils");
14
14
  const __1 = require("../..");
15
+ const PermissionFixture_1 = __importDefault(require("../../tests/fixtures/PermissionFixture"));
15
16
  const SeedFixture_1 = __importDefault(require("../../tests/fixtures/SeedFixture"));
16
17
  const toCheck = [
17
18
  {
@@ -74,6 +75,12 @@ const toCheck = [
74
75
  fixtureName: 'store',
75
76
  instanceOf: __1.StoreFixture,
76
77
  },
78
+ {
79
+ prop: 'permissions',
80
+ privatePropName: '_permissions',
81
+ fixtureName: 'permission',
82
+ instanceOf: PermissionFixture_1.default,
83
+ },
77
84
  ];
78
85
  class ResettingFixtureFieldsBeforeEachTest extends __1.AbstractSpruceFixtureTest {
79
86
  static shouldBeAbleToGetAllFixtures() {
@@ -4,7 +4,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
4
4
  protected static beforeEach(): Promise<void>;
5
5
  protected static canCreateCheckingPermissions(): Promise<void>;
6
6
  protected static sharesInstances(): Promise<void>;
7
- protected static viewsFixtureResetsInstance(): Promise<void>;
7
+ protected static permsFixtureResetsInstance(): Promise<void>;
8
8
  protected static throwsWhenMissingOnCan(): Promise<void>;
9
9
  protected static throwsWhenNotSettingResponse(): Promise<void>;
10
10
  protected static throwsWhenContractIdNotFaked(): Promise<void>;
@@ -13,7 +13,7 @@ const test_utils_1 = require("@sprucelabs/test-utils");
13
13
  const test_utils_2 = require("@sprucelabs/test-utils");
14
14
  const AbstractSpruceFixtureTest_1 = __importDefault(require("../../../tests/AbstractSpruceFixtureTest"));
15
15
  const FakeAuthorizer_1 = __importDefault(require("../../../tests/FakeAuthorizer"));
16
- const ViewFixture_1 = __importDefault(require("../../../tests/fixtures/ViewFixture"));
16
+ const PermissionFixture_1 = __importDefault(require("../../../tests/fixtures/PermissionFixture"));
17
17
  class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
18
18
  static async beforeEach() {
19
19
  await super.beforeEach();
@@ -25,9 +25,9 @@ class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
25
25
  static async sharesInstances() {
26
26
  test_utils_1.assert.isEqual(this.instance, this.instance);
27
27
  }
28
- static async viewsFixtureResetsInstance() {
28
+ static async permsFixtureResetsInstance() {
29
29
  const instance = this.instance;
30
- await ViewFixture_1.default.beforeEach();
30
+ PermissionFixture_1.default.beforeEach();
31
31
  test_utils_1.assert.isNotEqual(this.instance, instance);
32
32
  }
33
33
  static async throwsWhenMissingOnCan() {
@@ -70,7 +70,7 @@ class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
70
70
  }
71
71
  static async fixtureAndLoadOptionsShareAuthorizer() {
72
72
  this.setupEmptyViewFixture();
73
- const auth = this.views.getAuthorizer();
73
+ const auth = this.permissions.getAuthorizer();
74
74
  const router = this.views.getRouter();
75
75
  test_utils_1.assert.isEqual(auth, router.buildLoadOptions().authorizer);
76
76
  }
@@ -121,7 +121,7 @@ class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
121
121
  this.contractId = (0, test_utils_2.generateId)();
122
122
  }
123
123
  static async assertThrowsFakeError() {
124
- await test_utils_1.assert.doesThrowAsync(() => this.can(['test']), `Contract by the id '${this.contractId}'`);
124
+ await test_utils_1.assert.doesThrowAsync(() => this.can(['test']), `Contract with the id '${this.contractId}'`);
125
125
  }
126
126
  static fakePermissions(faked) {
127
127
  this.instance.fakePermissions({
@@ -141,7 +141,7 @@ class CheckingPermissionsTest extends AbstractSpruceFixtureTest_1.default {
141
141
  });
142
142
  }
143
143
  static get instance() {
144
- return FakeAuthorizer_1.default.getInstance();
144
+ return this.permissions.getAuthorizer();
145
145
  }
146
146
  }
147
147
  __decorate([
@@ -152,7 +152,7 @@ __decorate([
152
152
  ], CheckingPermissionsTest, "sharesInstances", null);
153
153
  __decorate([
154
154
  (0, test_utils_1.test)()
155
- ], CheckingPermissionsTest, "viewsFixtureResetsInstance", null);
155
+ ], CheckingPermissionsTest, "permsFixtureResetsInstance", null);
156
156
  __decorate([
157
157
  (0, test_utils_1.test)()
158
158
  ], CheckingPermissionsTest, "throwsWhenMissingOnCan", null);
@@ -0,0 +1,5 @@
1
+ import AbstractSpruceFixtureTest from '../../../tests/AbstractSpruceFixtureTest';
2
+ export default class PermissionFixtureTest extends AbstractSpruceFixtureTest {
3
+ protected static disablesPermissionsAtStart(): Promise<void>;
4
+ protected static permissionFixtureShouldUseSharedInstance(): Promise<void>;
5
+ }
@@ -9,18 +9,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const spruce_permission_utils_1 = require("@sprucelabs/spruce-permission-utils");
12
13
  const test_utils_1 = require("@sprucelabs/test-utils");
13
14
  const AbstractSpruceFixtureTest_1 = __importDefault(require("../../../tests/AbstractSpruceFixtureTest"));
14
15
  const fake_1 = __importDefault(require("../../../tests/decorators/fake"));
15
- let DisablingPermissionsInTestsTest = class DisablingPermissionsInTestsTest extends AbstractSpruceFixtureTest_1.default {
16
+ let PermissionFixtureTest = class PermissionFixtureTest extends AbstractSpruceFixtureTest_1.default {
16
17
  static async disablesPermissionsAtStart() {
17
18
  test_utils_1.assert.isEqual(process.env.SHOULD_REGISTER_PERMISSIONS, 'false');
18
19
  }
20
+ static async permissionFixtureShouldUseSharedInstance() {
21
+ const actual = this.permissions.getAuthorizer();
22
+ const expected = spruce_permission_utils_1.AuthorizerFactory.getInstance();
23
+ test_utils_1.assert.isEqual(actual, expected);
24
+ }
19
25
  };
20
26
  __decorate([
21
27
  (0, test_utils_1.test)()
22
- ], DisablingPermissionsInTestsTest, "disablesPermissionsAtStart", null);
23
- DisablingPermissionsInTestsTest = __decorate([
28
+ ], PermissionFixtureTest, "disablesPermissionsAtStart", null);
29
+ __decorate([
30
+ (0, test_utils_1.test)()
31
+ ], PermissionFixtureTest, "permissionFixtureShouldUseSharedInstance", null);
32
+ PermissionFixtureTest = __decorate([
24
33
  fake_1.default.login()
25
- ], DisablingPermissionsInTestsTest);
26
- exports.default = DisablingPermissionsInTestsTest;
34
+ ], PermissionFixtureTest);
35
+ exports.default = PermissionFixtureTest;
@@ -16,6 +16,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
16
16
  import { DatabaseFixture } from '@sprucelabs/data-stores';
17
17
  import { assert, test } from '@sprucelabs/test-utils';
18
18
  import { AbstractSpruceFixtureTest, LocationFixture, MercuryFixture, OrganizationFixture, PersonFixture, RoleFixture, SkillFixture, StoreFixture, ViewFixture, } from '../../index.js';
19
+ import PermissionFixture from '../../tests/fixtures/PermissionFixture.js';
19
20
  import SeedFixture from '../../tests/fixtures/SeedFixture.js';
20
21
  const toCheck = [
21
22
  {
@@ -78,6 +79,12 @@ const toCheck = [
78
79
  fixtureName: 'store',
79
80
  instanceOf: StoreFixture,
80
81
  },
82
+ {
83
+ prop: 'permissions',
84
+ privatePropName: '_permissions',
85
+ fixtureName: 'permission',
86
+ instanceOf: PermissionFixture,
87
+ },
81
88
  ];
82
89
  export default class ResettingFixtureFieldsBeforeEachTest extends AbstractSpruceFixtureTest {
83
90
  static shouldBeAbleToGetAllFixtures() {
@@ -4,7 +4,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
4
4
  protected static beforeEach(): Promise<void>;
5
5
  protected static canCreateCheckingPermissions(): Promise<void>;
6
6
  protected static sharesInstances(): Promise<void>;
7
- protected static viewsFixtureResetsInstance(): Promise<void>;
7
+ protected static permsFixtureResetsInstance(): Promise<void>;
8
8
  protected static throwsWhenMissingOnCan(): Promise<void>;
9
9
  protected static throwsWhenNotSettingResponse(): Promise<void>;
10
10
  protected static throwsWhenContractIdNotFaked(): Promise<void>;
@@ -17,7 +17,7 @@ import { test, assert } from '@sprucelabs/test-utils';
17
17
  import { errorAssert, generateId } from '@sprucelabs/test-utils';
18
18
  import AbstractSpruceFixtureTest from '../../../tests/AbstractSpruceFixtureTest.js';
19
19
  import FakeAuthorizer from '../../../tests/FakeAuthorizer.js';
20
- import ViewFixture from '../../../tests/fixtures/ViewFixture.js';
20
+ import PermissionFixture from '../../../tests/fixtures/PermissionFixture.js';
21
21
  export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
22
22
  static beforeEach() {
23
23
  const _super = Object.create(null, {
@@ -38,10 +38,10 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
38
38
  assert.isEqual(this.instance, this.instance);
39
39
  });
40
40
  }
41
- static viewsFixtureResetsInstance() {
41
+ static permsFixtureResetsInstance() {
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
43
  const instance = this.instance;
44
- yield ViewFixture.beforeEach();
44
+ PermissionFixture.beforeEach();
45
45
  assert.isNotEqual(this.instance, instance);
46
46
  });
47
47
  }
@@ -100,7 +100,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
100
100
  static fixtureAndLoadOptionsShareAuthorizer() {
101
101
  return __awaiter(this, void 0, void 0, function* () {
102
102
  this.setupEmptyViewFixture();
103
- const auth = this.views.getAuthorizer();
103
+ const auth = this.permissions.getAuthorizer();
104
104
  const router = this.views.getRouter();
105
105
  assert.isEqual(auth, router.buildLoadOptions().authorizer);
106
106
  });
@@ -165,7 +165,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
165
165
  }
166
166
  static assertThrowsFakeError() {
167
167
  return __awaiter(this, void 0, void 0, function* () {
168
- yield assert.doesThrowAsync(() => this.can(['test']), `Contract by the id '${this.contractId}'`);
168
+ yield assert.doesThrowAsync(() => this.can(['test']), `Contract with the id '${this.contractId}'`);
169
169
  });
170
170
  }
171
171
  static fakePermissions(faked) {
@@ -186,7 +186,7 @@ export default class CheckingPermissionsTest extends AbstractSpruceFixtureTest {
186
186
  });
187
187
  }
188
188
  static get instance() {
189
- return FakeAuthorizer.getInstance();
189
+ return this.permissions.getAuthorizer();
190
190
  }
191
191
  }
192
192
  __decorate([
@@ -197,7 +197,7 @@ __decorate([
197
197
  ], CheckingPermissionsTest, "sharesInstances", null);
198
198
  __decorate([
199
199
  test()
200
- ], CheckingPermissionsTest, "viewsFixtureResetsInstance", null);
200
+ ], CheckingPermissionsTest, "permsFixtureResetsInstance", null);
201
201
  __decorate([
202
202
  test()
203
203
  ], CheckingPermissionsTest, "throwsWhenMissingOnCan", null);
@@ -0,0 +1,5 @@
1
+ import AbstractSpruceFixtureTest from '../../../tests/AbstractSpruceFixtureTest';
2
+ export default class PermissionFixtureTest extends AbstractSpruceFixtureTest {
3
+ protected static disablesPermissionsAtStart(): Promise<void>;
4
+ protected static permissionFixtureShouldUseSharedInstance(): Promise<void>;
5
+ }
@@ -13,20 +13,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14
14
  });
15
15
  };
16
+ import { AuthorizerFactory } from '@sprucelabs/spruce-permission-utils';
16
17
  import { test, assert } from '@sprucelabs/test-utils';
17
18
  import AbstractSpruceFixtureTest from '../../../tests/AbstractSpruceFixtureTest.js';
18
19
  import fake from '../../../tests/decorators/fake.js';
19
- let DisablingPermissionsInTestsTest = class DisablingPermissionsInTestsTest extends AbstractSpruceFixtureTest {
20
+ let PermissionFixtureTest = class PermissionFixtureTest extends AbstractSpruceFixtureTest {
20
21
  static disablesPermissionsAtStart() {
21
22
  return __awaiter(this, void 0, void 0, function* () {
22
23
  assert.isEqual(process.env.SHOULD_REGISTER_PERMISSIONS, 'false');
23
24
  });
24
25
  }
26
+ static permissionFixtureShouldUseSharedInstance() {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const actual = this.permissions.getAuthorizer();
29
+ const expected = AuthorizerFactory.getInstance();
30
+ assert.isEqual(actual, expected);
31
+ });
32
+ }
25
33
  };
26
34
  __decorate([
27
35
  test()
28
- ], DisablingPermissionsInTestsTest, "disablesPermissionsAtStart", null);
29
- DisablingPermissionsInTestsTest = __decorate([
36
+ ], PermissionFixtureTest, "disablesPermissionsAtStart", null);
37
+ __decorate([
38
+ test()
39
+ ], PermissionFixtureTest, "permissionFixtureShouldUseSharedInstance", null);
40
+ PermissionFixtureTest = __decorate([
30
41
  fake.login()
31
- ], DisablingPermissionsInTestsTest);
32
- export default DisablingPermissionsInTestsTest;
42
+ ], PermissionFixtureTest);
43
+ export default PermissionFixtureTest;
@@ -1,7 +1,8 @@
1
1
  import { DatabaseFixture } from '@sprucelabs/data-stores';
2
2
  import { MercuryClient } from '@sprucelabs/mercury-client';
3
- import { Location, Organization, Person, Role, Skill } from '@sprucelabs/spruce-core-schemas';
3
+ import { Location, Organization, Person, Role, Skill as ISkill } from '@sprucelabs/spruce-core-schemas';
4
4
  import { AbstractSkillTest, SkillFactoryOptions } from '@sprucelabs/spruce-skill-booter';
5
+ import { Skill } from '@sprucelabs/spruce-skill-utils';
5
6
  import { FixtureConstructorOptionsMap, FixtureName } from '../types/fixture.types';
6
7
  import LocationFixture from './fixtures/LocationFixture';
7
8
  import MercuryFixture from './fixtures/MercuryFixture';
@@ -20,39 +21,13 @@ export default abstract class AbstractSpruceFixtureTest extends AbstractSkillTes
20
21
  static fakedTeammates: Person[];
21
22
  static fakedOwners: Person[];
22
23
  static fakedRoles: Role[];
23
- static fakedSkills: Skill[];
24
+ static fakedSkills: ISkill[];
24
25
  static fakedManagers: Person[];
25
26
  static fakedGuests: Person[];
26
27
  static fakedGroupManagers: Person[];
27
- static get fakedOrganizations(): Organization[];
28
- static set fakedOrganizations(orgs: Organization[]);
29
- static get fakedLocations(): Location[];
30
- static set fakedLocations(locations: Location[]);
31
28
  private static _fakedOrganizations;
32
29
  private static _fakedLocations;
33
30
  static cwd: string;
34
- static get views(): ViewFixture;
35
- static set views(fixture: ViewFixture | undefined);
36
- static get permissions(): PermissionFixture;
37
- static set permissions(fixture: PermissionFixture | undefined);
38
- static get roles(): RoleFixture;
39
- static set roles(fixture: RoleFixture | undefined);
40
- static get locations(): LocationFixture;
41
- static set locations(fixture: LocationFixture | undefined);
42
- static get organizations(): OrganizationFixture;
43
- static set organizations(fixture: OrganizationFixture | undefined);
44
- static get people(): PersonFixture;
45
- static set people(fixture: PersonFixture | undefined);
46
- static get seeder(): SeedFixture;
47
- static set seeder(fixture: SeedFixture | undefined);
48
- static get skills(): SkillFixture;
49
- static set skills(fixture: SkillFixture | undefined);
50
- static get mercury(): MercuryFixture;
51
- static set mercury(fixture: MercuryFixture | undefined);
52
- static get stores(): StoreFixture;
53
- static set stores(fixture: StoreFixture | undefined);
54
- static get database(): DatabaseFixture;
55
- static set database(fixture: DatabaseFixture | undefined);
56
31
  private static _views?;
57
32
  private static _roles?;
58
33
  private static _locations?;
@@ -64,6 +39,7 @@ export default abstract class AbstractSpruceFixtureTest extends AbstractSkillTes
64
39
  private static _stores?;
65
40
  private static _database?;
66
41
  private static _permissions?;
42
+ private static _fixtures?;
67
43
  protected static beforeAll(): Promise<void>;
68
44
  protected static beforeEach(): Promise<void>;
69
45
  private static clearLocalFixtures;
@@ -74,7 +50,7 @@ export default abstract class AbstractSpruceFixtureTest extends AbstractSkillTes
74
50
  name: string;
75
51
  slug?: string;
76
52
  }): Promise<{
77
- skill: import("@sprucelabs/spruce-skill-utils").Skill;
53
+ skill: Skill;
78
54
  client: import("@sprucelabs/mercury-types").MercuryEventEmitter<import("@sprucelabs/mercury-types").SkillEventContract> & {
79
55
  disconnect: () => Promise<void>;
80
56
  isConnected: () => boolean;
@@ -96,7 +72,34 @@ export default abstract class AbstractSpruceFixtureTest extends AbstractSkillTes
96
72
  executionPromise: Promise<void>;
97
73
  }>;
98
74
  protected static bootAndRegisterSkillFromTestDir(key: string): Promise<{
99
- skill: import("@sprucelabs/spruce-skill-utils").Skill;
75
+ skill: Skill;
100
76
  executionPromise: Promise<void>;
101
77
  }>;
78
+ protected static SkillFromTestDir(key: string, options?: SkillFactoryOptions | undefined): Promise<Skill>;
79
+ static get fakedOrganizations(): Organization[];
80
+ static set fakedOrganizations(orgs: Organization[]);
81
+ static get fakedLocations(): Location[];
82
+ static set fakedLocations(locations: Location[]);
83
+ static get views(): ViewFixture;
84
+ static set views(fixture: ViewFixture | undefined);
85
+ static get permissions(): PermissionFixture;
86
+ static set permissions(fixture: PermissionFixture | undefined);
87
+ static get roles(): RoleFixture;
88
+ static set roles(fixture: RoleFixture | undefined);
89
+ static get locations(): LocationFixture;
90
+ static set locations(fixture: LocationFixture | undefined);
91
+ static get organizations(): OrganizationFixture;
92
+ static set organizations(fixture: OrganizationFixture | undefined);
93
+ static get people(): PersonFixture;
94
+ static set people(fixture: PersonFixture | undefined);
95
+ static get seeder(): SeedFixture;
96
+ static set seeder(fixture: SeedFixture | undefined);
97
+ static get skills(): SkillFixture;
98
+ static set skills(fixture: SkillFixture | undefined);
99
+ static get mercury(): MercuryFixture;
100
+ static set mercury(fixture: MercuryFixture | undefined);
101
+ static get stores(): StoreFixture;
102
+ static set stores(fixture: StoreFixture | undefined);
103
+ static get database(): DatabaseFixture;
104
+ static set database(fixture: DatabaseFixture | undefined);
102
105
  }
@@ -23,6 +23,108 @@ import { diskUtil, testLog } from '@sprucelabs/spruce-skill-utils';
23
23
  import { assert } from '@sprucelabs/test-utils';
24
24
  import FixtureFactory from './fixtures/FixtureFactory.js';
25
25
  export default class AbstractSpruceFixtureTest extends AbstractSkillTest {
26
+ static beforeAll() {
27
+ const _super = Object.create(null, {
28
+ beforeAll: { get: () => super.beforeAll }
29
+ });
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ yield _super.beforeAll.call(this);
32
+ yield FixtureFactory.beforeAll();
33
+ console.error = testLog.error;
34
+ });
35
+ }
36
+ static beforeEach() {
37
+ const _super = Object.create(null, {
38
+ beforeEach: { get: () => super.beforeEach }
39
+ });
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ yield _super.beforeEach.call(this);
42
+ yield FixtureFactory.beforeEach(this.cwd);
43
+ this._fixtures = undefined;
44
+ this.clearLocalFixtures();
45
+ });
46
+ }
47
+ static clearLocalFixtures() {
48
+ this.views = undefined;
49
+ this.roles = undefined;
50
+ this.locations = undefined;
51
+ this.organizations = undefined;
52
+ this.people = undefined;
53
+ this.seeder = undefined;
54
+ this.skills = undefined;
55
+ this.mercury = undefined;
56
+ this.stores = undefined;
57
+ this.database = undefined;
58
+ this.permissions = undefined;
59
+ }
60
+ static afterEach() {
61
+ const _super = Object.create(null, {
62
+ afterEach: { get: () => super.afterEach }
63
+ });
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ yield _super.afterEach.call(this);
66
+ yield FixtureFactory.afterEach();
67
+ this.clearLocalFixtures();
68
+ });
69
+ }
70
+ static afterAll() {
71
+ const _super = Object.create(null, {
72
+ afterAll: { get: () => super.afterAll }
73
+ });
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ yield _super.afterAll.call(this);
76
+ yield FixtureFactory.afterAll();
77
+ });
78
+ }
79
+ static Fixture(name, options) {
80
+ var _a;
81
+ if (!this._fixtures) {
82
+ const pkg = diskUtil.resolvePath(this.cwd, 'package.json');
83
+ let namespace;
84
+ if (diskUtil.doesFileExist(pkg)) {
85
+ const values = JSON.parse(diskUtil.readFile(pkg));
86
+ namespace = (_a = values === null || values === void 0 ? void 0 : values.skill) === null || _a === void 0 ? void 0 : _a.namespace;
87
+ }
88
+ this._fixtures = new FixtureFactory({
89
+ cwd: this.cwd,
90
+ namespace,
91
+ });
92
+ }
93
+ return this._fixtures.Fixture(name, options);
94
+ }
95
+ static bootAndRegisterNewSkill(options) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const { name, slug } = options, skillOptions = __rest(options, ["name", "slug"]);
98
+ const { skill, client } = yield this.skills.loginAsDemoSkill({
99
+ name,
100
+ slug,
101
+ });
102
+ process.env.SKILL_ID = skill.id;
103
+ process.env.SKILL_API_KEY = skill.apiKey;
104
+ const { skill: bootedSkill, executionPromise } = yield this.bootSkill(skillOptions);
105
+ return { skill: bootedSkill, client, executionPromise };
106
+ });
107
+ }
108
+ static bootAndRegisterSkillFromTestDir(key) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const registeredSkill = yield this.skills.seedDemoSkill({
111
+ name: 'my test skill',
112
+ });
113
+ process.env.SKILL_ID = registeredSkill.id;
114
+ process.env.SKILL_API_KEY = registeredSkill.apiKey;
115
+ return this.bootSkillFromTestDir(key);
116
+ });
117
+ }
118
+ static SkillFromTestDir(key, options) {
119
+ const _super = Object.create(null, {
120
+ SkillFromTestDir: { get: () => super.SkillFromTestDir }
121
+ });
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ const skill = yield _super.SkillFromTestDir.call(this, key, options);
124
+ this._fixtures = undefined;
125
+ return skill;
126
+ });
127
+ }
26
128
  static get fakedOrganizations() {
27
129
  return this._fakedOrganizations;
28
130
  }
@@ -136,90 +238,6 @@ export default class AbstractSpruceFixtureTest extends AbstractSkillTest {
136
238
  static set database(fixture) {
137
239
  this._database = fixture;
138
240
  }
139
- static beforeAll() {
140
- const _super = Object.create(null, {
141
- beforeAll: { get: () => super.beforeAll }
142
- });
143
- return __awaiter(this, void 0, void 0, function* () {
144
- yield _super.beforeAll.call(this);
145
- yield FixtureFactory.beforeAll();
146
- console.error = testLog.error;
147
- });
148
- }
149
- static beforeEach() {
150
- const _super = Object.create(null, {
151
- beforeEach: { get: () => super.beforeEach }
152
- });
153
- return __awaiter(this, void 0, void 0, function* () {
154
- yield _super.beforeEach.call(this);
155
- yield FixtureFactory.beforeEach(this.cwd);
156
- this.clearLocalFixtures();
157
- });
158
- }
159
- static clearLocalFixtures() {
160
- this.views = undefined;
161
- this.roles = undefined;
162
- this.locations = undefined;
163
- this.organizations = undefined;
164
- this.people = undefined;
165
- this.seeder = undefined;
166
- this.skills = undefined;
167
- this.mercury = undefined;
168
- this.stores = undefined;
169
- this.database = undefined;
170
- }
171
- static afterEach() {
172
- const _super = Object.create(null, {
173
- afterEach: { get: () => super.afterEach }
174
- });
175
- return __awaiter(this, void 0, void 0, function* () {
176
- yield _super.afterEach.call(this);
177
- yield FixtureFactory.afterEach();
178
- this.clearLocalFixtures();
179
- });
180
- }
181
- static afterAll() {
182
- const _super = Object.create(null, {
183
- afterAll: { get: () => super.afterAll }
184
- });
185
- return __awaiter(this, void 0, void 0, function* () {
186
- yield _super.afterAll.call(this);
187
- yield FixtureFactory.afterAll();
188
- });
189
- }
190
- static Fixture(name, options) {
191
- var _a;
192
- const pkg = diskUtil.resolvePath(this.cwd, 'package.json');
193
- let namespace;
194
- if (diskUtil.doesFileExist(pkg)) {
195
- const values = JSON.parse(diskUtil.readFile(pkg));
196
- namespace = (_a = values === null || values === void 0 ? void 0 : values.skill) === null || _a === void 0 ? void 0 : _a.namespace;
197
- }
198
- return new FixtureFactory({ cwd: this.cwd, namespace }).Fixture(name, options);
199
- }
200
- static bootAndRegisterNewSkill(options) {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- const { name, slug } = options, skillOptions = __rest(options, ["name", "slug"]);
203
- const { skill, client } = yield this.skills.loginAsDemoSkill({
204
- name,
205
- slug,
206
- });
207
- process.env.SKILL_ID = skill.id;
208
- process.env.SKILL_API_KEY = skill.apiKey;
209
- const { skill: bootedSkill, executionPromise } = yield this.bootSkill(skillOptions);
210
- return { skill: bootedSkill, client, executionPromise };
211
- });
212
- }
213
- static bootAndRegisterSkillFromTestDir(key) {
214
- return __awaiter(this, void 0, void 0, function* () {
215
- const registeredSkill = yield this.skills.seedDemoSkill({
216
- name: 'my test skill',
217
- });
218
- process.env.SKILL_ID = registeredSkill.id;
219
- process.env.SKILL_API_KEY = registeredSkill.apiKey;
220
- return this.bootSkillFromTestDir(key);
221
- });
222
- }
223
241
  }
224
242
  AbstractSpruceFixtureTest._fakedOrganizations = [];
225
243
  AbstractSpruceFixtureTest._fakedLocations = [];
@@ -1,10 +1,7 @@
1
1
  import { Authorizer, AuthorizerCanOptions } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { PermissionContractId, PermissionId } from '@sprucelabs/mercury-types';
3
3
  export default class FakeAuthorizer implements Authorizer {
4
- private static instance?;
5
4
  private fakedContracts;
6
- static getInstance(): FakeAuthorizer;
7
- static reset(): void;
8
5
  fakePermissions<ContractId extends PermissionContractId = PermissionContractId>(options: FakeOptions<ContractId>): void;
9
6
  can<ContractId extends PermissionContractId, Ids extends PermissionId<ContractId>>(options: AuthorizerCanOptions<ContractId, Ids>): Promise<Record<Ids, boolean>>;
10
7
  private assertValidPermission;
@@ -13,15 +13,6 @@ export default class FakeAuthorizer {
13
13
  constructor() {
14
14
  this.fakedContracts = [];
15
15
  }
16
- static getInstance() {
17
- if (!this.instance) {
18
- this.instance = new this();
19
- }
20
- return this.instance;
21
- }
22
- static reset() {
23
- this.instance = undefined;
24
- }
25
16
  fakePermissions(options) {
26
17
  this.fakedContracts.unshift(options);
27
18
  }
@@ -48,7 +39,7 @@ Valid permissions on this contract are:
48
39
  ${faked.permissions.map((p) => p.id).join('\n')}`);
49
40
  }
50
41
  assertValidContractId(faked, contractId) {
51
- assert.isTruthy(faked, `Contract by the id '${contractId}' not found! You need to tell the authorizer how to respond. Try 'this.views.getAuthorizer().fakePermissions(...)'
42
+ assert.isTruthy(faked, `Contract with the id '${contractId}' not found! You need to tell the authorizer how to respond. Try 'this.views.getAuthorizer().fakePermissions(...)'
52
43
 
53
44
  Valid contracts are:
54
45
 
@@ -8,6 +8,8 @@ export default class FixtureFactory {
8
8
  cwd: string;
9
9
  namespace?: string;
10
10
  });
11
+ setCwd(cwd: string): void;
12
+ setNamespace(namespace: string): void;
11
13
  Fixture<Name extends FixtureName>(named: Name, options?: Partial<FixtureConstructorOptionsMap[Name]>): FixtureMap[Name];
12
14
  private getMercuryFixture;
13
15
  static destroy(): Promise<void>;
@@ -35,6 +35,12 @@ export default class FixtureFactory {
35
35
  }
36
36
  this.namespace = options.namespace;
37
37
  }
38
+ setCwd(cwd) {
39
+ this.cwd = cwd;
40
+ }
41
+ setNamespace(namespace) {
42
+ this.namespace = namespace;
43
+ }
38
44
  Fixture(named, options) {
39
45
  var _a, _b, _c, _d, _e;
40
46
  const mercuryFixture = this.getMercuryFixture(named);
@@ -105,7 +111,7 @@ export default class FixtureFactory {
105
111
  });
106
112
  break;
107
113
  case 'permission':
108
- fixture = new PermissionFixture();
114
+ fixture = new PermissionFixture(mercuryFixture);
109
115
  break;
110
116
  case 'view': {
111
117
  if (!this.namespace) {
@@ -113,7 +119,7 @@ export default class FixtureFactory {
113
119
  }
114
120
  fixture = new ViewFixture(Object.assign({
115
121
  //@ts-ignore
116
- people: (_e = options === null || options === void 0 ? void 0 : options.personFixture) !== null && _e !== void 0 ? _e : this.Fixture('person'), connectToApi: mercuryFixture.getConnectFactory(), fixtureFactory: this, namespace: this.namespace, proxyDecorator: ClientProxyDecorator.getInstance(), cwd: this.cwd }, options));
122
+ people: (_e = options === null || options === void 0 ? void 0 : options.personFixture) !== null && _e !== void 0 ? _e : this.Fixture('person'), connectToApi: mercuryFixture.getConnectFactory(), fixtureFactory: this, namespace: this.namespace, proxyDecorator: ClientProxyDecorator.getInstance(), cwd: this.cwd, permissions: this.Fixture('permission') }, options));
117
123
  break;
118
124
  }
119
125
  }
@@ -1,5 +1,8 @@
1
1
  import FakeAuthorizer from '../FakeAuthorizer';
2
+ import MercuryFixture from './MercuryFixture';
2
3
  export default class PermissionFixture {
4
+ private connectToApi;
5
+ constructor(mercury: MercuryFixture);
3
6
  static beforeEach(): void;
4
7
  getAuthorizer(): FakeAuthorizer;
5
8
  getAuthenticator(): import("@sprucelabs/heartwood-view-controllers").Authenticator;