@sprucelabs/spruce-test-fixtures 66.0.19 → 66.0.21

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 (57) hide show
  1. package/build/FakerTracker.d.ts +41 -0
  2. package/build/FakerTracker.js +56 -0
  3. package/build/esm/FakerTracker.d.ts +41 -0
  4. package/build/esm/FakerTracker.js +54 -0
  5. package/build/esm/tests/AbstractSpruceFixtureTest.d.ts +68 -27
  6. package/build/esm/tests/AbstractSpruceFixtureTest.js +256 -103
  7. package/build/esm/tests/decorators/fake.d.ts +11 -11
  8. package/build/esm/tests/decorators/fake.js +151 -173
  9. package/build/esm/tests/decorators/install.js +7 -4
  10. package/build/esm/tests/decorators/login.js +18 -18
  11. package/build/esm/tests/decorators/seed.js +34 -40
  12. package/build/esm/tests/fixtures/FixtureFactory.d.ts +2 -1
  13. package/build/esm/tests/fixtures/FixtureFactory.js +38 -35
  14. package/build/esm/tests/fixtures/FixtureWarehourse.d.ts +56 -0
  15. package/build/esm/tests/fixtures/FixtureWarehourse.js +165 -0
  16. package/build/esm/tests/fixtures/LocationFixture.d.ts +5 -5
  17. package/build/esm/tests/fixtures/LocationFixture.js +5 -5
  18. package/build/esm/tests/fixtures/MercuryFixture.d.ts +5 -0
  19. package/build/esm/tests/fixtures/MercuryFixture.js +50 -25
  20. package/build/esm/tests/fixtures/OrganizationFixture.d.ts +4 -4
  21. package/build/esm/tests/fixtures/PersonFixture.d.ts +2 -2
  22. package/build/esm/tests/fixtures/PersonFixture.js +23 -9
  23. package/build/esm/tests/fixtures/RoleFixture.d.ts +4 -4
  24. package/build/esm/tests/fixtures/RoleFixture.js +4 -4
  25. package/build/esm/tests/fixtures/SeedFixture.d.ts +13 -13
  26. package/build/esm/tests/fixtures/SkillFixture.d.ts +2 -2
  27. package/build/esm/tests/fixtures/SkillFixture.js +2 -2
  28. package/build/esm/tests/fixtures/SpyScope.d.ts +2 -2
  29. package/build/esm/tests/fixtures/ViewFixture.d.ts +7 -3
  30. package/build/esm/tests/fixtures/ViewFixture.js +11 -9
  31. package/build/tests/AbstractSpruceFixtureTest.d.ts +68 -27
  32. package/build/tests/AbstractSpruceFixtureTest.js +243 -98
  33. package/build/tests/decorators/fake.d.ts +11 -11
  34. package/build/tests/decorators/fake.js +151 -171
  35. package/build/tests/decorators/install.js +9 -3
  36. package/build/tests/decorators/login.js +20 -17
  37. package/build/tests/decorators/seed.js +34 -38
  38. package/build/tests/fixtures/FixtureFactory.d.ts +2 -1
  39. package/build/tests/fixtures/FixtureFactory.js +37 -35
  40. package/build/tests/fixtures/FixtureWarehourse.d.ts +56 -0
  41. package/build/tests/fixtures/FixtureWarehourse.js +170 -0
  42. package/build/tests/fixtures/LocationFixture.d.ts +5 -5
  43. package/build/tests/fixtures/LocationFixture.js +5 -5
  44. package/build/tests/fixtures/MercuryFixture.d.ts +5 -0
  45. package/build/tests/fixtures/MercuryFixture.js +48 -23
  46. package/build/tests/fixtures/OrganizationFixture.d.ts +4 -4
  47. package/build/tests/fixtures/PersonFixture.d.ts +2 -2
  48. package/build/tests/fixtures/PersonFixture.js +20 -6
  49. package/build/tests/fixtures/RoleFixture.d.ts +4 -4
  50. package/build/tests/fixtures/RoleFixture.js +4 -4
  51. package/build/tests/fixtures/SeedFixture.d.ts +13 -13
  52. package/build/tests/fixtures/SkillFixture.d.ts +2 -2
  53. package/build/tests/fixtures/SkillFixture.js +2 -2
  54. package/build/tests/fixtures/SpyScope.d.ts +2 -2
  55. package/build/tests/fixtures/ViewFixture.d.ts +7 -3
  56. package/build/tests/fixtures/ViewFixture.js +13 -9
  57. package/package.json +25 -25
