@sprucelabs/spruce-test-fixtures 66.0.19 → 66.0.21

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.
Files changed (57) hide show
  1. package/build/FakerTracker.d.ts +41 -0
  2. package/build/FakerTracker.js +56 -0
  3. package/build/esm/FakerTracker.d.ts +41 -0
  4. package/build/esm/FakerTracker.js +54 -0
  5. package/build/esm/tests/AbstractSpruceFixtureTest.d.ts +68 -27
  6. package/build/esm/tests/AbstractSpruceFixtureTest.js +256 -103
  7. package/build/esm/tests/decorators/fake.d.ts +11 -11
  8. package/build/esm/tests/decorators/fake.js +151 -173
  9. package/build/esm/tests/decorators/install.js +7 -4
  10. package/build/esm/tests/decorators/login.js +18 -18
  11. package/build/esm/tests/decorators/seed.js +34 -40
  12. package/build/esm/tests/fixtures/FixtureFactory.d.ts +2 -1
  13. package/build/esm/tests/fixtures/FixtureFactory.js +38 -35
  14. package/build/esm/tests/fixtures/FixtureWarehourse.d.ts +56 -0
  15. package/build/esm/tests/fixtures/FixtureWarehourse.js +165 -0
  16. package/build/esm/tests/fixtures/LocationFixture.d.ts +5 -5
  17. package/build/esm/tests/fixtures/LocationFixture.js +5 -5
  18. package/build/esm/tests/fixtures/MercuryFixture.d.ts +5 -0
  19. package/build/esm/tests/fixtures/MercuryFixture.js +50 -25
  20. package/build/esm/tests/fixtures/OrganizationFixture.d.ts +4 -4
  21. package/build/esm/tests/fixtures/PersonFixture.d.ts +2 -2
  22. package/build/esm/tests/fixtures/PersonFixture.js +23 -9
  23. package/build/esm/tests/fixtures/RoleFixture.d.ts +4 -4
  24. package/build/esm/tests/fixtures/RoleFixture.js +4 -4
  25. package/build/esm/tests/fixtures/SeedFixture.d.ts +13 -13
  26. package/build/esm/tests/fixtures/SkillFixture.d.ts +2 -2
  27. package/build/esm/tests/fixtures/SkillFixture.js +2 -2
  28. package/build/esm/tests/fixtures/SpyScope.d.ts +2 -2
  29. package/build/esm/tests/fixtures/ViewFixture.d.ts +7 -3
  30. package/build/esm/tests/fixtures/ViewFixture.js +11 -9
  31. package/build/tests/AbstractSpruceFixtureTest.d.ts +68 -27
  32. package/build/tests/AbstractSpruceFixtureTest.js +243 -98
  33. package/build/tests/decorators/fake.d.ts +11 -11
  34. package/build/tests/decorators/fake.js +151 -171
  35. package/build/tests/decorators/install.js +9 -3
  36. package/build/tests/decorators/login.js +20 -17
  37. package/build/tests/decorators/seed.js +34 -38
  38. package/build/tests/fixtures/FixtureFactory.d.ts +2 -1
  39. package/build/tests/fixtures/FixtureFactory.js +37 -35
  40. package/build/tests/fixtures/FixtureWarehourse.d.ts +56 -0
  41. package/build/tests/fixtures/FixtureWarehourse.js +170 -0
  42. package/build/tests/fixtures/LocationFixture.d.ts +5 -5
  43. package/build/tests/fixtures/LocationFixture.js +5 -5
  44. package/build/tests/fixtures/MercuryFixture.d.ts +5 -0
  45. package/build/tests/fixtures/MercuryFixture.js +48 -23
  46. package/build/tests/fixtures/OrganizationFixture.d.ts +4 -4
  47. package/build/tests/fixtures/PersonFixture.d.ts +2 -2
  48. package/build/tests/fixtures/PersonFixture.js +20 -6
  49. package/build/tests/fixtures/RoleFixture.d.ts +4 -4
  50. package/build/tests/fixtures/RoleFixture.js +4 -4
  51. package/build/tests/fixtures/SeedFixture.d.ts +13 -13
  52. package/build/tests/fixtures/SkillFixture.d.ts +2 -2
  53. package/build/tests/fixtures/SkillFixture.js +2 -2
  54. package/build/tests/fixtures/SpyScope.d.ts +2 -2
  55. package/build/tests/fixtures/ViewFixture.d.ts +7 -3
  56. package/build/tests/fixtures/ViewFixture.js +13 -9
  57. package/package.json +25 -25
