@sprucelabs/spruce-test-fixtures 66.0.20 → 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
@@ -7,23 +7,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { assert } from '@sprucelabs/test-utils';
10
+ import { assert, SpruceTestResolver } from '@sprucelabs/test-utils';
11
+ import FakerTracker from '../../FakerTracker.js';
11
12
  export default function install() { }
12
13
  install.skills = (...namespaces) => {
13
14
  if (namespaces.length === 0) {
14
15
  assert.fail(`You must pass the skill namespaces so I can install them.`);
15
16
  }
16
17
  return function (Class, key, descriptor) {
17
- const old = descriptor.value.bind(Class);
18
+ const old = descriptor.value;
18
19
  descriptor.value = (...args) => __awaiter(this, void 0, void 0, function* () {
19
- const orgsFixture = Class.Fixture('organization');
20
+ const orgsFixture = FakerTracker.getFixtures(Class.cwd).Fixture('organization');
20
21
  const latestOrg = yield orgsFixture.getNewestOrganization();
21
22
  assert.isTruthy(latestOrg, `You need to seed at least 1 organization. Heads up, I'll install it in the newest organization only.`);
22
23
  yield orgsFixture.installSkillsByNamespace({
23
24
  organizationId: latestOrg.id,
24
25
  namespaces,
25
26
  });
26
- return old(...args);
27
+ const Test = SpruceTestResolver.getActiveTest();
28
+ const bound = old.bind(Test);
29
+ return bound(...args);
27
30
  });
28
31
  };
29
32
  };
@@ -8,41 +8,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { MercuryClientFactory } from '@sprucelabs/mercury-client';
11
- import { assert } from '@sprucelabs/test-utils';
11
+ import { assert, SpruceTestResolver } from '@sprucelabs/test-utils';
12
12
  import { MercuryFixture, ViewFixture } from '../../index.js';
13
+ import FakerTracker from '../../FakerTracker.js';
13
14
  export default function login(phone) {
14
15
  return function (Class) {
15
16
  assert.isFunction(Class.Fixture, `You can only @login if your test extends AbstractSpruceFixtureTest`);
16
17
  MercuryFixture.setShouldAutomaticallyClearDefaultClient(false);
17
18
  ViewFixture.setShouldAutomaticallyResetAuth(false);
18
- const beforeAll = Class.beforeAll.bind(Class);
19
19
  let proxyGenerator;
20
- Class.beforeAll = () => __awaiter(this, void 0, void 0, function* () {
20
+ let client;
21
+ SpruceTestResolver.onWillCallBeforeAll(() => __awaiter(this, void 0, void 0, function* () {
21
22
  MercuryClientFactory.setIsTestMode(true);
22
- yield beforeAll();
23
- const viewFixture = Class.Fixture('view');
24
- const { client, person } = yield viewFixture.loginAsDemoPerson(phone);
23
+ }));
24
+ SpruceTestResolver.onDidCallBeforeAll(() => __awaiter(this, void 0, void 0, function* () {
25
+ const viewFixture = FakerTracker.getFixtures(Class.cwd).views;
26
+ const { client: c, person } = yield viewFixture.loginAsDemoPerson(phone);
27
+ client = c;
25
28
  proxyGenerator = viewFixture.getProxyTokenGenerator();
26
29
  //@ts-ignore
27
30
  login.loggedInPerson = person;
28
31
  MercuryFixture.setDefaultClient(client);
29
32
  ViewFixture.lockProxyCacheForPerson(person.id);
30
33
  yield emitDidLogin(client);
31
- });
32
- const beforeEach = Class.beforeEach.bind(Class);
33
- Class.beforeEach = () => __awaiter(this, void 0, void 0, function* () {
34
- Class.Fixture('view').setProxyTokenGenerator(proxyGenerator);
34
+ }));
35
+ SpruceTestResolver.onWillCallBeforeEach(() => __awaiter(this, void 0, void 0, function* () {
36
+ MercuryFixture.setDefaultContractToLocalEventsIfExist(Class.cwd);
37
+ FakerTracker.getFixtures(Class.cwd).views.setProxyTokenGenerator(proxyGenerator);
38
+ }));
39
+ SpruceTestResolver.onWillCallAfterAll(() => __awaiter(this, void 0, void 0, function* () {
35
40
  MercuryFixture.setDefaultContractToLocalEventsIfExist(Class.cwd);
36
- yield (beforeEach === null || beforeEach === void 0 ? void 0 : beforeEach());
37
- });
38
- const afterAll = Class.afterAll.bind(Class);
39
- Class.afterAll = () => __awaiter(this, void 0, void 0, function* () {
40
- const client = MercuryFixture.getDefaultClient();
41
41
  yield emitWillLogout(client);
42
- MercuryFixture.clearDefaultClient();
43
- yield afterAll();
42
+ }));
43
+ SpruceTestResolver.onDidCallAfterAll(() => __awaiter(this, void 0, void 0, function* () {
44
44
  yield (client === null || client === void 0 ? void 0 : client.disconnect());
45
- });
45
+ }));
46
46
  };
47
47
  }
