@sprucelabs/spruce-calendar-components 22.4.6 → 22.4.9

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 (37) hide show
  1. package/build/.spruce/schemas/schemas.types.d.ts +142 -142
  2. package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts +39 -0
  3. package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +105 -0
  4. package/build/__tests__/support/SpyEventManager.d.ts +40 -0
  5. package/build/__tests__/support/SpyEventManager.js +30 -0
  6. package/build/__tests__/support/SpyPeopleManager.d.ts +10 -0
  7. package/build/__tests__/support/SpyPeopleManager.js +23 -0
  8. package/build/__tests__/support/SpyRemoteEventStore.d.ts +18 -0
  9. package/build/__tests__/support/SpyRemoteEventStore.js +31 -0
  10. package/build/__tests__/support/SpyRemotePreferencesStore.d.ts +9 -0
  11. package/build/__tests__/support/SpyRemotePreferencesStore.js +17 -0
  12. package/build/__tests__/support/utilities/calendarAssert.d.ts +13 -0
  13. package/build/__tests__/support/utilities/calendarAssert.js +93 -0
  14. package/build/__tests__/support/utilities/calendarSkillAssert.d.ts +40 -0
  15. package/build/__tests__/support/utilities/calendarSkillAssert.js +346 -0
  16. package/build/__tests__/support/utilities/calendarToolBeltInteractor.d.ts +5 -0
  17. package/build/__tests__/support/utilities/calendarToolBeltInteractor.js +11 -0
  18. package/build/esm/.spruce/schemas/schemas.types.d.ts +142 -142
  19. package/build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts +39 -0
  20. package/build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +126 -0
  21. package/build/esm/__tests__/support/SpyEventManager.d.ts +40 -0
  22. package/build/esm/__tests__/support/SpyEventManager.js +38 -0
  23. package/build/esm/__tests__/support/SpyPeopleManager.d.ts +10 -0
  24. package/build/esm/__tests__/support/SpyPeopleManager.js +31 -0
  25. package/build/esm/__tests__/support/SpyRemoteEventStore.d.ts +18 -0
  26. package/build/esm/__tests__/support/SpyRemoteEventStore.js +46 -0
  27. package/build/esm/__tests__/support/SpyRemotePreferencesStore.d.ts +9 -0
  28. package/build/esm/__tests__/support/SpyRemotePreferencesStore.js +22 -0
  29. package/build/esm/__tests__/support/utilities/calendarAssert.d.ts +13 -0
  30. package/build/esm/__tests__/support/utilities/calendarAssert.js +88 -0
  31. package/build/esm/__tests__/support/utilities/calendarSkillAssert.d.ts +40 -0
  32. package/build/esm/__tests__/support/utilities/calendarSkillAssert.js +372 -0
  33. package/build/esm/__tests__/support/utilities/calendarToolBeltInteractor.d.ts +5 -0
  34. package/build/esm/__tests__/support/utilities/calendarToolBeltInteractor.js +20 -0
  35. package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +1 -1
  36. package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +1 -1
  37. package/package.json +34 -2