@@ -19,11 +19,12 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  return t;
20
20
  };
21
21
  import { AbstractSkillTest, } from '@sprucelabs/spruce-skill-booter';
22
- import { diskUtil, testLog } from '@sprucelabs/spruce-skill-utils';
22
+ import { testLog } from '@sprucelabs/spruce-skill-utils';
23
23
  import { assert } from '@sprucelabs/test-utils';
24
+ import FakerTracker from '../FakerTracker.js';
24
25
  import FixtureFactory from './fixtures/FixtureFactory.js';
25
26
  const env = require('dotenv');
26
- class AbstractSpruceFixtureTest extends AbstractSkillTest {
27
+ export default class AbstractSpruceFixtureTest extends AbstractSkillTest {
27
28
  static beforeAll() {
28
29
  const _super = Object.create(null, {
29
30
  beforeAll: { get: () => super.beforeAll }
@@ -42,22 +43,8 @@ class AbstractSpruceFixtureTest extends AbstractSkillTest {
42
43
  return __awaiter(this, void 0, void 0, function* () {
43
44
  yield _super.beforeEach.call(this);
44
45
  yield FixtureFactory.beforeEach(this.cwd);
45
- this._fixtures = undefined;
46
- this.clearLocalFixtures();
47
- });
48
- }
49
- static clearLocalFixtures() {
50
- this.views = undefined;
51
- this.roles = undefined;
52
- this.locations = undefined;
53
- this.organizations = undefined;
54
- this.people = undefined;
55
- this.seeder = undefined;
56
- this.skills = undefined;
57
- this.mercury = undefined;
58
- this.stores = undefined;
59
- this.database = undefined;
60
- this.permissions = undefined;
46
+ FakerTracker.resetFixtureWarehouse();
47
+ });
61
48
  }
62
49
  static afterEach() {
63
50
  const _super = Object.create(null, {
@@ -66,7 +53,7 @@ class AbstractSpruceFixtureTest extends AbstractSkillTest {
66
53
  return __awaiter(this, void 0, void 0, function* () {
67
54
  yield _super.afterEach.call(this);
68
55
  yield FixtureFactory.afterEach();
69
- this.clearLocalFixtures();
56
+ FakerTracker.resetFixtureWarehouse();
70
57
  });
71
58
  }
72
59
  static afterAll() {
@@ -78,22 +65,6 @@ class AbstractSpruceFixtureTest extends AbstractSkillTest {
78
65
  yield FixtureFactory.afterAll();
79
66
  });
80
67
  }
81
- static Fixture(name, options) {
82
- var _a;
83
- if (!this._fixtures) {
84
- const pkg = diskUtil.resolvePath(this.cwd, 'package.json');
85
- let namespace;
86
- if (diskUtil.doesFileExist(pkg)) {
87
- const values = JSON.parse(diskUtil.readFile(pkg));
88
- namespace = (_a = values === null || values === void 0 ? void 0 : values.skill) === null || _a === void 0 ? void 0 : _a.namespace;
89
- }
90
- this._fixtures = new FixtureFactory({
91
- cwd: this.cwd,
92
- namespace,
93
- });
94
- }
95
- return this._fixtures.Fixture(name, options);
96
- }
97
68
  static bootAndRegisterNewSkill(options) {
98
69
  return __awaiter(this, void 0, void 0, function* () {
99
70
  const { name, slug } = options, skillOptions = __rest(options, ["name", "slug"]);
@@ -123,131 +94,313 @@ class AbstractSpruceFixtureTest extends AbstractSkillTest {
123
94
  });
124
95
  return __awaiter(this, void 0, void 0, function* () {
125
96
  const skill = yield _super.SkillFromTestDir.call(this, key, options);
126
- this._fixtures = undefined;
127
97
  return skill;
128
98
  });
129
99
  }
100
+ static Fixture(name, options) {
101
+ return FakerTracker.getFixtures(this.cwd).Fixture(name, options);
102
+ }
103
+ static get fakedPerson() {
104
+ return FakerTracker.fakedPerson;
105
+ }
106
+ static set fakedPerson(person) {
107
+ FakerTracker.fakedPerson = person;
108
+ }
109
+ static get fakedPeople() {
110
+ return FakerTracker.fakedPeople;
111
+ }
112
+ static set fakedPeople(people) {
113
+ FakerTracker.fakedPeople = people;
114
+ }
115
+ static get fakedTeammates() {
116
+ return FakerTracker.fakedTeammates;
117
+ }
118
+ static set fakedTeammates(teammates) {
119
+ FakerTracker.fakedTeammates = teammates;
120
+ }
121
+ static get fakedOwners() {
122
+ return FakerTracker.fakedOwners;
123
+ }
124
+ static set fakedOwners(owners) {
125
+ FakerTracker.fakedOwners = owners;
126
+ }
127
+ static get fakedRoles() {
128
+ return FakerTracker.fakedRoles;
129
+ }
130
+ static set fakedRoles(roles) {
131
+ FakerTracker.fakedRoles = roles;
132
+ }
133
+ static get fakedSkills() {
134
+ return FakerTracker.fakedSkills;
135
+ }
136
+ static set fakedSkills(skills) {
137
+ FakerTracker.fakedSkills = skills;
138
+ }
139
+ static get fakedManagers() {
140
+ return FakerTracker.fakedManagers;
141
+ }
142
+ static set fakedManagers(managers) {
143
+ FakerTracker.fakedManagers = managers;
144
+ }
145
+ static get fakedGuests() {
146
+ return FakerTracker.fakedGuests;
147
+ }
148
+ static set fakedGuests(guests) {
149
+ FakerTracker.fakedGuests = guests;
150
+ }
151
+ static get fakedGroupManagers() {
152
+ return FakerTracker.fakedGroupManagers;
153
+ }
154
+ static set fakedGroupManagers(groupManagers) {
155
+ FakerTracker.fakedGroupManagers = groupManagers;
156
+ }
130
157
  static get fakedClient() {
131
- assert.isTruthy(this._fakedClient, `You gotta @fake.login() on your test class to get the test client.`);
132
- return this._fakedClient;
158
+ assert.isTruthy(FakerTracker.fakedClient, `You gotta @fake.login() on your test class to get the test client.`);
159
+ return FakerTracker.fakedClient;
133
160
  }
134
161
  static set fakedClient(client) {
135
- this._fakedClient = client;
162
+ FakerTracker.fakedClient = client;
136
163
  }
137
164
  static get fakedOrganizations() {
138
- return this._fakedOrganizations;
165
+ return FakerTracker.fakedOrganizations;
139
166
  }
140
167
  static set fakedOrganizations(orgs) {
141
- assert.isAbove(this._fakedOrganizations.length, 0, `You gotta @seed('organizations', 1) (and use @fake.login(...)) before getting faked orgs.`);
142
- this._fakedOrganizations = orgs;
168
+ FakerTracker.fakedOrganizations = orgs;
143
169
  }
144
170
  static get fakedLocations() {
145
- assert.isAbove(this._fakedLocations.length, 0, `You gotta @seed('locations', 1) (and use @fake.login(...)) before getting faked locations.`);
146
- return this._fakedLocations;
171
+ assert.isAbove(FakerTracker.fakedLocations.length, 0, `You gotta @seed('locations', 1) (and use @fake.login(...)) before getting faked locations.`);
172
+ return FakerTracker.fakedLocations;
147
173
  }
148
174
  static set fakedLocations(locations) {
149
- this._fakedLocations = locations;
175
+ FakerTracker.fakedLocations = locations;
150
176
  }
151
177
  static get views() {
152
- if (!this._views) {
153
- this._views = this.Fixture('view');
154
- }
155
- return this._views;
178
+ return FakerTracker.getFixtures(this.cwd).views;
156
179
  }
157
180
  static set views(fixture) {
158
- this._views = fixture;
181
+ FakerTracker.getFixtures(this.cwd).views = fixture;
159
182
  }
160
183
  static get permissions() {
161
- if (!this._permissions) {
162
- this._permissions = this.Fixture('permission');
163
- }
164
- return this._permissions;
184
+ return FakerTracker.getFixtures(this.cwd).permissions;
165
185
  }
166
186
  static set permissions(fixture) {
167
- this._permissions = fixture;
187
+ FakerTracker.getFixtures(this.cwd).permissions = fixture;
168
188
  }
169
189
  static get roles() {
170
- if (!this._roles) {
171
- this._roles = this.Fixture('role');
172
- }
173
- return this._roles;
190
+ return FakerTracker.getFixtures(this.cwd).roles;
174
191
  }
175
192
  static set roles(fixture) {
176
- this._roles = fixture;
193
+ FakerTracker.getFixtures(this.cwd).roles = fixture;
177
194
  }
178
195
  static get locations() {
179
- if (!this._locations) {
180
- this._locations = this.Fixture('location');
181
- }
182
- return this._locations;
196
+ return FakerTracker.getFixtures(this.cwd).locations;
183
197
  }
184
198
  static set locations(fixture) {
185
- this._locations = fixture;
199
+ FakerTracker.getFixtures(this.cwd).locations = fixture;
186
200
  }
187
201
  static get organizations() {
188
- if (!this._organizations) {
189
- this._organizations = this.Fixture('organization');
190
- }
191
- return this._organizations;
202
+ return FakerTracker.getFixtures(this.cwd).organizations;
192
203
  }
193
204
  static set organizations(fixture) {
194
- this._organizations = fixture;
205
+ FakerTracker.getFixtures(this.cwd).organizations = fixture;
195
206
  }
196
207
  static get people() {
197
- if (!this._people) {
198
- this._people = this.Fixture('person');
199
- }
200
- return this._people;
208
+ return FakerTracker.getFixtures(this.cwd).people;
201
209
  }
202
210
  static set people(fixture) {
203
- this._people = fixture;
211
+ FakerTracker.getFixtures(this.cwd).people = fixture;
204
212
  }
205
213
  static get seeder() {
206
- if (!this._seeder) {
207
- this._seeder = this.Fixture('seed');
208
- }
209
- return this._seeder;
214
+ return FakerTracker.getFixtures(this.cwd).seeder;
210
215
  }
211
216
  static set seeder(fixture) {
212
- this._seeder = fixture;
217
+ FakerTracker.getFixtures(this.cwd).seeder = fixture;
213
218
  }
214
219
  static get skills() {
215
- if (!this._skills) {
216
- this._skills = this.Fixture('skill');
217
- }
218
- return this._skills;
220
+ return FakerTracker.getFixtures(this.cwd).skills;
219
221
  }
220
222
  static set skills(fixture) {
221
- this._skills = fixture;
223
+ FakerTracker.getFixtures(this.cwd).skills = fixture;
222
224
  }
223
225
  static get mercury() {
224
- if (!this._mercury) {
225
- this._mercury = this.Fixture('mercury');
226
- }
227
- return this._mercury;
226
+ return FakerTracker.getFixtures(this.cwd).mercury;
228
227
  }
229
228
  static set mercury(fixture) {
230
- this._mercury = fixture;
229
+ FakerTracker.getFixtures(this.cwd).mercury = fixture;
231
230
  }
232
231
  static get stores() {
233
- if (!this._stores) {
234
- this._stores = this.Fixture('store');
235
- }
236
- return this._stores;
232
+ return FakerTracker.getFixtures(this.cwd).stores;
237
233
  }
238
234
  static set stores(fixture) {
239
- this._stores = fixture;
235
+ FakerTracker.getFixtures(this.cwd).stores = fixture;
240
236
  }
241
237
  static get database() {
242
- if (!this._database) {
243
- this._database = this.Fixture('database');
244
- }
245
- return this._database;
238
+ return FakerTracker.getFixtures(this.cwd).database;
246
239
  }
247
240
  static set database(fixture) {
248
- this._database = fixture;
241
+ FakerTracker.getFixtures(this.cwd).database = fixture;
242
+ }
243
+ //instance version of things above
244
+ beforeEach() {
245
+ const _super = Object.create(null, {
246
+ beforeEach: { get: () => super.beforeEach }
247
+ });
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ yield _super.beforeEach.call(this);
250
+ yield FixtureFactory.beforeEach(this.cwd);
251
+ FakerTracker.resetFixtureWarehouse();
252
+ });
253
+ }
254
+ afterEach() {
255
+ const _super = Object.create(null, {
256
+ afterEach: { get: () => super.afterEach }
257
+ });
258
+ return __awaiter(this, void 0, void 0, function* () {
259
+ yield _super.afterEach.call(this);
260
+ yield FixtureFactory.afterEach();
261
+ });
262
+ }
263
+ Fixture(name, options) {
264
+ return FakerTracker.getFixtures(this.cwd).Fixture(name, options);
265
+ }
266
+ get fakedPerson() {
267
+ return FakerTracker.fakedPerson;
268
+ }
269
+ set fakedPerson(person) {
270
+ FakerTracker.fakedPerson = person;
271
+ }
272
+ get fakedPeople() {
273
+ return FakerTracker.fakedPeople;
274
+ }
275
+ set fakedPeople(people) {
276
+ FakerTracker.fakedPeople = people;
277
+ }
278
+ get fakedTeammates() {
279
+ return FakerTracker.fakedTeammates;
280
+ }
281
+ set fakedTeammates(teammates) {
282
+ FakerTracker.fakedTeammates = teammates;
283
+ }
284
+ get fakedOwners() {
285
+ return FakerTracker.fakedOwners;
286
+ }
287
+ set fakedOwners(owners) {
288
+ FakerTracker.fakedOwners = owners;
289
+ }
290
+ get fakedRoles() {
291
+ return FakerTracker.fakedRoles;
292
+ }
293
+ set fakedRoles(roles) {
294
+ FakerTracker.fakedRoles = roles;
295
+ }
296
+ get fakedSkills() {
297
+ return FakerTracker.fakedSkills;
298
+ }
299
+ set fakedSkills(skills) {
300
+ FakerTracker.fakedSkills = skills;
301
+ }
302
+ get fakedManagers() {
303
+ return FakerTracker.fakedManagers;
304
+ }
305
+ set fakedManagers(managers) {
306
+ FakerTracker.fakedManagers = managers;
307
+ }
308
+ get fakedGuests() {
309
+ return FakerTracker.fakedGuests;
310
+ }
311
+ set fakedGuests(guests) {
312
+ FakerTracker.fakedGuests = guests;
313
+ }
314
+ get fakedGroupManagers() {
315
+ return FakerTracker.fakedGroupManagers;
316
+ }
317
+ set fakedGroupManagers(groupManagers) {
318
+ FakerTracker.fakedGroupManagers = groupManagers;
319
+ }
320
+ get fakedClient() {
321
+ assert.isTruthy(FakerTracker.fakedClient, `You gotta @fake.login() on your test class to get the test client.`);
322
+ return FakerTracker.fakedClient;
323
+ }
324
+ set fakedClient(client) {
325
+ FakerTracker.fakedClient = client;
326
+ }
327
+ get fakedOrganizations() {
328
+ return FakerTracker.fakedOrganizations;
329
+ }
330
+ set fakedOrganizations(orgs) {
331
+ FakerTracker.fakedOrganizations = orgs;
332
+ }
333
+ get fakedLocations() {
334
+ assert.isAbove(FakerTracker.fakedLocations.length, 0, `You gotta @seed('locations', 1) (and use @fake.login(...)) before getting faked locations.`);
335
+ return FakerTracker.fakedLocations;
336
+ }
337
+ set fakedLocations(locations) {
338
+ FakerTracker.fakedLocations = locations;
339
+ }
340
+ get views() {
341
+ return FakerTracker.getFixtures(this.cwd).views;
342
+ }
343
+ set views(fixture) {
344
+ FakerTracker.getFixtures(this.cwd).views = fixture;
345
+ }
346
+ get permissions() {
347
+ return FakerTracker.getFixtures(this.cwd).permissions;
348
+ }
349
+ set permissions(fixture) {
350
+ FakerTracker.getFixtures(this.cwd).permissions = fixture;
351
+ }
352
+ get roles() {
353
+ return FakerTracker.getFixtures(this.cwd).roles;
354
+ }
355
+ set roles(fixture) {
356
+ FakerTracker.getFixtures(this.cwd).roles = fixture;
357
+ }
358
+ get locations() {
359
+ return FakerTracker.getFixtures(this.cwd).locations;
360
+ }
361
+ set locations(fixture) {
362
+ FakerTracker.getFixtures(this.cwd).locations = fixture;
363
+ }
364
+ get organizations() {
365
+ return FakerTracker.getFixtures(this.cwd).organizations;
366
+ }
367
+ set organizations(fixture) {
368
+ FakerTracker.getFixtures(this.cwd).organizations = fixture;
369
+ }
370
+ get people() {
371
+ return FakerTracker.getFixtures(this.cwd).people;
372
+ }
373
+ set people(fixture) {
374
+ FakerTracker.getFixtures(this.cwd).people = fixture;
375
+ }
376
+ get seeder() {
377
+ return FakerTracker.getFixtures(this.cwd).seeder;
378
+ }
379
+ set seeder(fixture) {
380
+ FakerTracker.getFixtures(this.cwd).seeder = fixture;
381
+ }
382
+ get skills() {
383
+ return FakerTracker.getFixtures(this.cwd).skills;
384
+ }
385
+ set skills(fixture) {
386
+ FakerTracker.getFixtures(this.cwd).skills = fixture;
387
+ }
388
+ get mercury() {
389
+ return FakerTracker.getFixtures(this.cwd).mercury;
390
+ }
391
+ set mercury(fixture) {
392
+ FakerTracker.getFixtures(this.cwd).mercury = fixture;
393
+ }
394
+ get stores() {
395
+ return FakerTracker.getFixtures(this.cwd).stores;
396
+ }
397
+ set stores(fixture) {
398
+ FakerTracker.getFixtures(this.cwd).stores = fixture;
399
+ }
400
+ get database() {
401
+ return FakerTracker.getFixtures(this.cwd).database;
402
+ }
403
+ set database(fixture) {
404
+ FakerTracker.getFixtures(this.cwd).database = fixture;
249
405
  }
250
406
  }
251
- AbstractSpruceFixtureTest._fakedOrganizations = [];
252
- AbstractSpruceFixtureTest._fakedLocations = [];
253
- export default AbstractSpruceFixtureTest;
@@ -1,11 +1,21 @@
1
1
  import { MercuryClient } from '@sprucelabs/mercury-client';
2
2
  import { SpruceSchemas } from '@sprucelabs/mercury-types';
3
3
  import { CoreSeedTarget } from './seed';
4
+ declare function fake(target: CoreSeedTarget, total: number): (TestClass: any, _key: string, descriptor: any) => void;
5
+ declare namespace fake {
6
+ var login: (phone?: string) => (TestClass: any, shouldPassHookCalls?: boolean) => void;
7
+ var getClient: () => Client;
8
+ var getPerson: () => Person;
9
+ }
10
+ export default fake;
11
+ export declare function fakeTargetToPropName(target: CoreSeedTarget): keyof FakedData;
12
+ export declare function pluralToSingular(target: string): string;
13
+ export declare function singularToPlural(target: string): string;
4
14
  type Person = SpruceSchemas.Spruce.v2020_07_22.Person;
5
15
  type Skill = SpruceSchemas.Spruce.v2020_07_22.Skill;
6
16
  /** @ts-ignore */
7
17
  type Client = MercuryClient;
8
- interface ClassWithFakes {
18
+ interface FakedData {
9
19
  fakedOwners?: Person[];
10
20
  fakedTeammates?: Person[];
11
21
  fakedManagers?: Person[];
@@ -14,13 +24,3 @@ interface ClassWithFakes {
14
24
  fakedSkills: Skill[];
15
25
  fakedGroupManagers: Person[];
16
26
  }
17
- declare function fake(target: CoreSeedTarget, total: number): (TestClass: any, _key: string, descriptor: any) => void;
18
- declare namespace fake {
19
- var login: (phone?: string) => (TestClass: any, shouldPassHookCalls?: boolean) => void;
20
- var getClient: () => Client;
21
- var getPerson: () => Person;
22
- }
23
- export default fake;
24
- export declare function fakeTargetToPropName(target: CoreSeedTarget): keyof ClassWithFakes;
25
- export declare function pluralToSingular(target: string): string;
26
- export declare function singularToPlural(target: string): string;