@sprucelabs/spruce-test-fixtures 62.3.44 → 62.3.46

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,12 +22,15 @@ class ClientProxyDecorator {
22
22
  delete this.instance;
23
23
  }
24
24
  decorateEmitToPassProxyToken(client, token) {
25
- const newClient = Object.assign(Object.assign({}, client), { proxyToken: token,
25
+ const newClient = {
26
+ ...client,
27
+ proxyToken: token,
26
28
  //@ts-ignore
27
29
  emit: async (eventName, targetAndPayload, cb) => {
28
30
  let builtTp = await this.mixinProxyToken(token, targetAndPayload);
29
31
  return client.emit(eventName, builtTp, cb);
30
- }, emitAndFlattenResponses: async (
32
+ },
33
+ emitAndFlattenResponses: async (
31
34
  //@ts-ignore
32
35
  eventName,
33
36
  //@ts-ignore
@@ -36,20 +39,23 @@ class ClientProxyDecorator {
36
39
  cb) => {
37
40
  let builtTp = await this.mixinProxyToken(token, targetAndPayload);
38
41
  return client.emitAndFlattenResponses(eventName, builtTp, cb);
39
- } });
42
+ },
43
+ };
40
44
  spruce_skill_utils_1.functionDelegationUtil.delegateFunctionCalls(newClient, client);
41
45
  newClient.getProxyToken = () => token;
42
46
  return newClient;
43
47
  }
44
48
  async mixinProxyToken(token, targetAndPayload) {
45
- var _a;
46
- const t = token || (await ((_a = this.proxyTokenGenerator) === null || _a === void 0 ? void 0 : _a.call(this)));
49
+ const t = token || (await this.proxyTokenGenerator?.());
47
50
  let builtTp = targetAndPayload;
48
51
  if (t) {
49
52
  if (!builtTp) {
50
53
  builtTp = {};
51
54
  }
52
- builtTp.source = Object.assign(Object.assign({}, builtTp === null || builtTp === void 0 ? void 0 : builtTp.source), { proxyToken: t });
55
+ builtTp.source = {
56
+ ...builtTp?.source,
57
+ proxyToken: t,
58
+ };
53
59
  }
54
60
  return builtTp;
55
61
  }
