@sprucelabs/spruce-test-fixtures 62.3.43 → 62.3.45
Sign up to get free protection for your applications and to get access to all the features.
- package/build/ClientProxyDecorator.js +12 -6
- package/build/errors/SpruceError.js +3 -4
- package/build/tests/AbstractSpruceFixtureTest.js +2 -14
- package/build/tests/FakeThemeManager.js +3 -1
- package/build/tests/constants.js +28 -29
- package/build/tests/decorators/fake.js +82 -85
- package/build/tests/decorators/login.js +4 -6
- package/build/tests/decorators/seed.js +8 -10
- package/build/tests/eventFaker.js +5 -4
- package/build/tests/fixtures/FixtureFactory.js +17 -9
- package/build/tests/fixtures/LocationFixture.js +14 -21
- package/build/tests/fixtures/MercuryFixture.js +7 -12
- package/build/tests/fixtures/OrganizationFixture.js +13 -18
- package/build/tests/fixtures/PersonFixture.js +8 -18
- package/build/tests/fixtures/RoleFixture.js +2 -2
- package/build/tests/fixtures/SeedFixture.js +39 -23
- package/build/tests/fixtures/SkillFixture.js +16 -17
- package/build/tests/fixtures/SpyScope.js +1 -2
- package/build/tests/fixtures/ViewFixture.js +17 -15
- package/build/tests/fixtures/generateRandomName.js +1 -2
- package/build/tests/fixtures/scopeUtils.js +2 -2
- package/build/tests/routers/TestRouter.js +3 -5
- package/build/utilities/vcDisk.utility.js +2 -3
- package/package.json +20 -20
- package/tsconfig.json +1 -2
@@ -22,12 +22,15 @@ class ClientProxyDecorator {
|
|
22
22
|
delete this.instance;
|
23
23
|
}
|
24
24
|
decorateEmitToPassProxyToken(client, token) {
|
25
|
-
const newClient =
|
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
|
-
},
|
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
|
-
|
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 =
|
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
|
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 ${
|
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 ${
|
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 =
|
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
|
60
|
+
const { name, slug, ...skillOptions } = options;
|
73
61
|
const { skill, client } = await this.skills.loginAsDemoSkill({
|
74
62
|
name,
|
75
63
|
slug,
|
package/build/tests/constants.js
CHANGED
@@ -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 =
|
11
|
-
exports.DEMO_NUMBER_HIRING =
|
12
|
-
exports.DEMO_NUMBER_INSTALLING_SKILLS =
|
13
|
-
exports.DEMO_NUMBER_SECOND_LOGIN =
|
14
|
-
exports.DEMO_NUMBER_VIEW_FIXTURE =
|
15
|
-
exports.DEMO_NUMBER_MERCURY_FIXTURE =
|
16
|
-
exports.DEMO_NUMBER_LOCATION_FIXTURE =
|
17
|
-
exports.DEMO_NUMBER_ROLE_FIXTURE =
|
18
|
-
exports.DEMO_NUMBER_SEED_FIXTURE =
|
19
|
-
exports.DEMO_NUMBER_DECORATORS =
|
20
|
-
exports.DEMO_NUMBER_SKILL_DECORATORS =
|
21
|
-
exports.DEMO_NUMBER_ACCOUNT_RESET =
|
22
|
-
exports.DEMO_NUMBER_SKILL_FIXTURE =
|
23
|
-
exports.DEMO_NUMBER_LOCATION_FIXTURE_OUTSIDER =
|
24
|
-
exports.DEMO_NUMBER_ORGANIZATION_FIXTURE =
|
25
|
-
exports.DEMO_NUMBER_HANDLING_EVENTS_LOCALLY =
|
26
|
-
exports.DEMO_NUMBER_VIEW_FIXTURE_2 =
|
27
|
-
exports.DEMO_NUMBER_LOGIN_DECORATOR =
|
28
|
-
exports.DEMO_NUMBER_LOGIN_DECORATOR_2 =
|
29
|
-
exports.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET =
|
30
|
-
exports.DEMO_NUMBER_ACCOUNT_BEFORE_ALL_RESET_LOCATION =
|
31
|
-
exports.DEMO_NUMBER_VIEW_FIXTURE_CLIENT_2 =
|
32
|
-
exports.DEMO_NUMBER_TEST_CLIENT_RECENT =
|
33
|
-
exports.DEMO_NUMBER_SCOPE =
|
34
|
-
exports.DEMO_NUMBER_PERSON_FIXTURE =
|
35
|
-
exports.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE =
|
36
|
-
exports.DEMO_NUMBER_SEED_FIXTURE_STARTING_PHONE_ALT =
|
37
|
-
exports.DEMO_NUMBER_ACCOUNT_AFTER_ALL_RESET =
|
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 =
|
47
|
+
Class.fakedPeople = Class.fakedPeople?.[0] ? [Class.fakedPeople[0]] : [];
|
60
48
|
Class.fakedSkills = [];
|
61
|
-
Class.fakedTokens =
|
62
|
-
Class.fakedProxyTokens =
|
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 =
|
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
|
77
|
-
await
|
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 =
|
97
|
-
const beforeAll =
|
98
|
-
const afterEach =
|
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
|
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
|
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
|
117
|
+
catch {
|
132
118
|
//hits if not in skill because cant find nameplace
|
133
119
|
}
|
134
|
-
shouldPassHookCalls && (await
|
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
|
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
|
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 =
|
266
|
-
people
|
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) =>
|
287
|
-
? p.id ===
|
288
|
-
: p.id ===
|
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
|
296
|
-
person.lastName = payload
|
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
|
-
|
306
|
-
|
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 =
|
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
|
341
|
-
test_utils_1.assert.isFalsy(payload
|
342
|
-
for (const base of
|
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:
|
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) => !
|
361
|
-
l.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] =
|
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
|
-
|
414
|
-
const
|
415
|
-
|
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
|
-
|
434
|
-
|
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
|
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
|
-
|
468
|
-
|
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
|
-
|
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
|
499
|
+
if (payload?.name) {
|
498
500
|
match.name = payload.name;
|
499
501
|
}
|
500
|
-
if (payload
|
502
|
+
if (payload?.address) {
|
501
503
|
match.address = payload.address;
|
502
504
|
}
|
503
|
-
if (typeof
|
505
|
+
if (typeof payload?.isPublic !== 'undefined') {
|
504
506
|
match.isPublic = payload.isPublic;
|
505
507
|
}
|
506
|
-
const copy =
|
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
|
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 (
|
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
|
-
|
568
|
-
|
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 =
|
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 ===
|
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
|
586
|
+
const { source } = targeAndPayload ?? {};
|
589
587
|
const token = (0, test_utils_2.generateId)();
|
590
|
-
if (source
|
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
|
-
|
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:
|
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
|
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 ===
|
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
|
696
|
-
const matches = Class.fakedSkills.filter((s) =>
|
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 =
|
708
|
-
//@ts-ignore
|
709
|
-
, []);
|
706
|
+
const { ...copy } = m;
|
710
707
|
//@ts-ignore
|
711
708
|
delete copy.apiKey;
|
712
709
|
//@ts-ignore
|