@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
@@ -1,11 +1,18 @@
1
1
  import { AuthenticatorImpl } from '@sprucelabs/heartwood-view-controllers';
2
+ import { AuthorizerFactory } from '@sprucelabs/spruce-permission-utils';
2
3
  import FakeAuthorizer from '../FakeAuthorizer.js';
3
4
  export default class PermissionFixture {
5
+ constructor(mercury) {
6
+ this.connectToApi = mercury.getConnectFactory();
7
+ AuthorizerFactory.setConnectToApi(this.connectToApi);
8
+ }
4
9
  static beforeEach() {
5
10
  process.env.SHOULD_REGISTER_PERMISSIONS = 'false';
11
+ AuthorizerFactory.reset();
12
+ AuthorizerFactory.setClass(FakeAuthorizer);
6
13
  }
7
14
  getAuthorizer() {
8
- return FakeAuthorizer.getInstance();
15
+ return AuthorizerFactory.getInstance();
9
16
  }
10
17
  getAuthenticator() {
11
18
  return AuthenticatorImpl.getInstance();
@@ -6,9 +6,9 @@ import { ClientProxyDecorator } from '../..';
6
6
  import { TokenGenerator } from '../../ClientProxyDecorator';
7
7
  import { TestConnectFactory } from '../../types/fixture.types';
8
8
  import { ArgsFromSvc } from '../../types/view.types';
9
- import FakeAuthorizer from '../FakeAuthorizer';
10
9
  import TestRouter from '../routers/TestRouter';
11
10
  import FixtureFactory from './FixtureFactory';
11
+ import PermissionFixture from './PermissionFixture';
12
12
  import PersonFixture from './PersonFixture';
13
13
  import SpyScope from './SpyScope';
14
14
  type Factory = TestConnectFactory;
@@ -29,6 +29,7 @@ export default class ViewFixture {
29
29
  private locations;
30
30
  private proxyDecorator;
31
31
  private locale;
32
+ private permissions;
32
33
  static lockProxyCacheForPerson(id: any): void;
33
34
  static setShouldAutomaticallyResetAuth(shouldReset: false): void;
34
35
  constructor(options: {
@@ -40,6 +41,7 @@ export default class ViewFixture {
40
41
  controllerMap?: Record<string, any>;
41
42
  namespace: string;
42
43
  proxyDecorator: ClientProxyDecorator;
44
+ permissions: PermissionFixture;
43
45
  });
44
46
  getFactory(): ViewControllerFactory;
45
47
  getMaps(): import("../../utilities/SpyMapUtil").SpyMapUtil;
@@ -66,7 +68,7 @@ export default class ViewFixture {
66
68
  /**
67
69
  * @deprecated this.views.getAuthorizer() -> this.permissions.getAuthorizer()
68
70
  */
69
- getAuthorizer(): FakeAuthorizer;
71
+ getAuthorizer(): import("../FakeAuthorizer").default;
70
72
  getProxyTokenGenerator(): TokenGenerator | undefined;
71
73
  setProxyTokenGenerator(cb: TokenGenerator): void;
72
74
  loginAsDemoPerson(phone?: string): Promise<{
@@ -16,7 +16,6 @@ import SpruceError from '../../errors/SpruceError.js';
16
16
  import spyMapUtil from '../../utilities/SpyMapUtil.js';
17
17
  import vcDiskUtil from '../../utilities/vcDisk.utility.js';
18
18
  import FakeSkillViewController from '../Fake.svc.js';
19
- import FakeAuthorizer from '../FakeAuthorizer.js';
20
19
  import TestRouter from '../routers/TestRouter.js';
21
20
  import SpyScope from './SpyScope.js';
22
21
  export default class ViewFixture {
@@ -38,6 +37,7 @@ export default class ViewFixture {
38
37
  this.orgs = options.fixtureFactory.Fixture('organization', {
39
38
  people: this.people,
40
39
  });
40
+ this.permissions = options.permissions;
41
41
  this.locale = new LocaleImpl();
42
42
  this.locations = options.fixtureFactory.Fixture('location', {
43
43
  people: this.people,
@@ -154,7 +154,6 @@ export default class ViewFixture {
154
154
  };
155
155
  }
156
156
  TestRouter.reset();
157
- FakeAuthorizer.reset();
158
157
  ViewFixture.resetMaps();
159
158
  ActiveRecordCardViewController.setShouldThrowOnResponseError(true);
160
159
  process.env.SHOULD_REGISTER_VIEWS = 'false';
@@ -222,6 +221,7 @@ export default class ViewFixture {
222
221
  vcFactory: this.getFactory(),
223
222
  scope: this.getScope(),
224
223
  locale: this.getLocale(),
224
+ authorizer: this.permissions.getAuthorizer(),
225
225
  });
226
226
  return TestRouter.getInstance();
227
227
  }
@@ -229,13 +229,13 @@ export default class ViewFixture {
229
229
  * @deprecated this.views.getAuthorizer() -> this.permissions.getAuthorizer()
230
230
  */
231
231
  getAuthenticator() {
232
- return AuthenticatorImpl.getInstance();
232
+ return this.permissions.getAuthenticator();
233
233
  }
234
234
  /**
235
235
  * @deprecated this.views.getAuthorizer() -> this.permissions.getAuthorizer()
236
236
  */
237
237
  getAuthorizer() {
238
- return FakeAuthorizer.getInstance();
238
+ return this.permissions.getAuthorizer();
239
239
  }
240
240
  getProxyTokenGenerator() {
241
241
  return this.proxyDecorator.getProxyTokenGenerator();
@@ -246,7 +246,7 @@ export default class ViewFixture {
246
246
  loginAsDemoPerson(phone) {
247
247
  return __awaiter(this, void 0, void 0, function* () {
248
248
  const { person, token, client } = yield this.people.loginAsDemoPerson(phone);
249
- this.getAuthenticator().setSessionToken(token, person);
249
+ this.permissions.getAuthenticator().setSessionToken(token, person);
250
250
  this.proxyDecorator.setProxyTokenGenerator(() => __awaiter(this, void 0, void 0, function* () {
251
251
  if (!ViewFixture.loggedInPersonProxyTokens[person.id]) {
252
252
  const proxyToken = client.registerProxyToken();
@@ -1,5 +1,5 @@
1
1
  import { Locale } from '@sprucelabs/calendar-utils';
2
- import { Router, Scope, SkillViewController, SkillViewControllerArgs, SkillViewControllerId, SkillViewControllerLoadOptions, SkillViewControllerMap, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
+ import { Authorizer, Router, Scope, SkillViewController, SkillViewControllerArgs, SkillViewControllerId, SkillViewControllerLoadOptions, SkillViewControllerMap, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
3
3
  import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
4
4
  import { MercuryEventEmitter } from '@sprucelabs/mercury-types';
5
5
  import FakeThemeManager from '../../__tests__/support/FakeThemeManager';
@@ -23,6 +23,8 @@ export default class TestRouter extends AbstractEventEmitter<Contract> implement
23
23
  private scope;
24
24
  private locale;
25
25
  private readonly themes;
26
+ private authorizer;
27
+ private static authorizer;
26
28
  static setShouldThrowWhenRedirectingToBadSvc(shouldThrow: boolean): void;
27
29
  private constructor();
28
30
  static setShouldLoadDestinationVc(shouldLoad: boolean): void;
@@ -32,6 +34,7 @@ export default class TestRouter extends AbstractEventEmitter<Contract> implement
32
34
  vcFactory: ViewControllerFactory;
33
35
  scope: Scope;
34
36
  locale: Locale;
37
+ authorizer: Authorizer;
35
38
  }): void;
36
39
  getPresentVc(): SkillViewController<any> | undefined;
37
40
  redirect<Id extends SkillViewControllerId>(id: Id, args?: SkillViewControllerArgs<Id>): Promise<SkillViewControllerMap[Id]>;
@@ -12,7 +12,6 @@ import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
12
12
  import { buildEventContract, } from '@sprucelabs/mercury-types';
13
13
  import testRouterEmitPayloadSchema from './../../.spruce/schemas/spruceTestFixtures/v2021_07_19/testRouterEmitPayload.schema.js';
14
14
  import FakeThemeManager from '../../__tests__/support/FakeThemeManager.js';
15
- import FakeAuthorizer from '../FakeAuthorizer.js';
16
15
  const contract = buildEventContract({
17
16
  eventSignatures: {
18
17
  'did-redirect': {
@@ -30,6 +29,7 @@ export default class TestRouter extends AbstractEventEmitter {
30
29
  this.vcFactory = options.vcFactory;
31
30
  this.scope = options.scope;
32
31
  this.locale = options.locale;
32
+ this.authorizer = options.authorizer;
33
33
  }
34
34
  static setShouldLoadDestinationVc(shouldLoad) {
35
35
  this.shouldLoadDestinationVc = shouldLoad;
@@ -40,6 +40,7 @@ export default class TestRouter extends AbstractEventEmitter {
40
40
  vcFactory: this.vcFactory,
41
41
  scope: this.scope,
42
42
  locale: this.locale,
43
+ authorizer: this.authorizer,
43
44
  });
44
45
  routerTestPatcher.patchRedirectToThrow(this.instance);
45
46
  }
@@ -55,6 +56,7 @@ export default class TestRouter extends AbstractEventEmitter {
55
56
  this.vcFactory = options.vcFactory;
56
57
  this.scope = options.scope;
57
58
  this.locale = options.locale;
59
+ this.authorizer = options.authorizer;
58
60
  }
59
61
  getPresentVc() {
60
62
  return this.presentVc;
@@ -93,7 +95,7 @@ export default class TestRouter extends AbstractEventEmitter {
93
95
  authenticator: AuthenticatorImpl.getInstance(),
94
96
  args,
95
97
  locale: this.locale,
96
- authorizer: FakeAuthorizer.getInstance(),
98
+ authorizer: this.authorizer,
97
99
  scope: this.scope,
98
100
  themes: this.themes,
99
101
  };
@@ -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
  }
@@ -19,6 +19,79 @@ const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
19
19
  const test_utils_1 = require("@sprucelabs/test-utils");
20
20
  const FixtureFactory_1 = __importDefault(require("./fixtures/FixtureFactory"));
21
21
  class AbstractSpruceFixtureTest extends spruce_skill_booter_1.AbstractSkillTest {
22
+ static async beforeAll() {
23
+ await super.beforeAll();
24
+ await FixtureFactory_1.default.beforeAll();
25
+ console.error = spruce_skill_utils_1.testLog.error;
26
+ }
27
+ static async beforeEach() {
28
+ await super.beforeEach();
29
+ await FixtureFactory_1.default.beforeEach(this.cwd);
30
+ this._fixtures = undefined;
31
+ this.clearLocalFixtures();
32
+ }
33
+ static clearLocalFixtures() {
34
+ this.views = undefined;
35
+ this.roles = undefined;
36
+ this.locations = undefined;
37
+ this.organizations = undefined;
38
+ this.people = undefined;
39
+ this.seeder = undefined;
40
+ this.skills = undefined;
41
+ this.mercury = undefined;
42
+ this.stores = undefined;
43
+ this.database = undefined;
44
+ this.permissions = undefined;
45
+ }
46
+ static async afterEach() {
47
+ await super.afterEach();
48
+ await FixtureFactory_1.default.afterEach();
49
+ this.clearLocalFixtures();
50
+ }
51
+ static async afterAll() {
52
+ await super.afterAll();
53
+ await FixtureFactory_1.default.afterAll();
54
+ }
55
+ static Fixture(name, options) {
56
+ var _a;
57
+ if (!this._fixtures) {
58
+ const pkg = spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, 'package.json');
59
+ let namespace;
60
+ if (spruce_skill_utils_1.diskUtil.doesFileExist(pkg)) {
61
+ const values = JSON.parse(spruce_skill_utils_1.diskUtil.readFile(pkg));
62
+ namespace = (_a = values === null || values === void 0 ? void 0 : values.skill) === null || _a === void 0 ? void 0 : _a.namespace;
63
+ }
64
+ this._fixtures = new FixtureFactory_1.default({
65
+ cwd: this.cwd,
66
+ namespace,
67
+ });
68
+ }
69
+ return this._fixtures.Fixture(name, options);
70
+ }
71
+ static async bootAndRegisterNewSkill(options) {
72
+ const { name, slug } = options, skillOptions = __rest(options, ["name", "slug"]);
73
+ const { skill, client } = await this.skills.loginAsDemoSkill({
74
+ name,
75
+ slug,
76
+ });
77
+ process.env.SKILL_ID = skill.id;
78
+ process.env.SKILL_API_KEY = skill.apiKey;
79
+ const { skill: bootedSkill, executionPromise } = await this.bootSkill(skillOptions);
80
+ return { skill: bootedSkill, client, executionPromise };
81
+ }
82
+ static async bootAndRegisterSkillFromTestDir(key) {
83
+ const registeredSkill = await this.skills.seedDemoSkill({
84
+ name: 'my test skill',
85
+ });
86
+ process.env.SKILL_ID = registeredSkill.id;
87
+ process.env.SKILL_API_KEY = registeredSkill.apiKey;
88
+ return this.bootSkillFromTestDir(key);
89
+ }
90
+ static async SkillFromTestDir(key, options) {
91
+ const skill = await super.SkillFromTestDir(key, options);
92
+ this._fixtures = undefined;
93
+ return skill;
94
+ }
22
95
  static get fakedOrganizations() {
23
96
  return this._fakedOrganizations;
24
97
  }
@@ -132,66 +205,6 @@ class AbstractSpruceFixtureTest extends spruce_skill_booter_1.AbstractSkillTest
132
205
  static set database(fixture) {
133
206
  this._database = fixture;
134
207
  }
135
- static async beforeAll() {
136
- await super.beforeAll();
137
- await FixtureFactory_1.default.beforeAll();
138
- console.error = spruce_skill_utils_1.testLog.error;
139
- }
140
- static async beforeEach() {
141
- await super.beforeEach();
142
- await FixtureFactory_1.default.beforeEach(this.cwd);
143
- this.clearLocalFixtures();
144
- }
145
- static clearLocalFixtures() {
146
- this.views = undefined;
147
- this.roles = undefined;
148
- this.locations = undefined;
149
- this.organizations = undefined;
150
- this.people = undefined;
151
- this.seeder = undefined;
152
- this.skills = undefined;
153
- this.mercury = undefined;
154
- this.stores = undefined;
155
- this.database = undefined;
156
- }
157
- static async afterEach() {
158
- await super.afterEach();
159
- await FixtureFactory_1.default.afterEach();
160
- this.clearLocalFixtures();
161
- }
162
- static async afterAll() {
163
- await super.afterAll();
164
- await FixtureFactory_1.default.afterAll();
165
- }
166
- static Fixture(name, options) {
167
- var _a;
168
- const pkg = spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, 'package.json');
169
- let namespace;
170
- if (spruce_skill_utils_1.diskUtil.doesFileExist(pkg)) {
171
- const values = JSON.parse(spruce_skill_utils_1.diskUtil.readFile(pkg));
172
- namespace = (_a = values === null || values === void 0 ? void 0 : values.skill) === null || _a === void 0 ? void 0 : _a.namespace;
173
- }
174
- return new FixtureFactory_1.default({ cwd: this.cwd, namespace }).Fixture(name, options);
175
- }
176
- static async bootAndRegisterNewSkill(options) {
177
- const { name, slug } = options, skillOptions = __rest(options, ["name", "slug"]);
178
- const { skill, client } = await this.skills.loginAsDemoSkill({
179
- name,
180
- slug,
181
- });
182
- process.env.SKILL_ID = skill.id;
183
- process.env.SKILL_API_KEY = skill.apiKey;
184
- const { skill: bootedSkill, executionPromise } = await this.bootSkill(skillOptions);
185
- return { skill: bootedSkill, client, executionPromise };
186
- }
187
- static async bootAndRegisterSkillFromTestDir(key) {
188
- const registeredSkill = await this.skills.seedDemoSkill({
189
- name: 'my test skill',
190
- });
191
- process.env.SKILL_ID = registeredSkill.id;
192
- process.env.SKILL_API_KEY = registeredSkill.apiKey;
193
- return this.bootSkillFromTestDir(key);
194
- }
195
208
  }
196
209
  exports.default = AbstractSpruceFixtureTest;
197
210
  AbstractSpruceFixtureTest._fakedOrganizations = [];
@@ -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;
@@ -6,15 +6,6 @@ class FakeAuthorizer {
6
6
  constructor() {
7
7
  this.fakedContracts = [];
8
8
  }
9
- static getInstance() {
10
- if (!this.instance) {
11
- this.instance = new this();
12
- }
13
- return this.instance;
14
- }
15
- static reset() {
16
- this.instance = undefined;
17
- }
18
9
  fakePermissions(options) {
19
10
  this.fakedContracts.unshift(options);
20
11
  }
@@ -39,7 +30,7 @@ Valid permissions on this contract are:
39
30
  ${faked.permissions.map((p) => p.id).join('\n')}`);
40
31
  }
41
32
  assertValidContractId(faked, contractId) {
42
- test_utils_1.assert.isTruthy(faked, `Contract by the id '${contractId}' not found! You need to tell the authorizer how to respond. Try 'this.views.getAuthorizer().fakePermissions(...)'
33
+ test_utils_1.assert.isTruthy(faked, `Contract with the id '${contractId}' not found! You need to tell the authorizer how to respond. Try 'this.views.getAuthorizer().fakePermissions(...)'
43
34
 
44
35
  Valid contracts are:
45
36
 
@@ -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>;
@@ -31,6 +31,12 @@ class FixtureFactory {
31
31
  }
32
32
  this.namespace = options.namespace;
33
33
  }
34
+ setCwd(cwd) {
35
+ this.cwd = cwd;
36
+ }
37
+ setNamespace(namespace) {
38
+ this.namespace = namespace;
39
+ }
34
40
  Fixture(named, options) {
35
41
  var _a, _b, _c, _d, _e;
36
42
  const mercuryFixture = this.getMercuryFixture(named);
@@ -101,7 +107,7 @@ class FixtureFactory {
101
107
  });
102
108
  break;
103
109
  case 'permission':
104
- fixture = new PermissionFixture_1.default();
110
+ fixture = new PermissionFixture_1.default(mercuryFixture);
105
111
  break;
106
112
  case 'view': {
107
113
  if (!this.namespace) {
@@ -109,7 +115,7 @@ class FixtureFactory {
109
115
  }
110
116
  fixture = new ViewFixture_1.default(Object.assign({
111
117
  //@ts-ignore
112
- 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: __1.ClientProxyDecorator.getInstance(), cwd: this.cwd }, options));
118
+ 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: __1.ClientProxyDecorator.getInstance(), cwd: this.cwd, permissions: this.Fixture('permission') }, options));
113
119
  break;
114
120
  }
115
121
  }
@@ -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;
@@ -4,13 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
7
+ const spruce_permission_utils_1 = require("@sprucelabs/spruce-permission-utils");
7
8
  const FakeAuthorizer_1 = __importDefault(require("../FakeAuthorizer"));
8
9
  class PermissionFixture {
10
+ constructor(mercury) {
11
+ this.connectToApi = mercury.getConnectFactory();
12
+ spruce_permission_utils_1.AuthorizerFactory.setConnectToApi(this.connectToApi);
13
+ }
9
14
  static beforeEach() {
10
15
  process.env.SHOULD_REGISTER_PERMISSIONS = 'false';
16
+ spruce_permission_utils_1.AuthorizerFactory.reset();
17
+ spruce_permission_utils_1.AuthorizerFactory.setClass(FakeAuthorizer_1.default);
11
18
  }
12
19
  getAuthorizer() {
13
- return FakeAuthorizer_1.default.getInstance();
20
+ return spruce_permission_utils_1.AuthorizerFactory.getInstance();
14
21
  }
15
22
  getAuthenticator() {
16
23
  return heartwood_view_controllers_1.AuthenticatorImpl.getInstance();
@@ -6,9 +6,9 @@ import { ClientProxyDecorator } from '../..';
6
6
  import { TokenGenerator } from '../../ClientProxyDecorator';
7
7
  import { TestConnectFactory } from '../../types/fixture.types';
8
8
  import { ArgsFromSvc } from '../../types/view.types';
9
- import FakeAuthorizer from '../FakeAuthorizer';
10
9
  import TestRouter from '../routers/TestRouter';
11
10
  import FixtureFactory from './FixtureFactory';
11
+ import PermissionFixture from './PermissionFixture';
12
12
  import PersonFixture from './PersonFixture';
13
13
  import SpyScope from './SpyScope';
14
14
  type Factory = TestConnectFactory;
@@ -29,6 +29,7 @@ export default class ViewFixture {
29
29
  private locations;
30
30
  private proxyDecorator;
31
31
  private locale;
32
+ private permissions;
32
33
  static lockProxyCacheForPerson(id: any): void;
33
34
  static setShouldAutomaticallyResetAuth(shouldReset: false): void;
34
35
  constructor(options: {
@@ -40,6 +41,7 @@ export default class ViewFixture {
40
41
  controllerMap?: Record<string, any>;
41
42
  namespace: string;
42
43
  proxyDecorator: ClientProxyDecorator;
44
+ permissions: PermissionFixture;
43
45
  });
44
46
  getFactory(): ViewControllerFactory;
45
47
  getMaps(): import("../../utilities/SpyMapUtil").SpyMapUtil;
@@ -66,7 +68,7 @@ export default class ViewFixture {
66
68
  /**
67
69
  * @deprecated this.views.getAuthorizer() -> this.permissions.getAuthorizer()
68
70
  */
69
- getAuthorizer(): FakeAuthorizer;
71
+ getAuthorizer(): import("../FakeAuthorizer").default;
70
72
  getProxyTokenGenerator(): TokenGenerator | undefined;
71
73
  setProxyTokenGenerator(cb: TokenGenerator): void;
72
74
  loginAsDemoPerson(phone?: string): Promise<{
@@ -12,7 +12,6 @@ const SpruceError_1 = __importDefault(require("../../errors/SpruceError"));
12
12
  const SpyMapUtil_1 = __importDefault(require("../../utilities/SpyMapUtil"));
13
13
  const vcDisk_utility_1 = __importDefault(require("../../utilities/vcDisk.utility"));
14
14
  const Fake_svc_1 = __importDefault(require("../Fake.svc"));
15
- const FakeAuthorizer_1 = __importDefault(require("../FakeAuthorizer"));
16
15
  const TestRouter_1 = __importDefault(require("../routers/TestRouter"));
17
16
  const SpyScope_1 = __importDefault(require("./SpyScope"));
18
17
  class ViewFixture {
@@ -34,6 +33,7 @@ class ViewFixture {
34
33
  this.orgs = options.fixtureFactory.Fixture('organization', {
35
34
  people: this.people,
36
35
  });
36
+ this.permissions = options.permissions;
37
37
  this.locale = new calendar_utils_1.LocaleImpl();
38
38
  this.locations = options.fixtureFactory.Fixture('location', {
39
39
  people: this.people,
@@ -147,7 +147,6 @@ class ViewFixture {
147
147
  };
148
148
  }
149
149
  TestRouter_1.default.reset();
150
- FakeAuthorizer_1.default.reset();
151
150
  ViewFixture.resetMaps();
152
151
  heartwood_view_controllers_1.ActiveRecordCardViewController.setShouldThrowOnResponseError(true);
153
152
  process.env.SHOULD_REGISTER_VIEWS = 'false';
@@ -210,6 +209,7 @@ class ViewFixture {
210
209
  vcFactory: this.getFactory(),
211
210
  scope: this.getScope(),
212
211
  locale: this.getLocale(),
212
+ authorizer: this.permissions.getAuthorizer(),
213
213
  });
214
214
  return TestRouter_1.default.getInstance();
215
215
  }
@@ -217,13 +217,13 @@ class ViewFixture {
217
217
  * @deprecated this.views.getAuthorizer() -> this.permissions.getAuthorizer()
218
218
  */
219
219
  getAuthenticator() {
220
- return heartwood_view_controllers_1.AuthenticatorImpl.getInstance();
220
+ return this.permissions.getAuthenticator();
221
221
  }
222
222
  /**
223
223
  * @deprecated this.views.getAuthorizer() -> this.permissions.getAuthorizer()
224
224
  */
225
225
  getAuthorizer() {
226
- return FakeAuthorizer_1.default.getInstance();
226
+ return this.permissions.getAuthorizer();
227
227
  }
228
228
  getProxyTokenGenerator() {
229
229
  return this.proxyDecorator.getProxyTokenGenerator();
@@ -233,7 +233,7 @@ class ViewFixture {
233
233
  }
234
234
  async loginAsDemoPerson(phone) {
235
235
  const { person, token, client } = await this.people.loginAsDemoPerson(phone);
236
- this.getAuthenticator().setSessionToken(token, person);
236
+ this.permissions.getAuthenticator().setSessionToken(token, person);
237
237
  this.proxyDecorator.setProxyTokenGenerator(async () => {
238
238
  if (!ViewFixture.loggedInPersonProxyTokens[person.id]) {
239
239
  const proxyToken = client.registerProxyToken();
@@ -1,5 +1,5 @@
1
1
  import { Locale } from '@sprucelabs/calendar-utils';
2
- import { Router, Scope, SkillViewController, SkillViewControllerArgs, SkillViewControllerId, SkillViewControllerLoadOptions, SkillViewControllerMap, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
2
+ import { Authorizer, Router, Scope, SkillViewController, SkillViewControllerArgs, SkillViewControllerId, SkillViewControllerLoadOptions, SkillViewControllerMap, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
3
3
  import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
4
4
  import { MercuryEventEmitter } from '@sprucelabs/mercury-types';
5
5
  import FakeThemeManager from '../../__tests__/support/FakeThemeManager';
@@ -23,6 +23,8 @@ export default class TestRouter extends AbstractEventEmitter<Contract> implement
23
23
  private scope;
24
24
  private locale;
25
25
  private readonly themes;
26
+ private authorizer;
27
+ private static authorizer;
26
28
  static setShouldThrowWhenRedirectingToBadSvc(shouldThrow: boolean): void;
27
29
  private constructor();
28
30
  static setShouldLoadDestinationVc(shouldLoad: boolean): void;
@@ -32,6 +34,7 @@ export default class TestRouter extends AbstractEventEmitter<Contract> implement
32
34
  vcFactory: ViewControllerFactory;
33
35
  scope: Scope;
34
36
  locale: Locale;
37
+ authorizer: Authorizer;
35
38
  }): void;
36
39
  getPresentVc(): SkillViewController<any> | undefined;
37
40
  redirect<Id extends SkillViewControllerId>(id: Id, args?: SkillViewControllerArgs<Id>): Promise<SkillViewControllerMap[Id]>;