@sprucelabs/spruce-conversation-plugin 62.2.23 → 62.2.25

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 (137) hide show
  1. package/package.json +17 -17
  2. package/build/__tests__/behavioral/CheckingHealth.test.d.ts +0 -10
  3. package/build/__tests__/behavioral/CheckingHealth.test.js +0 -87
  4. package/build/__tests__/behavioral/KillingASkill.test.d.ts +0 -4
  5. package/build/__tests__/behavioral/KillingASkill.test.js +0 -29
  6. package/build/__tests__/behavioral/RegisteringConversationsOnBoot.test.d.ts +0 -13
  7. package/build/__tests__/behavioral/RegisteringConversationsOnBoot.test.js +0 -147
  8. package/build/__tests__/behavioral/RespondingToMessages.test.d.ts +0 -13
  9. package/build/__tests__/behavioral/RespondingToMessages.test.js +0 -134
  10. package/build/__tests__/behavioral/TestingAConversation.test.d.ts +0 -14
  11. package/build/__tests__/behavioral/TestingAConversation.test.js +0 -110
  12. package/build/__tests__/implementation/ConversationCoordinator.test.d.ts +0 -18
  13. package/build/__tests__/implementation/ConversationCoordinator.test.js +0 -185
  14. package/build/__tests__/implementation/MessageGraphicsInterface/EmailField.test.d.ts +0 -7
  15. package/build/__tests__/implementation/MessageGraphicsInterface/EmailField.test.js +0 -73
  16. package/build/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.d.ts +0 -4
  17. package/build/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.js +0 -42
  18. package/build/__tests__/implementation/MessageGraphicsInterface/MockMessageBeforeAndAfterEach.test.d.ts +0 -5
  19. package/build/__tests__/implementation/MessageGraphicsInterface/MockMessageBeforeAndAfterEach.test.js +0 -62
  20. package/build/__tests__/implementation/MessageGraphicsInterface/MockMessageInterface.test.d.ts +0 -18
  21. package/build/__tests__/implementation/MessageGraphicsInterface/MockMessageInterface.test.js +0 -168
  22. package/build/__tests__/implementation/MessageGraphicsInterface/SelectField.test.d.ts +0 -7
  23. package/build/__tests__/implementation/MessageGraphicsInterface/SelectField.test.js +0 -71
  24. package/build/__tests__/implementation/MessageGraphicsInterface/TextField.test.d.ts +0 -6
  25. package/build/__tests__/implementation/MessageGraphicsInterface/TextField.test.js +0 -48
  26. package/build/__tests__/implementation/ScriptTester.test.d.ts +0 -19
  27. package/build/__tests__/implementation/ScriptTester.test.js +0 -461
  28. package/build/__tests__/implementation/SuggesterUtil.test.d.ts +0 -7
  29. package/build/__tests__/implementation/SuggesterUtil.test.js +0 -63
  30. package/build/__tests__/implementation/TopicLoader.test.d.ts +0 -8
  31. package/build/__tests__/implementation/TopicLoader.test.js +0 -66
  32. package/build/__tests__/implementation/TopicScriptPlayer.test.d.ts +0 -23
  33. package/build/__tests__/implementation/TopicScriptPlayer.test.js +0 -436
  34. package/build/__tests__/implementation/TopicSuggester.test.d.ts +0 -8
  35. package/build/__tests__/implementation/TopicSuggester.test.js +0 -137
  36. package/build/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.d.ts +0 -0
  37. package/build/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.js +0 -1
  38. package/build/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.d.ts +0 -2
  39. package/build/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.js +0 -4
  40. package/build/__tests__/testDirsAndFiles/bad-skill/build/.spruce/events/listeners.d.ts +0 -2
  41. package/build/__tests__/testDirsAndFiles/bad-skill/build/.spruce/events/listeners.js +0 -3
  42. package/build/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.d.ts +0 -2
  43. package/build/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.js +0 -4
  44. package/build/__tests__/testDirsAndFiles/empty-skill/build/.spruce/events/listeners.d.ts +0 -2
  45. package/build/__tests__/testDirsAndFiles/empty-skill/build/.spruce/events/listeners.js +0 -3
  46. package/build/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.d.ts +0 -3
  47. package/build/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.js +0 -8
  48. package/build/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.d.ts +0 -3
  49. package/build/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.js +0 -12
  50. package/build/__tests__/testDirsAndFiles/skill/build/.spruce/events/listeners.d.ts +0 -2
  51. package/build/__tests__/testDirsAndFiles/skill/build/.spruce/events/listeners.js +0 -3
  52. package/build/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.d.ts +0 -3
  53. package/build/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.js +0 -8
  54. package/build/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.d.ts +0 -3
  55. package/build/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js +0 -12
  56. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.d.ts +0 -3
  57. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js +0 -21
  58. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.d.ts +0 -3
  59. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.js +0 -21
  60. package/build/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.d.ts +0 -3
  61. package/build/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.js +0 -29
  62. package/build/__tests__/testDirsAndFiles/skill-assertions/build/.spruce/events/listeners.d.ts +0 -2
  63. package/build/__tests__/testDirsAndFiles/skill-assertions/build/.spruce/events/listeners.js +0 -3
  64. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.d.ts +0 -3
  65. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.js +0 -22
  66. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.d.ts +0 -3
  67. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.js +0 -14
  68. package/build/__tests__/testDirsAndFiles/skill-with-one-topic/build/.spruce/events/listeners.d.ts +0 -2
  69. package/build/__tests__/testDirsAndFiles/skill-with-one-topic/build/.spruce/events/listeners.js +0 -3
  70. package/build/__tests__/testDirsAndFiles/skill-with-one-topic/build/conversations/bookAppointment.topic.d.ts +0 -3
  71. package/build/__tests__/testDirsAndFiles/skill-with-one-topic/build/conversations/bookAppointment.topic.js +0 -8
  72. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/.spruce/events/listeners.d.ts +0 -2
  73. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/.spruce/events/listeners.js +0 -3
  74. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.d.ts +0 -3
  75. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.js +0 -16
  76. package/build/esm/__tests__/behavioral/CheckingHealth.test.d.ts +0 -10
  77. package/build/esm/__tests__/behavioral/CheckingHealth.test.js +0 -104
  78. package/build/esm/__tests__/behavioral/KillingASkill.test.d.ts +0 -4
  79. package/build/esm/__tests__/behavioral/KillingASkill.test.js +0 -34
  80. package/build/esm/__tests__/behavioral/RegisteringConversationsOnBoot.test.d.ts +0 -13
  81. package/build/esm/__tests__/behavioral/RegisteringConversationsOnBoot.test.js +0 -171
  82. package/build/esm/__tests__/behavioral/RespondingToMessages.test.d.ts +0 -13
  83. package/build/esm/__tests__/behavioral/RespondingToMessages.test.js +0 -158
  84. package/build/esm/__tests__/behavioral/TestingAConversation.test.d.ts +0 -14
  85. package/build/esm/__tests__/behavioral/TestingAConversation.test.js +0 -137
  86. package/build/esm/__tests__/implementation/ConversationCoordinator.test.d.ts +0 -18
  87. package/build/esm/__tests__/implementation/ConversationCoordinator.test.js +0 -214
  88. package/build/esm/__tests__/implementation/MessageGraphicsInterface/EmailField.test.d.ts +0 -7
  89. package/build/esm/__tests__/implementation/MessageGraphicsInterface/EmailField.test.js +0 -84
  90. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.d.ts +0 -4
  91. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.js +0 -47
  92. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MockMessageBeforeAndAfterEach.test.d.ts +0 -5
  93. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MockMessageBeforeAndAfterEach.test.js +0 -47
  94. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MockMessageInterface.test.d.ts +0 -18
  95. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MockMessageInterface.test.js +0 -172
  96. package/build/esm/__tests__/implementation/MessageGraphicsInterface/SelectField.test.d.ts +0 -7
  97. package/build/esm/__tests__/implementation/MessageGraphicsInterface/SelectField.test.js +0 -80
  98. package/build/esm/__tests__/implementation/MessageGraphicsInterface/TextField.test.d.ts +0 -6
  99. package/build/esm/__tests__/implementation/MessageGraphicsInterface/TextField.test.js +0 -57
  100. package/build/esm/__tests__/implementation/ScriptTester.test.d.ts +0 -19
  101. package/build/esm/__tests__/implementation/ScriptTester.test.js +0 -470
  102. package/build/esm/__tests__/implementation/SuggesterUtil.test.d.ts +0 -7
  103. package/build/esm/__tests__/implementation/SuggesterUtil.test.js +0 -74
  104. package/build/esm/__tests__/implementation/TopicLoader.test.d.ts +0 -8
  105. package/build/esm/__tests__/implementation/TopicLoader.test.js +0 -79
  106. package/build/esm/__tests__/implementation/TopicScriptPlayer.test.d.ts +0 -23
  107. package/build/esm/__tests__/implementation/TopicScriptPlayer.test.js +0 -477
  108. package/build/esm/__tests__/implementation/TopicSuggester.test.d.ts +0 -8
  109. package/build/esm/__tests__/implementation/TopicSuggester.test.js +0 -130
  110. package/build/esm/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.d.ts +0 -0
  111. package/build/esm/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.js +0 -1
  112. package/build/esm/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.d.ts +0 -2
  113. package/build/esm/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.js +0 -2
  114. package/build/esm/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.d.ts +0 -2
  115. package/build/esm/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.js +0 -2
  116. package/build/esm/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.d.ts +0 -3
  117. package/build/esm/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.js +0 -6
  118. package/build/esm/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.d.ts +0 -3
  119. package/build/esm/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.js +0 -10
  120. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.d.ts +0 -3
  121. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.js +0 -6
  122. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.d.ts +0 -3
  123. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js +0 -10
  124. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.d.ts +0 -3
  125. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js +0 -28
  126. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.d.ts +0 -3
  127. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.js +0 -28
  128. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.d.ts +0 -3
  129. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.js +0 -36
  130. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.d.ts +0 -3
  131. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.js +0 -29
  132. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.d.ts +0 -3
  133. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.js +0 -21
  134. package/build/esm/__tests__/testDirsAndFiles/skill-with-one-topic/build/conversations/bookAppointment.topic.d.ts +0 -3
  135. package/build/esm/__tests__/testDirsAndFiles/skill-with-one-topic/build/conversations/bookAppointment.topic.js +0 -6
  136. package/build/esm/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.d.ts +0 -3
  137. package/build/esm/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.js +0 -14