48
48
  login.getClient = () => {
@@ -8,40 +8,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { MercuryTestClient } from '@sprucelabs/mercury-client';
11
- import { assert } from '@sprucelabs/test-utils';
11
+ import { assert, SpruceTestResolver } from '@sprucelabs/test-utils';
12
+ import FakerTracker from '../../FakerTracker.js';
13
+ import MercuryFixture from '../fixtures/MercuryFixture.js';
12
14
  import StoreFixture from '../fixtures/StoreFixture.js';
13
15
  import login from './login.js';
14
16
  export default function seed(storeName, totalToSeed, ...params) {
15
17
  return function (Class, key, descriptor) {
16
- var _a, _b;
17
18
  if ((storeName === 'organizations' || storeName === 'locations') &&
18
- !Class.beforeAll.__patched) {
19
- const beforeAll = Class.beforeAll.bind(Class);
19
+ !Class.__isSeedingPatched) {
20
20
  Class.__shouldResetAccount = false;
21
- Class.beforeAll = () => __awaiter(this, void 0, void 0, function* () {
22
- yield beforeAll();
21
+ SpruceTestResolver.onDidCallBeforeAll((Class) => __awaiter(this, void 0, void 0, function* () {
23
22
  yield login.on('did-login', () => __awaiter(this, void 0, void 0, function* () {
24
23
  yield forceResetAccount(Class);
25
24
  }));
26
- yield login.on('will-logout', () => __awaiter(this, void 0, void 0, function* () {
27
- // await forceResetAccount(Class)
28
- // if (shouldResetTestClientOnWillLogout) {
29
- //
30
- // MercuryTestClient.reset()
31
- // }
32
- }));
33
- });
34
- Class.beforeAll.__patched = true;
25
+ }));
26
+ Class.__isSeedingPatched = true;
35
27
  }
36
28
  StoreFixture.setShouldAutomaticallyResetDatabase(false);
37
29
  StoreFixture.resetDbConnectionSettings();
38
30
  const seed = attachSeeder(storeName, Class, totalToSeed, params);
39
- const bound = (_b = (_a = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value) === null || _a === void 0 ? void 0 : _a.bind) === null || _b === void 0 ? void 0 : _b.call(_a, Class);
31
+ const unbound = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value;
40
32
  attachCleanup(Class);
41
33
  descriptor.value = (...args) => __awaiter(this, void 0, void 0, function* () {
42
34
  yield optionallyReset(Class, key);
43
35
  yield seed();
44
- yield (bound === null || bound === void 0 ? void 0 : bound(...args));
36
+ const Test = SpruceTestResolver.getActiveTest();
37
+ const allArgs = [Test, args];
38
+ yield (unbound === null || unbound === void 0 ? void 0 : unbound.apply(...allArgs));
45
39
  });
46
40
  };
47
41
  }
@@ -65,7 +59,8 @@ function reset(Class) {
65
59
  return __awaiter(this, void 0, void 0, function* () {
66
60
  if (Class.__shouldResetAccount) {
67
61
  Class.__shouldResetAccount = false;
68
- yield Class.Fixture('seed').resetAccount();
62
+ const cwd = SpruceTestResolver.getActiveTest().cwd;
63
+ yield FakerTracker.getFixtures(cwd).seeder.resetAccount();
69
64
  }
70
65
  yield StoreFixture.reset();
71
66
  });
@@ -77,30 +72,26 @@ seed.disableResettingTestClient = () => {
77
72
  function attachCleanup(Class) {
78
73
  if (!Class.__attachedStoreAfterEach) {
79
74
  Class.__attachedStoreAfterEach = true;
80
- const afterEach = Class.afterEach.bind(Class);
81
- const beforeEach = Class.beforeEach.bind(Class);
82
- Class.afterEach = () => __awaiter(this, void 0, void 0, function* () {
83
- yield (afterEach === null || afterEach === void 0 ? void 0 : afterEach());
75
+ SpruceTestResolver.onWillCallBeforeEach((Class) => __awaiter(this, void 0, void 0, function* () {
76
+ MercuryFixture.setDefaultContractToLocalEventsIfExist(Class.cwd);
77
+ yield optionallyReset(Class, 'beforeEach');
78
+ }));
79
+ SpruceTestResolver.onDidCallAfterEach(() => __awaiter(this, void 0, void 0, function* () {
84
80
  shouldResetTestClient && MercuryTestClient.reset();
85
81
  delete Class.__lastReset;
86
- });
87
- Class.beforeEach = () => __awaiter(this, void 0, void 0, function* () {
88
- yield optionallyReset(Class, 'beforeEach');
89
- yield (beforeEach === null || beforeEach === void 0 ? void 0 : beforeEach());
90
- });
82
+ }));
91
83
  }
92
84
  }
93
85
  function attachSeeder(storeName, TestClass, totalToSeed, params) {
94
86
  var _a, _b, _c;
95
- //@ts-ignore
96
87
  const fixtureMap = {
97
- locations: 'seed',
98
- organizations: 'seed',
99
- teammates: 'seed',
100
- guests: 'seed',
101
- groupManagers: 'seed',
102
- managers: 'seed',
103
- owners: 'seed',
88
+ locations: 'seeder',
89
+ organizations: 'seeder',
90
+ teammates: 'seeder',
91
+ guests: 'seeder',
92
+ groupManagers: 'seeder',
93
+ managers: 'seeder',
94
+ owners: 'seeder',
104
95
  };
105
96
  //@ts-ignore
106
97
  const methodMap = {
@@ -122,22 +113,25 @@ function attachSeeder(storeName, TestClass, totalToSeed, params) {
122
113
  managers: 'totalManagers',
123
114
  owners: 'totalOwners',
124
115
  };
125
- const method = (_a = methodMap[storeName]) !== null && _a !== void 0 ? _a : 'seed';
116
+ const method = ((_a = methodMap[storeName]) !== null && _a !== void 0 ? _a : 'seed');
126
117
  const optionsKey = (_b = keyMap[storeName]) !== null && _b !== void 0 ? _b : 'totalToSeed';
127
- const fixtureName = (_c = fixtureMap[storeName]) !== null && _c !== void 0 ? _c : 'store';
118
+ const fixtureName = ((_c = fixtureMap[storeName]) !== null && _c !== void 0 ? _c : 'stores');
128
119
  const options = { [optionsKey]: totalToSeed };
129
120
  return function () {
130
121
  return __awaiter(this, void 0, void 0, function* () {
131
- let fixture = TestClass.Fixture(fixtureName);
132
- if (fixtureName === 'store') {
122
+ const ActiveTest = SpruceTestResolver.getActiveTest();
123
+ const fixtures = FakerTracker.getFixtures(ActiveTest.cwd);
124
+ let fixture = fixtures[fixtureName];
125
+ if (fixtureName === 'stores') {
133
126
  fixture = yield fixture.getStore(storeName);
134
- options.TestClass = TestClass;
127
+ options.TestClass = ActiveTest;
135
128
  }
136
129
  else {
137
130
  TestClass.__shouldResetAccount = true;
138
131
  }
139
132
  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.`);
140
133
  const args = [options, ...(params !== null && params !== void 0 ? params : [])];
134
+ //@ts-ignore
141
135
  yield fixture[method](...args);
142
136
  });
143
137
  };
@@ -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>;
@@ -42,13 +42,12 @@ class FixtureFactory {
42
42
  this.namespace = namespace;
43
43
  }
44
44
  Fixture(named, options) {
45
- var _a, _b, _c, _d, _e;
46
- const mercuryFixture = this.getMercuryFixture(named);
45
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
46
+ const mercuryFixture = this.getMercuryFixture();
47
47
  let fixture;
48
48
  switch (named) {
49
49
  case 'mercury':
50
- fixture = mercuryFixture;
51
- break;
50
+ return mercuryFixture;
52
51
  case 'person': {
53
52
  fixture = new PersonFixture({
54
53
  connectToApi: mercuryFixture.getConnectFactory(),
@@ -57,7 +56,8 @@ class FixtureFactory {
57
56
  }
58
57
  case 'role': {
59
58
  fixture = new RoleFixture({
60
- people: this.Fixture('person'),
59
+ //@ts-ignore
60
+ people: (_a = options === null || options === void 0 ? void 0 : options.people) !== null && _a !== void 0 ? _a : this.Fixture('person'),
61
61
  getNewestOrg: () => __awaiter(this, void 0, void 0, function* () {
62
62
  return this.Fixture('organization').getNewestOrganization();
63
63
  }),
@@ -65,23 +65,23 @@ class FixtureFactory {
65
65
  break;
66
66
  }
67
67
  case 'organization': {
68
- const people =
69
- //@ts-ignore
70
- (_a = options === null || options === void 0 ? void 0 : options.people) !== null && _a !== void 0 ? _a : new PersonFixture({
71
- connectToApi: mercuryFixture.getConnectFactory(),
72
- });
73
68
  fixture = new OrganizationFixture({
74
- people,
75
- roles: this.Fixture('role'),
69
+ people:
70
+ //@ts-ignore
71
+ (_b = options === null || options === void 0 ? void 0 : options.people) !== null && _b !== void 0 ? _b : new PersonFixture({
72
+ connectToApi: mercuryFixture.getConnectFactory(),
73
+ }),
74
+ //@ts-ignore
75
+ roles: (_c = options === null || options === void 0 ? void 0 : options.roles) !== null && _c !== void 0 ? _c : this.Fixture('role'),
76
76
  });
77
77
  break;
78
78
  }
79
79
  case 'skill': {
80
80
  const personFixture =
81
81
  //@ts-ignore
82
- (_b = options === null || options === void 0 ? void 0 : options.personFixture) !== null && _b !== void 0 ? _b : this.Fixture('person');
82
+ (_d = options === null || options === void 0 ? void 0 : options.people) !== null && _d !== void 0 ? _d : this.Fixture('person');
83
83
  fixture = new SkillFixture({
84
- personFixture,
84
+ people: personFixture,
85
85
  connectToApi: mercuryFixture.getConnectFactory(),
86
86
  });
87
87
  break;
@@ -96,20 +96,25 @@ class FixtureFactory {
96
96
  }
97
97
  case 'location': {
98
98
  fixture = new LocationFixture({
99
- roles: this.Fixture('role'),
100
99
  //@ts-ignore
101
- people: (_c = options === null || options === void 0 ? void 0 : options.people) !== null && _c !== void 0 ? _c : this.Fixture('person'),
100
+ roles: (_e = options === null || options === void 0 ? void 0 : options.roles) !== null && _e !== void 0 ? _e : this.Fixture('role'),
101
+ //@ts-ignore
102
+ people: (_f = options === null || options === void 0 ? void 0 : options.people) !== null && _f !== void 0 ? _f : this.Fixture('person'),
102
103
  organizations:
103
104
  //@ts-ignore
104
- (_d = options === null || options === void 0 ? void 0 : options.organizations) !== null && _d !== void 0 ? _d : this.Fixture('organization'),
105
+ (_g = options === null || options === void 0 ? void 0 : options.organizations) !== null && _g !== void 0 ? _g : this.Fixture('organization'),
105
106
  });
106
107
  break;
107
108
  }
108
109
  case 'seed':
109
110
  fixture = new SeedFixture({
110
- organizations: this.Fixture('organization'),
111
- locations: this.Fixture('location'),
112
- people: this.Fixture('person'),
111
+ organizations:
112
+ //@ts-ignore
113
+ (_h = options === null || options === void 0 ? void 0 : options.organizations) !== null && _h !== void 0 ? _h : this.Fixture('organization'),
114
+ //@ts-ignore
115
+ locations: (_j = options === null || options === void 0 ? void 0 : options.locations) !== null && _j !== void 0 ? _j : this.Fixture('location'),
116
+ //@ts-ignore
117
+ people: (_k = options === null || options === void 0 ? void 0 : options.people) !== null && _k !== void 0 ? _k : this.Fixture('person'),
113
118
  });
114
119
  break;
115
120
  case 'permission':
@@ -120,8 +125,10 @@ class FixtureFactory {
120
125
  throw new Error('You need to be in a registered skill to load view controllers.');
121
126
  }
122
127
  fixture = new ViewFixture(Object.assign({
128
+ //@ts-ignore
129
+ people: (_l = options === null || options === void 0 ? void 0 : options.people) !== null && _l !== void 0 ? _l : this.Fixture('person'), connectToApi: mercuryFixture.getConnectFactory(), fixtureFactory: this, namespace: this.namespace, proxyDecorator: ClientProxyDecorator.getInstance(), cwd: this.cwd, permissions:
123
130
  //@ts-ignore
124
- 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));
131
+ (_m = options === null || options === void 0 ? void 0 : options.permissions) !== null && _m !== void 0 ? _m : this.Fixture('permission') }, options));
125
132
  break;
126
133
  }
127
134
  }
@@ -145,30 +152,26 @@ class FixtureFactory {
145
152
  ],
146
153
  });
147
154
  }
148
- getMercuryFixture(name) {
149
- let mercury;
150
- if (name === 'view') {
151
- if (!FixtureFactory.viewMercury) {
152
- FixtureFactory.viewMercury = new MercuryFixture(this.cwd);
153
- FixtureFactory.fixtures.push(FixtureFactory.viewMercury);
154
- }
155
- mercury = FixtureFactory.viewMercury;
156
- }
157
- if (!mercury) {
158
- mercury = new MercuryFixture(this.cwd);
159
- FixtureFactory.fixtures.push(mercury);
155
+ static clearMercuryFixture() {
156
+ delete this.mercuryFixture;
157
+ }
158
+ getMercuryFixture() {
159
+ if (!FixtureFactory.mercuryFixture) {
160
+ FixtureFactory.mercuryFixture = new MercuryFixture(this.cwd);
160
161
  }
161
- return mercury;
162
+ return FixtureFactory.mercuryFixture;
162
163
  }
163
164
  static destroy() {
164
165
  return __awaiter(this, void 0, void 0, function* () {
166
+ var _a;
165
167
  for (const f of this.fixtures) {
166
168
  if (f.destroy) {
167
169
  yield f.destroy();
168
170
  }
169
171
  }
170
172
  this.fixtures = [];
171
- FixtureFactory.viewMercury = undefined;
173
+ yield ((_a = FixtureFactory.mercuryFixture) === null || _a === void 0 ? void 0 : _a.destroy());
174
+ FixtureFactory.mercuryFixture = undefined;
172
175
  });
173
176
  }
174
177
  static beforeAll() {
@@ -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,165 @@
1
+ import { diskUtil } from '@sprucelabs/spruce-skill-utils';
2
+ import FixtureFactory from './FixtureFactory.js';
3
+ export default class FixtureWarehouse {
4
+ constructor(cwd) {
5
+ this.cwd = cwd;
6
+ }
7
+ static Warehouse(cwd) {
8
+ return new this(cwd);
9
+ }
10
+ setCwd(cwd) {
11
+ if (this.cwd !== cwd) {
12
+ this.cwd = cwd;
13
+ delete this._fixtures;
14
+ FixtureFactory.clearMercuryFixture();
15
+ }
16
+ }
17
+ Fixture(name, options) {
18
+ var _a;
19
+ if (!this._fixtures) {
20
+ const pkg = diskUtil.resolvePath(this.cwd, 'package.json');
21
+ let namespace;
22
+ if (diskUtil.doesFileExist(pkg)) {
23
+ const values = JSON.parse(diskUtil.readFile(pkg));
24
+ namespace = (_a = values === null || values === void 0 ? void 0 : values.skill) === null || _a === void 0 ? void 0 : _a.namespace;
25
+ }
26
+ this._fixtures = new FixtureFactory({
27
+ cwd: this.cwd,
28
+ namespace,
29
+ });
30
+ }
31
+ return this._fixtures.Fixture(name, options);
32
+ }
33
+ get views() {
34
+ if (!this._views) {
35
+ this._views = this.Fixture('view', {
36
+ people: this.people,
37
+ organizations: this.organizations,
38
+ locations: this.locations,
39
+ permissions: this.permissions,
40
+ });
41
+ }
42
+ return this._views;
43
+ }
44
+ set views(fixture) {
45
+ this._views = fixture;
46
+ }
47
+ get permissions() {
48
+ if (!this._permissions) {
49
+ this._permissions = this.Fixture('permission');
50
+ }
51
+ return this._permissions;
52
+ }
53
+ set permissions(fixture) {
54
+ this._permissions = fixture;
55
+ }
56
+ get roles() {
57
+ if (!this._roles) {
58
+ this._roles = this.Fixture('role', {
59
+ people: this.people,
60
+ });
61
+ }
62
+ return this._roles;
63
+ }
64
+ set roles(fixture) {
65
+ this._roles = fixture;
66
+ }
67
+ get locations() {
68
+ if (!this._locations) {
69
+ this._locations = this.Fixture('location', {
70
+ organizations: this.organizations,
71
+ people: this.people,
72
+ roles: this.roles,
73
+ });
74
+ }
75
+ return this._locations;
76
+ }
77
+ set locations(fixture) {
78
+ this._locations = fixture;
79
+ }
80
+ get organizations() {
81
+ if (!this._organizations) {
82
+ this._organizations = this.Fixture('organization', {
83
+ people: this.people,
84
+ roles: this.roles,
85
+ });
86
+ }
87
+ return this._organizations;
88
+ }
89
+ set organizations(fixture) {
90
+ this._organizations = fixture;
91
+ }
92
+ get people() {
93
+ if (!this._people) {
94
+ this._people = this.Fixture('person');
95
+ }
96
+ return this._people;
97
+ }
98
+ set people(fixture) {
99
+ this._people = fixture;
100
+ }
101
+ get seeder() {
102
+ if (!this._seeder) {
103
+ this._seeder = this.Fixture('seed', {
104
+ locations: this.locations,
105
+ organizations: this.organizations,
106
+ people: this.people,
107
+ });
108
+ }
109
+ return this._seeder;
110
+ }
111
+ set seeder(fixture) {
112
+ this._seeder = fixture;
113
+ }
114
+ get skills() {
115
+ if (!this._skills) {
116
+ this._skills = this.Fixture('skill', {
117
+ people: this.people,
118
+ });
119
+ }
120
+ return this._skills;
121
+ }
122
+ set skills(fixture) {
123
+ this._skills = fixture;
124
+ }
125
+ get mercury() {
126
+ if (!this._mercury) {
127
+ this._mercury = this.Fixture('mercury');
128
+ }
129
+ return this._mercury;
130
+ }
131
+ set mercury(fixture) {
132
+ this._mercury = fixture;
133
+ }
134
+ get stores() {
135
+ if (!this._stores) {
136
+ this._stores = this.Fixture('store');
137
+ }
138
+ return this._stores;
139
+ }
140
+ set stores(fixture) {
141
+ this._stores = fixture;
142
+ }
143
+ get database() {
144
+ if (!this._database) {
145
+ this._database = this.Fixture('database');
146
+ }
147
+ return this._database;
148
+ }
149
+ set database(fixture) {
150
+ this._database = fixture;
151
+ }
152
+ reset() {
153
+ this.views = undefined;
154
+ this.roles = undefined;
155
+ this.locations = undefined;
156
+ this.organizations = undefined;
157
+ this.people = undefined;
158
+ this.seeder = undefined;
159
+ this.skills = undefined;
160
+ this.mercury = undefined;
161
+ this.stores = undefined;
162
+ this.database = undefined;
163
+ this.permissions = undefined;
164
+ }
165
+ }
@@ -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;