@@ -0,0 +1,18 @@
1
+ import { MercuryClient } from '@sprucelabs/mercury-client';
2
+ import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
3
+ import RemoteEventStoreImpl, { RemoteEventStoreOptions } from '../../stores/RemoteEventStore';
4
+ import { Calendar, UpdateEvent } from '../../types/calendar.types';
5
+ export default class SpyRemoteEventStore extends RemoteEventStoreImpl {
6
+ private calendars?;
7
+ lastPersistedEvent?: SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
8
+ constructor(options: Omit<RemoteEventStoreOptions, 'connectToApi'> & {
9
+ calendars?: Calendar[];
10
+ locationId?: string;
11
+ organizationId?: string;
12
+ client: MercuryClient;
13
+ });
14
+ setOrganizationId(id: string): void;
15
+ cancelEvent(_id: string): Promise<void>;
16
+ getCalendars(): Promise<SpruceSchemas.Calendar.v2021_05_19.Calendar[] | import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema, false>>[]>;
17
+ persist(event: UpdateEvent): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent>;
18
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const test_utils_1 = require("@sprucelabs/test-utils");
7
+ const RemoteEventStore_1 = __importDefault(require("../../stores/RemoteEventStore"));
8
+ class SpyRemoteEventStore extends RemoteEventStore_1.default {
9
+ constructor(options) {
10
+ const { calendars, client, locationId, organizationId } = options;
11
+ super({ connectToApi: async () => client });
12
+ this.client = client;
13
+ this.calendars = calendars;
14
+ this.locationId = locationId !== null && locationId !== void 0 ? locationId : (0, test_utils_1.generateId)();
15
+ this.organizationId = organizationId !== null && organizationId !== void 0 ? organizationId : (0, test_utils_1.generateId)();
16
+ }
17
+ setOrganizationId(id) {
18
+ this.organizationId = id;
19
+ }
20
+ async cancelEvent(_id) { }
21
+ async getCalendars() {
22
+ var _a;
23
+ return (_a = this.calendars) !== null && _a !== void 0 ? _a : super.getCalendars();
24
+ }
25
+ async persist(event) {
26
+ const results = await super.persist(event);
27
+ this.lastPersistedEvent = results;
28
+ return results;
29
+ }
30
+ }
31
+ exports.default = SpyRemoteEventStore;
@@ -0,0 +1,9 @@
1
+ import { MercuryClient } from '@sprucelabs/mercury-client';
2
+ import RemotePreferencesStore from '../../stores/RemotePreferencesStore';
3
+ export default class SpyRemotePreferencesStore extends RemotePreferencesStore {
4
+ constructor(options: {
5
+ client: MercuryClient;
6
+ visibleCalendarIds?: string[];
7
+ });
8
+ protected save(): Promise<void>;
9
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const RemotePreferencesStore_1 = __importDefault(require("../../stores/RemotePreferencesStore"));
7
+ class SpyRemotePreferencesStore extends RemotePreferencesStore_1.default {
8
+ constructor(options) {
9
+ const { visibleCalendarIds, client } = options;
10
+ super({ connectToApi: async () => client });
11
+ this.client = client;
12
+ this.isLoaded = true;
13
+ this.visibleCalendarIds = visibleCalendarIds;
14
+ }
15
+ async save() { }
16
+ }
17
+ exports.default = SpyRemotePreferencesStore;
@@ -0,0 +1,13 @@
1
+ import { CalendarEvent, SpruceSchemas, ViewController } from '@sprucelabs/heartwood-view-controllers';
2
+ declare type Calendar = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Calendar;
3
+ declare type Event = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
4
+ declare const calendarAssert: {
5
+ rendersTotalEvents(vc: ViewController<Calendar>, expected: number): void;
6
+ hasEvent(vc: ViewController<Calendar>, lookup: Partial<Event>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
7
+ eventsAreEqual(actual: Event[], expected: Event[]): void;
8
+ includesInEvent(events: Event[], lookup: Partial<Event>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
9
+ eventIsDuration(event: Event, expectedDuration: number): void;
10
+ eventsFallOnDows(events: CalendarEvent[], expectedDows: string[]): void;
11
+ eventEquals(actual: Partial<CalendarEvent> | undefined | null, expected: Partial<CalendarEvent> | undefined | null): void;
12
+ };
13
+ export default calendarAssert;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const calendar_utils_1 = require("@sprucelabs/calendar-utils");
7
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
8
+ const test_1 = require("@sprucelabs/test");
9
+ const just_clone_1 = __importDefault(require("just-clone"));
10
+ const calendarAssert = {
11
+ rendersTotalEvents(vc, expected) {
12
+ const model = heartwood_view_controllers_1.renderUtil.render(vc);
13
+ test_1.assert.isLength(model.events, expected);
14
+ },
15
+ hasEvent(vc, lookup) {
16
+ const { events } = heartwood_view_controllers_1.renderUtil.render(vc);
17
+ return this.includesInEvent(events, lookup);
18
+ },
19
+ eventsAreEqual(actual, expected) {
20
+ function sort(a, b) {
21
+ return a.id > b.id ? 1 : -1;
22
+ }
23
+ actual.sort(sort);
24
+ expected.sort(sort);
25
+ test_1.assert.isEqualDeep(actual, expected);
26
+ },
27
+ includesInEvent(events, lookup) {
28
+ const match = events.find((e) => {
29
+ try {
30
+ test_1.assert.doesInclude(e, lookup);
31
+ return e;
32
+ // eslint-disable-next-line no-empty
33
+ }
34
+ catch (_a) { }
35
+ return null;
36
+ });
37
+ test_1.assert.isTruthy(match, `I could not find an event that matched:\n\n${test_1.assertUtil.stringify(lookup)}`);
38
+ return match;
39
+ },
40
+ eventIsDuration(event, expectedDuration) {
41
+ const duration = event.timeBlocks.reduce((minutes, timeBlock) => {
42
+ minutes += timeBlock.durationMinutes;
43
+ return minutes;
44
+ }, 0);
45
+ test_1.assert.isEqual(duration, expectedDuration);
46
+ },
47
+ eventsFallOnDows(events, expectedDows) {
48
+ const remaining = [...expectedDows];
49
+ for (const event of events) {
50
+ const dow = calendar_utils_1.dateUtil.getDayOfWeek(event.startDateTimeMs);
51
+ const idx = remaining.indexOf(dow);
52
+ if (idx === -1) {
53
+ test_1.assert.fail(`Checking days of week and got ${dow} but it wasn't in the array of expected dows.`);
54
+ }
55
+ remaining.splice(idx, 1);
56
+ }
57
+ if (remaining.length > 0) {
58
+ test_1.assert.fail(`Didn't find the following days of week in events:\n\n${test_1.assertUtil.stringify(remaining)}`);
59
+ }
60
+ },
61
+ eventEquals(actual, expected) {
62
+ var _a, _b, _c;
63
+ test_1.assert.isTruthy(actual, 'Event is missing');
64
+ test_1.assert.isTruthy(expected, 'Event is missing');
65
+ test_1.assert.isEqual(actual.startDateTimeMs, expected.startDateTimeMs, 'startDateTimeMs does not match');
66
+ test_1.assert.isEqual((_a = actual.isBusy) !== null && _a !== void 0 ? _a : false, (_b = expected.isBusy) !== null && _b !== void 0 ? _b : false, `isBusy does not match, needs to be '${(_c = expected.isBusy) !== null && _c !== void 0 ? _c : false}'`);
67
+ const cleanedActual = (0, just_clone_1.default)(actual);
68
+ const cleanedExpected = (0, just_clone_1.default)(expected);
69
+ cleanEvent(cleanedActual);
70
+ cleanEvent(cleanedExpected);
71
+ test_1.assert.isEqualDeep(cleanedActual, cleanedExpected, 'Your event did not equal what I expected!');
72
+ },
73
+ };
74
+ function cleanEvent(obj, propsToIgnore = [
75
+ 'isSelected',
76
+ 'source',
77
+ 'dateCreated',
78
+ 'isBusy',
79
+ 'controller',
80
+ ]) {
81
+ for (const prop in obj) {
82
+ const value = obj[prop];
83
+ if (propsToIgnore.indexOf(prop) > -1 ||
84
+ value === null ||
85
+ typeof value === 'undefined') {
86
+ delete obj[prop];
87
+ }
88
+ else if (typeof value === 'object') {
89
+ cleanEvent(value);
90
+ }
91
+ }
92
+ }
93
+ exports.default = calendarAssert;
@@ -0,0 +1,40 @@
1
+ import { ToolBeltState, AbstractCalendarEventViewController, ToolBeltStateMachine, SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
2
+ import { MercuryClient } from '@sprucelabs/mercury-client';
3
+ import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
4
+ import AbstractCalendarEventToolBeltState from '../../../toolBelt/states/AbstractCalendarEventToolBeltState';
5
+ export interface AssertRemoteToolsOptions {
6
+ client: MercuryClient;
7
+ state: ToolBeltState;
8
+ views: ViewFixture;
9
+ }
10
+ interface TypeWithVcId {
11
+ typeSlug: string;
12
+ vcId: string;
13
+ }
14
+ export declare type AssertTypeSlug = string | TypeWithVcId;
15
+ declare const calendarSkillAssert: {
16
+ createdEventTypes: SpruceSchemas.Calendar.v2021_05_19.CalendarEventType[];
17
+ createdCalendars: SpruceSchemas.Calendar.v2021_05_19.Calendar[];
18
+ beforeEach(views: ViewFixture): Promise<void>;
19
+ createsCalendarOnInstall(calendarSlug: string, client: MercuryClient, typeSlugs?: string[]): Promise<void>;
20
+ createsCalendarsWithMultipleInstalls(calendarSlug: string, client: MercuryClient): Promise<void>;
21
+ createsEventTypesOnBoot(types: AssertTypeSlug[], client: MercuryClient, boot: () => Promise<any>): Promise<void>;
22
+ createsEventTypesWithMultipleBoots(types: AssertTypeSlug[], client: MercuryClient, boot: () => Promise<any>): Promise<void>;
23
+ isValidEventViewController(options: {
24
+ views: ViewFixture;
25
+ CalendarEventClass: typeof AbstractCalendarEventViewController;
26
+ ToolBeltStateClass: any;
27
+ }): void;
28
+ stateFetchesAndRendersRemoteTools(options: AssertRemoteToolsOptions): Promise<{
29
+ toolId: string;
30
+ Class: any;
31
+ }[]>;
32
+ toolBeltStateProperlyInheritsAbstractToolBeltState(stateMachine: ToolBeltStateMachine, state: AbstractCalendarEventToolBeltState): Promise<void>;
33
+ toolBeltStateAddsTool(options: {
34
+ state: AbstractCalendarEventToolBeltState;
35
+ toolId: string;
36
+ views: ViewFixture;
37
+ Class?: any;
38
+ }): Promise<SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool>;
39
+ };
40
+ export default calendarSkillAssert;
@@ -0,0 +1,346 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
7
+ const schema_1 = require("@sprucelabs/schema");
8
+ const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
9
+ const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
10
+ const test_1 = require("@sprucelabs/test");
11
+ const test_utils_1 = require("@sprucelabs/test-utils");
12
+ const AbstractCalendarEventToolBeltState_1 = __importDefault(require("../../../toolBelt/states/AbstractCalendarEventToolBeltState"));
13
+ const Calendar_vc_1 = __importDefault(require("../../../viewControllers/Calendar.vc"));
14
+ const EventControlsCard_vc_1 = __importDefault(require("../../../viewControllers/EventControlsCard.vc"));
15
+ const EventDateTimeTool_vc_1 = __importDefault(require("../../../viewControllers/EventDateTimeTool.vc"));
16
+ const EventRepeatingTool_vc_1 = __importDefault(require("../../../viewControllers/EventRepeatingTool.vc"));
17
+ const EventTitleTool_vc_1 = __importDefault(require("../../../viewControllers/EventTitleTool.vc"));
18
+ const RepeatingControlsList_vc_1 = __importDefault(require("../../../viewControllers/RepeatingControlsList.vc"));
19
+ const CalendarToolBeltStateMachineTestFactory_1 = __importDefault(require("../CalendarToolBeltStateMachineTestFactory"));
20
+ class TestTool1 extends heartwood_view_controllers_1.CardViewControllerImpl {
21
+ async handleUpdateContext() { }
22
+ getLineIcon() {
23
+ return 'cellphone';
24
+ }
25
+ }
26
+ class TestTool2 extends heartwood_view_controllers_1.CardViewControllerImpl {
27
+ handleUpdateContext() { }
28
+ getLineIcon() {
29
+ return 'calendar';
30
+ }
31
+ }
32
+ const vcs = {
33
+ ['calendar.repeating-controls-list']: RepeatingControlsList_vc_1.default,
34
+ ['calendar.event-repeating-tool']: EventRepeatingTool_vc_1.default,
35
+ ['calendar.calendar']: Calendar_vc_1.default,
36
+ ['calendar.event-date-time-tool']: EventDateTimeTool_vc_1.default,
37
+ ['calendar.event-title-tool']: EventTitleTool_vc_1.default,
38
+ ['calendar.event-controls-card']: EventControlsCard_vc_1.default,
39
+ };
40
+ const calendarSkillAssert = {
41
+ createdEventTypes: [],
42
+ createdCalendars: [],
43
+ async beforeEach(views) {
44
+ (0, schema_1.assertOptions)({ views }, ['views']);
45
+ //@ts-ignore
46
+ this._didBeforeEach = true;
47
+ this.createdEventTypes = [];
48
+ this.createdCalendars = [];
49
+ const factory = views.getFactory();
50
+ factory.mixinControllers(vcs);
51
+ await spruce_test_fixtures_1.eventFaker.on('calendar.register-event-tools::v2021_05_19', () => ({
52
+ vcIds: [],
53
+ }));
54
+ await fakeEventTypeEvents(this.createdEventTypes);
55
+ await fakeCalendarEvents(this.createdCalendars);
56
+ },
57
+ async createsCalendarOnInstall(calendarSlug, client, typeSlugs) {
58
+ var _a, _b, _c, _d;
59
+ assertRanBeforeEach(this);
60
+ (0, schema_1.assertOptions)({
61
+ calendarSlug,
62
+ client,
63
+ }, ['calendarSlug', 'client']);
64
+ const [{ organizations }] = await client.emitAndFlattenResponses('list-organizations::v2020_12_25', {
65
+ payload: {
66
+ shouldOnlyShowMine: true,
67
+ },
68
+ });
69
+ const organization = organizations.pop();
70
+ test_1.assert.isTruthy(organization, `You gotta @seed('organizations', 1) before you can assert a calendar is created on install.`);
71
+ const skill = spruce_skill_utils_1.AuthService.Auth(process.cwd()).getCurrentSkill();
72
+ test_1.assert.isTruthy(skill, `Make sure you registered your skill before you can do anything else. Try 'spruce register'.`);
73
+ const responses = await client.emit('did-install::v2020_12_25', {
74
+ target: {
75
+ organizationId: organization.id,
76
+ skillId: skill.id,
77
+ },
78
+ });
79
+ if (responses.totalErrors > 0) {
80
+ throw (_b = (_a = responses.responses[0].errors) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : `did-instal error`;
81
+ }
82
+ if (responses.totalResponses === 0) {
83
+ test_1.assert.fail(`did-install listener missing! To get this test passing your skill will need to be listening to did-install, try 'spruce create.listener' and look under Mercury. You may also need to boot your skill with 'await this.bootSkill()'`);
84
+ }
85
+ let cal;
86
+ try {
87
+ const [{ calendar }] = await client.emitAndFlattenResponses('calendar.get-calendar::v2021_05_19', {
88
+ target: {
89
+ slug: calendarSlug,
90
+ organizationId: organization.id,
91
+ },
92
+ });
93
+ cal = calendar;
94
+ }
95
+ catch (err) {
96
+ test_1.assert.fail(`It looks like you still need to create a calendar, maybe the following code will help:
97
+ const events = event.skill.getFeatureByCode('event') as EventFeature
98
+ const client = await events.connectToApi()
99
+
100
+ await client.emitAndFlattenResponses(
101
+ 'calendar.create-calendar::v2021_05_19',
102
+ {
103
+ target: {
104
+ organizationId,
105
+ },
106
+ payload: {
107
+ availableTimeSlotBehavior: 'exclude or exclude',
108
+ title: '${calendarSlug}',
109
+ slug: '${calendarSlug}',
110
+ },
111
+ }
112
+ )\n\nOh, and here's the original error: ${(_d = (_c = err.stack) !== null && _c !== void 0 ? _c : err.message) !== null && _d !== void 0 ? _d : err}`);
113
+ }
114
+ if (typeSlugs) {
115
+ test_1.assert.isEqualDeep(cal.eventTypes, typeSlugs, `Your calendar does not have types set to: [${typeSlugs.join(', ')}]`);
116
+ }
117
+ },
118
+ async createsCalendarsWithMultipleInstalls(calendarSlug, client) {
119
+ await this.createsCalendarOnInstall(calendarSlug, client);
120
+ try {
121
+ await this.createsCalendarOnInstall(calendarSlug, client);
122
+ }
123
+ catch (err) {
124
+ test_1.assert.fail(`You tried to create the same calendar twice! It's time for the next step (don't forget to extract):
125
+
126
+ try {
127
+ await client.emitAndFlattenResponses('calendar.get-calendar::v2021_05_19', {
128
+ target: {
129
+ organizationId,
130
+ slug: 'shifts',
131
+ },
132
+ })
133
+ } catch {
134
+ await client.emitAndFlattenResponses(
135
+ 'calendar.create-calendar::v2021_05_19',
136
+ {
137
+ target: {
138
+ organizationId,
139
+ },
140
+ payload: {
141
+ availableTimeSlotBehavior: 'exclude or include',
142
+ title: 'Shifts',
143
+ slug: 'shifts',
144
+ },
145
+ }
146
+ )
147
+ }`);
148
+ }
149
+ },
150
+ async createsEventTypesOnBoot(types, client, boot) {
151
+ assertRanBeforeEach(this);
152
+ await (boot === null || boot === void 0 ? void 0 : boot());
153
+ test_1.assert.isTruthy(
154
+ //@ts-ignore
155
+ client.auth.skill, `You gotta be logged in as a skill! Try 'const { client } = await this.skills.loginAsCurrentSkill()'`);
156
+ const typeSlugs = types.map((t) => (typeof t === 'string' ? t : t.typeSlug));
157
+ const vcIds = types.map((t) => (typeof t === 'string' ? undefined : t.vcId));
158
+ function sort(a, b) {
159
+ return a.typeSlug > b.typeSlug ? 1 : -1;
160
+ }
161
+ const normalizedExpected = typeSlugs
162
+ .map((slug, idx) => ({
163
+ typeSlug: slug,
164
+ viewControllerId: vcIds[idx],
165
+ }))
166
+ .sort(sort);
167
+ const [{ calendarEventTypes }] = await client.emitAndFlattenResponses('calendar.list-calendar-event-types::v2021_05_19', {
168
+ payload: {
169
+ shouldShowOnlyMine: true,
170
+ },
171
+ });
172
+ test_1.assert.isAbove(calendarEventTypes.length, 0, `No event types were created. Make sure you are listening to the 'did-boot' event and booted. Use 'spruce create.listener' and look under Skill (or await this.bootSkill()). Then, drop in something like this:\n\n
173
+ await client.emitAndFlattenResponses('calendar.create-calendar-event-type::v2021_05_19', {
174
+ payload: {
175
+ name: '${typeSlugs[0]}',
176
+ slug: '${typeSlugs[0]}'
177
+ }
178
+ })`);
179
+ const normalizedActual = calendarEventTypes
180
+ .map((cet) => ({
181
+ typeSlug: cet.slug,
182
+ viewControllerId: cet.viewControllerId,
183
+ }))
184
+ .sort(sort);
185
+ test_1.assert.isEqualDeep(normalizedActual, normalizedExpected, 'The event types I was found were not created as expected.');
186
+ },
187
+ async createsEventTypesWithMultipleBoots(types, client, boot) {
188
+ await this.createsEventTypesOnBoot(types, client, boot);
189
+ await this.createsEventTypesOnBoot(types, client, boot);
190
+ },
191
+ isValidEventViewController(options) {
192
+ const { views, ToolBeltStateClass: ToolBeltClass, CalendarEventClass, } = (0, schema_1.assertOptions)(options, [
193
+ 'views',
194
+ 'CalendarEventClass',
195
+ 'ToolBeltStateClass',
196
+ ]);
197
+ const event = heartwood_view_controllers_1.calendarSeeder.generateEventValues();
198
+ const calendarVc = views.Controller('calendar', {
199
+ events: [event],
200
+ });
201
+ //@ts-ignore
202
+ views.getFactory().mixinControllers({
203
+ [event.id]: CalendarEventClass,
204
+ });
205
+ calendarVc.setDefaultControllerForEvents(event.id);
206
+ const vc = calendarVc.getEventVc(event.id);
207
+ test_1.assert.isFunction(vc.getToolBeltState, `Bad event vc. You need to make sure your event vc extends and implements what it needs to! Try:
208
+
209
+ class MyEventViewController
210
+ extends AbstractCalendarEventViewController
211
+ implements EventWithToolBeltState`);
212
+ const state = vc.getToolBeltState();
213
+ test_1.assert.isTrue(state instanceof ToolBeltClass, `Your event vc did not return the state I expected. Make sure getToolBeltState() is returning an instance of ${ToolBeltClass.name}.`);
214
+ },
215
+ async stateFetchesAndRendersRemoteTools(options) {
216
+ assertRanBeforeEach(this);
217
+ const { views, state } = (0, schema_1.assertOptions)(options, ['state', 'views']);
218
+ const event = Object.assign(Object.assign({}, heartwood_view_controllers_1.calendarSeeder.generateEventValues()), { eventTypeSlug: (0, test_utils_1.generateId)() });
219
+ const org = await views.getScope().getCurrentOrganization();
220
+ test_1.assert.isTruthy(org, `You gotta @seed('organizations', 1) to test fetching and rendering remote tools.`);
221
+ let passedTargetAndPayload;
222
+ const VC_NAME_1 = 'calendars.test-one';
223
+ const VC_NAME_2 = 'calendars.test-two';
224
+ const vcIds = [VC_NAME_1, VC_NAME_2];
225
+ const Classes = [TestTool1, TestTool2];
226
+ views.getFactory().mixinControllers({
227
+ [VC_NAME_1]: TestTool1,
228
+ [VC_NAME_2]: TestTool2,
229
+ });
230
+ await spruce_test_fixtures_1.eventFaker.on('calendar.register-event-tools::v2021_05_19', (targetAndPayload) => {
231
+ passedTargetAndPayload = targetAndPayload;
232
+ return {
233
+ vcIds,
234
+ };
235
+ });
236
+ const { toolBeltVc, stateMachine } = await CalendarToolBeltStateMachineTestFactory_1.default.StateMachine(views);
237
+ await stateMachine.updateContext({ event });
238
+ await stateMachine.transitionTo(state);
239
+ test_1.assert.isTruthy(passedTargetAndPayload, `You aren't emitting 'calendar.register-event-tools::v2021_05_19'.
240
+
241
+ Try adding the following to your state's load():
242
+
243
+ const tools = new CalendarToolRegistrar(stateMachine)
244
+ await tools.fetchAndAddCards()
245
+ `);
246
+ test_1.assert.isEqualDeep(passedTargetAndPayload.target, { organizationId: org.id, calendarEventId: event.id }, `Your target is not what is expected! Make sure you are sending organizationId and calendarEventId`);
247
+ test_1.assert.isEqualDeep(passedTargetAndPayload.payload, {
248
+ eventTypeSlug: event.eventTypeSlug,
249
+ }, `Your payload does not what is expected! Make sure you pass through eventTypeSlug.`);
250
+ const tools = toolBeltVc.getTools();
251
+ test_1.assert.isAbove(tools.length, 0, `It looks like you didn't add any tools to the tool belt! try sm.getToolBeltVc().addTool()`);
252
+ const results = [];
253
+ for (let c = 0; c < vcIds.length; c++) {
254
+ const id = vcIds[c];
255
+ const tool = toolBeltVc.getTool(id);
256
+ results.push({
257
+ toolId: id,
258
+ Class: Classes[c],
259
+ });
260
+ test_1.assert.isTruthy(tool, `You didn't add the tools I expected! Make sure you are using the CalendarToolRegistrar!`);
261
+ }
262
+ return results;
263
+ },
264
+ async toolBeltStateProperlyInheritsAbstractToolBeltState(stateMachine, state) {
265
+ assertRanBeforeEach(this);
266
+ (0, schema_1.assertOptions)({ stateMachine, state }, ['stateMachine', 'state']);
267
+ test_1.assert.isTrue(state instanceof AbstractCalendarEventToolBeltState_1.default, `Your state does not extend 'AbstractCalendarEventToolBeltState'. Make sure you do that next!`);
268
+ await stateMachine.transitionTo(state);
269
+ test_1.assert.isTruthy(state.getIsLoaded(), `You need to call super.load(stateMachine) in your state!`);
270
+ await stateMachine.on('did-update-context', () => { });
271
+ const originalListenCount = stateMachine.listenCount('did-update-context');
272
+ await state.destroy();
273
+ const count = stateMachine.listenCount('did-update-context');
274
+ test_1.assert.isAbove(count, originalListenCount - 2, `You 'sm.off(...)'ed too many listeners, make sure you pass the callback to remove to 'this.sm.off(...)'. It's the second param.`);
275
+ test_1.assert.isEqual(count, originalListenCount - 1, `Don't forget to remove all listeners to the stateMachine. Either implement 'destroy()' and call 'this.sm.off(...)' or try 'await super.destroy()' in your state.`);
276
+ },
277
+ async toolBeltStateAddsTool(options) {
278
+ const { state, toolId, views, Class } = (0, schema_1.assertOptions)(options, [
279
+ 'state',
280
+ 'toolId',
281
+ 'views',
282
+ ]);
283
+ const { toolBeltVc, stateMachine } = await CalendarToolBeltStateMachineTestFactory_1.default.StateMachine(views);
284
+ await stateMachine.transitionTo(state);
285
+ test_1.assert.isTruthy(toolBeltVc.getTool(toolId), `I could not find the tool with the id '${toolId}', try 'this.addTool(...)' from inside your state!`);
286
+ //@ts-ignore
287
+ const match = state.vcs.find((o) => o.toolId === toolId);
288
+ test_1.assert.isTruthy(match, `It looks like you added your tool directly to the toolBeltVc instead of to your parent class. 'this.addTool(...)'`);
289
+ if (Class) {
290
+ heartwood_view_controllers_1.vcAssert.assertToolInstanceOf(toolBeltVc, toolId, Class);
291
+ }
292
+ return toolBeltVc.getTool(toolId);
293
+ },
294
+ };
295
+ exports.default = calendarSkillAssert;
296
+ async function fakeEventTypeEvents(eventTypes) {
297
+ await spruce_test_fixtures_1.eventFaker.on('calendar.list-calendar-event-types::v2021_05_19', ({ source }) => {
298
+ const matches = eventTypes.filter((t) => t.source.skillId === (source === null || source === void 0 ? void 0 : source.skillId));
299
+ return {
300
+ calendarEventTypes: matches,
301
+ count: matches.length,
302
+ };
303
+ });
304
+ await spruce_test_fixtures_1.eventFaker.on('calendar.create-calendar-event-type::v2021_05_19', ({ payload, source }) => {
305
+ const type = Object.assign({ id: (0, test_utils_1.generateId)(), source: source, viewControllerId: null }, payload);
306
+ eventTypes.push(type);
307
+ return {
308
+ calendarEventType: type,
309
+ };
310
+ });
311
+ await spruce_test_fixtures_1.eventFaker.on('calendar.upsert-calendar-event-type::v2021_05_19', ({ payload, source, target }) => {
312
+ const match = eventTypes.find((t) => t.slug === target.slug);
313
+ if (match) {
314
+ match.name = payload.name;
315
+ return {
316
+ calendarEventType: match,
317
+ };
318
+ }
319
+ const type = Object.assign({ id: (0, test_utils_1.generateId)(), source: source, viewControllerId: null, slug: target.slug }, payload);
320
+ eventTypes.push(type);
321
+ return {
322
+ calendarEventType: type,
323
+ };
324
+ });
325
+ }
326
+ async function fakeCalendarEvents(calendars) {
327
+ await spruce_test_fixtures_1.eventFaker.on('calendar.create-calendar::v2021_05_19', ({ payload, source, target }) => {
328
+ const matches = calendars.filter((c) => c.slug === payload.slug);
329
+ test_1.assert.isLength(matches, 0, `You already created a calendar the slug: ${payload.slug}!`);
330
+ const calendar = Object.assign({ id: (0, test_utils_1.generateId)(), source: source, target }, payload);
331
+ calendars.push(calendar);
332
+ return { calendar };
333
+ });
334
+ //@ts-ignore
335
+ await spruce_test_fixtures_1.eventFaker.on('calendar.get-calendar::v2021_05_19', ({ target }) => {
336
+ const calendar = calendars.find((c) => c.slug === target.slug);
337
+ return {
338
+ calendar,
339
+ };
340
+ });
341
+ }
342
+ function assertRanBeforeEach(me) {
343
+ test_1.assert.isTrue(
344
+ //@ts-ignore
345
+ me._didBeforeEach, `You gotta add 'await calendarSkillAssert.beforeEach(...)' to the beforeEach() of your test.`);
346
+ }
@@ -0,0 +1,5 @@
1
+ import { CalendarToolBeltContext, CalendarToolBeltStateMachine } from '../../../types/calendar.types';
2
+ declare const calendarToolBeltInteractor: {
3
+ simulateRandomContextUpdate(stateMachine: CalendarToolBeltStateMachine): Promise<CalendarToolBeltContext>;
4
+ };
5
+ export default calendarToolBeltInteractor;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
4
+ const calendarToolBeltInteractor = {
5
+ async simulateRandomContextUpdate(stateMachine) {
6
+ const context = Object.assign(Object.assign({}, stateMachine.getContext()), { event: Object.assign({}, heartwood_view_controllers_1.calendarSeeder.generateEventValues()) });
7
+ await stateMachine.updateContext(context);
8
+ return context;
9
+ },
10
+ };
11
+ exports.default = calendarToolBeltInteractor;