@sprucelabs/spruce-test-fixtures 62.3.44 → 62.3.45
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/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
|
@@ -27,7 +27,7 @@ function login(phone) {
|
|
|
27
27
|
Class.beforeEach = async () => {
|
|
28
28
|
Class.Fixture('view').setProxyTokenGenerator(proxyGenerator);
|
|
29
29
|
__1.MercuryFixture.setDefaultContractToLocalEventsIfExist(Class.cwd);
|
|
30
|
-
await
|
|
30
|
+
await beforeEach?.();
|
|
31
31
|
};
|
|
32
32
|
const afterAll = Class.afterAll.bind(Class);
|
|
33
33
|
Class.afterAll = async () => {
|
|
@@ -35,7 +35,7 @@ function login(phone) {
|
|
|
35
35
|
await emitWillLogout(client);
|
|
36
36
|
__1.MercuryFixture.clearDefaultClient();
|
|
37
37
|
await afterAll();
|
|
38
|
-
await
|
|
38
|
+
await client?.disconnect();
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
}
|
|
@@ -61,17 +61,15 @@ login.on = async (name, cb) => {
|
|
|
61
61
|
login.listeners[name] = cb;
|
|
62
62
|
};
|
|
63
63
|
async function emitDidLogin(client) {
|
|
64
|
-
var _a;
|
|
65
64
|
//@ts-ignore
|
|
66
|
-
let didLogin =
|
|
65
|
+
let didLogin = login?.listeners?.['did-login'];
|
|
67
66
|
if (didLogin) {
|
|
68
67
|
await didLogin(client);
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
async function emitWillLogout(client) {
|
|
72
|
-
var _a;
|
|
73
71
|
//@ts-ignore
|
|
74
|
-
let willLogout =
|
|
72
|
+
let willLogout = login?.listeners?.['will-logout'];
|
|
75
73
|
if (willLogout) {
|
|
76
74
|
await willLogout(client);
|
|
77
75
|
}
|
|
@@ -10,7 +10,6 @@ const StoreFixture_1 = __importDefault(require("../fixtures/StoreFixture"));
|
|
|
10
10
|
const login_1 = __importDefault(require("./login"));
|
|
11
11
|
function seed(storeName, totalToSeed, ...params) {
|
|
12
12
|
return function (Class, key, descriptor) {
|
|
13
|
-
var _a, _b;
|
|
14
13
|
if ((storeName === 'organizations' || storeName === 'locations') &&
|
|
15
14
|
!Class.beforeAll.__patched) {
|
|
16
15
|
const beforeAll = Class.beforeAll.bind(Class);
|
|
@@ -33,12 +32,12 @@ function seed(storeName, totalToSeed, ...params) {
|
|
|
33
32
|
StoreFixture_1.default.setShouldAutomaticallyResetDatabase(false);
|
|
34
33
|
StoreFixture_1.default.resetDbConnectionSettings();
|
|
35
34
|
const seed = attachSeeder(storeName, Class, totalToSeed, params);
|
|
36
|
-
const bound =
|
|
35
|
+
const bound = descriptor?.value?.bind?.(Class);
|
|
37
36
|
attachCleanup(Class);
|
|
38
37
|
descriptor.value = async (...args) => {
|
|
39
38
|
await optionallyReset(Class, key);
|
|
40
39
|
await seed();
|
|
41
|
-
await
|
|
40
|
+
await bound?.(...args);
|
|
42
41
|
};
|
|
43
42
|
};
|
|
44
43
|
}
|
|
@@ -71,18 +70,17 @@ function attachCleanup(Class) {
|
|
|
71
70
|
const afterEach = Class.afterEach.bind(Class);
|
|
72
71
|
const beforeEach = Class.beforeEach.bind(Class);
|
|
73
72
|
Class.afterEach = async () => {
|
|
74
|
-
await
|
|
73
|
+
await afterEach?.();
|
|
75
74
|
shouldResetTestClient && mercury_client_1.MercuryTestClient.reset();
|
|
76
75
|
delete Class.__lastReset;
|
|
77
76
|
};
|
|
78
77
|
Class.beforeEach = async () => {
|
|
79
78
|
await optionallyReset(Class, 'beforeEach');
|
|
80
|
-
await
|
|
79
|
+
await beforeEach?.();
|
|
81
80
|
};
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
function attachSeeder(storeName, TestClass, totalToSeed, params) {
|
|
85
|
-
var _a, _b, _c;
|
|
86
84
|
//@ts-ignore
|
|
87
85
|
const fixtureMap = {
|
|
88
86
|
locations: 'seed',
|
|
@@ -113,9 +111,9 @@ function attachSeeder(storeName, TestClass, totalToSeed, params) {
|
|
|
113
111
|
managers: 'totalManagers',
|
|
114
112
|
owners: 'totalOwners',
|
|
115
113
|
};
|
|
116
|
-
const method =
|
|
117
|
-
const optionsKey =
|
|
118
|
-
const fixtureName =
|
|
114
|
+
const method = methodMap[storeName] ?? 'seed';
|
|
115
|
+
const optionsKey = keyMap[storeName] ?? 'totalToSeed';
|
|
116
|
+
const fixtureName = fixtureMap[storeName] ?? 'store';
|
|
119
117
|
const options = { [optionsKey]: totalToSeed };
|
|
120
118
|
return async function () {
|
|
121
119
|
let fixture = TestClass.Fixture(fixtureName);
|
|
@@ -127,7 +125,7 @@ function attachSeeder(storeName, TestClass, totalToSeed, params) {
|
|
|
127
125
|
TestClass.__shouldResetAccount = true;
|
|
128
126
|
}
|
|
129
127
|
test_utils_1.assert.isFunction(fixture[method], `The '${storeName}' store you created needs a method called 'seed(options: StoreSeedOptions)' in order for seeding. You must implement it yourself... for now.`);
|
|
130
|
-
const args = [options, ...(params
|
|
128
|
+
const args = [options, ...(params ?? [])];
|
|
131
129
|
await fixture[method](...args);
|
|
132
130
|
};
|
|
133
131
|
}
|
|
@@ -10,10 +10,11 @@ const eventFaker = {
|
|
|
10
10
|
const client = getClient(fqen);
|
|
11
11
|
await client.off(fqen);
|
|
12
12
|
await client.on(fqen, () => {
|
|
13
|
-
throw (error
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
throw (error ??
|
|
14
|
+
new SpruceError_1.default({
|
|
15
|
+
code: 'FAKE_EVENT_ERROR',
|
|
16
|
+
fqen,
|
|
17
|
+
}));
|
|
17
18
|
});
|
|
18
19
|
},
|
|
19
20
|
async handleReactiveEvent(fqen) {
|
|
@@ -38,7 +38,6 @@ class FixtureFactory {
|
|
|
38
38
|
this.namespace = namespace;
|
|
39
39
|
}
|
|
40
40
|
Fixture(named, options) {
|
|
41
|
-
var _a, _b, _c, _d, _e;
|
|
42
41
|
const mercuryFixture = this.getMercuryFixture(named);
|
|
43
42
|
let fixture;
|
|
44
43
|
switch (named) {
|
|
@@ -63,9 +62,10 @@ class FixtureFactory {
|
|
|
63
62
|
case 'organization': {
|
|
64
63
|
const people =
|
|
65
64
|
//@ts-ignore
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
options?.people ??
|
|
66
|
+
new PersonFixture_1.default({
|
|
67
|
+
connectToApi: mercuryFixture.getConnectFactory(),
|
|
68
|
+
});
|
|
69
69
|
fixture = new OrganizationFixture_1.default({
|
|
70
70
|
people,
|
|
71
71
|
roles: this.Fixture('role'),
|
|
@@ -75,7 +75,7 @@ class FixtureFactory {
|
|
|
75
75
|
case 'skill': {
|
|
76
76
|
const personFixture =
|
|
77
77
|
//@ts-ignore
|
|
78
|
-
|
|
78
|
+
options?.personFixture ?? this.Fixture('person');
|
|
79
79
|
fixture = new SkillFixture_1.default({
|
|
80
80
|
personFixture,
|
|
81
81
|
connectToApi: mercuryFixture.getConnectFactory(),
|
|
@@ -94,10 +94,10 @@ class FixtureFactory {
|
|
|
94
94
|
fixture = new LocationFixture_1.default({
|
|
95
95
|
roles: this.Fixture('role'),
|
|
96
96
|
//@ts-ignore
|
|
97
|
-
people:
|
|
97
|
+
people: options?.people ?? this.Fixture('person'),
|
|
98
98
|
organizations:
|
|
99
99
|
//@ts-ignore
|
|
100
|
-
|
|
100
|
+
options?.organizations ?? this.Fixture('organization'),
|
|
101
101
|
});
|
|
102
102
|
break;
|
|
103
103
|
}
|
|
@@ -115,9 +115,17 @@ class FixtureFactory {
|
|
|
115
115
|
if (!this.namespace) {
|
|
116
116
|
throw new Error('You need to be in a registered skill to load view controllers.');
|
|
117
117
|
}
|
|
118
|
-
fixture = new ViewFixture_1.default(
|
|
118
|
+
fixture = new ViewFixture_1.default({
|
|
119
119
|
//@ts-ignore
|
|
120
|
-
people:
|
|
120
|
+
people: options?.personFixture ?? this.Fixture('person'),
|
|
121
|
+
connectToApi: mercuryFixture.getConnectFactory(),
|
|
122
|
+
fixtureFactory: this,
|
|
123
|
+
namespace: this.namespace,
|
|
124
|
+
proxyDecorator: __1.ClientProxyDecorator.getInstance(),
|
|
125
|
+
cwd: this.cwd,
|
|
126
|
+
permissions: this.Fixture('permission'),
|
|
127
|
+
...options,
|
|
128
|
+
});
|
|
121
129
|
break;
|
|
122
130
|
}
|
|
123
131
|
}
|
|
@@ -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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
|
|
15
4
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
@@ -22,18 +11,17 @@ class LocationFixture {
|
|
|
22
11
|
this.roles = options.roles;
|
|
23
12
|
}
|
|
24
13
|
async seedDemoLocation(values) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let _d = values !== null && values !== void 0 ? values : {}, { organizationId: orgId } = _d, rest = __rest(_d, ["organizationId"]);
|
|
14
|
+
const { client } = await this.people.loginAsDemoPerson(values?.phone ?? undefined);
|
|
15
|
+
let { organizationId: orgId, ...rest } = values ?? {};
|
|
28
16
|
if (!orgId) {
|
|
29
|
-
const last = await this.orgs.getNewestOrganization(
|
|
17
|
+
const last = await this.orgs.getNewestOrganization(values?.phone ?? undefined);
|
|
30
18
|
if (last) {
|
|
31
19
|
orgId = last.id;
|
|
32
20
|
}
|
|
33
21
|
else {
|
|
34
22
|
const org = await this.orgs.seedDemoOrganization({
|
|
35
23
|
name: 'Org to support seed location',
|
|
36
|
-
phone:
|
|
24
|
+
phone: values?.phone ?? undefined,
|
|
37
25
|
});
|
|
38
26
|
orgId = org.id;
|
|
39
27
|
}
|
|
@@ -42,13 +30,19 @@ class LocationFixture {
|
|
|
42
30
|
target: {
|
|
43
31
|
organizationId: orgId,
|
|
44
32
|
},
|
|
45
|
-
payload:
|
|
33
|
+
payload: {
|
|
34
|
+
name: `Location ${LocationFixture.locationCount++} - ${(0, test_utils_2.generateId)()}`,
|
|
35
|
+
slug: this.generateLocationSlug(),
|
|
36
|
+
isPublic: true,
|
|
37
|
+
address: {
|
|
46
38
|
street1: '123 Main St',
|
|
47
39
|
city: 'Denver',
|
|
48
40
|
province: 'CO',
|
|
49
41
|
zip: '80211',
|
|
50
42
|
country: 'USA',
|
|
51
|
-
}
|
|
43
|
+
},
|
|
44
|
+
...rest,
|
|
45
|
+
},
|
|
52
46
|
});
|
|
53
47
|
const { location } = spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
|
|
54
48
|
return location;
|
|
@@ -68,7 +62,6 @@ class LocationFixture {
|
|
|
68
62
|
return location;
|
|
69
63
|
}
|
|
70
64
|
async getNewestLocation(organizationId) {
|
|
71
|
-
var _a;
|
|
72
65
|
const { client } = await this.people.loginAsDemoPerson();
|
|
73
66
|
if (!organizationId) {
|
|
74
67
|
const org = await this.orgs.getNewestOrganization();
|
|
@@ -86,7 +79,7 @@ class LocationFixture {
|
|
|
86
79
|
},
|
|
87
80
|
});
|
|
88
81
|
const { locations } = spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(results);
|
|
89
|
-
return
|
|
82
|
+
return locations.pop() ?? null;
|
|
90
83
|
}
|
|
91
84
|
async listLocations(organizationId) {
|
|
92
85
|
const { client } = await this.people.loginAsDemoPerson();
|
|
@@ -95,7 +88,7 @@ class LocationFixture {
|
|
|
95
88
|
if (!org) {
|
|
96
89
|
throw new Error(`You have to @seed('organizations',1) before you can list locations.`);
|
|
97
90
|
}
|
|
98
|
-
organizationId = org
|
|
91
|
+
organizationId = org?.id;
|
|
99
92
|
}
|
|
100
93
|
const results = await client.emit('list-locations::v2020_12_25', {
|
|
101
94
|
target: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
const mercury_client_1 = require("@sprucelabs/mercury-client");
|
|
5
4
|
require("@sprucelabs/mercury-core-events");
|
|
@@ -9,7 +8,7 @@ const spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
|
|
|
9
8
|
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
10
9
|
const env = require('dotenv');
|
|
11
10
|
env.config();
|
|
12
|
-
const TEST_HOST =
|
|
11
|
+
const TEST_HOST = process.env.TEST_HOST ?? process.env.HOST;
|
|
13
12
|
class MercuryFixture {
|
|
14
13
|
static setDefaultClient(client) {
|
|
15
14
|
//@ts-ignore
|
|
@@ -38,7 +37,7 @@ class MercuryFixture {
|
|
|
38
37
|
this.connectToApi = this.connectToApi.bind(this);
|
|
39
38
|
}
|
|
40
39
|
async connectToApi(options) {
|
|
41
|
-
const shouldReUseClient =
|
|
40
|
+
const shouldReUseClient = options?.shouldReUseClient !== false;
|
|
42
41
|
if (shouldReUseClient && MercuryFixture.defaultClient) {
|
|
43
42
|
return MercuryFixture.defaultClient;
|
|
44
43
|
}
|
|
@@ -63,7 +62,6 @@ class MercuryFixture {
|
|
|
63
62
|
return promise;
|
|
64
63
|
}
|
|
65
64
|
static setDefaultContractToLocalEventsIfExist(cwd) {
|
|
66
|
-
var _a;
|
|
67
65
|
if (MercuryFixture.shouldAutoImportContracts &&
|
|
68
66
|
spruce_skill_utils_1.diskUtil.doesBuiltHashSprucePathExist(cwd)) {
|
|
69
67
|
try {
|
|
@@ -79,7 +77,7 @@ class MercuryFixture {
|
|
|
79
77
|
}
|
|
80
78
|
catch (err) {
|
|
81
79
|
//since we default to the
|
|
82
|
-
if (
|
|
80
|
+
if (err.options?.code === 'EVENT_CONTRACTS_NOT_SYNCED') {
|
|
83
81
|
MercuryFixture.setDefaultContract(mercury_core_events_1.coreEventContracts[0]);
|
|
84
82
|
return;
|
|
85
83
|
}
|
|
@@ -92,11 +90,10 @@ class MercuryFixture {
|
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
static setDefaultContract(contract) {
|
|
95
|
-
var _a;
|
|
96
93
|
//@ts-ignore
|
|
97
94
|
mercury_client_1.MercuryClientFactory.setDefaultContract(contract);
|
|
98
95
|
//@ts-ignore
|
|
99
|
-
|
|
96
|
+
mercury_client_1.MercuryTestClient.emitter?.mixinOnlyUniqueSignatures(contract);
|
|
100
97
|
}
|
|
101
98
|
getConnectFactory() {
|
|
102
99
|
return this.connectToApi;
|
|
@@ -112,12 +109,10 @@ class MercuryFixture {
|
|
|
112
109
|
this.clientPromises = [];
|
|
113
110
|
}
|
|
114
111
|
static beforeAll() {
|
|
115
|
-
var _a, _b;
|
|
116
112
|
this.originalHost =
|
|
117
|
-
|
|
113
|
+
process.env.TEST_HOST ?? process.env.HOST ?? TEST_HOST;
|
|
118
114
|
}
|
|
119
115
|
static async beforeEach(cwd) {
|
|
120
|
-
var _a;
|
|
121
116
|
if (this.originalHost) {
|
|
122
117
|
process.env.HOST = this.originalHost;
|
|
123
118
|
}
|
|
@@ -133,14 +128,14 @@ class MercuryFixture {
|
|
|
133
128
|
this.setDefaultContractToLocalEventsIfExist(cwd);
|
|
134
129
|
try {
|
|
135
130
|
const auth = spruce_skill_utils_1.AuthService.Auth(cwd);
|
|
136
|
-
const namespace =
|
|
131
|
+
const namespace = auth.getCurrentSkill()?.slug;
|
|
137
132
|
if (namespace) {
|
|
138
133
|
mercury_client_1.MercuryTestClient.setNamespacesThatMustBeHandledLocally([
|
|
139
134
|
namespace,
|
|
140
135
|
]);
|
|
141
136
|
}
|
|
142
137
|
}
|
|
143
|
-
catch
|
|
138
|
+
catch { }
|
|
144
139
|
}
|
|
145
140
|
static setShouldRequireLocalListeners(shouldRequireLocal) {
|
|
146
141
|
this.shouldRequireLocalListeners = shouldRequireLocal;
|
|
@@ -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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
const schema_1 = require("@sprucelabs/schema");
|
|
15
4
|
class OrganizationFixture {
|
|
@@ -20,14 +9,19 @@ class OrganizationFixture {
|
|
|
20
9
|
this.roles = options.roles;
|
|
21
10
|
}
|
|
22
11
|
async seedDemoOrganization(values) {
|
|
23
|
-
const
|
|
24
|
-
const allValues =
|
|
12
|
+
const { phone, ...rest } = values ?? {};
|
|
13
|
+
const allValues = {
|
|
14
|
+
slug: this.generateOrgSlug(),
|
|
15
|
+
name: `Organization from fixture - ${new Date().getTime() * Math.random()}`,
|
|
16
|
+
address: {
|
|
25
17
|
street1: `${Math.round(Math.random() * 9999)} Main St.`,
|
|
26
18
|
city: 'Denver',
|
|
27
19
|
province: 'CO',
|
|
28
20
|
zip: '80212',
|
|
29
21
|
country: 'USA',
|
|
30
|
-
}
|
|
22
|
+
},
|
|
23
|
+
...rest,
|
|
24
|
+
};
|
|
31
25
|
const { client } = await this.people.loginAsDemoPerson(phone);
|
|
32
26
|
const [{ organization }] = await client.emitAndFlattenResponses('create-organization::v2020_12_25', {
|
|
33
27
|
payload: allValues,
|
|
@@ -45,7 +39,7 @@ class OrganizationFixture {
|
|
|
45
39
|
return organization;
|
|
46
40
|
}
|
|
47
41
|
async updateOrganization(id, values) {
|
|
48
|
-
const { phone
|
|
42
|
+
const { phone, ...payload } = values;
|
|
49
43
|
const { client } = await this.people.loginAsDemoPerson(phone);
|
|
50
44
|
await client.emitAndFlattenResponses('update-organization::v2020_12_25', {
|
|
51
45
|
target: {
|
|
@@ -55,7 +49,6 @@ class OrganizationFixture {
|
|
|
55
49
|
});
|
|
56
50
|
}
|
|
57
51
|
async getNewestOrganization(phone) {
|
|
58
|
-
var _a;
|
|
59
52
|
const { client } = await this.people.loginAsDemoPerson(phone);
|
|
60
53
|
const [{ organizations }] = await client.emitAndFlattenResponses('list-organizations::v2020_12_25', {
|
|
61
54
|
payload: {
|
|
@@ -65,7 +58,7 @@ class OrganizationFixture {
|
|
|
65
58
|
},
|
|
66
59
|
},
|
|
67
60
|
});
|
|
68
|
-
return
|
|
61
|
+
return organizations.pop() ?? null;
|
|
69
62
|
}
|
|
70
63
|
generateOrgSlug() {
|
|
71
64
|
return `my-org-${new Date().getTime()}-${this.orgCounter++}`;
|
|
@@ -83,7 +76,9 @@ class OrganizationFixture {
|
|
|
83
76
|
});
|
|
84
77
|
}
|
|
85
78
|
async isPartOfOrg(options) {
|
|
86
|
-
const roles = await this.roles.listRoles(
|
|
79
|
+
const roles = await this.roles.listRoles({
|
|
80
|
+
...options,
|
|
81
|
+
});
|
|
87
82
|
return roles.length > 0;
|
|
88
83
|
}
|
|
89
84
|
async removePerson(options) {
|
|
@@ -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
|
};
|
|
@@ -23,14 +12,16 @@ class PersonFixture {
|
|
|
23
12
|
this.connectToApi = options.connectToApi;
|
|
24
13
|
}
|
|
25
14
|
async listPeople(options) {
|
|
26
|
-
const { organizationId, locationId
|
|
15
|
+
const { organizationId, locationId, ...rest } = options;
|
|
27
16
|
const { client } = await this.loginAsDemoPerson();
|
|
28
17
|
const [{ people }] = await client.emitAndFlattenResponses('list-people::v2020_12_25', {
|
|
29
18
|
target: {
|
|
30
19
|
organizationId,
|
|
31
20
|
locationId,
|
|
32
21
|
},
|
|
33
|
-
payload:
|
|
22
|
+
payload: {
|
|
23
|
+
...rest,
|
|
24
|
+
},
|
|
34
25
|
});
|
|
35
26
|
return people;
|
|
36
27
|
}
|
|
@@ -39,10 +30,9 @@ class PersonFixture {
|
|
|
39
30
|
const [{ person }] = await client.emitAndFlattenResponses('update-person::v2020_12_25', {
|
|
40
31
|
payload: values,
|
|
41
32
|
});
|
|
42
|
-
return
|
|
33
|
+
return { ...person, ...values };
|
|
43
34
|
}
|
|
44
35
|
async loginAsDemoPerson(phone) {
|
|
45
|
-
var _a, _b, _c;
|
|
46
36
|
if (this.lastLoggedIn &&
|
|
47
37
|
(!phone ||
|
|
48
38
|
(0, schema_1.formatPhoneNumber)(phone) === this.lastLoggedIn.person.phone)) {
|
|
@@ -51,14 +41,14 @@ class PersonFixture {
|
|
|
51
41
|
const client = (await this.connectToApi({
|
|
52
42
|
shouldReUseClient: !phone,
|
|
53
43
|
}));
|
|
54
|
-
if (
|
|
44
|
+
if (client.auth?.person) {
|
|
55
45
|
return {
|
|
56
46
|
client,
|
|
57
47
|
person: client.auth.person,
|
|
58
48
|
token: client.auth.token,
|
|
59
49
|
};
|
|
60
50
|
}
|
|
61
|
-
let p = phone
|
|
51
|
+
let p = phone ?? process.env.DEMO_NUMBER;
|
|
62
52
|
if (!p || p.length === 0) {
|
|
63
53
|
throw new schema_1.SchemaError({
|
|
64
54
|
code: 'MISSING_PARAMETERS',
|
|
@@ -68,7 +58,7 @@ class PersonFixture {
|
|
|
68
58
|
}
|
|
69
59
|
const formattedPhone = (0, schema_1.formatPhoneNumber)(p);
|
|
70
60
|
//@ts-ignore
|
|
71
|
-
if (
|
|
61
|
+
if (client.auth?.person?.phone === formattedPhone) {
|
|
72
62
|
return {
|
|
73
63
|
client,
|
|
74
64
|
person: client.auth.person,
|
|
@@ -9,11 +9,11 @@ class RoleFixture {
|
|
|
9
9
|
this.getNewestOrgHandler = options.getNewestOrg;
|
|
10
10
|
}
|
|
11
11
|
async listRoles(options) {
|
|
12
|
-
let { organizationId, locationId, personId, phone, shouldIncludeMetaRoles, } = options
|
|
12
|
+
let { organizationId, locationId, personId, phone, shouldIncludeMetaRoles, } = options ?? {};
|
|
13
13
|
const { client } = await this.personFixture.loginAsDemoPerson(phone);
|
|
14
14
|
if (!organizationId && !locationId) {
|
|
15
15
|
const latest = await this.getNewestOrgHandler();
|
|
16
|
-
organizationId = latest
|
|
16
|
+
organizationId = latest?.id;
|
|
17
17
|
}
|
|
18
18
|
if (!organizationId && !locationId) {
|
|
19
19
|
throw new schema_1.SchemaError({
|
|
@@ -15,35 +15,45 @@ class SeedFixture {
|
|
|
15
15
|
this.people = options.people;
|
|
16
16
|
}
|
|
17
17
|
async seedOrganizations(options) {
|
|
18
|
-
const { totalOrganizations, phone } = options
|
|
19
|
-
const orgs = await Promise.all(new Array(totalOrganizations
|
|
18
|
+
const { totalOrganizations, phone } = options ?? {};
|
|
19
|
+
const orgs = await Promise.all(new Array(totalOrganizations ?? 3)
|
|
20
20
|
.fill(0)
|
|
21
21
|
.map(() => this.organizations.seedDemoOrganization({ phone })));
|
|
22
22
|
return orgs;
|
|
23
23
|
}
|
|
24
24
|
async seedGuests(options) {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
await this.seedPeople({
|
|
26
|
+
...options,
|
|
27
|
+
startingPhone: SeedFixture.lastPhone ?? '555-999-0000',
|
|
28
|
+
});
|
|
27
29
|
return [];
|
|
28
30
|
}
|
|
29
31
|
async seedTeammates(options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
await this.seedPeople({
|
|
33
|
+
...options,
|
|
34
|
+
startingPhone: SeedFixture.lastPhone ?? '555-999-1000',
|
|
35
|
+
});
|
|
32
36
|
return [];
|
|
33
37
|
}
|
|
34
38
|
async seedGroupManagers(options) {
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
await this.seedPeople({
|
|
40
|
+
...options,
|
|
41
|
+
startingPhone: SeedFixture.lastPhone ?? '555-999-2000',
|
|
42
|
+
});
|
|
37
43
|
return [];
|
|
38
44
|
}
|
|
39
45
|
async seedManagers(options) {
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
await this.seedPeople({
|
|
47
|
+
...options,
|
|
48
|
+
startingPhone: SeedFixture.lastPhone ?? '555-999-3000',
|
|
49
|
+
});
|
|
42
50
|
return [];
|
|
43
51
|
}
|
|
44
52
|
async seedOwners(options) {
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
await this.seedPeople({
|
|
54
|
+
...options,
|
|
55
|
+
startingPhone: SeedFixture.lastPhone ?? '555-999-4000',
|
|
56
|
+
});
|
|
47
57
|
return [];
|
|
48
58
|
}
|
|
49
59
|
async seedAccount(options) {
|
|
@@ -56,11 +66,14 @@ class SeedFixture {
|
|
|
56
66
|
const locations = await Promise.all(new Array(totalLocations - 1).fill(0).map(() => this.locations.seedDemoLocation({
|
|
57
67
|
organizationId,
|
|
58
68
|
})));
|
|
59
|
-
const results = await this.seedPeople(
|
|
60
|
-
|
|
69
|
+
const results = await this.seedPeople({
|
|
70
|
+
...options,
|
|
71
|
+
locationId: location.id,
|
|
72
|
+
organizationId,
|
|
73
|
+
});
|
|
74
|
+
return { locations: [location, ...locations], ...results };
|
|
61
75
|
}
|
|
62
76
|
async seedPeople(options) {
|
|
63
|
-
var _a;
|
|
64
77
|
let { totalGroupManagers, totalGuests, totalManagers, totalOwners, totalTeammates, startingPhone, locationId, organizationId, } = options;
|
|
65
78
|
if (!organizationId) {
|
|
66
79
|
const org = await this.organizations.getNewestOrganization();
|
|
@@ -69,7 +82,7 @@ class SeedFixture {
|
|
|
69
82
|
}
|
|
70
83
|
if (!locationId) {
|
|
71
84
|
const location = await this.locations.getNewestLocation();
|
|
72
|
-
locationId = location
|
|
85
|
+
locationId = location?.id;
|
|
73
86
|
}
|
|
74
87
|
const results = {
|
|
75
88
|
guests: [],
|
|
@@ -78,11 +91,11 @@ class SeedFixture {
|
|
|
78
91
|
groupManagers: [],
|
|
79
92
|
owners: [],
|
|
80
93
|
};
|
|
81
|
-
let totalToGenerate = (totalGroupManagers
|
|
82
|
-
(totalGuests
|
|
83
|
-
(totalManagers
|
|
84
|
-
(totalOwners
|
|
85
|
-
(totalTeammates
|
|
94
|
+
let totalToGenerate = (totalGroupManagers ?? 0) +
|
|
95
|
+
(totalGuests ?? 0) +
|
|
96
|
+
(totalManagers ?? 0) +
|
|
97
|
+
(totalOwners ?? 0) +
|
|
98
|
+
(totalTeammates ?? 0);
|
|
86
99
|
if (totalToGenerate > 0) {
|
|
87
100
|
totalToGenerate++;
|
|
88
101
|
if (!startingPhone) {
|
|
@@ -99,7 +112,7 @@ class SeedFixture {
|
|
|
99
112
|
for (const base of bases) {
|
|
100
113
|
const key = `total${spruce_skill_utils_1.namesUtil.toPascal(base)}s`;
|
|
101
114
|
//@ts-ignore
|
|
102
|
-
const total =
|
|
115
|
+
const total = options[key] ?? 0;
|
|
103
116
|
if (total > 0) {
|
|
104
117
|
const people = await this.seedPeopleWithRole({
|
|
105
118
|
total,
|
|
@@ -127,7 +140,10 @@ class SeedFixture {
|
|
|
127
140
|
const updated = person.firstName
|
|
128
141
|
? {}
|
|
129
142
|
: await this.people.generateRandomName(client);
|
|
130
|
-
person =
|
|
143
|
+
person = {
|
|
144
|
+
...person,
|
|
145
|
+
...updated,
|
|
146
|
+
};
|
|
131
147
|
if (locationId) {
|
|
132
148
|
await this.locations.addPerson({
|
|
133
149
|
locationId,
|