@sprucelabs/spruce-test-fixtures 66.0.20 → 66.0.22

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 +24 -24
@@ -22,9 +22,10 @@ import { MercuryClientFactory, MercuryTestClient, } from '@sprucelabs/mercury-cl
22
22
  import { assertOptions, formatPhoneNumber, isValidNumber, } from '@sprucelabs/schema';
23
23
  import { BASE_ROLES_WITH_META, META_BASE_ROLES, } from '@sprucelabs/spruce-core-schemas';
24
24
  import { namesUtil, testLog } from '@sprucelabs/spruce-skill-utils';
25
- import { assert } from '@sprucelabs/test-utils';
25
+ import { assert, SpruceTestResolver } from '@sprucelabs/test-utils';
26
26
  import { generateId } from '@sprucelabs/test-utils';
27
27
  import SpruceError from '../../errors/SpruceError.js';
28
+ import FakerTracker from '../../FakerTracker.js';
28
29
  import AbstractSpruceFixtureTest from '../AbstractSpruceFixtureTest.js';
29
30
  import eventFaker from '../eventFaker.js';
30
31
  import generateRandomName from '../fixtures/generateRandomName.js';
@@ -40,28 +41,12 @@ const strategies = {
40
41
  groupManagers: buildSeeder('groupManagers'),
41
42
  owners: buildSeeder('owners'),
42
43
  };
