@sprucelabs/spruce-conversation-plugin 45.2.9 → 46.0.2

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 (123) hide show
  1. package/build/__tests__/behavioral/CheckingHealth.test.d.ts +10 -0
  2. package/build/__tests__/behavioral/CheckingHealth.test.js +87 -0
  3. package/build/__tests__/behavioral/KillingASkill.test.d.ts +4 -0
  4. package/build/__tests__/behavioral/KillingASkill.test.js +27 -0
  5. package/build/__tests__/behavioral/RegisteringConversationsOnBoot.test.d.ts +11 -0
  6. package/build/__tests__/behavioral/RegisteringConversationsOnBoot.test.js +106 -0
  7. package/build/__tests__/behavioral/RespondingToMessages.test.d.ts +13 -0
  8. package/build/__tests__/behavioral/RespondingToMessages.test.js +139 -0
  9. package/build/__tests__/behavioral/TestingAConversation.test.d.ts +10 -0
  10. package/build/__tests__/behavioral/TestingAConversation.test.js +70 -0
  11. package/build/__tests__/implementation/ConversationCoordinator.test.d.ts +15 -0
  12. package/build/__tests__/implementation/ConversationCoordinator.test.js +142 -0
  13. package/build/__tests__/implementation/MessageGraphicsInterface/EmailField.test.d.ts +7 -0
  14. package/build/__tests__/implementation/MessageGraphicsInterface/EmailField.test.js +71 -0
  15. package/build/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.d.ts +4 -0
  16. package/build/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.js +42 -0
  17. package/build/__tests__/implementation/MessageGraphicsInterface/SelectField.test.d.ts +7 -0
  18. package/build/__tests__/implementation/MessageGraphicsInterface/SelectField.test.js +71 -0
  19. package/build/__tests__/implementation/MessageGraphicsInterface/TextField.test.d.ts +6 -0
  20. package/build/__tests__/implementation/MessageGraphicsInterface/TextField.test.js +46 -0
  21. package/build/__tests__/implementation/ScriptTester.test.d.ts +18 -0
  22. package/build/__tests__/implementation/ScriptTester.test.js +459 -0
  23. package/build/__tests__/implementation/SuggesterUtil.test.d.ts +7 -0
  24. package/build/__tests__/implementation/SuggesterUtil.test.js +63 -0
  25. package/build/__tests__/implementation/TopicLoader.test.d.ts +8 -0
  26. package/build/__tests__/implementation/TopicLoader.test.js +66 -0
  27. package/build/__tests__/implementation/TopicScriptPlayer.test.d.ts +21 -0
  28. package/build/__tests__/implementation/TopicScriptPlayer.test.js +413 -0
  29. package/build/__tests__/implementation/TopicSuggester.test.d.ts +8 -0
  30. package/build/__tests__/implementation/TopicSuggester.test.js +131 -0
  31. package/build/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.d.ts +0 -0
  32. package/build/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.js +1 -0
  33. package/build/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.d.ts +2 -0
  34. package/build/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.js +4 -0
  35. package/build/__tests__/testDirsAndFiles/bad-skill/build/.spruce/events/listeners.d.ts +2 -0
  36. package/build/__tests__/testDirsAndFiles/bad-skill/build/.spruce/events/listeners.js +3 -0
  37. package/build/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.d.ts +2 -0
  38. package/build/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.js +4 -0
  39. package/build/__tests__/testDirsAndFiles/empty-skill/build/.spruce/events/listeners.d.ts +2 -0
  40. package/build/__tests__/testDirsAndFiles/empty-skill/build/.spruce/events/listeners.js +3 -0
  41. package/build/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.d.ts +3 -0
  42. package/build/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.js +8 -0
  43. package/build/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.d.ts +3 -0
  44. package/build/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.js +8 -0
  45. package/build/__tests__/testDirsAndFiles/skill/build/.spruce/events/listeners.d.ts +2 -0
  46. package/build/__tests__/testDirsAndFiles/skill/build/.spruce/events/listeners.js +3 -0
  47. package/build/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.d.ts +3 -0
  48. package/build/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.js +8 -0
  49. package/build/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.d.ts +3 -0
  50. package/build/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js +8 -0
  51. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.d.ts +3 -0
  52. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js +18 -0
  53. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.d.ts +3 -0
  54. package/build/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.js +18 -0
  55. package/build/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.d.ts +3 -0
  56. package/build/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.js +29 -0
  57. package/build/__tests__/testDirsAndFiles/skill-assertions/build/.spruce/events/listeners.d.ts +2 -0
  58. package/build/__tests__/testDirsAndFiles/skill-assertions/build/.spruce/events/listeners.js +3 -0
  59. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.d.ts +3 -0
  60. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.js +22 -0
  61. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.d.ts +3 -0
  62. package/build/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.js +14 -0
  63. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/.spruce/events/listeners.d.ts +2 -0
  64. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/.spruce/events/listeners.js +3 -0
  65. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.d.ts +3 -0
  66. package/build/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.js +12 -0
  67. package/build/esm/__tests__/behavioral/CheckingHealth.test.d.ts +10 -0
  68. package/build/esm/__tests__/behavioral/CheckingHealth.test.js +104 -0
  69. package/build/esm/__tests__/behavioral/KillingASkill.test.d.ts +4 -0
  70. package/build/esm/__tests__/behavioral/KillingASkill.test.js +32 -0
  71. package/build/esm/__tests__/behavioral/RegisteringConversationsOnBoot.test.d.ts +11 -0
  72. package/build/esm/__tests__/behavioral/RegisteringConversationsOnBoot.test.js +126 -0
  73. package/build/esm/__tests__/behavioral/RespondingToMessages.test.d.ts +13 -0
  74. package/build/esm/__tests__/behavioral/RespondingToMessages.test.js +156 -0
  75. package/build/esm/__tests__/behavioral/TestingAConversation.test.d.ts +10 -0
  76. package/build/esm/__tests__/behavioral/TestingAConversation.test.js +93 -0
  77. package/build/esm/__tests__/implementation/ConversationCoordinator.test.d.ts +15 -0
  78. package/build/esm/__tests__/implementation/ConversationCoordinator.test.js +168 -0
  79. package/build/esm/__tests__/implementation/MessageGraphicsInterface/EmailField.test.d.ts +7 -0
  80. package/build/esm/__tests__/implementation/MessageGraphicsInterface/EmailField.test.js +82 -0
  81. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.d.ts +4 -0
  82. package/build/esm/__tests__/implementation/MessageGraphicsInterface/MessageGraphicsInterface.test.js +47 -0
  83. package/build/esm/__tests__/implementation/MessageGraphicsInterface/SelectField.test.d.ts +7 -0
  84. package/build/esm/__tests__/implementation/MessageGraphicsInterface/SelectField.test.js +80 -0
  85. package/build/esm/__tests__/implementation/MessageGraphicsInterface/TextField.test.d.ts +6 -0
  86. package/build/esm/__tests__/implementation/MessageGraphicsInterface/TextField.test.js +55 -0
  87. package/build/esm/__tests__/implementation/ScriptTester.test.d.ts +18 -0
  88. package/build/esm/__tests__/implementation/ScriptTester.test.js +465 -0
  89. package/build/esm/__tests__/implementation/SuggesterUtil.test.d.ts +7 -0
  90. package/build/esm/__tests__/implementation/SuggesterUtil.test.js +74 -0
  91. package/build/esm/__tests__/implementation/TopicLoader.test.d.ts +8 -0
  92. package/build/esm/__tests__/implementation/TopicLoader.test.js +79 -0
  93. package/build/esm/__tests__/implementation/TopicScriptPlayer.test.d.ts +21 -0
  94. package/build/esm/__tests__/implementation/TopicScriptPlayer.test.js +452 -0
  95. package/build/esm/__tests__/implementation/TopicSuggester.test.d.ts +8 -0
  96. package/build/esm/__tests__/implementation/TopicSuggester.test.js +124 -0
  97. package/build/esm/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.d.ts +0 -0
  98. package/build/esm/__tests__/testDirsAndFiles/bad-empty/conversations/bookAppointment.topic.js +1 -0
  99. package/build/esm/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.d.ts +2 -0
  100. package/build/esm/__tests__/testDirsAndFiles/bad-missing-params/conversations/bookAppointment.topic.js +2 -0
  101. package/build/esm/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.d.ts +2 -0
  102. package/build/esm/__tests__/testDirsAndFiles/bad-skill/build/conversations/bookAppointment.topic.js +2 -0
  103. package/build/esm/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.d.ts +3 -0
  104. package/build/esm/__tests__/testDirsAndFiles/good/conversations/bookAppointment.topic.js +6 -0
  105. package/build/esm/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.d.ts +3 -0
  106. package/build/esm/__tests__/testDirsAndFiles/good/conversations/cancelAppointment.topic.js +6 -0
  107. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.d.ts +3 -0
  108. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/bookAppointment.topic.js +6 -0
  109. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.d.ts +3 -0
  110. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/cancelAppointment.topic.js +6 -0
  111. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.d.ts +3 -0
  112. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColor.topic.js +25 -0
  113. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.d.ts +3 -0
  114. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/favoriteColorTopicChanger.topic.js +25 -0
  115. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.d.ts +3 -0
  116. package/build/esm/__tests__/testDirsAndFiles/skill/build/conversations/mixedStringsAndCallbacks.topic.js +36 -0
  117. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.d.ts +3 -0
  118. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptCallbackOptions.topic.js +29 -0
  119. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.d.ts +3 -0
  120. package/build/esm/__tests__/testDirsAndFiles/skill-assertions/build/conversations/assertsScriptOnlyCalledOnce.topic.js +21 -0
  121. package/build/esm/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.d.ts +3 -0
  122. package/build/esm/__tests__/testDirsAndFiles/skill-with-script-that-throws/build/conversations/cancelAppointment.topic.js +10 -0
  123. package/package.json +17 -17