@@ -1,158 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import { eventResponseUtil } from '@sprucelabs/spruce-event-utils';
17
- import { MercuryFixture } from '@sprucelabs/spruce-test-fixtures';
18
- import { test, assert } from '@sprucelabs/test-utils';
19
- import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
20
- MercuryFixture.setShouldRequireLocalListeners(false);
21
- export default class RespondingToMessagesTest extends AbstractConversationTest {
22
- static beforeEach() {
23
- const _super = Object.create(null, {
24
- beforeEach: { get: () => super.beforeEach }
25
- });
26
- return __awaiter(this, void 0, void 0, function* () {
27
- yield _super.beforeEach.call(this);
28
- //@ts-ignore
29
- this.client = undefined;
30
- });
31
- }
32
- static respondsToFirstMessageWithSuggestedTopics() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- this.cwd = this.resolveTestPath('skill');
35
- const results = yield this.sendMessage();
36
- const { suggestedTopics } = eventResponseUtil.getFirstResponseOrThrow(results);
37
- assert.isArray(suggestedTopics);
38
- assert.isLength(suggestedTopics, 1);
39
- });
40
- }
41
- static scriptSendsMessages() {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- this.cwd = this.resolveTestPath('skill');
44
- const sentMessages = [];
45
- yield this.boot();
46
- yield this.client.on('send-message::v2020_12_25', (targetAndPayload) => __awaiter(this, void 0, void 0, function* () {
47
- const { payload } = targetAndPayload;
48
- sentMessages.push(payload.message);
49
- return { message: payload.message };
50
- }));
51
- yield this.sendMessage({ topic: 'bookAppointment' });
52
- assert.isLength(sentMessages, 2);
53
- });
54
- }
55
- static scriptCallbacksCanRespondToEventWithTransitionAndRepairs() {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- this.cwd = this.resolveTestPath('skill');
58
- yield this.sendMessage({
59
- topic: 'favoriteColor',
60
- message: { body: 'favorite color' },
61
- });
62
- const results = yield this.sendMessage({
63
- topic: 'favoriteColor',
64
- message: { body: 'blue' },
65
- });
66
- const { transitionConversationTo, repairs } = eventResponseUtil.getFirstResponseOrThrow(results);
67
- assert.isEqual(transitionConversationTo, 'discovery');
68
- assert.isEqualDeep(repairs, ['go', 'team']);
69
- });
70
- }
71
- static scriptCallbacksCanRespondToEventWithTransitionAndTopicChangers() {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- this.cwd = this.resolveTestPath('skill');
74
- yield this.sendMessage({
75
- topic: 'favoriteColorTopicChanger',
76
- message: { body: 'favorite color' },
77
- });
78
- const results = yield this.sendMessage({
79
- topic: 'favoriteColorTopicChanger',
80
- message: { body: 'blue' },
81
- });
82
- const { transitionConversationTo, topicChangers } = eventResponseUtil.getFirstResponseOrThrow(results);
83
- assert.isEqual(transitionConversationTo, 'discovery');
84
- assert.isEqualDeep(topicChangers, ['now', 'this']);
85
- });
86
- }
87
- static scriptCallbackGetsRandAndMessage() {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- this.cwd = this.resolveTestPath('skill-assertions');
90
- const results = yield this.sendMessage({
91
- topic: 'assertsScriptCallbackOptions',
92
- message: { body: 'hello' },
93
- });
94
- eventResponseUtil.getFirstResponseOrThrow(results);
95
- });
96
- }
97
- static eachPersonGetsTheirOwnConversation() {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- this.cwd = this.resolveTestPath('skill-assertions');
100
- yield this.sendMessage({
101
- topic: 'assertsScriptOnlyCalledOnce',
102
- message: { body: 'hey hey', source: { personId: '234234234' } },
103
- });
104
- yield this.sendMessage({
105
- topic: 'assertsScriptOnlyCalledOnce',
106
- message: { body: 'hey hey', source: { personId: '234234' } },
107
- });
108
- yield this.sendMessage({
109
- topic: 'assertsScriptOnlyCalledOnce',
110
- message: { body: 'hey hey', source: { personId: '323' } },
111
- });
112
- });
113
- }
114
- static sendMessage(options) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const client = yield this.boot();
117
- const results = yield client.emit('did-message::v2020_12_25', {
118
- target: {},
119
- payload: Object.assign(Object.assign({}, options), { message: this.buildMessage(Object.assign({ body: 'I wanna book an appointment!', source: {
120
- isCore: null,
121
- personId: '12345',
122
- } }, options === null || options === void 0 ? void 0 : options.message)) }),
123
- });
124
- return results;
125
- });
126
- }
127
- static boot() {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- if (!this.client) {
130
- const { skill } = yield this.bootAndRegisterNewSkill({
131
- name: 'my skill yo',
132
- });
133
- const events = skill.getFeatureByCode('event');
134
- const client = yield events.connectToApi();
135
- this.client = client;
136
- }
137
- return this.client;
138
- });
139
- }
140
- }
141
- __decorate([
142
- test()
143
- ], RespondingToMessagesTest, "respondsToFirstMessageWithSuggestedTopics", null);
144
- __decorate([
145
- test()
146
- ], RespondingToMessagesTest, "scriptSendsMessages", null);
147
- __decorate([
148
- test()
149
- ], RespondingToMessagesTest, "scriptCallbacksCanRespondToEventWithTransitionAndRepairs", null);
150
- __decorate([
151
- test()
152
- ], RespondingToMessagesTest, "scriptCallbacksCanRespondToEventWithTransitionAndTopicChangers", null);
153
- __decorate([
154
- test()
155
- ], RespondingToMessagesTest, "scriptCallbackGetsRandAndMessage", null);
156
- __decorate([
157
- test()
158
- ], RespondingToMessagesTest, "eachPersonGetsTheirOwnConversation", null);
@@ -1,14 +0,0 @@
1
- import { SkillContext } from '@sprucelabs/spruce-skill-utils';
2
- import AbstractConversationTest from '../../tests/AbstractConversationTest';
3
- export default class TestingAConversationTest extends AbstractConversationTest {
4
- protected static afterEach(): Promise<void>;
5
- protected static afterAll(): Promise<void>;
6
- protected static bootingNormallyDoesNotGoToTestMode(): Promise<void>;
7
- protected static bootsInTestModeWithProperAction(): Promise<void>;
8
- protected static throwsWithBadScript(): Promise<void>;
9
- protected static throwsWithThrowsInScript(): Promise<void>;
10
- protected static scriptTesterGetsContext(context: SkillContext): Promise<void>;
11
- private static getScriptTester;
12
- private static bootAndGetConversationFeature;
13
- private static getConversationFeature;
14
- }
@@ -1,137 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import { MercuryClientFactory } from '@sprucelabs/mercury-client';
17
- import { test, assert } from '@sprucelabs/test-utils';
18
- import { errorAssert } from '@sprucelabs/test-utils';
19
- import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
20
- export default class TestingAConversationTest extends AbstractConversationTest {
21
- static afterEach() {
22
- const _super = Object.create(null, {
23
- afterEach: { get: () => super.afterEach }
24
- });
25
- return __awaiter(this, void 0, void 0, function* () {
26
- yield _super.afterEach.call(this);
27
- process.env.ACTION = undefined;
28
- });
29
- }
30
- static afterAll() {
31
- const _super = Object.create(null, {
32
- afterAll: { get: () => super.afterAll }
33
- });
34
- return __awaiter(this, void 0, void 0, function* () {
35
- yield _super.afterAll.call(this);
36
- process.env.ACTION = undefined;
37
- });
38
- }
39
- static bootingNormallyDoesNotGoToTestMode() {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- this.cwd = this.resolveTestPath('empty-skill');
42
- const conversation = yield this.bootAndGetConversationFeature({
43
- shouldSuppressBootErrors: true,
44
- });
45
- assert.isFalse(conversation.isTesting());
46
- this.clearSkillBootErrors();
47
- });
48
- }
49
- static bootsInTestModeWithProperAction() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- process.env.ACTION = 'test.conversation';
52
- const conversation = yield this.bootAndGetConversationFeature();
53
- assert.isTrue(conversation.isTesting());
54
- });
55
- }
56
- static throwsWithBadScript() {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- this.cwd = this.resolveTestPath('bad-skill');
59
- process.env.ACTION = 'test.conversation';
60
- const skill = yield this.Skill();
61
- const err = yield assert.doesThrowAsync(() => skill.execute());
62
- errorAssert.assertError(err, 'INVALID_TOPIC');
63
- });
64
- }
65
- static throwsWithThrowsInScript() {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- this.cwd = this.resolveTestPath('skill-with-script-that-throws');
68
- process.env.ACTION = 'test.conversation';
69
- process.env.FIRST_MESSAGE = 'hey there!';
70
- const skill = yield this.Skill();
71
- const err = yield assert.doesThrowAsync(() => skill.execute());
72
- errorAssert.assertError(err, 'CONVERSATION_ABORTED');
73
- });
74
- }
75
- static scriptTesterGetsContext(context) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- this.cwd = this.resolveTestPath('skill-with-one-topic');
78
- MercuryClientFactory.setIsTestMode(true);
79
- process.env.ACTION = 'test.conversation';
80
- process.env.FIRST_MESSAGE = 'hey there!';
81
- const skill = yield this.Skill();
82
- const getContext = () => context;
83
- //@ts-ignore
84
- skill.getContext = getContext;
85
- void this.bootSkill({ skill });
86
- yield this.wait(100);
87
- const scriptTester = yield this.getScriptTester(skill);
88
- //@ts-ignore
89
- scriptTester.writeHandler = () => { };
90
- //@ts-ignore
91
- const player = scriptTester.player;
92
- assert.isTruthy(player);
93
- //@ts-ignore
94
- assert.isEqualDeep(player.getContext(), context);
95
- yield skill.kill();
96
- });
97
- }
98
- static getScriptTester(skill) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const conversation = this.getConversationFeature(skill);
101
- //@ts-ignore
102
- while (!conversation.tester) {
103
- yield this.wait(100);
104
- }
105
- //@ts-ignore
106
- const scriptTester = conversation.tester;
107
- assert.isTruthy(scriptTester);
108
- return scriptTester;
109
- });
110
- }
111
- static bootAndGetConversationFeature(options) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- const { skill } = yield this.bootSkill(options);
114
- const conversation = this.getConversationFeature(skill);
115
- return conversation;
116
- });
117
- }
118
- static getConversationFeature(skill) {
119
- return skill.getFeatureByCode('conversation');
120
- }
121
- }
122
- __decorate([
123
- test()
124
- ], TestingAConversationTest, "bootingNormallyDoesNotGoToTestMode", null);
125
- __decorate([
126
- test()
127
- ], TestingAConversationTest, "bootsInTestModeWithProperAction", null);
128
- __decorate([
129
- test()
130
- ], TestingAConversationTest, "throwsWithBadScript", null);
131
- __decorate([
132
- test()
133
- ], TestingAConversationTest, "throwsWithThrowsInScript", null);
134
- __decorate([
135
- test('can get context 1', { hello: 'world' }),
136
- test('can get context 2', { what: 'the!?' })
137
- ], TestingAConversationTest, "scriptTesterGetsContext", null);
@@ -1,18 +0,0 @@
1
- import { SkillContext } from '@sprucelabs/spruce-skill-utils';
2
- import AbstractConversationTest from '../../tests/AbstractConversationTest';
3
- export default class TopicCoordinatorTest extends AbstractConversationTest {
4
- private static coordinator;
5
- private static sentMessages;
6
- private static skillContext;
7
- protected static beforeEach(): Promise<void>;
8
- protected static canCreateTopicCoordinator(): Promise<void>;
9
- protected static hasHandleMessage(): Promise<void>;
10
- protected static handledMessageMustHaveASource(): Promise<void>;
11
- protected static respondsWithSuggestedTopicsToFirstMessage(): Promise<void>;
12
- protected static handlesNoSkillWithTopics(): Promise<void>;
13
- protected static throwsWhenSentBadTopic(): Promise<void>;
14
- protected static playsScriptWhenTopicIsSelected(): Promise<void>;
15
- protected static canHandlePromptsInScript(): Promise<void>;
16
- protected static canPlaceMixedScriptsUntilTheEndAndStartsOver(): Promise<void>;
17
- protected static passesThroughContextGetter(context: SkillContext): Promise<void>;
18
- }
@@ -1,214 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import { fake } from '@sprucelabs/spruce-test-fixtures';
17
- import { test, assert } from '@sprucelabs/test-utils';
18
- import { errorAssert } from '@sprucelabs/test-utils';
19
- import { ConversationCoordinator } from '../../conversations/ConversationCoordinator.js';
20
- import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
21
- class TopicCoordinatorTest extends AbstractConversationTest {
22
- static beforeEach() {
23
- const _super = Object.create(null, {
24
- beforeEach: { get: () => super.beforeEach }
25
- });
26
- return __awaiter(this, void 0, void 0, function* () {
27
- yield _super.beforeEach.call(this);
28
- this.sentMessages = [];
29
- this.coordinator = (yield ConversationCoordinator.Coordinator({
30
- lineDelay: 0,
31
- sendMessageHandler: (message) => __awaiter(this, void 0, void 0, function* () {
32
- this.sentMessages.push(message);
33
- }),
34
- topicLookupPath: this.resolveTestPath('skill', 'build'),
35
- getContext: () => this.skillContext,
36
- Class: SpyCoordinator,
37
- }));
38
- });
39
- }
40
- static canCreateTopicCoordinator() {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- assert.isTruthy(this.coordinator);
43
- });
44
- }
45
- static hasHandleMessage() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- assert.isFunction(this.coordinator.handleMessage);
48
- });
49
- }
50
- static handledMessageMustHaveASource() {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const err = yield assert.doesThrowAsync(() => this.coordinator.handleMessage(this.buildMessage({ body: 'waka waka' })));
53
- errorAssert.assertError(err, 'MISSING_PARAMETERS', {
54
- parameters: ['source.personId'],
55
- });
56
- });
57
- }
58
- static respondsWithSuggestedTopicsToFirstMessage() {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const results = yield this.coordinator.handleMessage(this.buildMessage({
61
- body: 'help me book!',
62
- source: { personId: '1234' },
63
- }));
64
- assert.isArray(results.suggestedTopics);
65
- assert.isLength(results.suggestedTopics, 3);
66
- });
67
- }
68
- static handlesNoSkillWithTopics() {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const coordinator = yield ConversationCoordinator.Coordinator({
71
- topicLookupPath: this.cwd,
72
- sendMessageHandler: () => __awaiter(this, void 0, void 0, function* () { }),
73
- getContext: () => this.skillContext,
74
- });
75
- const results = yield coordinator.handleMessage(this.buildMessage({
76
- body: 'help me book!',
77
- source: { personId: '1234' },
78
- }));
79
- assert.isArray(results.suggestedTopics);
80
- assert.isLength(results.suggestedTopics, 0);
81
- });
82
- }
83
- static throwsWhenSentBadTopic() {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- const err = yield assert.doesThrowAsync(() => this.coordinator.handleMessage(this.buildMessage({ body: '1', source: { personId: '1234' } }), 'aoeu'));
86
- errorAssert.assertError(err, 'TOPIC_NOT_FOUND', {
87
- suppliedTopic: 'aoeu',
88
- validTopics: [
89
- 'bookAppointment',
90
- 'cancelAppointment',
91
- 'favoriteColor',
92
- 'favoriteColorTopicChanger',
93
- 'mixedStringsAndCallbacks',
94
- ],
95
- });
96
- });
97
- }
98
- static playsScriptWhenTopicIsSelected() {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- yield this.coordinator.handleMessage(this.buildMessage({ body: '1', source: { personId: '1234' } }), 'bookAppointment');
101
- assert.isLength(this.sentMessages, 2);
102
- assert.isEqual(this.sentMessages[0].body, 'Sweet, lets book!');
103
- });
104
- }
105
- static canHandlePromptsInScript() {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- var _a;
108
- void this.coordinator.handleMessage(this.buildMessage({ body: '1', source: { personId: '1234' } }), 'favoriteColor');
109
- yield this.wait(10);
110
- assert.isLength(this.sentMessages, 1);
111
- assert.isEqual(this.sentMessages[0].body, 'what is your favorite color?');
112
- void this.coordinator.handleMessage(this.buildMessage({ body: 'blue', source: { personId: '1234' } }), 'favoriteColor');
113
- yield this.wait(10);
114
- assert.isLength(this.sentMessages, 2);
115
- assert.isEqual(this.sentMessages[this.sentMessages.length - 1].body, 'blue');
116
- void this.coordinator.handleMessage(this.buildMessage({ body: 'blue', source: { personId: '1234' } }), 'bookAppointment');
117
- yield this.wait(10);
118
- assert.isLength(this.sentMessages, 4);
119
- assert.isEqual((_a = this.sentMessages.pop()) === null || _a === void 0 ? void 0 : _a.body, 'Lemme find your appointment!');
120
- });
121
- }
122
- static canPlaceMixedScriptsUntilTheEndAndStartsOver() {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
125
- yield this.coordinator.handleMessage(this.buildMessage({ body: '1', source: { personId: '1234' } }), 'mixedStringsAndCallbacks');
126
- yield this.wait(10);
127
- assert.isLength(this.sentMessages, 2);
128
- assert.isEqual((_a = this.sentMessages[0]) === null || _a === void 0 ? void 0 : _a.body, 'string 1');
129
- assert.isEqual((_b = this.sentMessages[1]) === null || _b === void 0 ? void 0 : _b.body, 'prompt 1');
130
- this.sentMessages = [];
131
- yield this.coordinator.handleMessage(this.buildMessage({
132
- body: 'answer 1',
133
- source: { personId: '1234' },
134
- }), 'mixedStringsAndCallbacks');
135
- yield this.wait(100);
136
- assert.isLength(this.sentMessages, 3);
137
- assert.isEqual((_c = this.sentMessages[0]) === null || _c === void 0 ? void 0 : _c.body, 'answer 1');
138
- assert.isEqual((_d = this.sentMessages[1]) === null || _d === void 0 ? void 0 : _d.body, 'string 2');
139
- assert.isEqual((_e = this.sentMessages[2]) === null || _e === void 0 ? void 0 : _e.body, 'prompt 2');
140
- this.sentMessages = [];
141
- yield this.coordinator.handleMessage(this.buildMessage({
142
- body: 'answer 2',
143
- source: { personId: '1234' },
144
- }), 'mixedStringsAndCallbacks');
145
- assert.isLength(this.sentMessages, 2);
146
- assert.isEqual((_f = this.sentMessages[0]) === null || _f === void 0 ? void 0 : _f.body, 'answer 2');
147
- assert.isEqual((_g = this.sentMessages[1]) === null || _g === void 0 ? void 0 : _g.body, 'and done');
148
- this.sentMessages = [];
149
- yield this.coordinator.handleMessage(this.buildMessage({
150
- body: 'answer 1',
151
- source: { personId: '1234' },
152
- }), 'mixedStringsAndCallbacks');
153
- yield this.wait(100);
154
- assert.isLength(this.sentMessages, 2);
155
- assert.isEqual((_h = this.sentMessages[0]) === null || _h === void 0 ? void 0 : _h.body, 'string 1');
156
- assert.isEqual((_j = this.sentMessages[1]) === null || _j === void 0 ? void 0 : _j.body, 'prompt 1');
157
- });
158
- }
159
- static passesThroughContextGetter(context) {
160
- return __awaiter(this, void 0, void 0, function* () {
161
- yield this.coordinator.handleMessage(this.buildMessage({
162
- body: 'answer 2',
163
- source: { personId: '1234' },
164
- }), 'bookAppointment');
165
- this.skillContext = context;
166
- const player = this.coordinator.getPlayer();
167
- assert.isTruthy(player);
168
- //@ts-ignore
169
- const actual = player.getContext();
170
- assert.isEqualDeep(actual, this.skillContext);
171
- });
172
- }
173
- }
174
- TopicCoordinatorTest.sentMessages = [];
175
- TopicCoordinatorTest.skillContext = {
176
- client: fake.getClient(),
177
- };
178
- export default TopicCoordinatorTest;
179
- __decorate([
180
- test()
181
- ], TopicCoordinatorTest, "canCreateTopicCoordinator", null);
182
- __decorate([
183
- test()
184
- ], TopicCoordinatorTest, "hasHandleMessage", null);
185
- __decorate([
186
- test()
187
- ], TopicCoordinatorTest, "handledMessageMustHaveASource", null);
188
- __decorate([
189
- test()
190
- ], TopicCoordinatorTest, "respondsWithSuggestedTopicsToFirstMessage", null);
191
- __decorate([
192
- test()
193
- ], TopicCoordinatorTest, "handlesNoSkillWithTopics", null);
194
- __decorate([
195
- test()
196
- ], TopicCoordinatorTest, "throwsWhenSentBadTopic", null);
197
- __decorate([
198
- test()
199
- ], TopicCoordinatorTest, "playsScriptWhenTopicIsSelected", null);
200
- __decorate([
201
- test()
202
- ], TopicCoordinatorTest, "canHandlePromptsInScript", null);
203
- __decorate([
204
- test()
205
- ], TopicCoordinatorTest, "canPlaceMixedScriptsUntilTheEndAndStartsOver", null);
206
- __decorate([
207
- test('can passthrough context 1', { hello: 'world' }),
208
- test('can passthrough context 2', { go: 'team' })
209
- ], TopicCoordinatorTest, "passesThroughContextGetter", null);
210
- class SpyCoordinator extends ConversationCoordinator {
211
- getPlayer() {
212
- return this.player;
213
- }
214
- }
@@ -1,7 +0,0 @@
1
- import AbstractGraphicsInterfaceTest from '../../../tests/AbstractGraphicsInterfaceTest';
2
- export default class TextFieldTest extends AbstractGraphicsInterfaceTest {
3
- protected static promptSendsLabel(): Promise<void>;
4
- protected static noPromptSendsNoMessage(): Promise<void>;
5
- protected static respondingWithBadEmailGivesYouAnotherChance(): Promise<void>;
6
- protected static respondingWithBadEmail2TimesErrors(): Promise<void>;
7
- }
@@ -1,84 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import { test, assert } from '@sprucelabs/test-utils';
17
- import EmailFieldHandler from '../../../interfaces/fieldHandlers/EmailFieldHandler.js';
18
- import AbstractGraphicsInterfaceTest from '../../../tests/AbstractGraphicsInterfaceTest.js';
19
- export default class TextFieldTest extends AbstractGraphicsInterfaceTest {
20
- static promptSendsLabel() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- void this.ui.prompt({
23
- type: 'email',
24
- label: 'Tell me about your life.',
25
- });
26
- assert.doesInclude(this.sentMessages, {
27
- body: 'Tell me about your life.',
28
- });
29
- });
30
- }
31
- static noPromptSendsNoMessage() {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- void this.ui.prompt({
34
- type: 'email',
35
- });
36
- assert.isLength(this.sentMessages, 0);
37
- });
38
- }
39
- static respondingWithBadEmailGivesYouAnotherChance() {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- EmailFieldHandler.repairs = ['repair', 'repair'];
42
- let wasHit = false;
43
- void this.ui
44
- .prompt({
45
- type: 'email',
46
- label: 'What is your email?',
47
- })
48
- .then(() => {
49
- wasHit = true;
50
- });
51
- assert.isLength(this.sentMessages, 1);
52
- assert.doesInclude(this.sentMessages, { body: 'What is your email?' });
53
- yield this.sendMessage('aoeuaoeu');
54
- assert.isLength(this.sentMessages, 2);
55
- assert.doesInclude(this.sentMessages, { body: 'repair' });
56
- assert.isFalse(wasHit);
57
- });
58
- }
59
- static respondingWithBadEmail2TimesErrors() {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- const promise = this.ui.prompt({
62
- type: 'email',
63
- label: 'What is your email?',
64
- });
65
- assert.isLength(this.sentMessages, 1);
66
- assert.doesInclude(this.sentMessages, { body: 'What is your email?' });
67
- yield this.sendMessage('aoeuaoeu');
68
- yield this.sendMessage('aoeuaoeu');
69
- yield assert.doesThrowAsync(() => promise);
70
- });
71
- }
72
- }
73
- __decorate([
74
- test()
75
- ], TextFieldTest, "promptSendsLabel", null);
76
- __decorate([
77
- test()
78
- ], TextFieldTest, "noPromptSendsNoMessage", null);
79
- __decorate([
80
- test()
81
- ], TextFieldTest, "respondingWithBadEmailGivesYouAnotherChance", null);
82
- __decorate([
83
- test()
84
- ], TextFieldTest, "respondingWithBadEmail2TimesErrors", null);
@@ -1,4 +0,0 @@
1
- import AbstractGraphicsInterfaceTest from '../../../tests/AbstractGraphicsInterfaceTest';
2
- export default class MessageGraphicsInterfaceTest extends AbstractGraphicsInterfaceTest {
3
- protected static selectAsksAgainWithBadResponse(): Promise<void>;
4
- }