43
- function resetFakedRecords(Class) {
44
- var _a, _b, _c;
44
+ function resetFakedRecords() {
45
45
  if (shouldSkipNextReset) {
46
46
  shouldSkipNextReset = false;
47
47
  return;
48
48
  }
49
- Class._fakedOrganizations = [];
50
- Class._fakedLocations = [];
51
- Class.fakedTeammates = [];
52
- Class.fakedInstalledSkills = [];
53
- Class.fakedPeopleRoles = [];
54
- Class.fakedManagers = [];
55
- Class.fakedOwners = [];
56
- Class.fakedGroupManagers = [];
57
- Class.fakedGuests = [];
58
- Class.fakedRoles = [];
59
- Class.fakedPeople = ((_a = Class.fakedPeople) === null || _a === void 0 ? void 0 : _a[0]) ? [Class.fakedPeople[0]] : [];
60
- Class.fakedSkills = [];
61
- Class.fakedTokens = ((_b = Class.fakedTokens) === null || _b === void 0 ? void 0 : _b[0]) ? [Class.fakedTokens[0]] : [];
62
- Class.fakedProxyTokens = ((_c = Class.fakedProxyTokens) === null || _c === void 0 ? void 0 : _c[0])
63
- ? [Class.fakedProxyTokens[0]]
64
- : [];
49
+ FakerTracker.resetFakedData();
65
50
  }
66
51
  export default function fake(target, total) {
67
52
  assertOptions({ target, total }, ['target', 'total']);
@@ -70,10 +55,10 @@ export default function fake(target, total) {
70
55
  const Class = TestClass;
71
56
  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);
72
57
  descriptor.value = (...args) => __awaiter(this, void 0, void 0, function* () {
73
- assert.isTruthy(Class.fakedPerson, `You gotta @faker.login(...) before you can create fake '${target}'!`);
58
+ assert.isTruthy(FakerTracker.fakedPerson, `You gotta @faker.login(...) before you can create fake '${target}'!`);
74
59
  const strategy = strategies[target];
75
60
  assert.isTruthy(strategy, `Faking ${target} is not ready yet!`);
76
- yield (strategy === null || strategy === void 0 ? void 0 : strategy(Class, total));
61
+ yield (strategy === null || strategy === void 0 ? void 0 : strategy(total));
77
62
  yield (bound === null || bound === void 0 ? void 0 : bound(...args));
78
63
  });
79
64
  };
@@ -87,54 +72,46 @@ fake.login = (phone = '555-000-0000') => {
87
72
  ViewFixture.setShouldAutomaticallyResetAuth(false);
88
73
  seed.disableResettingTestClient();
89
74
  return function (TestClass, shouldPassHookCalls = true) {
90
- var _a, _b, _c;
91
75
  if (!(TestClass.prototype instanceof AbstractSpruceFixtureTest)) {
92
76
  testLog.warn(`@fake.login() is attached to an incompatible test class (${TestClass.name}). You can safely remove it or have your test class extend AbstractSpruceFixtureTest.`);
93
77
  return;
94
78
  }
95
- const Class = TestClass;
96
- const beforeEach = (_a = Class.beforeEach) === null || _a === void 0 ? void 0 : _a.bind(Class);
97
- const beforeAll = (_b = Class.beforeAll) === null || _b === void 0 ? void 0 : _b.bind(Class);
98
- const afterEach = (_c = Class.afterEach) === null || _c === void 0 ? void 0 : _c.bind(Class);
99
79
  if (shouldPassHookCalls) {
100
80
  const old = MercuryFixture.beforeEach.bind(MercuryFixture);
101
81
  MercuryFixture.beforeEach = (...args) => __awaiter(this, void 0, void 0, function* () {
102
82
  //@ts-ignore
103
83
  yield old(...args);
104
- yield setupFakeListeners(Class);
84
+ yield setupFakeListeners();
105
85
  });
106
86
  }
107
- Class.beforeAll = () => __awaiter(this, void 0, void 0, function* () {
108
- yield (beforeAll === null || beforeAll === void 0 ? void 0 : beforeAll());
109
- resetFakedRecords(Class);
110
- yield setupFakeListeners(Class);
111
- yield login(Class, phone);
112
- MercuryFixture.setDefaultClient(Class.fakedClient);
113
- });
114
- Class.afterEach = () => __awaiter(this, void 0, void 0, function* () {
115
- yield setupFakeListeners(Class);
116
- yield (afterEach === null || afterEach === void 0 ? void 0 : afterEach());
117
- });
118
- Class.beforeEach = () => __awaiter(this, void 0, void 0, function* () {
119
- resetFakedRecords(Class);
120
- yield setupFakeListeners(Class);
87
+ SpruceTestResolver.onDidCallBeforeAll(() => __awaiter(this, void 0, void 0, function* () {
88
+ resetFakedRecords();
89
+ yield setupFakeListeners();
90
+ yield login(phone);
91
+ MercuryFixture.setDefaultClient(FakerTracker.fakedClient);
92
+ }));
93
+ SpruceTestResolver.onDidCallAfterEach(() => __awaiter(this, void 0, void 0, function* () {
94
+ yield setupFakeListeners();
95
+ }));
96
+ SpruceTestResolver.onWillCallBeforeEach((TestClass) => __awaiter(this, void 0, void 0, function* () {
97
+ resetFakedRecords();
98
+ yield setupFakeListeners();
121
99
  if (!TestClass.cwd) {
122
100
  return;
123
101
  }
124
102
  ViewFixture.resetAuth();
125
103
  try {
126
- if (Class.fakedPerson) {
127
- const auth = Class.permissions.getAuthenticator();
104
+ if (FakerTracker.fakedPerson) {
105
+ const auth = getFixturesForActiveTest().permissions.getAuthenticator();
128
106
  auth.setSessionToken(
129
107
  //@ts-ignore
130
- Class.fakedClient.auth.token, Class.fakedPerson);
108
+ FakerTracker.fakedClient.auth.token, FakerTracker.fakedPerson);
131
109
  }
132
110
  }
133
111
  catch (_a) {
134
112
  //hits if not in skill because cant find nameplace
135
113
  }
136
- shouldPassHookCalls && (yield (beforeEach === null || beforeEach === void 0 ? void 0 : beforeEach()));
137
- });
114
+ }));
138
115
  };
139
116
  };
140
117
  fake.getClient = () => {
@@ -144,35 +121,35 @@ fake.getPerson = () => {
144
121
  //@ts-ignore
145
122
  return fake.getClient().auth.person;
146
123
  };
147
- function login(Class, phone) {
124
+ function login(phone) {
148
125
  return __awaiter(this, void 0, void 0, function* () {
149
- const { person, client } = yield loginUsingViewsFallingBackToPeople(Class, phone);
126
+ const { person, client } = yield loginUsingViewsFallingBackToPeople(phone);
150
127
  if (!person.firstName) {
151
128
  givePersonName(person);
152
129
  }
153
130
  yield client.registerProxyToken();
154
131
  //@ts-ignore
155
132
  client.auth.person = person;
156
- Class.fakedClient = client;
157
- Class.fakedPerson = person;
133
+ FakerTracker.fakedClient = client;
134
+ FakerTracker.fakedPerson = person;
158
135
  });
159
136
  }
160
- function loginUsingViewsFallingBackToPeople(Class, phone) {
137
+ function loginUsingViewsFallingBackToPeople(phone) {
161
138
  return __awaiter(this, void 0, void 0, function* () {
162
139
  let person;
163
140
  let client;
164
141
  try {
165
- const { person: p, client: c } = yield Class.views.loginAsDemoPerson(phone);
142
+ const { person: p, client: c } = yield getFixturesForActiveTest().views.loginAsDemoPerson(phone);
166
143
  person = p;
167
144
  client = c;
168
145
  }
169
146
  catch (_a) {
170
- const { person: p, client: c } = yield Class.people.loginAsDemoPerson(phone);
147
+ const { person: p, client: c } = yield getFixturesForActiveTest().people.loginAsDemoPerson(phone);
171
148
  person = p;
172
149
  client = c;
173
150
  }
174
151
  return {
175
- person: Class.fakedPeople.find((p) => p.id === person.id),
152
+ person: FakerTracker.fakedPeople.find((p) => p.id === person.id),
176
153
  client,
177
154
  };
178
155
  });
@@ -183,42 +160,41 @@ function givePersonName(person) {
183
160
  person.firstName = names.firstName;
184
161
  person.lastName = names.lastName;
185
162
  }
186
- function setupFakeListeners(Class) {
163
+ function setupFakeListeners() {
187
164
  return __awaiter(this, void 0, void 0, function* () {
188
165
  yield Promise.all([
189
- fakeSkillLifecycleEvents(Class),
190
- fakeGetPerson(Class),
191
- fakeRegisterProxyToken(Class),
192
- fakeWhoAmI(Class),
193
- fakeInstallEvents(Class),
194
- fakeAuthenticationEvents(Class),
195
- fakeAddRole(Class),
196
- fakeGetRole(Class),
197
- fakeRemoveRole(Class),
198
- fakeListRoles(Class),
199
- fakeListPeople(Class),
200
- fakeUpdatePerson(Class),
201
- fakeListLocations(Class),
202
- fakeGetLocation(Class),
203
- fakeUpdateLocation(Class),
204
- fakeDeleteOrganization(Class),
205
- fakeCreateLocation(Class),
206
- fakeCreateOrganization(Class),
207
- fakeGetOrganization(Class),
208
- fakeUpdateOrganization(Class),
209
- fakeListOrganization(Class),
166
+ fakeSkillLifecycleEvents(),
167
+ fakeGetPerson(),
168
+ fakeRegisterProxyToken(),
169
+ fakeWhoAmI(),
170
+ fakeInstallEvents(),
171
+ fakeAuthenticationEvents(),
172
+ fakeAddRole(),
173
+ fakeGetRole(),
174
+ fakeRemoveRole(),
175
+ fakeListRoles(),
176
+ fakeListPeople(),
177
+ fakeUpdatePerson(),
178
+ fakeListLocations(),
179
+ fakeGetLocation(),
180
+ fakeUpdateLocation(),
181
+ fakeDeleteOrganization(),
182
+ fakeCreateLocation(),
183
+ fakeCreateOrganization(),
184
+ fakeGetOrganization(),
185
+ fakeUpdateOrganization(),
186
+ fakeListOrganization(),
210
187
  fakeRegisterListeners(),
211
188
  ]);
212
189
  });
213
190
  }
214
- function fakeAddRole(Class) {
191
+ function fakeAddRole() {
215
192
  return __awaiter(this, void 0, void 0, function* () {
216
193
  yield eventFaker.on('add-role::v2020_12_25', ({ payload, target }) => {
217
194
  const { organizationId, locationId } = target !== null && target !== void 0 ? target : {};
218
195
  const { roleId } = payload;
219
- const person = getPersonById(Class, payload.personId);
196
+ const person = getPersonById(payload.personId);
220
197
  addPersonAsRoleToLocationOrOrg({
221
- Class,
222
198
  roleId,
223
199
  person,
224
200
  organizationId,
@@ -229,33 +205,33 @@ function fakeAddRole(Class) {
229
205
  });
230
206
  }
231
207
  function addPersonAsRoleToLocationOrOrg(options) {
232
- const { Class, roleId, person, organizationId, locationId } = options;
233
- const role = getRoleById(Class, roleId);
208
+ const { roleId, person, organizationId, locationId } = options;
209
+ const role = getRoleById(roleId);
234
210
  const key = roleBaseToLocalFakedProp(role.base);
235
211
  //@ts-ignore
236
- assert.isTruthy(Class[key], `Could not find property ${key}`);
237
- const idx = Class[key].findIndex((p) => p.id === person.id);
212
+ assert.isTruthy(FakerTracker[key], `Could not find property ${key}`);
213
+ const idx = FakerTracker[key].findIndex((p) => p.id === person.id);
238
214
  if (idx === -1) {
239
215
  //@ts-ignore
240
- Class[key].unshift(person);
216
+ FakerTracker[key].unshift(person);
241
217
  }
242
- Class.fakedPeopleRoles.push({
218
+ FakerTracker.fakedPeopleRoles.push({
243
219
  personId: person.id,
244
220
  roleId: role.id,
245
221
  organizationId,
246
222
  locationId,
247
223
  });
248
224
  }
249
- function getRoleById(Class, roleId) {
250
- const role = Class.fakedRoles.find((r) => r.id === roleId);
225
+ function getRoleById(roleId) {
226
+ const role = FakerTracker.fakedRoles.find((r) => r.id === roleId);
251
227
  assert.isTruthy(role, `Could not load faked role with the id of ${roleId}.`);
252
228
  return role;
253
229
  }
254
- function fakeGetRole(Class) {
230
+ function fakeGetRole() {
255
231
  return __awaiter(this, void 0, void 0, function* () {
256
232
  yield eventFaker.on('get-role::v2020_12_25', ({ target }) => {
257
233
  const { roleId } = target;
258
- const role = Class.fakedRoles.find((r) => r.id === roleId);
234
+ const role = FakerTracker.fakedRoles.find((r) => r.id === roleId);
259
235
  if (!role) {
260
236
  throw new SpruceError({
261
237
  code: 'NOT_FOUND',
@@ -268,16 +244,16 @@ function fakeGetRole(Class) {
268
244
  });
269
245
  });
270
246
  }
271
- function fakeRemoveRole(Class) {
247
+ function fakeRemoveRole() {
272
248
  return __awaiter(this, void 0, void 0, function* () {
273
249
  yield eventFaker.on('remove-role::v2020_12_25', ({ payload }) => {
274
250
  var _a;
275
251
  const { personId, roleId } = payload;
276
- const role = getRoleById(Class, roleId);
277
- const people = Class[roleBaseToLocalFakedProp(role.base)];
252
+ const role = getRoleById(roleId);
253
+ const people = FakerTracker[roleBaseToLocalFakedProp(role.base)];
278
254
  const idx = (_a = people === null || people === void 0 ? void 0 : people.findIndex((p) => p.id === personId)) !== null && _a !== void 0 ? _a : -1;
279
255
  people === null || people === void 0 ? void 0 : people.splice(idx, 1);
280
- Class.fakedPeopleRoles = Class.fakedPeopleRoles.filter((p) => !(p.personId === personId && p.roleId === roleId));
256
+ FakerTracker.fakedPeopleRoles = FakerTracker.fakedPeopleRoles.filter((p) => !(p.personId === personId && p.roleId === roleId));
281
257
  return {};
282
258
  });
283
259
  });
@@ -285,8 +261,8 @@ function fakeRemoveRole(Class) {
285
261
  function roleBaseToLocalFakedProp(base) {
286
262
  return fakeTargetToPropName((base + 's'));
287
263
  }
288
- function getPersonById(Class, personId, shouldThrowWhenNotFound = true) {
289
- const person = Class.fakedPeople.find((p) => p.id === personId);
264
+ function getPersonById(personId, shouldThrowWhenNotFound = true) {
265
+ const person = FakerTracker.fakedPeople.find((p) => p.id === personId);
290
266
  if (!person && shouldThrowWhenNotFound) {
291
267
  throw new SpruceError({
292
268
  code: 'INVALID_TARGET',
@@ -295,10 +271,10 @@ function getPersonById(Class, personId, shouldThrowWhenNotFound = true) {
295
271
  }
296
272
  return person;
297
273
  }
298
- function fakeUpdatePerson(Class) {
274
+ function fakeUpdatePerson() {
299
275
  return __awaiter(this, void 0, void 0, function* () {
300
276
  yield eventFaker.on('update-person::v2020_12_25', ({ target, source, payload }) => {
301
- const person = Class.fakedPeople.find((p) => (target === null || target === void 0 ? void 0 : target.personId)
277
+ const person = FakerTracker.fakedPeople.find((p) => (target === null || target === void 0 ? void 0 : target.personId)
302
278
  ? p.id === (target === null || target === void 0 ? void 0 : target.personId)
303
279
  : p.id === (source === null || source === void 0 ? void 0 : source.personId));
304
280
  if (!person) {
@@ -316,7 +292,7 @@ function fakeUpdatePerson(Class) {
316
292
  });
317
293
  });
318
294
  }
319
- function fakeListRoles(Class) {
295
+ function fakeListRoles() {
320
296
  return __awaiter(this, void 0, void 0, function* () {
321
297
  yield eventFaker.on('list-roles::v2020_12_25', ({ target, payload }) => {
322
298
  var _a;
@@ -324,20 +300,20 @@ function fakeListRoles(Class) {
324
300
  const { shouldIncludeMetaRoles, shouldIncludePrivateRoles } = payload !== null && payload !== void 0 ? payload : {};
325
301
  let roles = [];
326
302
  if (personId) {
327
- const personRoles = Class.fakedPeopleRoles
303
+ const personRoles = FakerTracker.fakedPeopleRoles
328
304
  .filter((p) => p.personId === personId &&
329
305
  ((p.organizationId &&
330
306
  p.organizationId === organizationId) ||
331
307
  (p.locationId && p.locationId === locationId) ||
332
308
  (!locationId && !organizationId)))
333
- .map((pr) => getRoleById(Class, pr.roleId));
309
+ .map((pr) => getRoleById(pr.roleId));
334
310
  roles = personRoles;
335
311
  }
336
312
  else {
337
313
  if (locationId) {
338
- organizationId = (_a = Class._fakedLocations.find((l) => l.id === locationId)) === null || _a === void 0 ? void 0 : _a.organizationId;
314
+ organizationId = (_a = FakerTracker.fakedLocations.find((l) => l.id === locationId)) === null || _a === void 0 ? void 0 : _a.organizationId;
339
315
  }
340
- roles = Class.fakedRoles.filter((r) => r.organizationId === organizationId);
316
+ roles = FakerTracker.fakedRoles.filter((r) => r.organizationId === organizationId);
341
317
  }
342
318
  if (!shouldIncludeMetaRoles) {
343
319
  roles = roles.filter((r) => META_BASE_ROLES.findIndex((m) => m.slug === r.base) === -1);
@@ -351,7 +327,7 @@ function fakeListRoles(Class) {
351
327
  });
352
328
  });
353
329
  }
354
- function fakeListPeople(Class) {
330
+ function fakeListPeople() {
355
331
  return __awaiter(this, void 0, void 0, function* () {
356
332
  yield eventFaker.on('list-people::v2020_12_25', ({ payload }) => {
357
333
  var _a;
@@ -359,35 +335,35 @@ function fakeListPeople(Class) {
359
335
  assert.isFalsy(payload === null || payload === void 0 ? void 0 : payload.roleIds, `@fake does not support listing people by roleIds. You will need to use 'eventFaker.on('list-people')' to fake your own response OR consider checking this.fakedPeople on your test class.`);
360
336
  assert.isFalsy(payload === null || payload === void 0 ? void 0 : payload.personIds, `@fake does not support listing people by personIds. You will need to use 'eventFaker.on(...)' to fake your own response OR consider checking this.fakedPeople on your test class`);
361
337
  for (const base of (_a = payload === null || payload === void 0 ? void 0 : payload.roleBases) !== null && _a !== void 0 ? _a : []) {
362
- const faked = getFakedRecordsByRoleBase(Class, base);
338
+ const faked = getFakedRecordsByRoleBase(base);
363
339
  if (faked) {
364
340
  people.push(...faked);
365
341
  }
366
342
  }
367
343
  return {
368
- people: (payload === null || payload === void 0 ? void 0 : payload.roleBases) ? people : Class.fakedPeople,
344
+ people: (payload === null || payload === void 0 ? void 0 : payload.roleBases) ? people : FakerTracker.fakedPeople,
369
345
  };
370
346
  });
371
347
  });
372
348
  }
373
- function getFakedRecordsByRoleBase(Class, base) {
349
+ function getFakedRecordsByRoleBase(base) {
374
350
  //@ts-ignore
375
- return Class[fakeTargetToPropName(singularToPlural(base))];
351
+ return FakerTracker[fakeTargetToPropName(singularToPlural(base))];
376
352
  }
377
- function fakeListLocations(Class) {
353
+ function fakeListLocations() {
378
354
  return __awaiter(this, void 0, void 0, function* () {
379
355
  yield eventFaker.on('list-locations::v2020_12_25', ({ target, payload }) => {
380
356
  return {
381
- locations: applyPaging(Class._fakedLocations, payload).filter((l) => !(target === null || target === void 0 ? void 0 : target.organizationId) ||
357
+ locations: applyPaging(FakerTracker.fakedLocations, payload).filter((l) => !(target === null || target === void 0 ? void 0 : target.organizationId) ||
382
358
  l.organizationId === (target === null || target === void 0 ? void 0 : target.organizationId)),
383
359
  };
384
360
  });
385
361
  });
386
362
  }
387
- function fakeGetLocation(Class) {
363
+ function fakeGetLocation() {
388
364
  return __awaiter(this, void 0, void 0, function* () {
389
365
  yield eventFaker.on('get-location::v2020_12_25', ({ target }) => {
390
- const match = Class._fakedLocations.find((l) => l.id === target.locationId);
366
+ const match = FakerTracker.fakedLocations.find((l) => l.id === target.locationId);
391
367
  if (!match) {
392
368
  throw new SpruceError({
393
369
  code: 'INVALID_TARGET',
@@ -400,56 +376,55 @@ function fakeGetLocation(Class) {
400
376
  });
401
377
  });
402
378
  }
403
- function fakeUpdateLocation(Class) {
379
+ function fakeUpdateLocation() {
404
380
  return __awaiter(this, void 0, void 0, function* () {
405
381
  yield eventFaker.on('update-location::v2020_12_25', ({ target, payload }) => {
406
382
  const { locationId } = target;
407
- let idx = Class._fakedLocations.findIndex((l) => l.id === locationId);
408
- if (!Class._fakedLocations[idx]) {
383
+ let idx = FakerTracker.fakedLocations.findIndex((l) => l.id === locationId);
384
+ if (!FakerTracker.fakedLocations[idx]) {
409
385
  throw new SpruceError({
410
386
  code: 'INVALID_TARGET',
411
387
  friendlyMessage: `I could not find that location to update!`,
412
388
  });
413
389
  }
414
- Class._fakedLocations[idx] = Object.assign(Object.assign(Object.assign({}, Class._fakedLocations[idx]), payload), { dateUpdated: Date.now() });
390
+ FakerTracker.fakedLocations[idx] = Object.assign(Object.assign(Object.assign({}, FakerTracker.fakedLocations[idx]), payload), { dateUpdated: Date.now() });
415
391
  return {
416
- location: Class._fakedLocations[idx],
392
+ location: FakerTracker.fakedLocations[idx],
417
393
  };
418
394
  });
419
395
  });
420
396
  }
421
- function fakeDeleteOrganization(Class) {
397
+ function fakeDeleteOrganization() {
422
398
  return __awaiter(this, void 0, void 0, function* () {
423
399
  yield eventFaker.on('delete-organization::v2020_12_25', ({ target: { organizationId } }) => {
424
- const idx = Class._fakedOrganizations.findIndex((o) => o.id === organizationId);
400
+ const idx = FakerTracker.fakedOrganizations.findIndex((o) => o.id === organizationId);
425
401
  if (idx === -1) {
426
402
  throw new SpruceError({
427
403
  code: 'INVALID_TARGET',
428
404
  friendlyMessage: `I could not find that organization to delete!`,
429
405
  });
430
406
  }
431
- const match = Class._fakedOrganizations[idx];
432
- Class._fakedOrganizations.splice(idx, 1);
407
+ const match = FakerTracker.fakedOrganizations[idx];
408
+ FakerTracker.fakedOrganizations.splice(idx, 1);
433
409
  return {
434
410
  organization: match,
435
411
  };
436
412
  });
437
413
  });
438
414
  }
439
- function fakeCreateLocation(Class) {
415
+ function fakeCreateLocation() {
440
416
  return __awaiter(this, void 0, void 0, function* () {
441
417
  yield eventFaker.on('create-location::v2020_12_25', ({ target, payload, source }) => {
442
418
  var _a;
443
419
  const { personId } = source !== null && source !== void 0 ? source : {};
444
420
  //@ts-ignore - delete when you find this (pushing through upgrades)
445
421
  const location = Object.assign(Object.assign({ id: generateId(), dateCreated: new Date().getTime(), organizationId: target.organizationId }, payload), { slug: (_a = payload.slug) !== null && _a !== void 0 ? _a : namesUtil.toKebab(payload.name) });
446
- Class._fakedLocations.unshift(location);
422
+ FakerTracker.fakedLocations.unshift(location);
447
423
  if (personId) {
448
- const role = Class.fakedRoles.find((r) => r.base === 'owner');
424
+ const role = FakerTracker.fakedRoles.find((r) => r.base === 'owner');
449
425
  addPersonAsRoleToLocationOrOrg({
450
- Class,
451
426
  roleId: role.id,
452
- person: Class.fakedPerson,
427
+ person: FakerTracker.fakedPerson,
453
428
  locationId: location.id,
454
429
  });
455
430
  }
@@ -459,18 +434,17 @@ function fakeCreateLocation(Class) {
459
434
  });
460
435
  });
461
436
  }
462
- function fakeCreateOrganization(Class) {
437
+ function fakeCreateOrganization() {
463
438
  return __awaiter(this, void 0, void 0, function* () {
464
439
  yield eventFaker.on('create-organization::v2020_12_25', ({ payload }) => {
465
440
  var _a;
466
441
  const organization = Object.assign(Object.assign({ id: generateId(), dateCreated: new Date().getTime(), isPublic: null }, payload), { slug: (_a = payload.slug) !== null && _a !== void 0 ? _a : namesUtil.toKebab(payload.name) });
467
- Class._fakedOrganizations.unshift(organization);
468
- const roles = seedRoles(Class, organization.id);
442
+ FakerTracker.fakedOrganizations.unshift(organization);
443
+ const roles = seedRoles(organization.id);
469
444
  addPersonAsRoleToLocationOrOrg({
470
- Class,
471
445
  organizationId: organization.id,
472
446
  roleId: roles.find((r) => r.base === 'owner').id,
473
- person: Class.fakedPerson,
447
+ person: FakerTracker.fakedPerson,
474
448
  });
475
449
  return {
476
450
  organization,
@@ -478,11 +452,11 @@ function fakeCreateOrganization(Class) {
478
452
  });
479
453
  });
480
454
  }
481
- function fakeGetPerson(Class) {
455
+ function fakeGetPerson() {
482
456
  return __awaiter(this, void 0, void 0, function* () {
483
457
  yield eventFaker.on('get-person::v2020_12_25', ({ target }) => {
484
458
  assert.isTruthy(target === null || target === void 0 ? void 0 : target.personId, `@fake only supports 'get-person::v2020_12_25' when passing an id. To fake more, use 'eventFaker.on(...)'.`);
485
- const person = getPersonById(Class, target.personId);
459
+ const person = getPersonById(target.personId);
486
460
  if (!person) {
487
461
  throw new SpruceError({
488
462
  code: 'INVALID_TARGET',
@@ -495,14 +469,14 @@ function fakeGetPerson(Class) {
495
469
  });
496
470
  });
497
471
  }
498
- function fakeSkillLifecycleEvents(Class) {
472
+ function fakeSkillLifecycleEvents() {
499
473
  return __awaiter(this, void 0, void 0, function* () {
500
474
  process.env.SKILL_ID = process.env.SKILL_ID || generateId();
501
475
  process.env.SKILL_API_KEY = process.env.SKILL_API_KEY || generateId();
502
476
  yield eventFaker.on('register-skill::v2020_12_25', ({ payload }) => {
503
477
  var _a;
504
- const skill = Object.assign(Object.assign({ apiKey: generateId(), creators: [{ personId: Class.fakedPerson.id }], dateCreated: new Date().getTime(), id: generateId() }, payload), { slug: (_a = payload.slug) !== null && _a !== void 0 ? _a : generateId() });
505
- Class.fakedSkills.unshift(skill);
478
+ const skill = Object.assign(Object.assign({ apiKey: generateId(), creators: [{ personId: FakerTracker.fakedPerson.id }], dateCreated: new Date().getTime(), id: generateId() }, payload), { slug: (_a = payload.slug) !== null && _a !== void 0 ? _a : generateId() });
479
+ FakerTracker.fakedSkills.unshift(skill);
506
480
  return {
507
481
  skill,
508
482
  };
@@ -520,20 +494,20 @@ function buildCasualName(names) {
520
494
  var _a;
521
495
  return `${(_a = names.firstName) !== null && _a !== void 0 ? _a : 'friend'} ${names.lastName ? names.lastName[0] + '.' : ''}`.trim();
522
496
  }
523
- function fakeGetOrganization(Class) {
497
+ function fakeGetOrganization() {
524
498
  return __awaiter(this, void 0, void 0, function* () {
525
499
  yield eventFaker.on('get-organization::v2020_12_25', ({ target }) => {
526
- const match = findOrgFromTarget(Class, target);
500
+ const match = findOrgFromTarget(target);
527
501
  return {
528
502
  organization: match,
529
503
  };
530
504
  });
531
505
  });
532
506
  }
533
- function fakeUpdateOrganization(Class) {
507
+ function fakeUpdateOrganization() {
534
508
  return __awaiter(this, void 0, void 0, function* () {
535
509
  yield eventFaker.on('update-organization::v2020_12_25', ({ target, payload }) => {
536
- const match = findOrgFromTarget(Class, target);
510
+ const match = findOrgFromTarget(target);
537
511
  if (payload === null || payload === void 0 ? void 0 : payload.name) {
538
512
  match.name = payload.name;
539
513
  }
@@ -554,12 +528,12 @@ function fakeUpdateOrganization(Class) {
554
528
  });
555
529
  });
556
530
  }
557
- function fakeListOrganization(Class) {
531
+ function fakeListOrganization() {
558
532
  return __awaiter(this, void 0, void 0, function* () {
559
533
  yield eventFaker.on('list-organizations::v2020_12_25', (targetAndPayload) => {
560
534
  const { payload } = targetAndPayload !== null && targetAndPayload !== void 0 ? targetAndPayload : {};
561
535
  return {
562
- organizations: applyPaging(Class._fakedOrganizations, payload),
536
+ organizations: applyPaging(FakerTracker.fakedOrganizations, payload),
563
537
  };
564
538
  });
565
539
  });
@@ -572,14 +546,14 @@ function applyPaging(records, payload) {
572
546
  }
573
547
  return copy;
574
548
  }
575
- function seedOrganizations(Class, total) {
549
+ function seedOrganizations(total) {
576
550
  return __awaiter(this, void 0, void 0, function* () {
577
- yield Class.seeder.seedOrganizations({
551
+ yield getFixturesForActiveTest().seeder.seedOrganizations({
578
552
  totalOrganizations: total,
579
553
  });
580
554
  });
581
555
  }
582
- function seedRoles(Class, orgId) {
556
+ function seedRoles(orgId) {
583
557
  const roles = BASE_ROLES_WITH_META.map((r) => ({
584
558
  id: generateId(),
585
559
  name: `Faked ${r.name}`,
@@ -588,40 +562,40 @@ function seedRoles(Class, orgId) {
588
562
  organizationId: orgId,
589
563
  isPublic: r.slug === 'guest',
590
564
  }));
591
- Class.fakedRoles.push(...roles);
565
+ FakerTracker.fakedRoles.push(...roles);
592
566
  return roles;
593
567
  }
594
- function seedLocations(Class, total) {
568
+ function seedLocations(total) {
595
569
  return __awaiter(this, void 0, void 0, function* () {
596
- yield Class.seeder.seedAccount({
570
+ yield getFixturesForActiveTest().seeder.seedAccount({
597
571
  totalLocations: total,
598
572
  });
599
573
  });
600
574
  }
601
575
  function buildSeeder(target) {
602
- return function seed(Class, total) {
576
+ return function seed(total) {
603
577
  return __awaiter(this, void 0, void 0, function* () {
604
- if (Class._fakedLocations.length === 0) {
578
+ if (FakerTracker.fakedLocations.length === 0) {
605
579
  assert.fail(`You gotta @seed('locations', 1) before seeding teammates!`);
606
580
  }
607
581
  //@ts-ignore
608
- yield Class.seeder[`seed${upperCaseFirst(target)}`]({
582
+ yield getFixturesForActiveTest().seeder[`seed${upperCaseFirst(target)}`]({
609
583
  [`total${upperCaseFirst(target)}`]: total,
610
584
  });
611
585
  });
612
586
  };
613
587
  }
614
- function fakeWhoAmI(Class) {
588
+ function fakeWhoAmI() {
615
589
  return __awaiter(this, void 0, void 0, function* () {
616
590
  yield eventFaker.on('whoami::v2020_12_25', (targetAndPayload) => {
617
591
  var _a;
618
592
  const { source } = targetAndPayload !== null && targetAndPayload !== void 0 ? targetAndPayload : {};
619
593
  let { personId, proxyToken } = source !== null && source !== void 0 ? source : {};
620
594
  if (proxyToken) {
621
- personId = (_a = Class.fakedProxyTokens.find((t) => t.token === proxyToken)) === null || _a === void 0 ? void 0 : _a.personId;
595
+ personId = (_a = FakerTracker.fakedProxyTokens.find((t) => t.token === proxyToken)) === null || _a === void 0 ? void 0 : _a.personId;
622
596
  }
623
- const person = getPersonById(Class, personId, false);
624
- const skill = Class.fakedSkills.find((s) => s.id === (source === null || source === void 0 ? void 0 : source.skillId));
597
+ const person = getPersonById(personId, false);
598
+ const skill = FakerTracker.fakedSkills.find((s) => s.id === (source === null || source === void 0 ? void 0 : source.skillId));
625
599
  return {
626
600
  auth: {
627
601
  skill,
@@ -634,13 +608,13 @@ function fakeWhoAmI(Class) {
634
608
  });
635
609
  });
636
610
  }
637
- function fakeRegisterProxyToken(Class) {
611
+ function fakeRegisterProxyToken() {
638
612
  return __awaiter(this, void 0, void 0, function* () {
639
613
  yield eventFaker.on('register-proxy-token::v2020_12_25', (targeAndPayload) => {
640
614
  const { source } = targeAndPayload !== null && targeAndPayload !== void 0 ? targeAndPayload : {};
641
615
  const token = generateId();
642
616
  if (source === null || source === void 0 ? void 0 : source.personId) {
643
- Class.fakedProxyTokens.push({
617
+ FakerTracker.fakedProxyTokens.push({
644
618
  personId: source.personId,
645
619
  token,
646
620
  });
@@ -651,31 +625,31 @@ function fakeRegisterProxyToken(Class) {
651
625
  });
652
626
  });
653
627
  }
654
- function fakeAuthenticationEvents(Class) {
628
+ function fakeAuthenticationEvents() {
655
629
  return __awaiter(this, void 0, void 0, function* () {
656
630
  yield eventFaker.on('request-pin::v2020_12_25', ({ payload }) => {
657
631
  var _a;
658
632
  const formattedPhone = formatPhoneNumber(payload.phone);
659
- let person = Class.fakedPeople.find((p) => p.phone === formattedPhone);
633
+ let person = FakerTracker.fakedPeople.find((p) => p.phone === formattedPhone);
660
634
  if (!person) {
661
635
  person =
662
- ((_a = Class.fakedPerson) === null || _a === void 0 ? void 0 : _a.phone) === formattedPhone
663
- ? Class.fakedPerson
636
+ ((_a = FakerTracker.fakedPerson) === null || _a === void 0 ? void 0 : _a.phone) === formattedPhone
637
+ ? FakerTracker.fakedPerson
664
638
  : {
665
639
  id: generateId(),
666
640
  casualName: 'friend',
667
641
  dateCreated: new Date().getTime(),
668
642
  phone: formatPhoneNumber(formattedPhone),
669
643
  };
670
- Class.fakedPeople.push(person);
644
+ FakerTracker.fakedPeople.push(person);
671
645
  }
672
646
  return {
673
647
  challenge: person.phone,
674
648
  };
675
649
  });
676
650
  yield eventFaker.on('confirm-pin::v2020_12_25', ({ payload }) => {
677
- const idx = Class.fakedPeople.findIndex((p) => p.phone === payload.challenge);
678
- const person = Class.fakedPeople[idx];
651
+ const idx = FakerTracker.fakedPeople.findIndex((p) => p.phone === payload.challenge);
652
+ const person = FakerTracker.fakedPeople[idx];
679
653
  if (!person) {
680
654
  throw new SpruceError({
681
655
  code: 'INVALID_PIN',
@@ -684,7 +658,7 @@ function fakeAuthenticationEvents(Class) {
684
658
  //@ts-ignore
685
659
  delete person._challenge;
686
660
  const token = generateId();
687
- Class.fakedTokens.push({
661
+ FakerTracker.fakedTokens.push({
688
662
  personId: person.id,
689
663
  token,
690
664
  });
@@ -695,7 +669,7 @@ function fakeAuthenticationEvents(Class) {
695
669
  });
696
670
  yield eventFaker.on('authenticate::v2020_12_25', ({ payload }) => {
697
671
  const { token, apiKey, skillId } = payload !== null && payload !== void 0 ? payload : {};
698
- let skill = Class.fakedSkills.find((s) => s.apiKey === apiKey && s.id === skillId);
672
+ let skill = FakerTracker.fakedSkills.find((s) => s.apiKey === apiKey && s.id === skillId);
699
673
  if (!skill &&
700
674
  apiKey &&
701
675
  skillId &&
@@ -718,12 +692,12 @@ function fakeAuthenticationEvents(Class) {
718
692
  },
719
693
  };
720
694
  }
721
- const match = Class.fakedTokens.find((f) => f.token === token);
695
+ const match = FakerTracker.fakedTokens.find((f) => f.token === token);
722
696
  if (!match) {
723
697
  //@ts-ignore
724
698
  throw new SpruceError({ code: 'INVALID_AUTH_TOKEN' });
725
699
  }
726
- const person = getPersonById(Class, match.personId);
700
+ const person = getPersonById(match.personId);
727
701
  return {
728
702
  type: 'authenticated',
729
703
  auth: {
@@ -733,15 +707,15 @@ function fakeAuthenticationEvents(Class) {
733
707
  });
734
708
  });
735
709
  }
736
- function fakeInstallEvents(Class) {
710
+ function fakeInstallEvents() {
737
711
  return __awaiter(this, void 0, void 0, function* () {
738
712
  yield eventFaker.on('is-skill-installed::v2020_12_25', ({ payload }) => {
739
713
  return {
740
- isInstalled: !!Class.fakedInstalledSkills.find((i) => i.skillId === (payload === null || payload === void 0 ? void 0 : payload.skillId)),
714
+ isInstalled: !!FakerTracker.fakedInstalledSkills.find((i) => i.skillId === (payload === null || payload === void 0 ? void 0 : payload.skillId)),
741
715
  };
742
716
  });
743
717
  yield eventFaker.on('install-skill::v2020_12_25', ({ target, payload }) => {
744
- Class.fakedInstalledSkills.push({
718
+ FakerTracker.fakedInstalledSkills.push({
745
719
  orgId: target.organizationId,
746
720
  skillId: payload.skillId,
747
721
  });
@@ -749,7 +723,7 @@ function fakeInstallEvents(Class) {
749
723
  });
750
724
  yield eventFaker.on('list-skills::v2020_12_25', ({ payload }) => {
751
725
  const namespaces = payload === null || payload === void 0 ? void 0 : payload.namespaces;
752
- const matches = Class.fakedSkills.filter((s) => { var _a; return ((_a = namespaces === null || namespaces === void 0 ? void 0 : namespaces.indexOf(s.slug)) !== null && _a !== void 0 ? _a : 0) > -1; });
726
+ const matches = FakerTracker.fakedSkills.filter((s) => { var _a; return ((_a = namespaces === null || namespaces === void 0 ? void 0 : namespaces.indexOf(s.slug)) !== null && _a !== void 0 ? _a : 0) > -1; });
753
727
  if (matches.length === 0) {
754
728
  throw new SpruceError({
755
729
  //@ts-ignore
@@ -786,8 +760,8 @@ export function singularToPlural(target) {
786
760
  return target + 's';
787
761
  }
788
762
  let shouldSkipNextReset = false;
789
- function findOrgFromTarget(Class, target) {
790
- const match = Class._fakedOrganizations.find((o) => o.id === target.organizationId);
763
+ function findOrgFromTarget(target) {
764
+ const match = FakerTracker.fakedOrganizations.find((o) => o.id === target.organizationId);
791
765
  if (!match) {
792
766
  throw new SpruceError({
793
767
  code: 'INVALID_TARGET',
@@ -801,3 +775,7 @@ function fakeRegisterListeners() {
801
775
  yield eventFaker.on('register-listeners::v2020_12_25', () => __awaiter(this, void 0, void 0, function* () { }));
802
776
  });
803
777
  }
778
+ function getFixturesForActiveTest() {
779
+ const Test = SpruceTestResolver.getActiveTest();
780
+ return FakerTracker.getFixtures(Test.cwd);
781
+ }