@@ -1,23 +1,29 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.default = install;
4
7
  const test_utils_1 = require("@sprucelabs/test-utils");
8
+ const FakerTracker_1 = __importDefault(require("../../FakerTracker"));
5
9
  function install() { }
6
10
  install.skills = (...namespaces) => {
7
11
  if (namespaces.length === 0) {
8
12
  test_utils_1.assert.fail(`You must pass the skill namespaces so I can install them.`);
9
13
  }
10
14
  return function (Class, key, descriptor) {
11
- const old = descriptor.value.bind(Class);
15
+ const old = descriptor.value;
12
16
  descriptor.value = async (...args) => {
13
- const orgsFixture = Class.Fixture('organization');
17
+ const orgsFixture = FakerTracker_1.default.getFixtures(Class.cwd).Fixture('organization');
14
18
  const latestOrg = await orgsFixture.getNewestOrganization();
15
19
  test_utils_1.assert.isTruthy(latestOrg, `You need to seed at least 1 organization. Heads up, I'll install it in the newest organization only.`);
16
20
  await orgsFixture.installSkillsByNamespace({
17
21
  organizationId: latestOrg.id,
18
22
  namespaces,
19
23
  });
20
- return old(...args);
24
+ const Test = test_utils_1.SpruceTestResolver.getActiveTest();
25
+ const bound = old.bind(Test);
26
+ return bound(...args);
21
27
  };
22
28
  };
23
29
  };
@@ -1,42 +1,45 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.default = login;
4
7
  const mercury_client_1 = require("@sprucelabs/mercury-client");
5
8
  const test_utils_1 = require("@sprucelabs/test-utils");
6
9
  const __1 = require("../..");
10
+ const FakerTracker_1 = __importDefault(require("../../FakerTracker"));
7
11
  function login(phone) {
8
12
  return function (Class) {
9
13
  test_utils_1.assert.isFunction(Class.Fixture, `You can only @login if your test extends AbstractSpruceFixtureTest`);
10
14
  __1.MercuryFixture.setShouldAutomaticallyClearDefaultClient(false);
11
15
  __1.ViewFixture.setShouldAutomaticallyResetAuth(false);
12
- const beforeAll = Class.beforeAll.bind(Class);
13
16
  let proxyGenerator;
14
- Class.beforeAll = async () => {
17
+ let client;
18
+ test_utils_1.SpruceTestResolver.onWillCallBeforeAll(async () => {
15
19
  mercury_client_1.MercuryClientFactory.setIsTestMode(true);
16
- await beforeAll();
17
- const viewFixture = Class.Fixture('view');
18
- const { client, person } = await viewFixture.loginAsDemoPerson(phone);
20
+ });
21
+ test_utils_1.SpruceTestResolver.onDidCallBeforeAll(async () => {
22
+ const viewFixture = FakerTracker_1.default.getFixtures(Class.cwd).views;
23
+ const { client: c, person } = await viewFixture.loginAsDemoPerson(phone);
24
+ client = c;
19
25
  proxyGenerator = viewFixture.getProxyTokenGenerator();
20
26
  //@ts-ignore
21
27
  login.loggedInPerson = person;
22
28
  __1.MercuryFixture.setDefaultClient(client);
23
29
  __1.ViewFixture.lockProxyCacheForPerson(person.id);
24
30
  await emitDidLogin(client);
25
- };
26
- const beforeEach = Class.beforeEach.bind(Class);
27
- Class.beforeEach = async () => {
28
- Class.Fixture('view').setProxyTokenGenerator(proxyGenerator);
31
+ });
32
+ test_utils_1.SpruceTestResolver.onWillCallBeforeEach(async () => {
33
+ __1.MercuryFixture.setDefaultContractToLocalEventsIfExist(Class.cwd);
34
+ FakerTracker_1.default.getFixtures(Class.cwd).views.setProxyTokenGenerator(proxyGenerator);
35
+ });
36
+ test_utils_1.SpruceTestResolver.onWillCallAfterAll(async () => {
29
37
  __1.MercuryFixture.setDefaultContractToLocalEventsIfExist(Class.cwd);
30
- await beforeEach?.();
31
- };
32
- const afterAll = Class.afterAll.bind(Class);
33
- Class.afterAll = async () => {
34
- const client = __1.MercuryFixture.getDefaultClient();
35
38
  await emitWillLogout(client);
36
- __1.MercuryFixture.clearDefaultClient();
37
- await afterAll();
39
+ });
40
+ test_utils_1.SpruceTestResolver.onDidCallAfterAll(async () => {
38
41
  await client?.disconnect();
39
- };
42
+ });
40
43
  };
41
44
  }