@@ -6,10 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const error_1 = __importDefault(require("@sprucelabs/error"));
7
7
  class SpruceError extends error_1.default {
8
8
  friendlyMessage() {
9
- var _a, _b, _c;
10
9
  const { options } = this;
11
10
  let message;
12
- switch (options === null || options === void 0 ? void 0 : options.code) {
11
+ switch (options?.code) {
13
12
  case 'INVALID_FIXTURE':
14
13
  message = `"${options.suppliedName}" is not a valid fixture name. Try: \n\n${options.validNames.join('\n')}`;
15
14
  break;
@@ -17,10 +16,10 @@ class SpruceError extends error_1.default {
17
16
  message = `Couldn't find skill with slug ${options.slug}!`;
18
17
  break;
19
18
  case 'INVALID_VIEW_CONTROLLER':
20
- message = `Dang! The view controller named ${(_a = options.name) !== null && _a !== void 0 ? _a : options.id} is not valid..`;
19
+ message = `Dang! The view controller named ${options.name ?? options.id} is not valid..`;
21
20
  break;
22
21
  case 'UNKNOWN_VIEW_CONTROLLER_ERROR':
23
- message = `No idea what happened when trying to load the view controller ${(_b = options.name) !== null && _b !== void 0 ? _b : options.id}! The original error is:\n\n${(_c = options.originalError) === null || _c === void 0 ? void 0 : _c.stack}`;
22
+ message = `No idea what happened when trying to load the view controller ${options.name ?? options.id}! The original error is:\n\n${options.originalError?.stack}`;
24
23
  break;
25
24
  case 'FAKE_EVENT_ERROR':
26
25
  message = `A faked response to '${options.fqen}' threw an error! If this failed a test it's time to try/catch and possibly render an alert()! If this was expected (the tests pass), then ignore it.`;
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
@@ -53,13 +42,12 @@ class AbstractSpruceFixtureTest extends spruce_skill_booter_1.AbstractSkillTest
53
42
  await FixtureFactory_1.default.afterAll();
54
43
  }
55
44
  static Fixture(name, options) {
56
- var _a;
57
45
  if (!this._fixtures) {
58
46
  const pkg = spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, 'package.json');
59
47
  let namespace;
60
48
  if (spruce_skill_utils_1.diskUtil.doesFileExist(pkg)) {
61
49
  const values = JSON.parse(spruce_skill_utils_1.diskUtil.readFile(pkg));
62
- namespace = (_a = values === null || values === void 0 ? void 0 : values.skill) === null || _a === void 0 ? void 0 : _a.namespace;
50
+ namespace = values?.skill?.namespace;
63
51
  }
64
52
  this._fixtures = new FixtureFactory_1.default({
65
53
  cwd: this.cwd,
@@ -69,7 +57,7 @@ class AbstractSpruceFixtureTest extends spruce_skill_booter_1.AbstractSkillTest
69
57
  return this._fixtures.Fixture(name, options);
70
58
  }
71
59
  static async bootAndRegisterNewSkill(options) {
72
- const { name, slug } = options, skillOptions = __rest(options, ["name", "slug"]);
60
+ const { name, slug, ...skillOptions } = options;
73
61
  const { skill, client } = await this.skills.loginAsDemoSkill({
74
62
  name,
75
63
  slug,
@@ -31,7 +31,9 @@ class FakeThemeManager {
31
31
  };
32
32
  }
33
33
  setTheme(theme) {
34
- this.theme = Object.assign({}, theme);
34
+ this.theme = {
35
+ ...theme,
36
+ };
35
37
  }
36
38
  getTheme() {
37
39
  return this.theme;
@@ -2,36 +2,35 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
6
  exports.DEMO_NUMBER_ACCOUNT_AFTER_ALL_RESET = exports.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE_ALT = exports.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE = exports.DEMO_NUMBER_PERSON_FIXTURE = exports.DEMO_NUMBER_SCOPE = exports.DEMO_NUMBER_TEST_CLIENT_RECENT = exports.DEMO_NUMBER_VIEW_FIXTURE_CLIENT_2 = exports.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET_LOCATION = exports.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET = exports.DEMO_NUMBER_LOGIN_DECORATOR_2 = exports.DEMO_NUMBER_LOGIN_DECORATOR = exports.DEMO_NUMBER_VIEW_FIXTURE_2 = exports.DEMO_NUMBER_HANDLING_EVENTS_LOCALLY = exports.DEMO_NUMBER_ORGANIZATION_FIXTURE = exports.DEMO_NUMBER_LOCATION_FIXTURE_OUTSIDER = exports.DEMO_NUMBER_SKILL_FIXTURE = exports.DEMO_NUMBER_ACCOUNT_RESET = exports.DEMO_NUMBER_SKILL_DECORATORS = exports.DEMO_NUMBER_DECORATORS = exports.DEMO_NUMBER_SEED_FIXTURE = exports.DEMO_NUMBER_ROLE_FIXTURE = exports.DEMO_NUMBER_LOCATION_FIXTURE = exports.DEMO_NUMBER_MERCURY_FIXTURE = exports.DEMO_NUMBER_VIEW_FIXTURE = exports.DEMO_NUMBER_SECOND_LOGIN = exports.DEMO_NUMBER_INSTALLING_SKILLS = exports.DEMO_NUMBER_HIRING = exports.DEMO_NUMBER = void 0;
8
7
  const dotenv_1 = __importDefault(require("dotenv"));
9
8
  dotenv_1.default.config();
10
- exports.DEMO_NUMBER = (_a = process.env.DEMO_NUMBER) !== null && _a !== void 0 ? _a : '**MISSING**';
11
- exports.DEMO_NUMBER_HIRING = (_b = process.env.DEMO_NUMBER_HIRING) !== null && _b !== void 0 ? _b : '**MISSING**';
12
- exports.DEMO_NUMBER_INSTALLING_SKILLS = (_c = process.env.DEMO_NUMBER_INSTALLING_SKILLS) !== null && _c !== void 0 ? _c : '**MISSING**';
13
- exports.DEMO_NUMBER_SECOND_LOGIN = (_d = process.env.DEMO_NUMBER_SECOND_LOGIN) !== null && _d !== void 0 ? _d : '**MISSING**';
14
- exports.DEMO_NUMBER_VIEW_FIXTURE = (_e = process.env.DEMO_NUMBER_VIEW_FIXTURE) !== null && _e !== void 0 ? _e : '**MISSING**';
15
- exports.DEMO_NUMBER_MERCURY_FIXTURE = (_f = process.env.DEMO_NUMBER_MERCURY_FIXTURE) !== null && _f !== void 0 ? _f : '***missing***';
16
- exports.DEMO_NUMBER_LOCATION_FIXTURE = (_g = process.env.DEMO_NUMBER_LOCATION_FIXTURE) !== null && _g !== void 0 ? _g : '***missing***';
17
- exports.DEMO_NUMBER_ROLE_FIXTURE = (_h = process.env.DEMO_NUMBER_ROLE_FIXTURE) !== null && _h !== void 0 ? _h : '***missing***';
18
- exports.DEMO_NUMBER_SEED_FIXTURE = (_j = process.env.DEMO_NUMBER_SEED_FIXTURE) !== null && _j !== void 0 ? _j : '***missing***';
19
- exports.DEMO_NUMBER_DECORATORS = (_k = process.env.DEMO_NUMBER_DECORATORS) !== null && _k !== void 0 ? _k : '***missing***';
20
- exports.DEMO_NUMBER_SKILL_DECORATORS = (_l = process.env.DEMO_NUMBER_SKILL_DECORATORS) !== null && _l !== void 0 ? _l : '***missing***';
21
- exports.DEMO_NUMBER_ACCOUNT_RESET = (_m = process.env.DEMO_NUMBER_ACCOUNT_RESET) !== null && _m !== void 0 ? _m : '***missing***';
22
- exports.DEMO_NUMBER_SKILL_FIXTURE = (_o = process.env.DEMO_NUMBER_SKILL_FIXTURE) !== null && _o !== void 0 ? _o : '***missing***';
23
- exports.DEMO_NUMBER_LOCATION_FIXTURE_OUTSIDER = (_p = process.env.DEMO_NUMBER_LOCATION_FIXTURE_OUTSIDER) !== null && _p !== void 0 ? _p : '***missing***';
24
- exports.DEMO_NUMBER_ORGANIZATION_FIXTURE = (_q = process.env.DEMO_NUMBER_ORGANIZATION_FIXTURE) !== null && _q !== void 0 ? _q : '***missing***';
25
- exports.DEMO_NUMBER_HANDLING_EVENTS_LOCALLY = (_r = process.env.DEMO_NUMBER_HANDLING_EVENTS_LOCALLY) !== null && _r !== void 0 ? _r : '***missing***';
26
- exports.DEMO_NUMBER_VIEW_FIXTURE_2 = (_s = process.env.DEMO_NUMBER_VIEW_FIXTURE_2) !== null && _s !== void 0 ? _s : '***missing***';
27
- exports.DEMO_NUMBER_LOGIN_DECORATOR = (_t = process.env.DEMO_NUMBER_LOGIN_DECORATOR) !== null && _t !== void 0 ? _t : '***missing***';
28
- exports.DEMO_NUMBER_LOGIN_DECORATOR_2 = (_u = process.env.DEMO_NUMBER_LOGIN_DECORATOR_2) !== null && _u !== void 0 ? _u : '***missing***';
29
- exports.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET = (_v = process.env.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET) !== null && _v !== void 0 ? _v : '***missing***';
30
- exports.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET_LOCATION = (_w = process.env.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET_LOCATION) !== null && _w !== void 0 ? _w : '***missing***';
31
- exports.DEMO_NUMBER_VIEW_FIXTURE_CLIENT_2 = (_x = process.env.DEMO_NUMBER_VIEW_FIXTURE_CLIENT_2) !== null && _x !== void 0 ? _x : '***missing***';
32
- exports.DEMO_NUMBER_TEST_CLIENT_RECENT = (_y = process.env.DEMO_NUMBER_TEST_CLIENT_RECENT) !== null && _y !== void 0 ? _y : '***missing***';
33
- exports.DEMO_NUMBER_SCOPE = (_z = process.env.DEMO_NUMBER_SCOPE) !== null && _z !== void 0 ? _z : '***missing***';
34
- exports.DEMO_NUMBER_PERSON_FIXTURE = (_0 = process.env.DEMO_NUMBER_PERSON_FIXTURE) !== null && _0 !== void 0 ? _0 : '**missing**';
35
- exports.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE = (_1 = process.env.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE) !== null && _1 !== void 0 ? _1 : '**missing**';
36
- exports.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE_ALT = (_2 = process.env.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE_ALT) !== null && _2 !== void 0 ? _2 : '**missing**';
37
- exports.DEMO_NUMBER_ACCOUNT_AFTER_ALL_RESET = (_3 = process.env.DEMO_NUMBER_ACCOUNT_AFTER_ALL_RESET) !== null && _3 !== void 0 ? _3 : '***missing***';
9
+ exports.DEMO_NUMBER = process.env.DEMO_NUMBER ?? '**MISSING**';
10
+ exports.DEMO_NUMBER_HIRING = process.env.DEMO_NUMBER_HIRING ?? '**MISSING**';
11
+ exports.DEMO_NUMBER_INSTALLING_SKILLS = process.env.DEMO_NUMBER_INSTALLING_SKILLS ?? '**MISSING**';
12
+ exports.DEMO_NUMBER_SECOND_LOGIN = process.env.DEMO_NUMBER_SECOND_LOGIN ?? '**MISSING**';
13
+ exports.DEMO_NUMBER_VIEW_FIXTURE = process.env.DEMO_NUMBER_VIEW_FIXTURE ?? '**MISSING**';
14
+ exports.DEMO_NUMBER_MERCURY_FIXTURE = process.env.DEMO_NUMBER_MERCURY_FIXTURE ?? '***missing***';
15
+ exports.DEMO_NUMBER_LOCATION_FIXTURE = process.env.DEMO_NUMBER_LOCATION_FIXTURE ?? '***missing***';
16
+ exports.DEMO_NUMBER_ROLE_FIXTURE = process.env.DEMO_NUMBER_ROLE_FIXTURE ?? '***missing***';
17
+ exports.DEMO_NUMBER_SEED_FIXTURE = process.env.DEMO_NUMBER_SEED_FIXTURE ?? '***missing***';
18
+ exports.DEMO_NUMBER_DECORATORS = process.env.DEMO_NUMBER_DECORATORS ?? '***missing***';
19
+ exports.DEMO_NUMBER_SKILL_DECORATORS = process.env.DEMO_NUMBER_SKILL_DECORATORS ?? '***missing***';
20
+ exports.DEMO_NUMBER_ACCOUNT_RESET = process.env.DEMO_NUMBER_ACCOUNT_RESET ?? '***missing***';
21
+ exports.DEMO_NUMBER_SKILL_FIXTURE = process.env.DEMO_NUMBER_SKILL_FIXTURE ?? '***missing***';
22
+ exports.DEMO_NUMBER_LOCATION_FIXTURE_OUTSIDER = process.env.DEMO_NUMBER_LOCATION_FIXTURE_OUTSIDER ?? '***missing***';
23
+ exports.DEMO_NUMBER_ORGANIZATION_FIXTURE = process.env.DEMO_NUMBER_ORGANIZATION_FIXTURE ?? '***missing***';
24
+ exports.DEMO_NUMBER_HANDLING_EVENTS_LOCALLY = process.env.DEMO_NUMBER_HANDLING_EVENTS_LOCALLY ?? '***missing***';
25
+ exports.DEMO_NUMBER_VIEW_FIXTURE_2 = process.env.DEMO_NUMBER_VIEW_FIXTURE_2 ?? '***missing***';
26
+ exports.DEMO_NUMBER_LOGIN_DECORATOR = process.env.DEMO_NUMBER_LOGIN_DECORATOR ?? '***missing***';
27
+ exports.DEMO_NUMBER_LOGIN_DECORATOR_2 = process.env.DEMO_NUMBER_LOGIN_DECORATOR_2 ?? '***missing***';
28
+ exports.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET = process.env.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET ?? '***missing***';
29
+ exports.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET_LOCATION = process.env.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET_LOCATION ?? '***missing***';
30
+ exports.DEMO_NUMBER_VIEW_FIXTURE_CLIENT_2 = process.env.DEMO_NUMBER_VIEW_FIXTURE_CLIENT_2 ?? '***missing***';
31
+ exports.DEMO_NUMBER_TEST_CLIENT_RECENT = process.env.DEMO_NUMBER_TEST_CLIENT_RECENT ?? '***missing***';
32
+ exports.DEMO_NUMBER_SCOPE = process.env.DEMO_NUMBER_SCOPE ?? '***missing***';
33
+ exports.DEMO_NUMBER_PERSON_FIXTURE = process.env.DEMO_NUMBER_PERSON_FIXTURE ?? '**missing**';
34
+ exports.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE = process.env.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE ?? '**missing**';
35
+ exports.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE_ALT = process.env.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE_ALT ?? '**missing**';
36
+ exports.DEMO_NUMBER_ACCOUNT_AFTER_ALL_RESET = process.env.DEMO_NUMBER_ACCOUNT_AFTER_ALL_RESET ?? '***missing***';
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
@@ -41,7 +30,6 @@ const strategies = {
41
30
  owners: buildSeeder('owners'),
42
31
  };
43
32
  function resetFakedRecords(Class) {
44
- var _a, _b, _c;
45
33
  if (shouldSkipNextReset) {
46
34
  shouldSkipNextReset = false;
47
35
  return;
@@ -56,25 +44,24 @@ function resetFakedRecords(Class) {
56
44
  Class.fakedGroupManagers = [];
57
45
  Class.fakedGuests = [];
58
46
  Class.fakedRoles = [];
59
- Class.fakedPeople = ((_a = Class.fakedPeople) === null || _a === void 0 ? void 0 : _a[0]) ? [Class.fakedPeople[0]] : [];
47
+ Class.fakedPeople = Class.fakedPeople?.[0] ? [Class.fakedPeople[0]] : [];
60
48
  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])
49
+ Class.fakedTokens = Class.fakedTokens?.[0] ? [Class.fakedTokens[0]] : [];
50
+ Class.fakedProxyTokens = Class.fakedProxyTokens?.[0]
63
51
  ? [Class.fakedProxyTokens[0]]
64
52
  : [];
65
53
  }
66
54
  function fake(target, total) {
67
55
  (0, schema_1.assertOptions)({ target, total }, ['target', 'total']);
68
56
  return function (TestClass, _key, descriptor) {
69
- var _a, _b;
70
57
  const Class = TestClass;
71
- 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);
58
+ const bound = descriptor?.value?.bind?.(Class);
72
59
  descriptor.value = async (...args) => {
73
60
  test_utils_1.assert.isTruthy(Class.fakedPerson, `You gotta @faker.login(...) before you can create fake '${target}'!`);
74
61
  const strategy = strategies[target];
75
62
  test_utils_1.assert.isTruthy(strategy, `Faking ${target} is not ready yet!`);
76
- await (strategy === null || strategy === void 0 ? void 0 : strategy(Class, total));
77
- await (bound === null || bound === void 0 ? void 0 : bound(...args));
63
+ await strategy?.(Class, total);
64
+ await bound?.(...args);
78
65
  };
79
66
  };
80
67
  }
@@ -87,15 +74,14 @@ fake.login = (phone = '555-000-0000') => {
87
74
  ViewFixture_1.default.setShouldAutomaticallyResetAuth(false);
88
75
  seed_1.default.disableResettingTestClient();
89
76
  return function (TestClass, shouldPassHookCalls = true) {
90
- var _a, _b, _c;
91
77
  if (!(TestClass.prototype instanceof AbstractSpruceFixtureTest_1.default)) {
92
78
  spruce_skill_utils_1.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
79
  return;
94
80
  }
95
81
  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);
82
+ const beforeEach = Class.beforeEach?.bind(Class);
83
+ const beforeAll = Class.beforeAll?.bind(Class);
84
+ const afterEach = Class.afterEach?.bind(Class);
99
85
  if (shouldPassHookCalls) {
100
86
  const old = MercuryFixture_1.default.beforeEach.bind(MercuryFixture_1.default);
101
87
  MercuryFixture_1.default.beforeEach = async (...args) => {
@@ -105,7 +91,7 @@ fake.login = (phone = '555-000-0000') => {
105
91
  };
106
92
  }
107
93
  Class.beforeAll = async () => {
108
- await (beforeAll === null || beforeAll === void 0 ? void 0 : beforeAll());
94
+ await beforeAll?.();
109
95
  resetFakedRecords(Class);
110
96
  await setupFakeListeners(Class);
111
97
  await login(Class, phone);
@@ -113,7 +99,7 @@ fake.login = (phone = '555-000-0000') => {
113
99
  };
114
100
  Class.afterEach = async () => {
115
101
  await setupFakeListeners(Class);
116
- await (afterEach === null || afterEach === void 0 ? void 0 : afterEach());
102
+ await afterEach?.();
117
103
  };
118
104
  Class.beforeEach = async () => {
119
105
  resetFakedRecords(Class);
@@ -128,10 +114,10 @@ fake.login = (phone = '555-000-0000') => {
128
114
  //@ts-ignore
129
115
  Class.fakedClient.auth.token, Class.fakedPerson);
130
116
  }
131
- catch (_a) {
117
+ catch {
132
118
  //hits if not in skill because cant find nameplace
133
119
  }
134
- shouldPassHookCalls && (await (beforeEach === null || beforeEach === void 0 ? void 0 : beforeEach()));
120
+ shouldPassHookCalls && (await beforeEach?.());
135
121
  };
136
122
  };
137
123
  };
@@ -161,7 +147,7 @@ async function loginUsingViewsFallingBackToPeople(Class, phone) {
161
147
  person = p;
162
148
  client = c;
163
149
  }
164
- catch (_a) {
150
+ catch {
165
151
  const { person: p, client: c } = await Class.people.loginAsDemoPerson(phone);
166
152
  person = p;
167
153
  client = c;
@@ -205,7 +191,7 @@ async function setupFakeListeners(Class) {
205
191
  }
206
192
  async function fakeAddRole(Class) {
207
193
  await eventFaker_1.default.on('add-role::v2020_12_25', ({ payload, target }) => {
208
- const { organizationId, locationId } = target !== null && target !== void 0 ? target : {};
194
+ const { organizationId, locationId } = target ?? {};
209
195
  const { roleId } = payload;
210
196
  const person = getPersonById(Class, payload.personId);
211
197
  addPersonAsRoleToLocationOrOrg({
@@ -258,12 +244,11 @@ async function fakeGetRole(Class) {
258
244
  }
259
245
  async function fakeRemoveRole(Class) {
260
246
  await eventFaker_1.default.on('remove-role::v2020_12_25', ({ payload }) => {
261
- var _a;
262
247
  const { personId, roleId } = payload;
263
248
  const role = getRoleById(Class, roleId);
264
249
  const people = Class[roleBaseToLocalFakedProp(role.base)];
265
- const idx = (_a = people === null || people === void 0 ? void 0 : people.findIndex((p) => p.id === personId)) !== null && _a !== void 0 ? _a : -1;
266
- people === null || people === void 0 ? void 0 : people.splice(idx, 1);
250
+ const idx = people?.findIndex((p) => p.id === personId) ?? -1;
251
+ people?.splice(idx, 1);
267
252
  Class.fakedPeopleRoles = Class.fakedPeopleRoles.filter((p) => !(p.personId === personId && p.roleId === roleId));
268
253
  return {};
269
254
  });
@@ -283,17 +268,17 @@ function getPersonById(Class, personId, shouldThrowWhenNotFound = true) {
283
268
  }
284
269
  async function fakeUpdatePerson(Class) {
285
270
  await eventFaker_1.default.on('update-person::v2020_12_25', ({ target, source, payload }) => {
286
- const person = Class.fakedPeople.find((p) => (target === null || target === void 0 ? void 0 : target.personId)
287
- ? p.id === (target === null || target === void 0 ? void 0 : target.personId)
288
- : p.id === (source === null || source === void 0 ? void 0 : source.personId));
271
+ const person = Class.fakedPeople.find((p) => target?.personId
272
+ ? p.id === target?.personId
273
+ : p.id === source?.personId);
289
274
  if (!person) {
290
275
  throw new SpruceError_1.default({
291
276
  code: 'INVALID_TARGET',
292
277
  friendlyMessage: `I could not update the faked person you were looking for!`,
293
278
  });
294
279
  }
295
- person.firstName = payload === null || payload === void 0 ? void 0 : payload.firstName;
296
- person.lastName = payload === null || payload === void 0 ? void 0 : payload.lastName;
280
+ person.firstName = payload?.firstName;
281
+ person.lastName = payload?.lastName;
297
282
  person.casualName = buildCasualName(person);
298
283
  return {
299
284
  person,
@@ -302,9 +287,8 @@ async function fakeUpdatePerson(Class) {
302
287
  }
303
288
  async function fakeListRoles(Class) {
304
289
  await eventFaker_1.default.on('list-roles::v2020_12_25', ({ target, payload }) => {
305
- var _a;
306
- let { personId, organizationId, locationId } = target !== null && target !== void 0 ? target : {};
307
- const { shouldIncludeMetaRoles, shouldIncludePrivateRoles } = payload !== null && payload !== void 0 ? payload : {};
290
+ let { personId, organizationId, locationId } = target ?? {};
291
+ const { shouldIncludeMetaRoles, shouldIncludePrivateRoles } = payload ?? {};
308
292
  let roles = [];
309
293
  if (personId) {
310
294
  const personRoles = Class.fakedPeopleRoles
@@ -318,7 +302,7 @@ async function fakeListRoles(Class) {
318
302
  }
319
303
  else {
320
304
  if (locationId) {
321
- organizationId = (_a = Class._fakedLocations.find((l) => l.id === locationId)) === null || _a === void 0 ? void 0 : _a.organizationId;
305
+ organizationId = Class._fakedLocations.find((l) => l.id === locationId)?.organizationId;
322
306
  }
323
307
  roles = Class.fakedRoles.filter((r) => r.organizationId === organizationId);
324
308
  }
@@ -335,18 +319,17 @@ async function fakeListRoles(Class) {
335
319
  }
336
320
  async function fakeListPeople(Class) {
337
321
  await eventFaker_1.default.on('list-people::v2020_12_25', ({ payload }) => {
338
- var _a;
339
322
  let people = [];
340
- test_utils_1.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.`);
341
- test_utils_1.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`);
342
- for (const base of (_a = payload === null || payload === void 0 ? void 0 : payload.roleBases) !== null && _a !== void 0 ? _a : []) {
323
+ test_utils_1.assert.isFalsy(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.`);
324
+ test_utils_1.assert.isFalsy(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`);
325
+ for (const base of payload?.roleBases ?? []) {
343
326
  const faked = getFakedRecordsByRoleBase(Class, base);
344
327
  if (faked) {
345
328
  people.push(...faked);
346
329
  }
347
330
  }
348
331
  return {
349
- people: (payload === null || payload === void 0 ? void 0 : payload.roleBases) ? people : Class.fakedPeople,
332
+ people: payload?.roleBases ? people : Class.fakedPeople,
350
333
  };
351
334
  });
352
335
  }
@@ -357,8 +340,8 @@ function getFakedRecordsByRoleBase(Class, base) {
357
340
  async function fakeListLocations(Class) {
358
341
  await eventFaker_1.default.on('list-locations::v2020_12_25', ({ target, payload }) => {
359
342
  return {
360
- locations: applyPaging(Class._fakedLocations, payload).filter((l) => !(target === null || target === void 0 ? void 0 : target.organizationId) ||
361
- l.organizationId === (target === null || target === void 0 ? void 0 : target.organizationId)),
343
+ locations: applyPaging(Class._fakedLocations, payload).filter((l) => !target?.organizationId ||
344
+ l.organizationId === target?.organizationId),
362
345
  };
363
346
  });
364
347
  }
@@ -386,7 +369,11 @@ async function fakeUpdateLocation(Class) {
386
369
  friendlyMessage: `I could not find that location to update!`,
387
370
  });
388
371
  }
389
- Class._fakedLocations[idx] = Object.assign(Object.assign(Object.assign({}, Class._fakedLocations[idx]), payload), { dateUpdated: Date.now() });
372
+ Class._fakedLocations[idx] = {
373
+ ...Class._fakedLocations[idx],
374
+ ...payload,
375
+ dateUpdated: Date.now(),
376
+ };
390
377
  return {
391
378
  location: Class._fakedLocations[idx],
392
379
  };
@@ -410,9 +397,14 @@ async function fakeDeleteOrganization(Class) {
410
397
  }
411
398
  async function fakeCreateLocation(Class) {
412
399
  await eventFaker_1.default.on('create-location::v2020_12_25', ({ target, payload, source }) => {
413
- var _a;
414
- const { personId } = source !== null && source !== void 0 ? source : {};
415
- const location = Object.assign(Object.assign({ id: (0, test_utils_2.generateId)(), dateCreated: new Date().getTime(), organizationId: target.organizationId }, payload), { slug: (_a = payload.slug) !== null && _a !== void 0 ? _a : spruce_skill_utils_1.namesUtil.toKebab(payload.name) });
400
+ const { personId } = source ?? {};
401
+ const location = {
402
+ id: (0, test_utils_2.generateId)(),
403
+ dateCreated: new Date().getTime(),
404
+ organizationId: target.organizationId,
405
+ ...payload,
406
+ slug: payload.slug ?? spruce_skill_utils_1.namesUtil.toKebab(payload.name),
407
+ };
416
408
  Class._fakedLocations.unshift(location);
417
409
  if (personId) {
418
410
  const role = Class.fakedRoles.find((r) => r.base === 'owner');
@@ -430,8 +422,13 @@ async function fakeCreateLocation(Class) {
430
422
  }
431
423
  async function fakeCreateOrganization(Class) {
432
424
  await eventFaker_1.default.on('create-organization::v2020_12_25', ({ payload }) => {
433
- var _a;
434
- const organization = Object.assign(Object.assign({ id: (0, test_utils_2.generateId)(), dateCreated: new Date().getTime(), isPublic: null }, payload), { slug: (_a = payload.slug) !== null && _a !== void 0 ? _a : spruce_skill_utils_1.namesUtil.toKebab(payload.name) });
425
+ const organization = {
426
+ id: (0, test_utils_2.generateId)(),
427
+ dateCreated: new Date().getTime(),
428
+ isPublic: null,
429
+ ...payload,
430
+ slug: payload.slug ?? spruce_skill_utils_1.namesUtil.toKebab(payload.name),
431
+ };
435
432
  Class._fakedOrganizations.unshift(organization);
436
433
  const roles = seedRoles(Class, organization.id);
437
434
  addPersonAsRoleToLocationOrOrg({
@@ -447,7 +444,7 @@ async function fakeCreateOrganization(Class) {
447
444
  }
448
445
  async function fakeGetPerson(Class) {
449
446
  await eventFaker_1.default.on('get-person::v2020_12_25', ({ target }) => {
450
- test_utils_1.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(...)'.`);
447
+ test_utils_1.assert.isTruthy(target?.personId, `@fake only supports 'get-person::v2020_12_25' when passing an id. To fake more, use 'eventFaker.on(...)'.`);
451
448
  const person = getPersonById(Class, target.personId);
452
449
  if (!person) {
453
450
  throw new SpruceError_1.default({
@@ -464,8 +461,14 @@ async function fakeSkillLifecycleEvents(Class) {
464
461
  process.env.SKILL_ID = process.env.SKILL_ID || (0, test_utils_2.generateId)();
465
462
  process.env.SKILL_API_KEY = process.env.SKILL_API_KEY || (0, test_utils_2.generateId)();
466
463
  await eventFaker_1.default.on('register-skill::v2020_12_25', ({ payload }) => {
467
- var _a;
468
- const skill = Object.assign(Object.assign({ apiKey: (0, test_utils_2.generateId)(), creators: [{ personId: Class.fakedPerson.id }], dateCreated: new Date().getTime(), id: (0, test_utils_2.generateId)() }, payload), { slug: (_a = payload.slug) !== null && _a !== void 0 ? _a : (0, test_utils_2.generateId)() });
464
+ const skill = {
465
+ apiKey: (0, test_utils_2.generateId)(),
466
+ creators: [{ personId: Class.fakedPerson.id }],
467
+ dateCreated: new Date().getTime(),
468
+ id: (0, test_utils_2.generateId)(),
469
+ ...payload,
470
+ slug: payload.slug ?? (0, test_utils_2.generateId)(),
471
+ };
469
472
  Class.fakedSkills.unshift(skill);
470
473
  return {
471
474
  skill,
@@ -480,8 +483,7 @@ async function fakeSkillLifecycleEvents(Class) {
480
483
  }));
481
484
  }
482
485
  function buildCasualName(names) {
483
- var _a;
484
- return `${(_a = names.firstName) !== null && _a !== void 0 ? _a : 'friend'} ${names.lastName ? names.lastName[0] + '.' : ''}`.trim();
486
+ return `${names.firstName ?? 'friend'} ${names.lastName ? names.lastName[0] + '.' : ''}`.trim();
485
487
  }
486
488
  async function fakeGetOrganization(Class) {
487
489
  await eventFaker_1.default.on('get-organization::v2020_12_25', ({ target }) => {
@@ -494,18 +496,16 @@ async function fakeGetOrganization(Class) {
494
496
  async function fakeUpdateOrganization(Class) {
495
497
  await eventFaker_1.default.on('update-organization::v2020_12_25', ({ target, payload }) => {
496
498
  const match = findOrgFromTarget(Class, target);
497
- if (payload === null || payload === void 0 ? void 0 : payload.name) {
499
+ if (payload?.name) {
498
500
  match.name = payload.name;
499
501
  }
500
- if (payload === null || payload === void 0 ? void 0 : payload.address) {
502
+ if (payload?.address) {
501
503
  match.address = payload.address;
502
504
  }
503
- if (typeof (payload === null || payload === void 0 ? void 0 : payload.isPublic) !== 'undefined') {
505
+ if (typeof payload?.isPublic !== 'undefined') {
504
506
  match.isPublic = payload.isPublic;
505
507
  }
506
- const copy = __rest(match
507
- //@ts-ignore
508
- , []);
508
+ const { ...copy } = match;
509
509
  //@ts-ignore
510
510
  delete copy.id;
511
511
  return {
@@ -515,16 +515,15 @@ async function fakeUpdateOrganization(Class) {
515
515
  }
516
516
  async function fakeListOrganization(Class) {
517
517
  await eventFaker_1.default.on('list-organizations::v2020_12_25', (targetAndPayload) => {
518
- const { payload } = targetAndPayload !== null && targetAndPayload !== void 0 ? targetAndPayload : {};
518
+ const { payload } = targetAndPayload ?? {};
519
519
  return {
520
520
  organizations: applyPaging(Class._fakedOrganizations, payload),
521
521
  };
522
522
  });
523
523
  }
524
524
  function applyPaging(records, payload) {
525
- var _a;
526
525
  let copy = [...records];
527
- if ((_a = payload === null || payload === void 0 ? void 0 : payload.paging) === null || _a === void 0 ? void 0 : _a.pageSize) {
526
+ if (payload?.paging?.pageSize) {
528
527
  copy = copy.slice(0, payload.paging.pageSize);
529
528
  }
530
529
  return copy;
@@ -564,14 +563,13 @@ function buildSeeder(target) {
564
563
  }
565
564
  async function fakeWhoAmI(Class) {
566
565
  await eventFaker_1.default.on('whoami::v2020_12_25', (targetAndPayload) => {
567
- var _a;
568
- const { source } = targetAndPayload !== null && targetAndPayload !== void 0 ? targetAndPayload : {};
569
- let { personId, proxyToken } = source !== null && source !== void 0 ? source : {};
566
+ const { source } = targetAndPayload ?? {};
567
+ let { personId, proxyToken } = source ?? {};
570
568
  if (proxyToken) {
571
- personId = (_a = Class.fakedProxyTokens.find((t) => t.token === proxyToken)) === null || _a === void 0 ? void 0 : _a.personId;
569
+ personId = Class.fakedProxyTokens.find((t) => t.token === proxyToken)?.personId;
572
570
  }
573
571
  const person = getPersonById(Class, personId, false);
574
- const skill = Class.fakedSkills.find((s) => s.id === (source === null || source === void 0 ? void 0 : source.skillId));
572
+ const skill = Class.fakedSkills.find((s) => s.id === source?.skillId);
575
573
  return {
576
574
  auth: {
577
575
  skill,
@@ -585,9 +583,9 @@ async function fakeWhoAmI(Class) {
585
583
  }
586
584
  async function fakeRegisterProxyToken(Class) {
587
585
  await eventFaker_1.default.on('register-proxy-token::v2020_12_25', (targeAndPayload) => {
588
- const { source } = targeAndPayload !== null && targeAndPayload !== void 0 ? targeAndPayload : {};
586
+ const { source } = targeAndPayload ?? {};
589
587
  const token = (0, test_utils_2.generateId)();
590
- if (source === null || source === void 0 ? void 0 : source.personId) {
588
+ if (source?.personId) {
591
589
  Class.fakedProxyTokens.push({
592
590
  personId: source.personId,
593
591
  token,
@@ -600,12 +598,11 @@ async function fakeRegisterProxyToken(Class) {
600
598
  }
601
599
  async function fakeAuthenticationEvents(Class) {
602
600
  await eventFaker_1.default.on('request-pin::v2020_12_25', ({ payload }) => {
603
- var _a;
604
601
  const formattedPhone = (0, schema_1.formatPhoneNumber)(payload.phone);
605
602
  let person = Class.fakedPeople.find((p) => p.phone === formattedPhone);
606
603
  if (!person) {
607
604
  person =
608
- ((_a = Class.fakedPerson) === null || _a === void 0 ? void 0 : _a.phone) === formattedPhone
605
+ Class.fakedPerson?.phone === formattedPhone
609
606
  ? Class.fakedPerson
610
607
  : {
611
608
  id: (0, test_utils_2.generateId)(),
@@ -636,11 +633,13 @@ async function fakeAuthenticationEvents(Class) {
636
633
  });
637
634
  return {
638
635
  token,
639
- person: Object.assign({}, person),
636
+ person: {
637
+ ...person,
638
+ },
640
639
  };
641
640
  });
642
641
  await eventFaker_1.default.on('authenticate::v2020_12_25', ({ payload }) => {
643
- const { token, apiKey, skillId } = payload !== null && payload !== void 0 ? payload : {};
642
+ const { token, apiKey, skillId } = payload ?? {};
644
643
  let skill = Class.fakedSkills.find((s) => s.apiKey === apiKey && s.id === skillId);
645
644
  if (!skill &&
646
645
  apiKey &&
@@ -681,7 +680,7 @@ async function fakeAuthenticationEvents(Class) {
681
680
  async function fakeInstallEvents(Class) {
682
681
  await eventFaker_1.default.on('is-skill-installed::v2020_12_25', ({ payload }) => {
683
682
  return {
684
- isInstalled: !!Class.fakedInstalledSkills.find((i) => i.skillId === (payload === null || payload === void 0 ? void 0 : payload.skillId)),
683
+ isInstalled: !!Class.fakedInstalledSkills.find((i) => i.skillId === payload?.skillId),
685
684
  };
686
685
  });
687
686
  await eventFaker_1.default.on('install-skill::v2020_12_25', ({ target, payload }) => {
@@ -692,8 +691,8 @@ async function fakeInstallEvents(Class) {
692
691
  return {};
693
692
  });
694
693
  await eventFaker_1.default.on('list-skills::v2020_12_25', ({ payload }) => {
695
- const namespaces = payload === null || payload === void 0 ? void 0 : payload.namespaces;
696
- 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; });
694
+ const namespaces = payload?.namespaces;
695
+ const matches = Class.fakedSkills.filter((s) => (namespaces?.indexOf(s.slug) ?? 0) > -1);
697
696
  if (matches.length === 0) {
698
697
  throw new SpruceError_1.default({
699
698
  //@ts-ignore
@@ -704,9 +703,7 @@ async function fakeInstallEvents(Class) {
704
703
  }
705
704
  return {
706
705
  skills: matches.map((m) => {
707
- const copy = __rest(m
708
- //@ts-ignore
709
- , []);
706
+ const { ...copy } = m;
710
707
  //@ts-ignore
711
708
  delete copy.apiKey;
712
709
  //@ts-ignore