@sprucelabs/spruce-test-fixtures 44.2.1 → 44.2.4

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.
@@ -192,7 +192,7 @@ function fakeAddRole(Class) {
192
192
  }
193
193
  function addPersonAsRoleToLocationOrOrg(options) {
194
194
  const { Class, roleId, person, organizationId, locationId } = options;
195
- const role = Class.fakedRoles.find((r) => r.id === roleId);
195
+ const role = getRoleById(Class, roleId);
196
196
  const key = roleBaseToLocalFakedProp(role.base);
197
197
  //@ts-ignore
198
198
  assert.isTruthy(Class[key], `Could not find property ${key}`);
@@ -208,6 +208,11 @@ function addPersonAsRoleToLocationOrOrg(options) {
208
208
  locationId,
209
209
  });
210
210
  }
211
+ function getRoleById(Class, roleId) {
212
+ const role = Class.fakedRoles.find((r) => r.id === roleId);
213
+ assert.isTruthy(role, `Could not load faked role with the id of ${roleId}.`);
214
+ return role;
215
+ }
211
216
  function fakeGetRole(Class) {
212
217
  return __awaiter(this, void 0, void 0, function* () {
213
218
  yield eventFaker.on('get-role::v2020_12_25', ({ target }) => {
@@ -230,7 +235,7 @@ function fakeRemoveRole(Class) {
230
235
  yield eventFaker.on('remove-role::v2020_12_25', ({ payload }) => {
231
236
  var _a;
232
237
  const { personId, roleId } = payload;
233
- const role = Class.fakedRoles.find((r) => r.id === roleId);
238
+ const role = getRoleById(Class, roleId);
234
239
  const people = Class[roleBaseToLocalFakedProp(role.base)];
235
240
  const idx = (_a = people === null || people === void 0 ? void 0 : people.findIndex((p) => p.id === personId)) !== null && _a !== void 0 ? _a : -1;
236
241
  people === null || people === void 0 ? void 0 : people.splice(idx, 1);
@@ -242,8 +247,15 @@ function fakeRemoveRole(Class) {
242
247
  function roleBaseToLocalFakedProp(base) {
243
248
  return fakeTargetToPropName((base + 's'));
244
249
  }
245
- function getPersonById(Class, personId) {
246
- return Class.fakedPeople.find((p) => p.id === personId);
250
+ function getPersonById(Class, personId, shouldThrowWhenNotFound = true) {
251
+ const person = Class.fakedPeople.find((p) => p.id === personId);
252
+ if (!person && shouldThrowWhenNotFound) {
253
+ throw new SpruceError({
254
+ code: 'INVALID_TARGET',
255
+ friendlyMessage: `I could not find a faked person with the id ${personId} you were looking.`,
256
+ });
257
+ }
258
+ return person;
247
259
  }
248
260
  function fakeUpdatePerson(Class) {
249
261
  return __awaiter(this, void 0, void 0, function* () {
@@ -271,7 +283,7 @@ function fakeListRoles(Class) {
271
283
  ((p.organizationId && p.organizationId === organizationId) ||
272
284
  (p.locationId && p.locationId === locationId) ||
273
285
  (!locationId && !organizationId)))
274
- .map((pr) => Class.fakedRoles.find((r) => r.id === pr.roleId));
286
+ .map((pr) => getRoleById(Class, pr.roleId));
275
287
  roles = personRoles;
276
288
  }
277
289
  else {
@@ -537,7 +549,7 @@ function fakeWhoAmI(Class) {
537
549
  if (proxyToken) {
538
550
  personId = (_a = Class.fakedProxyTokens.find((t) => t.token === proxyToken)) === null || _a === void 0 ? void 0 : _a.personId;
539
551
  }
540
- const person = getPersonById(Class, personId);
552
+ const person = getPersonById(Class, personId, false);
541
553
  const skill = Class.fakedSkills.find((s) => s.id === (source === null || source === void 0 ? void 0 : source.skillId));
542
554
  return {
543
555
  auth: {
@@ -184,7 +184,7 @@ async function fakeAddRole(Class) {
184
184
  }
185
185
  function addPersonAsRoleToLocationOrOrg(options) {
186
186
  const { Class, roleId, person, organizationId, locationId } = options;
187
- const role = Class.fakedRoles.find((r) => r.id === roleId);
187
+ const role = getRoleById(Class, roleId);
188
188
  const key = roleBaseToLocalFakedProp(role.base);
189
189
  //@ts-ignore
190
190
  test_1.assert.isTruthy(Class[key], `Could not find property ${key}`);
@@ -200,6 +200,11 @@ function addPersonAsRoleToLocationOrOrg(options) {
200
200
  locationId,
201
201
  });
202
202
  }
203
+ function getRoleById(Class, roleId) {
204
+ const role = Class.fakedRoles.find((r) => r.id === roleId);
205
+ test_1.assert.isTruthy(role, `Could not load faked role with the id of ${roleId}.`);
206
+ return role;
207
+ }
203
208
  async function fakeGetRole(Class) {
204
209
  await eventFaker_1.default.on('get-role::v2020_12_25', ({ target }) => {
205
210
  const { roleId } = target;
@@ -219,7 +224,7 @@ async function fakeRemoveRole(Class) {
219
224
  await eventFaker_1.default.on('remove-role::v2020_12_25', ({ payload }) => {
220
225
  var _a;
221
226
  const { personId, roleId } = payload;
222
- const role = Class.fakedRoles.find((r) => r.id === roleId);
227
+ const role = getRoleById(Class, roleId);
223
228
  const people = Class[roleBaseToLocalFakedProp(role.base)];
224
229
  const idx = (_a = people === null || people === void 0 ? void 0 : people.findIndex((p) => p.id === personId)) !== null && _a !== void 0 ? _a : -1;
225
230
  people === null || people === void 0 ? void 0 : people.splice(idx, 1);
@@ -230,8 +235,15 @@ async function fakeRemoveRole(Class) {
230
235
  function roleBaseToLocalFakedProp(base) {
231
236
  return fakeTargetToPropName((base + 's'));
232
237
  }
233
- function getPersonById(Class, personId) {
234
- return Class.fakedPeople.find((p) => p.id === personId);
238
+ function getPersonById(Class, personId, shouldThrowWhenNotFound = true) {
239
+ const person = Class.fakedPeople.find((p) => p.id === personId);
240
+ if (!person && shouldThrowWhenNotFound) {
241
+ throw new SpruceError_1.default({
242
+ code: 'INVALID_TARGET',
243
+ friendlyMessage: `I could not find a faked person with the id ${personId} you were looking.`,
244
+ });
245
+ }
246
+ return person;
235
247
  }
236
248
  async function fakeUpdatePerson(Class) {
237
249
  await eventFaker_1.default.on('update-person::v2020_12_25', ({ target, source, payload }) => {
@@ -256,7 +268,7 @@ async function fakeListRoles(Class) {
256
268
  ((p.organizationId && p.organizationId === organizationId) ||
257
269
  (p.locationId && p.locationId === locationId) ||
258
270
  (!locationId && !organizationId)))
259
- .map((pr) => Class.fakedRoles.find((r) => r.id === pr.roleId));
271
+ .map((pr) => getRoleById(Class, pr.roleId));
260
272
  roles = personRoles;
261
273
  }
262
274
  else {
@@ -492,7 +504,7 @@ async function fakeWhoAmI(Class) {
492
504
  if (proxyToken) {
493
505
  personId = (_a = Class.fakedProxyTokens.find((t) => t.token === proxyToken)) === null || _a === void 0 ? void 0 : _a.personId;
494
506
  }
495
- const person = getPersonById(Class, personId);
507
+ const person = getPersonById(Class, personId, false);
496
508
  const skill = Class.fakedSkills.find((s) => s.id === (source === null || source === void 0 ? void 0 : source.skillId));
497
509
  return {
498
510
  auth: {
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "@sprucelabs/spruce-test-fixtures"
14
14
  ]
15
15
  },
16
- "version": "44.2.1",
16
+ "version": "44.2.4",
17
17
  "files": [
18
18
  "build/**/*",
19
19
  "!build/__tests__",
@@ -62,17 +62,17 @@
62
62
  "lint.tsc": "tsc -p . --noEmit"
63
63
  },
64
64
  "dependencies": {
65
- "@sprucelabs/data-stores": "^17.0.51",
65
+ "@sprucelabs/data-stores": "^17.0.53",
66
66
  "@sprucelabs/error": "^5.0.487",
67
- "@sprucelabs/heartwood-view-controllers": "^86.12.2",
68
- "@sprucelabs/mercury-client": "^31.0.82",
69
- "@sprucelabs/mercury-core-events": "^12.0.83",
70
- "@sprucelabs/mercury-event-emitter": "^31.0.82",
67
+ "@sprucelabs/heartwood-view-controllers": "^86.13.2",
68
+ "@sprucelabs/mercury-client": "^31.0.84",
69
+ "@sprucelabs/mercury-core-events": "^12.0.85",
70
+ "@sprucelabs/mercury-event-emitter": "^31.0.84",
71
71
  "@sprucelabs/schema": "^28.3.13",
72
72
  "@sprucelabs/spruce-core-schemas": "^34.2.11",
73
- "@sprucelabs/spruce-event-utils": "^27.0.62",
74
- "@sprucelabs/spruce-skill-booter": "^44.2.1",
75
- "@sprucelabs/spruce-skill-utils": "^26.2.9",
73
+ "@sprucelabs/spruce-event-utils": "^27.0.64",
74
+ "@sprucelabs/spruce-skill-booter": "^44.2.4",
75
+ "@sprucelabs/spruce-skill-utils": "^26.3.1",
76
76
  "dotenv": "^16.0.1",
77
77
  "unique-names-generator": "^4.7.1"
78
78
  },
@@ -131,5 +131,5 @@
131
131
  ]
132
132
  ]
133
133
  },
134
- "gitHead": "1c2891ca64be4fc9d176803e08b5c284057f38c4"
134
+ "gitHead": "3a88cbbe9d9822d2bd4649a0338accc91050722e"
135
135
  }