@sprucelabs/spruce-test-fixtures 44.1.40 → 44.2.2
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.
- package/build/esm/tests/decorators/fake.js +25 -8
- package/build/esm/tests/fixtures/ViewFixture.d.ts +1 -0
- package/build/esm/tests/fixtures/ViewFixture.js +3 -0
- package/build/tests/decorators/fake.js +25 -8
- package/build/tests/fixtures/ViewFixture.d.ts +1 -0
- package/build/tests/fixtures/ViewFixture.js +3 -0
- package/package.json +3 -3
|
@@ -81,13 +81,15 @@ fake.login = (phone = '555-000-0000') => {
|
|
|
81
81
|
MercuryClientFactory.setIsTestMode(true);
|
|
82
82
|
seed.disableResettingTestClient();
|
|
83
83
|
return function (TestClass, shouldPassHookCalls = true) {
|
|
84
|
-
var _a, _b;
|
|
84
|
+
var _a, _b, _c;
|
|
85
85
|
if (!(TestClass.prototype instanceof AbstractSpruceFixtureTest)) {
|
|
86
86
|
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.`);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
const Class = TestClass;
|
|
90
90
|
const beforeEach = (_a = Class.beforeEach) === null || _a === void 0 ? void 0 : _a.bind(Class);
|
|
91
|
+
const beforeAll = (_b = Class.beforeAll) === null || _b === void 0 ? void 0 : _b.bind(Class);
|
|
92
|
+
const afterEach = (_c = Class.afterEach) === null || _c === void 0 ? void 0 : _c.bind(Class);
|
|
91
93
|
if (shouldPassHookCalls) {
|
|
92
94
|
const old = MercuryFixture.beforeEach.bind(MercuryFixture);
|
|
93
95
|
MercuryFixture.beforeEach = (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -97,7 +99,6 @@ fake.login = (phone = '555-000-0000') => {
|
|
|
97
99
|
MercuryFixture.setDefaultClient(Class.fakedOwnerClient);
|
|
98
100
|
});
|
|
99
101
|
}
|
|
100
|
-
const beforeAll = (_b = Class.beforeAll) === null || _b === void 0 ? void 0 : _b.bind(Class);
|
|
101
102
|
Class.beforeAll = () => __awaiter(this, void 0, void 0, function* () {
|
|
102
103
|
yield (beforeAll === null || beforeAll === void 0 ? void 0 : beforeAll());
|
|
103
104
|
resetFakes(Class);
|
|
@@ -105,6 +106,10 @@ fake.login = (phone = '555-000-0000') => {
|
|
|
105
106
|
yield login(Class, phone);
|
|
106
107
|
MercuryFixture.setDefaultClient(Class.fakedOwnerClient);
|
|
107
108
|
});
|
|
109
|
+
Class.afterEach = () => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
yield setupFakes(Class);
|
|
111
|
+
yield (afterEach === null || afterEach === void 0 ? void 0 : afterEach());
|
|
112
|
+
});
|
|
108
113
|
Class.beforeEach = () => __awaiter(this, void 0, void 0, function* () {
|
|
109
114
|
yield fakeAuthenticationEvents(Class);
|
|
110
115
|
resetFakes(Class);
|
|
@@ -187,7 +192,7 @@ function fakeAddRole(Class) {
|
|
|
187
192
|
}
|
|
188
193
|
function addPersonAsRoleToLocationOrOrg(options) {
|
|
189
194
|
const { Class, roleId, person, organizationId, locationId } = options;
|
|
190
|
-
const role = Class
|
|
195
|
+
const role = getRoleById(Class, roleId);
|
|
191
196
|
const key = roleBaseToLocalFakedProp(role.base);
|
|
192
197
|
//@ts-ignore
|
|
193
198
|
assert.isTruthy(Class[key], `Could not find property ${key}`);
|
|
@@ -203,6 +208,11 @@ function addPersonAsRoleToLocationOrOrg(options) {
|
|
|
203
208
|
locationId,
|
|
204
209
|
});
|
|
205
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
|
+
}
|
|
206
216
|
function fakeGetRole(Class) {
|
|
207
217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
208
218
|
yield eventFaker.on('get-role::v2020_12_25', ({ target }) => {
|
|
@@ -225,7 +235,7 @@ function fakeRemoveRole(Class) {
|
|
|
225
235
|
yield eventFaker.on('remove-role::v2020_12_25', ({ payload }) => {
|
|
226
236
|
var _a;
|
|
227
237
|
const { personId, roleId } = payload;
|
|
228
|
-
const role = Class
|
|
238
|
+
const role = getRoleById(Class, roleId);
|
|
229
239
|
const people = Class[roleBaseToLocalFakedProp(role.base)];
|
|
230
240
|
const idx = (_a = people === null || people === void 0 ? void 0 : people.findIndex((p) => p.id === personId)) !== null && _a !== void 0 ? _a : -1;
|
|
231
241
|
people === null || people === void 0 ? void 0 : people.splice(idx, 1);
|
|
@@ -237,8 +247,15 @@ function fakeRemoveRole(Class) {
|
|
|
237
247
|
function roleBaseToLocalFakedProp(base) {
|
|
238
248
|
return fakeTargetToPropName((base + 's'));
|
|
239
249
|
}
|
|
240
|
-
function getPersonById(Class, personId) {
|
|
241
|
-
|
|
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;
|
|
242
259
|
}
|
|
243
260
|
function fakeUpdatePerson(Class) {
|
|
244
261
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -266,7 +283,7 @@ function fakeListRoles(Class) {
|
|
|
266
283
|
((p.organizationId && p.organizationId === organizationId) ||
|
|
267
284
|
(p.locationId && p.locationId === locationId) ||
|
|
268
285
|
(!locationId && !organizationId)))
|
|
269
|
-
.map((pr) => Class
|
|
286
|
+
.map((pr) => getRoleById(Class, pr.roleId));
|
|
270
287
|
roles = personRoles;
|
|
271
288
|
}
|
|
272
289
|
else {
|
|
@@ -532,7 +549,7 @@ function fakeWhoAmI(Class) {
|
|
|
532
549
|
if (proxyToken) {
|
|
533
550
|
personId = (_a = Class.fakedProxyTokens.find((t) => t.token === proxyToken)) === null || _a === void 0 ? void 0 : _a.personId;
|
|
534
551
|
}
|
|
535
|
-
const person = getPersonById(Class, personId);
|
|
552
|
+
const person = getPersonById(Class, personId, false);
|
|
536
553
|
const skill = Class.fakedSkills.find((s) => s.id === (source === null || source === void 0 ? void 0 : source.skillId));
|
|
537
554
|
return {
|
|
538
555
|
auth: {
|
|
@@ -45,6 +45,7 @@ export default class ViewFixture {
|
|
|
45
45
|
render<VC extends ViewController<any>>(vc: VC): ReturnType<VC['render']>;
|
|
46
46
|
private static getSharedFactory;
|
|
47
47
|
Controller<N extends ViewControllerId>(name: N, options: ControllerOptions<N>): import("@sprucelabs/heartwood-view-controllers").ViewControllerMap[N];
|
|
48
|
+
setClient(client: MercuryClient): void;
|
|
48
49
|
static beforeAll(): Promise<void>;
|
|
49
50
|
static beforeEach(): Promise<void>;
|
|
50
51
|
private static resetMaps;
|
|
@@ -79,13 +79,15 @@ fake.login = (phone = '555-000-0000') => {
|
|
|
79
79
|
mercury_client_1.MercuryClientFactory.setIsTestMode(true);
|
|
80
80
|
seed_1.default.disableResettingTestClient();
|
|
81
81
|
return function (TestClass, shouldPassHookCalls = true) {
|
|
82
|
-
var _a, _b;
|
|
82
|
+
var _a, _b, _c;
|
|
83
83
|
if (!(TestClass.prototype instanceof AbstractSpruceFixtureTest_1.default)) {
|
|
84
84
|
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.`);
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
const Class = TestClass;
|
|
88
88
|
const beforeEach = (_a = Class.beforeEach) === null || _a === void 0 ? void 0 : _a.bind(Class);
|
|
89
|
+
const beforeAll = (_b = Class.beforeAll) === null || _b === void 0 ? void 0 : _b.bind(Class);
|
|
90
|
+
const afterEach = (_c = Class.afterEach) === null || _c === void 0 ? void 0 : _c.bind(Class);
|
|
89
91
|
if (shouldPassHookCalls) {
|
|
90
92
|
const old = MercuryFixture_1.default.beforeEach.bind(MercuryFixture_1.default);
|
|
91
93
|
MercuryFixture_1.default.beforeEach = async (...args) => {
|
|
@@ -95,7 +97,6 @@ fake.login = (phone = '555-000-0000') => {
|
|
|
95
97
|
MercuryFixture_1.default.setDefaultClient(Class.fakedOwnerClient);
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
|
-
const beforeAll = (_b = Class.beforeAll) === null || _b === void 0 ? void 0 : _b.bind(Class);
|
|
99
100
|
Class.beforeAll = async () => {
|
|
100
101
|
await (beforeAll === null || beforeAll === void 0 ? void 0 : beforeAll());
|
|
101
102
|
resetFakes(Class);
|
|
@@ -103,6 +104,10 @@ fake.login = (phone = '555-000-0000') => {
|
|
|
103
104
|
await login(Class, phone);
|
|
104
105
|
MercuryFixture_1.default.setDefaultClient(Class.fakedOwnerClient);
|
|
105
106
|
};
|
|
107
|
+
Class.afterEach = async () => {
|
|
108
|
+
await setupFakes(Class);
|
|
109
|
+
await (afterEach === null || afterEach === void 0 ? void 0 : afterEach());
|
|
110
|
+
};
|
|
106
111
|
Class.beforeEach = async () => {
|
|
107
112
|
await fakeAuthenticationEvents(Class);
|
|
108
113
|
resetFakes(Class);
|
|
@@ -179,7 +184,7 @@ async function fakeAddRole(Class) {
|
|
|
179
184
|
}
|
|
180
185
|
function addPersonAsRoleToLocationOrOrg(options) {
|
|
181
186
|
const { Class, roleId, person, organizationId, locationId } = options;
|
|
182
|
-
const role = Class
|
|
187
|
+
const role = getRoleById(Class, roleId);
|
|
183
188
|
const key = roleBaseToLocalFakedProp(role.base);
|
|
184
189
|
//@ts-ignore
|
|
185
190
|
test_1.assert.isTruthy(Class[key], `Could not find property ${key}`);
|
|
@@ -195,6 +200,11 @@ function addPersonAsRoleToLocationOrOrg(options) {
|
|
|
195
200
|
locationId,
|
|
196
201
|
});
|
|
197
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
|
+
}
|
|
198
208
|
async function fakeGetRole(Class) {
|
|
199
209
|
await eventFaker_1.default.on('get-role::v2020_12_25', ({ target }) => {
|
|
200
210
|
const { roleId } = target;
|
|
@@ -214,7 +224,7 @@ async function fakeRemoveRole(Class) {
|
|
|
214
224
|
await eventFaker_1.default.on('remove-role::v2020_12_25', ({ payload }) => {
|
|
215
225
|
var _a;
|
|
216
226
|
const { personId, roleId } = payload;
|
|
217
|
-
const role = Class
|
|
227
|
+
const role = getRoleById(Class, roleId);
|
|
218
228
|
const people = Class[roleBaseToLocalFakedProp(role.base)];
|
|
219
229
|
const idx = (_a = people === null || people === void 0 ? void 0 : people.findIndex((p) => p.id === personId)) !== null && _a !== void 0 ? _a : -1;
|
|
220
230
|
people === null || people === void 0 ? void 0 : people.splice(idx, 1);
|
|
@@ -225,8 +235,15 @@ async function fakeRemoveRole(Class) {
|
|
|
225
235
|
function roleBaseToLocalFakedProp(base) {
|
|
226
236
|
return fakeTargetToPropName((base + 's'));
|
|
227
237
|
}
|
|
228
|
-
function getPersonById(Class, personId) {
|
|
229
|
-
|
|
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;
|
|
230
247
|
}
|
|
231
248
|
async function fakeUpdatePerson(Class) {
|
|
232
249
|
await eventFaker_1.default.on('update-person::v2020_12_25', ({ target, source, payload }) => {
|
|
@@ -251,7 +268,7 @@ async function fakeListRoles(Class) {
|
|
|
251
268
|
((p.organizationId && p.organizationId === organizationId) ||
|
|
252
269
|
(p.locationId && p.locationId === locationId) ||
|
|
253
270
|
(!locationId && !organizationId)))
|
|
254
|
-
.map((pr) => Class
|
|
271
|
+
.map((pr) => getRoleById(Class, pr.roleId));
|
|
255
272
|
roles = personRoles;
|
|
256
273
|
}
|
|
257
274
|
else {
|
|
@@ -487,7 +504,7 @@ async function fakeWhoAmI(Class) {
|
|
|
487
504
|
if (proxyToken) {
|
|
488
505
|
personId = (_a = Class.fakedProxyTokens.find((t) => t.token === proxyToken)) === null || _a === void 0 ? void 0 : _a.personId;
|
|
489
506
|
}
|
|
490
|
-
const person = getPersonById(Class, personId);
|
|
507
|
+
const person = getPersonById(Class, personId, false);
|
|
491
508
|
const skill = Class.fakedSkills.find((s) => s.id === (source === null || source === void 0 ? void 0 : source.skillId));
|
|
492
509
|
return {
|
|
493
510
|
auth: {
|
|
@@ -45,6 +45,7 @@ export default class ViewFixture {
|
|
|
45
45
|
render<VC extends ViewController<any>>(vc: VC): ReturnType<VC['render']>;
|
|
46
46
|
private static getSharedFactory;
|
|
47
47
|
Controller<N extends ViewControllerId>(name: N, options: ControllerOptions<N>): import("@sprucelabs/heartwood-view-controllers").ViewControllerMap[N];
|
|
48
|
+
setClient(client: MercuryClient): void;
|
|
48
49
|
static beforeAll(): Promise<void>;
|
|
49
50
|
static beforeEach(): Promise<void>;
|
|
50
51
|
private static resetMaps;
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@sprucelabs/spruce-test-fixtures"
|
|
14
14
|
]
|
|
15
15
|
},
|
|
16
|
-
"version": "44.
|
|
16
|
+
"version": "44.2.2",
|
|
17
17
|
"files": [
|
|
18
18
|
"build/**/*",
|
|
19
19
|
"!build/__tests__",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@sprucelabs/schema": "^28.3.13",
|
|
72
72
|
"@sprucelabs/spruce-core-schemas": "^34.2.11",
|
|
73
73
|
"@sprucelabs/spruce-event-utils": "^27.0.62",
|
|
74
|
-
"@sprucelabs/spruce-skill-booter": "^44.
|
|
74
|
+
"@sprucelabs/spruce-skill-booter": "^44.2.2",
|
|
75
75
|
"@sprucelabs/spruce-skill-utils": "^26.2.9",
|
|
76
76
|
"dotenv": "^16.0.1",
|
|
77
77
|
"unique-names-generator": "^4.7.1"
|
|
@@ -131,5 +131,5 @@
|
|
|
131
131
|
]
|
|
132
132
|
]
|
|
133
133
|
},
|
|
134
|
-
"gitHead": "
|
|
134
|
+
"gitHead": "ed608c08a3b4de84dbdb459da6023b0cba138b97"
|
|
135
135
|
}
|