@@ -0,0 +1,93 @@
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';
17
+ import { errorAssert } from '@sprucelabs/test-utils';
18
+ import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
19
+ export default class TestingAConversationTest extends AbstractConversationTest {
20
+ static afterEach() {
21
+ const _super = Object.create(null, {
22
+ afterEach: { get: () => super.afterEach }
23
+ });
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ yield _super.afterEach.call(this);
26
+ process.env.ACTION = undefined;
27
+ });
28
+ }
29
+ static afterAll() {
30
+ const _super = Object.create(null, {
31
+ afterAll: { get: () => super.afterAll }
32
+ });
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ yield _super.afterAll.call(this);
35
+ process.env.ACTION = undefined;
36
+ });
37
+ }
38
+ static bootingNormallyDoesNotGoToTestMode() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ this.cwd = this.resolveTestPath('empty-skill');
41
+ const conversation = yield this.bootAndGetConversationFeature({
42
+ shouldSuppressBootErrors: true,
43
+ });
44
+ assert.isFalse(conversation.isTesting());
45
+ this.clearSkillBootErrors();
46
+ });
47
+ }
48
+ static bootsInTestModeWithProperAction() {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ process.env.ACTION = 'test.conversation';
51
+ const conversation = yield this.bootAndGetConversationFeature();
52
+ assert.isTrue(conversation.isTesting());
53
+ });
54
+ }
55
+ static throwsWithBadScript() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ this.cwd = this.resolveTestPath('bad-skill');
58
+ process.env.ACTION = 'test.conversation';
59
+ const skill = yield this.Skill();
60
+ const err = yield assert.doesThrowAsync(() => skill.execute());
61
+ errorAssert.assertError(err, 'INVALID_TOPIC');
62
+ });
63
+ }
64
+ static throwsWithThrowsInScript() {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ this.cwd = this.resolveTestPath('skill-with-script-that-throws');
67
+ process.env.ACTION = 'test.conversation';
68
+ process.env.FIRST_MESSAGE = 'hey there!';
69
+ const skill = yield this.Skill();
70
+ const err = yield assert.doesThrowAsync(() => skill.execute());
71
+ errorAssert.assertError(err, 'CONVERSATION_ABORTED');
72
+ });
73
+ }
74
+ static bootAndGetConversationFeature(options) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const { skill } = yield this.bootSkill(options);
77
+ const conversation = skill.getFeatureByCode('conversation');
78
+ return conversation;
79
+ });
80
+ }
81
+ }
82
+ __decorate([
83
+ test()
84
+ ], TestingAConversationTest, "bootingNormallyDoesNotGoToTestMode", null);
85
+ __decorate([
86
+ test()
87
+ ], TestingAConversationTest, "bootsInTestModeWithProperAction", null);
88
+ __decorate([
89
+ test()
90
+ ], TestingAConversationTest, "throwsWithBadScript", null);
91
+ __decorate([
92
+ test()
93
+ ], TestingAConversationTest, "throwsWithThrowsInScript", null);
@@ -0,0 +1,15 @@
1
+ import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
+ export default class TopicCoordinatorTest extends AbstractConversationTest {
3
+ private static coordinator;
4
+ private static sentMessages;
5
+ protected static beforeEach(): Promise<void>;
6
+ protected static canCreateTopicCoordinator(): Promise<void>;
7
+ protected static hasHandleMessage(): Promise<void>;
8
+ protected static handledMessageMustHaveASource(): Promise<void>;
9
+ protected static respondsWithSuggestedTopicsToFirstMessage(): Promise<void>;
10
+ protected static handlesNoSkillWithTopics(): Promise<void>;
11
+ protected static throwsWhenSentBadTopic(): Promise<void>;
12
+ protected static playsScriptWhenTopicIsSelected(): Promise<void>;
13
+ protected static canHandlePromptsInScript(): Promise<void>;
14
+ protected static canPlaceMixedScriptsUntilTheEndAndStartsOver(): Promise<void>;
15
+ }
@@ -0,0 +1,168 @@
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';
17
+ import { errorAssert } from '@sprucelabs/test-utils';
18
+ import { ConversationCoordinator } from '../../conversations/ConversationCoordinator.js';
19
+ import AbstractConversationTest from '../../tests/AbstractConversationTest.js';
20
+ export default class TopicCoordinatorTest extends AbstractConversationTest {
21
+ static beforeEach() {
22
+ const _super = Object.create(null, {
23
+ beforeEach: { get: () => super.beforeEach }
24
+ });
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ yield _super.beforeEach.call(this);
27
+ this.sentMessages = [];
28
+ this.coordinator = yield ConversationCoordinator.Coordinator({
29
+ lineDelay: 0,
30
+ sendMessageHandler: (message) => __awaiter(this, void 0, void 0, function* () {
31
+ this.sentMessages.push(message);
32
+ }),
33
+ topicLookupPath: this.resolveTestPath('skill', 'build'),
34
+ });
35
+ });
36
+ }
37
+ static canCreateTopicCoordinator() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ assert.isTruthy(this.coordinator);
40
+ });
41
+ }
42
+ static hasHandleMessage() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ assert.isFunction(this.coordinator.handleMessage);
45
+ });
46
+ }
47
+ static handledMessageMustHaveASource() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const err = yield assert.doesThrowAsync(() => this.coordinator.handleMessage(this.buildMessage({ body: 'waka waka' })));
50
+ errorAssert.assertError(err, 'MISSING_PARAMETERS', {
51
+ parameters: ['source.personId'],
52
+ });
53
+ });
54
+ }
55
+ static respondsWithSuggestedTopicsToFirstMessage() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const results = yield this.coordinator.handleMessage(this.buildMessage({ body: 'help me book!', source: { personId: '1234' } }));
58
+ assert.isArray(results.suggestedTopics);
59
+ assert.isLength(results.suggestedTopics, 3);
60
+ });
61
+ }
62
+ static handlesNoSkillWithTopics() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const coordinator = yield ConversationCoordinator.Coordinator({
65
+ topicLookupPath: this.cwd,
66
+ sendMessageHandler: () => __awaiter(this, void 0, void 0, function* () { }),
67
+ });
68
+ const results = yield coordinator.handleMessage(this.buildMessage({ body: 'help me book!', source: { personId: '1234' } }));
69
+ assert.isArray(results.suggestedTopics);
70
+ assert.isLength(results.suggestedTopics, 0);
71
+ });
72
+ }
73
+ static throwsWhenSentBadTopic() {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const err = yield assert.doesThrowAsync(() => this.coordinator.handleMessage(this.buildMessage({ body: '1', source: { personId: '1234' } }), 'aoeu'));
76
+ errorAssert.assertError(err, 'TOPIC_NOT_FOUND', {
77
+ suppliedTopic: 'aoeu',
78
+ validTopics: [
79
+ 'bookAppointment',
80
+ 'cancelAppointment',
81
+ 'favoriteColor',
82
+ 'favoriteColorTopicChanger',
83
+ 'mixedStringsAndCallbacks',
84
+ ],
85
+ });
86
+ });
87
+ }
88
+ static playsScriptWhenTopicIsSelected() {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ yield this.coordinator.handleMessage(this.buildMessage({ body: '1', source: { personId: '1234' } }), 'bookAppointment');
91
+ assert.isLength(this.sentMessages, 2);
92
+ assert.isEqual(this.sentMessages[0].body, 'Sweet, lets book!');
93
+ });
94
+ }
95
+ static canHandlePromptsInScript() {
96
+ var _a;
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ void this.coordinator.handleMessage(this.buildMessage({ body: '1', source: { personId: '1234' } }), 'favoriteColor');
99
+ yield this.wait(10);
100
+ assert.isLength(this.sentMessages, 1);
101
+ assert.isEqual(this.sentMessages[0].body, 'what is your favorite color?');
102
+ void this.coordinator.handleMessage(this.buildMessage({ body: 'blue', source: { personId: '1234' } }), 'favoriteColor');
103
+ yield this.wait(10);
104
+ assert.isLength(this.sentMessages, 2);
105
+ assert.isEqual(this.sentMessages[this.sentMessages.length - 1].body, 'blue');
106
+ void this.coordinator.handleMessage(this.buildMessage({ body: 'blue', source: { personId: '1234' } }), 'bookAppointment');
107
+ yield this.wait(10);
108
+ assert.isLength(this.sentMessages, 4);
109
+ assert.isEqual((_a = this.sentMessages.pop()) === null || _a === void 0 ? void 0 : _a.body, 'Lemme find your appointment!');
110
+ });
111
+ }
112
+ static canPlaceMixedScriptsUntilTheEndAndStartsOver() {
113
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ yield this.coordinator.handleMessage(this.buildMessage({ body: '1', source: { personId: '1234' } }), 'mixedStringsAndCallbacks');
116
+ yield this.wait(10);
117
+ assert.isLength(this.sentMessages, 2);
118
+ assert.isEqual((_a = this.sentMessages[0]) === null || _a === void 0 ? void 0 : _a.body, 'string 1');
119
+ assert.isEqual((_b = this.sentMessages[1]) === null || _b === void 0 ? void 0 : _b.body, 'prompt 1');
120
+ this.sentMessages = [];
121
+ yield this.coordinator.handleMessage(this.buildMessage({ body: 'answer 1', source: { personId: '1234' } }), 'mixedStringsAndCallbacks');
122
+ yield this.wait(100);
123
+ assert.isLength(this.sentMessages, 3);
124
+ assert.isEqual((_c = this.sentMessages[0]) === null || _c === void 0 ? void 0 : _c.body, 'answer 1');
125
+ assert.isEqual((_d = this.sentMessages[1]) === null || _d === void 0 ? void 0 : _d.body, 'string 2');
126
+ assert.isEqual((_e = this.sentMessages[2]) === null || _e === void 0 ? void 0 : _e.body, 'prompt 2');
127
+ this.sentMessages = [];
128
+ yield this.coordinator.handleMessage(this.buildMessage({ body: 'answer 2', source: { personId: '1234' } }), 'mixedStringsAndCallbacks');
129
+ assert.isLength(this.sentMessages, 2);
130
+ assert.isEqual((_f = this.sentMessages[0]) === null || _f === void 0 ? void 0 : _f.body, 'answer 2');
131
+ assert.isEqual((_g = this.sentMessages[1]) === null || _g === void 0 ? void 0 : _g.body, 'and done');
132
+ this.sentMessages = [];
133
+ yield this.coordinator.handleMessage(this.buildMessage({ body: 'answer 1', source: { personId: '1234' } }), 'mixedStringsAndCallbacks');
134
+ yield this.wait(100);
135
+ assert.isLength(this.sentMessages, 2);
136
+ assert.isEqual((_h = this.sentMessages[0]) === null || _h === void 0 ? void 0 : _h.body, 'string 1');
137
+ assert.isEqual((_j = this.sentMessages[1]) === null || _j === void 0 ? void 0 : _j.body, 'prompt 1');
138
+ });
139
+ }
140
+ }
141
+ TopicCoordinatorTest.sentMessages = [];
142
+ __decorate([
143
+ test()
144
+ ], TopicCoordinatorTest, "canCreateTopicCoordinator", null);
145
+ __decorate([
146
+ test()
147
+ ], TopicCoordinatorTest, "hasHandleMessage", null);
148
+ __decorate([
149
+ test()
150
+ ], TopicCoordinatorTest, "handledMessageMustHaveASource", null);
151
+ __decorate([
152
+ test()
153
+ ], TopicCoordinatorTest, "respondsWithSuggestedTopicsToFirstMessage", null);
154
+ __decorate([
155
+ test()
156
+ ], TopicCoordinatorTest, "handlesNoSkillWithTopics", null);
157
+ __decorate([
158
+ test()
159
+ ], TopicCoordinatorTest, "throwsWhenSentBadTopic", null);
160
+ __decorate([
161
+ test()
162
+ ], TopicCoordinatorTest, "playsScriptWhenTopicIsSelected", null);
163
+ __decorate([
164
+ test()
165
+ ], TopicCoordinatorTest, "canHandlePromptsInScript", null);
166
+ __decorate([
167
+ test()
168
+ ], TopicCoordinatorTest, "canPlaceMixedScriptsUntilTheEndAndStartsOver", null);
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,82 @@
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';
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, { body: 'Tell me about your life.' });
27
+ });
28
+ }
29
+ static noPromptSendsNoMessage() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ void this.ui.prompt({
32
+ type: 'email',
33
+ });
34
+ assert.isLength(this.sentMessages, 0);
35
+ });
36
+ }
37
+ static respondingWithBadEmailGivesYouAnotherChance() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ EmailFieldHandler.repairs = ['repair', 'repair'];
40
+ let wasHit = false;
41
+ void this.ui
42
+ .prompt({
43
+ type: 'email',
44
+ label: 'What is your email?',
45
+ })
46
+ .then(() => {
47
+ wasHit = true;
48
+ });
49
+ assert.isLength(this.sentMessages, 1);
50
+ assert.doesInclude(this.sentMessages, { body: 'What is your email?' });
51
+ yield this.sendMessage('aoeuaoeu');
52
+ assert.isLength(this.sentMessages, 2);
53
+ assert.doesInclude(this.sentMessages, { body: 'repair' });
54
+ assert.isFalse(wasHit);
55
+ });
56
+ }
57
+ static respondingWithBadEmail2TimesErrors() {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const promise = this.ui.prompt({
60
+ type: 'email',
61
+ label: 'What is your email?',
62
+ });
63
+ assert.isLength(this.sentMessages, 1);
64
+ assert.doesInclude(this.sentMessages, { body: 'What is your email?' });
65
+ yield this.sendMessage('aoeuaoeu');
66
+ yield this.sendMessage('aoeuaoeu');
67
+ yield assert.doesThrowAsync(() => promise);
68
+ });
69
+ }
70
+ }
71
+ __decorate([
72
+ test()
73
+ ], TextFieldTest, "promptSendsLabel", null);
74
+ __decorate([
75
+ test()
76
+ ], TextFieldTest, "noPromptSendsNoMessage", null);
77
+ __decorate([
78
+ test()
79
+ ], TextFieldTest, "respondingWithBadEmailGivesYouAnotherChance", null);
80
+ __decorate([
81
+ test()
82
+ ], TextFieldTest, "respondingWithBadEmail2TimesErrors", null);
@@ -0,0 +1,4 @@
1
+ import AbstractGraphicsInterfaceTest from '../../../tests/AbstractGraphicsInterfaceTest';
2
+ export default class MessageGraphicsInterfaceTest extends AbstractGraphicsInterfaceTest {
3
+ protected static selectAsksAgainWithBadResponse(): Promise<void>;
4
+ }
@@ -0,0 +1,47 @@
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';
17
+ import { errorAssert } from '@sprucelabs/test-utils';
18
+ import AbstractGraphicsInterfaceTest from '../../../tests/AbstractGraphicsInterfaceTest.js';
19
+ export default class MessageGraphicsInterfaceTest extends AbstractGraphicsInterfaceTest {
20
+ static selectAsksAgainWithBadResponse() {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const promise = this.ui.prompt({
23
+ type: 'select',
24
+ label: 'What would you like to do?',
25
+ isRequired: true,
26
+ options: {
27
+ choices: [
28
+ {
29
+ label: 'Book appointment',
30
+ value: 'bookAppointment',
31
+ },
32
+ {
33
+ label: 'Cancel appointment',
34
+ value: 'cancelAppointment',
35
+ },
36
+ ],
37
+ },
38
+ });
39
+ yield this.sendMessage('get me out of here!');
40
+ const err = yield assert.doesThrowAsync(() => __awaiter(this, void 0, void 0, function* () { return yield promise; }));
41
+ errorAssert.assertError(err, 'ABORT');
42
+ });
43
+ }
44
+ }
45
+ __decorate([
46
+ test()
47
+ ], MessageGraphicsInterfaceTest, "selectAsksAgainWithBadResponse", null);
@@ -0,0 +1,7 @@
1
+ import AbstractGraphicsInterfaceTest from '../../../tests/AbstractGraphicsInterfaceTest';
2
+ export default class MessageGraphicsInterfaceTest extends AbstractGraphicsInterfaceTest {
3
+ protected static respondingWithNumberSelectsOptions(): Promise<void>;
4
+ protected static respondingWithBadNumberAsksYouToSelectAgain(): Promise<void>;
5
+ protected static respondingWithCloseMatchSelectsChoice(): Promise<void>;
6
+ private static renderAppointmentSelect;
7
+ }
@@ -0,0 +1,80 @@
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';
17
+ import AbstractGraphicsInterfaceTest from '../../../tests/AbstractGraphicsInterfaceTest.js';
18
+ export default class MessageGraphicsInterfaceTest extends AbstractGraphicsInterfaceTest {
19
+ static respondingWithNumberSelectsOptions() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const promise = this.renderAppointmentSelect();
22
+ yield this.sendMessage('1');
23
+ const results = yield promise;
24
+ assert.isEqual(results, 'bookAppointment');
25
+ });
26
+ }
27
+ static respondingWithBadNumberAsksYouToSelectAgain() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ void this.renderAppointmentSelect();
30
+ yield this.sendMessage('5');
31
+ yield this.sendMessage('5');
32
+ assert.doesInclude(this.sentMessages, { body: 'invalid-value-repair' });
33
+ assert.doesInclude(this.sentMessages, { body: 'invalid-value-repair2' });
34
+ const last = this.sentMessages.pop();
35
+ assert.isTruthy(last === null || last === void 0 ? void 0 : last.choices);
36
+ });
37
+ }
38
+ static respondingWithCloseMatchSelectsChoice() {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const promise = this.renderAppointmentSelect();
41
+ yield this.sendMessage('book please');
42
+ const selection = yield promise;
43
+ assert.isEqual(selection, 'bookAppointment');
44
+ });
45
+ }
46
+ static renderAppointmentSelect() {
47
+ const choices = [
48
+ {
49
+ label: 'Book appointment',
50
+ value: 'bookAppointment',
51
+ },
52
+ {
53
+ label: 'Cancel appointment',
54
+ value: 'cancelAppointment',
55
+ },
56
+ ];
57
+ const response = this.ui.prompt({
58
+ type: 'select',
59
+ label: 'What would you like to do?',
60
+ isRequired: true,
61
+ options: {
62
+ choices,
63
+ },
64
+ });
65
+ assert.doesInclude(this.sentMessages, {
66
+ body: 'What would you like to do?',
67
+ choices,
68
+ });
69
+ return response;
70
+ }
71
+ }
72
+ __decorate([
73
+ test()
74
+ ], MessageGraphicsInterfaceTest, "respondingWithNumberSelectsOptions", null);
75
+ __decorate([
76
+ test()
77
+ ], MessageGraphicsInterfaceTest, "respondingWithBadNumberAsksYouToSelectAgain", null);
78
+ __decorate([
79
+ test()
80
+ ], MessageGraphicsInterfaceTest, "respondingWithCloseMatchSelectsChoice", null);
@@ -0,0 +1,6 @@
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 canRespondToPrompt(): Promise<void>;
6
+ }
@@ -0,0 +1,55 @@
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';
17
+ import AbstractGraphicsInterfaceTest from '../../../tests/AbstractGraphicsInterfaceTest.js';
18
+ export default class TextFieldTest extends AbstractGraphicsInterfaceTest {
19
+ static promptSendsLabel() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ void this.ui.prompt({
22
+ type: 'text',
23
+ label: 'Tell me about your life.',
24
+ });
25
+ assert.doesInclude(this.sentMessages, { body: 'Tell me about your life.' });
26
+ });
27
+ }
28
+ static noPromptSendsNoMessage() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ void this.ui.prompt({
31
+ type: 'text',
32
+ });
33
+ assert.isLength(this.sentMessages, 0);
34
+ });
35
+ }
36
+ static canRespondToPrompt() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const promise = this.ui.prompt({
39
+ type: 'text',
40
+ });
41
+ yield this.sendMessage('hey there!');
42
+ const answer = yield promise;
43
+ assert.isEqual(answer, 'hey there!');
44
+ });
45
+ }
46
+ }
47
+ __decorate([
48
+ test()
49
+ ], TextFieldTest, "promptSendsLabel", null);
50
+ __decorate([
51
+ test()
52
+ ], TextFieldTest, "noPromptSendsNoMessage", null);
53
+ __decorate([
54
+ test()
55
+ ], TextFieldTest, "canRespondToPrompt", null);
@@ -0,0 +1,18 @@
1
+ import AbstractConversationTest from '../../tests/AbstractConversationTest';
2
+ import { Script } from '../../types/conversation.types';
3
+ export default class ScriptTesterTest extends AbstractConversationTest {
4
+ protected static throwsWithoutScript(): Promise<void>;
5
+ protected static acceptsSimpleScript(): Promise<void>;
6
+ protected static callingGoDoesntCrash(): Promise<void>;
7
+ protected static cantHandleMessageBeforeStartup(): Promise<void>;
8
+ protected static selectingBadScriptToStartThrows(): Promise<void>;
9
+ private static readonly basicBookingScript;
10
+ protected static asksWhichScriptYouWantToStartWithWhenThereIsMoreThanOne(): Promise<void>;
11
+ protected static playsSimpleScript(script: Script): Promise<void>;
12
+ protected static canSendInputToThePlayer(answer: string): Promise<void>;
13
+ protected static promptsForFirstMessageIfNoneSentToGo(): Promise<void>;
14
+ protected static showsConfidenceRatingBasedOnFirstMesageSent(): Promise<void>;
15
+ protected static promptsToStartAgainAfterDone(): Promise<void>;
16
+ protected static messagesAboutTransitionResponseTopicChanger(): Promise<void>;
17
+ protected static messagesAboutTransitionResponseWithRepairs(): Promise<void>;
18
+ }