42
45
  login.getClient = () => {
@@ -6,38 +6,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = seed;
7
7
  const mercury_client_1 = require("@sprucelabs/mercury-client");
8
8
  const test_utils_1 = require("@sprucelabs/test-utils");
9
+ const FakerTracker_1 = __importDefault(require("../../FakerTracker"));
10
+ const MercuryFixture_1 = __importDefault(require("../fixtures/MercuryFixture"));
9
11
  const StoreFixture_1 = __importDefault(require("../fixtures/StoreFixture"));
10
12
  const login_1 = __importDefault(require("./login"));
11
13
  function seed(storeName, totalToSeed, ...params) {
12
14
  return function (Class, key, descriptor) {
13
15
  if ((storeName === 'organizations' || storeName === 'locations') &&
14
- !Class.beforeAll.__patched) {
15
- const beforeAll = Class.beforeAll.bind(Class);
16
+ !Class.__isSeedingPatched) {
16
17
  Class.__shouldResetAccount = false;
17
- Class.beforeAll = async () => {
18
- await beforeAll();
18
+ test_utils_1.SpruceTestResolver.onDidCallBeforeAll(async (Class) => {
19
19
  await login_1.default.on('did-login', async () => {
20
20
  await forceResetAccount(Class);
21
21
  });
22
- await login_1.default.on('will-logout', async () => {
23
- // await forceResetAccount(Class)
24
- // if (shouldResetTestClientOnWillLogout) {
25
- //
26
- // MercuryTestClient.reset()
27
- // }
28
- });
29
- };
30
- Class.beforeAll.__patched = true;
22
+ });
23
+ Class.__isSeedingPatched = true;
31
24
  }
32
25
  StoreFixture_1.default.setShouldAutomaticallyResetDatabase(false);
33
26
  StoreFixture_1.default.resetDbConnectionSettings();
34
27
  const seed = attachSeeder(storeName, Class, totalToSeed, params);
35
- const bound = descriptor?.value?.bind?.(Class);
28
+ const unbound = descriptor?.value;
36
29
  attachCleanup(Class);
37
30
  descriptor.value = async (...args) => {
38
31
  await optionallyReset(Class, key);
39
32
  await seed();
40
- await bound?.(...args);
33
+ const Test = test_utils_1.SpruceTestResolver.getActiveTest();
34
+ const allArgs = [Test, args];
35
+ await unbound?.apply(...allArgs);
41
36
  };
42
37
  };
43
38
  }
@@ -56,7 +51,8 @@ async function optionallyReset(Class, key) {
56
51
  async function reset(Class) {
57
52
  if (Class.__shouldResetAccount) {
58
53
  Class.__shouldResetAccount = false;
59
- await Class.Fixture('seed').resetAccount();
54
+ const cwd = test_utils_1.SpruceTestResolver.getActiveTest().cwd;
55
+ await FakerTracker_1.default.getFixtures(cwd).seeder.resetAccount();
60
56
  }
61
57
  await StoreFixture_1.default.reset();
62
58
  }
@@ -67,29 +63,25 @@ seed.disableResettingTestClient = () => {
67
63
  function attachCleanup(Class) {
68
64
  if (!Class.__attachedStoreAfterEach) {
69
65
  Class.__attachedStoreAfterEach = true;
70
- const afterEach = Class.afterEach.bind(Class);
71
- const beforeEach = Class.beforeEach.bind(Class);
72
- Class.afterEach = async () => {
73
- await afterEach?.();
66
+ test_utils_1.SpruceTestResolver.onWillCallBeforeEach(async (Class) => {
67
+ MercuryFixture_1.default.setDefaultContractToLocalEventsIfExist(Class.cwd);
68
+ await optionallyReset(Class, 'beforeEach');
69
+ });
70
+ test_utils_1.SpruceTestResolver.onDidCallAfterEach(async () => {
74
71
  shouldResetTestClient && mercury_client_1.MercuryTestClient.reset();
75
72
  delete Class.__lastReset;
76
- };
77
- Class.beforeEach = async () => {
78
- await optionallyReset(Class, 'beforeEach');
79
- await beforeEach?.();
80
- };
73
+ });
81
74
  }
82
75
  }
83
76
  function attachSeeder(storeName, TestClass, totalToSeed, params) {
84
- //@ts-ignore
85
77
  const fixtureMap = {
86
- locations: 'seed',
87
- organizations: 'seed',
88
- teammates: 'seed',
89
- guests: 'seed',
90
- groupManagers: 'seed',
91
- managers: 'seed',
92
- owners: 'seed',
78
+ locations: 'seeder',
79
+ organizations: 'seeder',
80
+ teammates: 'seeder',
81
+ guests: 'seeder',
82
+ groupManagers: 'seeder',
83
+ managers: 'seeder',
84
+ owners: 'seeder',
93
85
  };
94
86
  //@ts-ignore
95
87
  const methodMap = {
@@ -111,21 +103,25 @@ function attachSeeder(storeName, TestClass, totalToSeed, params) {
111
103
  managers: 'totalManagers',
112
104
  owners: 'totalOwners',
113
105
  };
114
- const method = methodMap[storeName] ?? 'seed';
106
+ const method = (methodMap[storeName] ?? 'seed');
115
107
  const optionsKey = keyMap[storeName] ?? 'totalToSeed';
116
- const fixtureName = fixtureMap[storeName] ?? 'store';
108
+ const fixtureName = (fixtureMap[storeName] ??
109
+ 'stores');
117
110
  const options = { [optionsKey]: totalToSeed };
118
111
  return async function () {
119
- let fixture = TestClass.Fixture(fixtureName);
120
- if (fixtureName === 'store') {
112
+ const ActiveTest = test_utils_1.SpruceTestResolver.getActiveTest();
113
+ const fixtures = FakerTracker_1.default.getFixtures(ActiveTest.cwd);
114
+ let fixture = fixtures[fixtureName];
115
+ if (fixtureName === 'stores') {
121
116
  fixture = await fixture.getStore(storeName);
122
- options.TestClass = TestClass;
117
+ options.TestClass = ActiveTest;
123
118
  }
124
119
  else {
125
120
  TestClass.__shouldResetAccount = true;
126
121
  }
127
122
  test_utils_1.assert.isFunction(fixture[method], `The '${storeName}' store you created needs a method called 'seed(options: StoreSeedOptions)' in order for seeding. You must implement it yourself... for now.`);
128
123
  const args = [options, ...(params ?? [])];
124
+ //@ts-ignore
129
125
  await fixture[method](...args);
130
126
  };
131
127
  }
@@ -3,7 +3,7 @@ export default class FixtureFactory {
3
3
  private static fixtures;
4
4
  private cwd;
5
5
  private namespace?;
6
- private static viewMercury?;
6
+ private static mercuryFixture?;
7
7
  constructor(options: {
8
8
  cwd: string;
9
9
  namespace?: string;
@@ -11,6 +11,7 @@ export default class FixtureFactory {
11
11
  setCwd(cwd: string): void;
12
12
  setNamespace(namespace: string): void;
13
13
  Fixture<Name extends FixtureName>(named: Name, options?: Partial<FixtureConstructorOptionsMap[Name]>): FixtureMap[Name];
14
+ static clearMercuryFixture(): void;
14
15
  private getMercuryFixture;
15
16
  static destroy(): Promise<void>;
16
17
  static beforeAll(): Promise<void>;
@@ -38,12 +38,11 @@ class FixtureFactory {
38
38
  this.namespace = namespace;
39
39
  }
40
40
  Fixture(named, options) {
41
- const mercuryFixture = this.getMercuryFixture(named);
41
+ const mercuryFixture = this.getMercuryFixture();
42
42
  let fixture;
43
43
  switch (named) {
44
44
  case 'mercury':
45
- fixture = mercuryFixture;
46
- break;
45
+ return mercuryFixture;
47
46
  case 'person': {
48
47
  fixture = new PersonFixture_1.default({
49
48
  connectToApi: mercuryFixture.getConnectFactory(),
@@ -52,7 +51,8 @@ class FixtureFactory {
52
51
  }
53
52
  case 'role': {
54
53
  fixture = new RoleFixture_1.default({
55
- people: this.Fixture('person'),
54
+ //@ts-ignore
55
+ people: options?.people ?? this.Fixture('person'),
56
56
  getNewestOrg: async () => {
57
57
  return this.Fixture('organization').getNewestOrganization();
58
58
  },
@@ -60,24 +60,24 @@ class FixtureFactory {
60
60
  break;
61
61
  }
62
62
  case 'organization': {
63
- const people =
64
- //@ts-ignore
65
- options?.people ??
66
- new PersonFixture_1.default({
67
- connectToApi: mercuryFixture.getConnectFactory(),
68
- });
69
63
  fixture = new OrganizationFixture_1.default({
70
- people,
71
- roles: this.Fixture('role'),
64
+ people:
65
+ //@ts-ignore
66
+ options?.people ??
67
+ new PersonFixture_1.default({
68
+ connectToApi: mercuryFixture.getConnectFactory(),
69
+ }),
70
+ //@ts-ignore
71
+ roles: options?.roles ?? this.Fixture('role'),
72
72
  });
73
73
  break;
74
74
  }
75
75
  case 'skill': {
76
76
  const personFixture =
77
77
  //@ts-ignore
78
- options?.personFixture ?? this.Fixture('person');
78
+ options?.people ?? this.Fixture('person');
79
79
  fixture = new SkillFixture_1.default({
80
- personFixture,
80
+ people: personFixture,
81
81
  connectToApi: mercuryFixture.getConnectFactory(),
82
82
  });
83
83
  break;
@@ -92,7 +92,8 @@ class FixtureFactory {
92
92
  }
93
93
  case 'location': {
94
94
  fixture = new LocationFixture_1.default({
95
- roles: this.Fixture('role'),
95
+ //@ts-ignore
96
+ roles: options?.roles ?? this.Fixture('role'),
96
97
  //@ts-ignore
97
98
  people: options?.people ?? this.Fixture('person'),
98
99
  organizations:
@@ -103,9 +104,13 @@ class FixtureFactory {
103
104
  }
104
105
  case 'seed':
105
106
  fixture = new SeedFixture_1.default({
106
- organizations: this.Fixture('organization'),
107
- locations: this.Fixture('location'),
108
- people: this.Fixture('person'),
107
+ organizations:
108
+ //@ts-ignore
109
+ options?.organizations ?? this.Fixture('organization'),
110
+ //@ts-ignore
111
+ locations: options?.locations ?? this.Fixture('location'),
112
+ //@ts-ignore
113
+ people: options?.people ?? this.Fixture('person'),
109
114
  });
110
115
  break;
111
116
  case 'permission':
@@ -116,14 +121,16 @@ class FixtureFactory {
116
121
  throw new Error('You need to be in a registered skill to load view controllers.');
117
122
  }
118
123
  fixture = new ViewFixture_1.default({
119
- //@ts-ignore
120
- people: options?.personFixture ?? this.Fixture('person'),
124
+ //@ts-ignore
125
+ people: options?.people ?? this.Fixture('person'),
121
126
  connectToApi: mercuryFixture.getConnectFactory(),
122
127
  fixtureFactory: this,
123
128
  namespace: this.namespace,
124
129
  proxyDecorator: __1.ClientProxyDecorator.getInstance(),
125
130
  cwd: this.cwd,
126
- permissions: this.Fixture('permission'),
131
+ permissions:
132
+ //@ts-ignore
133
+ options?.permissions ?? this.Fixture('permission'),
127
134
  ...options,
128
135
  });
129
136
  break;
@@ -149,20 +156,14 @@ class FixtureFactory {
149
156
  ],
150
157
  });
151
158
  }
152
- getMercuryFixture(name) {
153
- let mercury;
154
- if (name === 'view') {
155
- if (!FixtureFactory.viewMercury) {
156
- FixtureFactory.viewMercury = new MercuryFixture_1.default(this.cwd);
157
- FixtureFactory.fixtures.push(FixtureFactory.viewMercury);
158
- }
159
- mercury = FixtureFactory.viewMercury;
160
- }
161
- if (!mercury) {
162
- mercury = new MercuryFixture_1.default(this.cwd);
163
- FixtureFactory.fixtures.push(mercury);
159
+ static clearMercuryFixture() {
160
+ delete this.mercuryFixture;
161
+ }
162
+ getMercuryFixture() {
163
+ if (!FixtureFactory.mercuryFixture) {
164
+ FixtureFactory.mercuryFixture = new MercuryFixture_1.default(this.cwd);
164
165
  }
165
- return mercury;
166
+ return FixtureFactory.mercuryFixture;
166
167
  }
167
168
  static async destroy() {
168
169
  for (const f of this.fixtures) {
@@ -171,7 +172,8 @@ class FixtureFactory {
171
172
  }
172
173
  }
173
174
  this.fixtures = [];
174
- FixtureFactory.viewMercury = undefined;
175
+ await FixtureFactory.mercuryFixture?.destroy();
176
+ FixtureFactory.mercuryFixture = undefined;
175
177
  }
176
178
  static async beforeAll() {
177
179
  await Promise.all([
@@ -0,0 +1,56 @@
1
+ import { DatabaseFixture } from '@sprucelabs/data-stores';
2
+ import { MercuryClient } from '@sprucelabs/mercury-client';
3
+ import { FixtureName, FixtureConstructorOptionsMap } from '../../types/fixture.types';
4
+ import LocationFixture from './LocationFixture';
5
+ import MercuryFixture from './MercuryFixture';
6
+ import OrganizationFixture from './OrganizationFixture';
7
+ import PermissionFixture from './PermissionFixture';
8
+ import PersonFixture from './PersonFixture';
9
+ import RoleFixture from './RoleFixture';
10
+ import SeedFixture from './SeedFixture';
11
+ import SkillFixture from './SkillFixture';
12
+ import StoreFixture from './StoreFixture';
13
+ import ViewFixture from './ViewFixture';
14
+ export default class FixtureWarehouse {
15
+ _fakedClient?: MercuryClient;
16
+ private _views?;
17
+ private _roles?;
18
+ private _locations?;
19
+ private _organizations?;
20
+ private _people?;
21
+ private _seeder?;
22
+ private _skills?;
23
+ private _mercury?;
24
+ private _stores?;
25
+ private _database?;
26
+ private _permissions?;
27
+ private _fixtures?;
28
+ private cwd;
29
+ protected constructor(cwd: string);
30
+ static Warehouse(cwd: string): FixtureWarehouse;
31
+ setCwd(cwd: string): void;
32
+ Fixture<Name extends FixtureName>(name: Name, options?: Partial<FixtureConstructorOptionsMap[Name]>): import("../../types/fixture.types").FixtureMap[Name];
33
+ get views(): ViewFixture;
34
+ set views(fixture: ViewFixture | undefined);
35
+ get permissions(): PermissionFixture;
36
+ set permissions(fixture: PermissionFixture | undefined);
37
+ get roles(): RoleFixture;
38
+ set roles(fixture: RoleFixture | undefined);
39
+ get locations(): LocationFixture;
40
+ set locations(fixture: LocationFixture | undefined);
41
+ get organizations(): OrganizationFixture;
42
+ set organizations(fixture: OrganizationFixture | undefined);
43
+ get people(): PersonFixture;
44
+ set people(fixture: PersonFixture | undefined);
45
+ get seeder(): SeedFixture;
46
+ set seeder(fixture: SeedFixture | undefined);
47
+ get skills(): SkillFixture;
48
+ set skills(fixture: SkillFixture | undefined);
49
+ get mercury(): MercuryFixture;
50
+ set mercury(fixture: MercuryFixture | undefined);
51
+ get stores(): StoreFixture;
52
+ set stores(fixture: StoreFixture | undefined);
53
+ get database(): DatabaseFixture;
54
+ set database(fixture: DatabaseFixture | undefined);
55
+ reset(): void;
56
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
7
+ const FixtureFactory_1 = __importDefault(require("./FixtureFactory"));
8
+ class FixtureWarehouse {
9
+ constructor(cwd) {
10
+ this.cwd = cwd;
11
+ }
12
+ static Warehouse(cwd) {
13
+ return new this(cwd);
14
+ }
15
+ setCwd(cwd) {
16
+ if (this.cwd !== cwd) {
17
+ this.cwd = cwd;
18
+ delete this._fixtures;
19
+ FixtureFactory_1.default.clearMercuryFixture();
20
+ }
21
+ }
22
+ Fixture(name, options) {
23
+ if (!this._fixtures) {
24
+ const pkg = spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, 'package.json');
25
+ let namespace;
26
+ if (spruce_skill_utils_1.diskUtil.doesFileExist(pkg)) {
27
+ const values = JSON.parse(spruce_skill_utils_1.diskUtil.readFile(pkg));
28
+ namespace = values?.skill?.namespace;
29
+ }
30
+ this._fixtures = new FixtureFactory_1.default({
31
+ cwd: this.cwd,
32
+ namespace,
33
+ });
34
+ }
35
+ return this._fixtures.Fixture(name, options);
36
+ }
37
+ get views() {
38
+ if (!this._views) {
39
+ this._views = this.Fixture('view', {
40
+ people: this.people,
41
+ organizations: this.organizations,
42
+ locations: this.locations,
43
+ permissions: this.permissions,
44
+ });
45
+ }
46
+ return this._views;
47
+ }
48
+ set views(fixture) {
49
+ this._views = fixture;
50
+ }
51
+ get permissions() {
52
+ if (!this._permissions) {
53
+ this._permissions = this.Fixture('permission');
54
+ }
55
+ return this._permissions;
56
+ }
57
+ set permissions(fixture) {
58
+ this._permissions = fixture;
59
+ }
60
+ get roles() {
61
+ if (!this._roles) {
62
+ this._roles = this.Fixture('role', {
63
+ people: this.people,
64
+ });
65
+ }
66
+ return this._roles;
67
+ }
68
+ set roles(fixture) {
69
+ this._roles = fixture;
70
+ }
71
+ get locations() {
72
+ if (!this._locations) {
73
+ this._locations = this.Fixture('location', {
74
+ organizations: this.organizations,
75
+ people: this.people,
76
+ roles: this.roles,
77
+ });
78
+ }
79
+ return this._locations;
80
+ }
81
+ set locations(fixture) {
82
+ this._locations = fixture;
83
+ }
84
+ get organizations() {
85
+ if (!this._organizations) {
86
+ this._organizations = this.Fixture('organization', {
87
+ people: this.people,
88
+ roles: this.roles,
89
+ });
90
+ }
91
+ return this._organizations;
92
+ }
93
+ set organizations(fixture) {
94
+ this._organizations = fixture;
95
+ }
96
+ get people() {
97
+ if (!this._people) {
98
+ this._people = this.Fixture('person');
99
+ }
100
+ return this._people;
101
+ }
102
+ set people(fixture) {
103
+ this._people = fixture;
104
+ }
105
+ get seeder() {
106
+ if (!this._seeder) {
107
+ this._seeder = this.Fixture('seed', {
108
+ locations: this.locations,
109
+ organizations: this.organizations,
110
+ people: this.people,
111
+ });
112
+ }
113
+ return this._seeder;
114
+ }
115
+ set seeder(fixture) {
116
+ this._seeder = fixture;
117
+ }
118
+ get skills() {
119
+ if (!this._skills) {
120
+ this._skills = this.Fixture('skill', {
121
+ people: this.people,
122
+ });
123
+ }
124
+ return this._skills;
125
+ }
126
+ set skills(fixture) {
127
+ this._skills = fixture;
128
+ }
129
+ get mercury() {
130
+ if (!this._mercury) {
131
+ this._mercury = this.Fixture('mercury');
132
+ }
133
+ return this._mercury;
134
+ }
135
+ set mercury(fixture) {
136
+ this._mercury = fixture;
137
+ }
138
+ get stores() {
139
+ if (!this._stores) {
140
+ this._stores = this.Fixture('store');
141
+ }
142
+ return this._stores;
143
+ }
144
+ set stores(fixture) {
145
+ this._stores = fixture;
146
+ }
147
+ get database() {
148
+ if (!this._database) {
149
+ this._database = this.Fixture('database');
150
+ }
151
+ return this._database;
152
+ }
153
+ set database(fixture) {
154
+ this._database = fixture;
155
+ }
156
+ reset() {
157
+ this.views = undefined;
158
+ this.roles = undefined;
159
+ this.locations = undefined;
160
+ this.organizations = undefined;
161
+ this.people = undefined;
162
+ this.seeder = undefined;
163
+ this.skills = undefined;
164
+ this.mercury = undefined;
165
+ this.stores = undefined;
166
+ this.database = undefined;
167
+ this.permissions = undefined;
168
+ }
169
+ }
170
+ exports.default = FixtureWarehouse;
@@ -4,7 +4,7 @@ import PersonFixture from './PersonFixture';
4
4
  import RoleFixture from './RoleFixture';
5
5
  export default class LocationFixture {
6
6
  private people;
7
- private orgs;
7
+ private organizations;
8
8
  private roles;
9
9
  private locationCounter;
10
10
  private static locationCount;
@@ -13,11 +13,11 @@ export default class LocationFixture {
13
13
  organizations: OrganizationFixture;
14
14
  roles: RoleFixture;
15
15
  });
16
- seedDemoLocation(values?: SeedLocationValues): Promise<Pick<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Spruce.v2020_07_22.LocationSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false>>, "id" | "address" | "phone" | "name" | "organizationId" | "timezone" | "dateCreated" | "dateUpdated" | "dateDeleted" | "isPublic" | "slug" | "num">>;
16
+ seedDemoLocation(values?: SeedLocationValues): Promise<Pick<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Spruce.v2020_07_22.LocationSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false>>, "id" | "address" | "phone" | "organizationId" | "timezone" | "dateCreated" | "dateUpdated" | "name" | "slug" | "dateDeleted" | "num" | "isPublic">>;
17
17
  private generateLocationSlug;
18
- getLocationById(id: string): Promise<Pick<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Spruce.v2020_07_22.LocationSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false>>, "id" | "address" | "phone" | "name" | "organizationId" | "timezone" | "dateCreated" | "dateUpdated" | "dateDeleted" | "isPublic" | "slug" | "num">>;
19
- getNewestLocation(organizationId?: string): Promise<Pick<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Spruce.v2020_07_22.LocationSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false>>, "id" | "address" | "phone" | "name" | "organizationId" | "timezone" | "dateCreated" | "dateUpdated" | "dateDeleted" | "isPublic" | "slug" | "num"> | null>;
20
- listLocations(organizationId?: string): Promise<Pick<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Spruce.v2020_07_22.LocationSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false>>, "id" | "address" | "phone" | "name" | "organizationId" | "timezone" | "dateCreated" | "dateUpdated" | "dateDeleted" | "isPublic" | "slug" | "num">[]>;
18
+ getLocationById(id: string): Promise<Pick<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Spruce.v2020_07_22.LocationSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false>>, "id" | "address" | "phone" | "organizationId" | "timezone" | "dateCreated" | "dateUpdated" | "name" | "slug" | "dateDeleted" | "num" | "isPublic">>;
19
+ getNewestLocation(organizationId?: string): Promise<Pick<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Spruce.v2020_07_22.LocationSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false>>, "id" | "address" | "phone" | "organizationId" | "timezone" | "dateCreated" | "dateUpdated" | "name" | "slug" | "dateDeleted" | "num" | "isPublic"> | null>;
20
+ listLocations(organizationId?: string): Promise<Pick<import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Spruce.v2020_07_22.LocationSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Spruce.v2020_07_22.LocationSchema, false>>, "id" | "address" | "phone" | "organizationId" | "timezone" | "dateCreated" | "dateUpdated" | "name" | "slug" | "dateDeleted" | "num" | "isPublic">[]>;
21
21
  isPartOfLocation(options: {
22
22
  personId: string;
23
23
  locationId: string;