@sprucelabs/spruce-conversation-plugin 52.3.24 → 52.4.0

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.
@@ -0,0 +1,5 @@
1
+ import AbstractSpruceTest from '@sprucelabs/test-utils';
2
+ export default class SpyMessageBeforeAndAfterEachTest extends AbstractSpruceTest {
3
+ protected static throwsIfInstantiatingTwoWithoutCallingAfterEach(): Promise<void>;
4
+ protected static throwsIfDanglingPrompt(): Promise<void>;
5
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ 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;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
36
+ const test_utils_1 = __importStar(require("@sprucelabs/test-utils"));
37
+ const MockMessageInterface_1 = __importDefault(require("../../../interfaces/MockMessageInterface"));
38
+ let SpyMessageBeforeAndAfterEachTest = class SpyMessageBeforeAndAfterEachTest extends test_utils_1.default {
39
+ static async throwsIfInstantiatingTwoWithoutCallingAfterEach() {
40
+ MockMessageInterface_1.default.Ui();
41
+ test_utils_1.assert.doesThrow(() => MockMessageInterface_1.default.Ui());
42
+ MockMessageInterface_1.default.afterEach();
43
+ MockMessageInterface_1.default.Ui();
44
+ }
45
+ static async throwsIfDanglingPrompt() {
46
+ MockMessageInterface_1.default.afterEach();
47
+ const ui = MockMessageInterface_1.default.Ui();
48
+ void ui.prompt({ type: 'number' });
49
+ ui.renderLine('Hey there!');
50
+ test_utils_1.assert.doesThrow(() => MockMessageInterface_1.default.afterEach());
51
+ }
52
+ };
53
+ __decorate([
54
+ (0, test_utils_1.test)()
55
+ ], SpyMessageBeforeAndAfterEachTest, "throwsIfInstantiatingTwoWithoutCallingAfterEach", null);
56
+ __decorate([
57
+ (0, test_utils_1.test)()
58
+ ], SpyMessageBeforeAndAfterEachTest, "throwsIfDanglingPrompt", null);
59
+ SpyMessageBeforeAndAfterEachTest = __decorate([
60
+ spruce_test_fixtures_1.fake.login()
61
+ ], SpyMessageBeforeAndAfterEachTest);
62
+ exports.default = SpyMessageBeforeAndAfterEachTest;
@@ -0,0 +1,18 @@
1
+ import AbstractSpruceTest from '@sprucelabs/test-utils';
2
+ export default class SpyMessageInterfaceTest extends AbstractSpruceTest {
3
+ private static ui;
4
+ protected static beforeEach(): Promise<void>;
5
+ protected static afterEach(): Promise<void>;
6
+ protected static knowsIfDidntPromp(): Promise<void>;
7
+ protected static holdsUntilPromptIsAnswered(): Promise<void>;
8
+ protected static tracksPrompts(): Promise<void>;
9
+ protected static throwsIfRenderedAfterPrompt(): Promise<void>;
10
+ protected static canAssertSelectChoices(): Promise<void>;
11
+ protected static canAssertDifferentSelectChoices(): Promise<void>;
12
+ protected static canAssertIfRequired(): Promise<void>;
13
+ private static assertPromptedWithChoices;
14
+ private static promptWithChoices;
15
+ private static resetUi;
16
+ private static prompt;
17
+ private static assertNotJustPromptedFor;
18
+ }
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ 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;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const test_utils_1 = __importStar(require("@sprucelabs/test-utils"));
36
+ const MockMessageInterface_1 = __importDefault(require("../../../interfaces/MockMessageInterface"));
37
+ class SpyMessageInterfaceTest extends test_utils_1.default {
38
+ static async beforeEach() {
39
+ await super.beforeEach();
40
+ this.ui = MockMessageInterface_1.default.Ui();
41
+ }
42
+ static async afterEach() {
43
+ await super.afterEach();
44
+ MockMessageInterface_1.default.afterEach();
45
+ }
46
+ static async knowsIfDidntPromp() {
47
+ this.assertNotJustPromptedFor('number');
48
+ }
49
+ static async holdsUntilPromptIsAnswered() {
50
+ const promise = this.prompt({ type: 'text' });
51
+ const expected = (0, test_utils_1.generateId)();
52
+ this.ui.answerPrompt(expected);
53
+ const answer = await promise;
54
+ test_utils_1.assert.isEqual(answer, expected);
55
+ }
56
+ static async tracksPrompts() {
57
+ void this.prompt({
58
+ type: 'number',
59
+ isRequired: true,
60
+ });
61
+ this.ui.assertJustPromptedFor('number');
62
+ this.assertNotJustPromptedFor('text');
63
+ this.resetUi();
64
+ }
65
+ static async throwsIfRenderedAfterPrompt() {
66
+ void this.prompt({
67
+ type: 'number',
68
+ isRequired: true,
69
+ });
70
+ this.ui.renderLine('go dogs go!');
71
+ this.assertNotJustPromptedFor('number');
72
+ this.resetUi();
73
+ }
74
+ static async canAssertSelectChoices() {
75
+ this.promptWithChoices([
76
+ {
77
+ label: 'Hey',
78
+ value: 'hello',
79
+ },
80
+ ]);
81
+ test_utils_1.assert.doesThrow(() => this.assertPromptedWithChoices([
82
+ {
83
+ value: 'what the!?',
84
+ },
85
+ ]));
86
+ this.assertPromptedWithChoices([
87
+ {
88
+ value: 'hello',
89
+ },
90
+ ]);
91
+ this.resetUi();
92
+ }
93
+ static async canAssertDifferentSelectChoices() {
94
+ const value = (0, test_utils_1.generateId)();
95
+ this.promptWithChoices([
96
+ {
97
+ value,
98
+ label: 'What theee!!!!??',
99
+ },
100
+ { value: 'hello', label: 'Hello!' },
101
+ ]);
102
+ this.assertPromptedWithChoices([
103
+ {
104
+ value,
105
+ },
106
+ {
107
+ value: 'hello',
108
+ },
109
+ ]);
110
+ this.resetUi();
111
+ }
112
+ static async canAssertIfRequired() {
113
+ void this.prompt({
114
+ type: 'number',
115
+ options: {
116
+ min: 0,
117
+ max: 100,
118
+ },
119
+ });
120
+ test_utils_1.assert.doesThrow(() => this.ui.assertJustPromptedFor('number', { min: 10, max: 20 }));
121
+ this.ui.assertJustPromptedFor('number', { min: 0, max: 100 });
122
+ this.resetUi();
123
+ }
124
+ static assertPromptedWithChoices(expected) {
125
+ return this.ui.assertJustPromptedFor('select', {
126
+ choices: expected,
127
+ });
128
+ }
129
+ static promptWithChoices(choices) {
130
+ void this.prompt({
131
+ type: 'select',
132
+ options: {
133
+ choices,
134
+ },
135
+ });
136
+ }
137
+ static resetUi() {
138
+ this.ui.reset();
139
+ }
140
+ static prompt(definition) {
141
+ return this.ui.prompt(definition);
142
+ }
143
+ static assertNotJustPromptedFor(type) {
144
+ test_utils_1.assert.doesThrow(() => this.ui.assertJustPromptedFor(type));
145
+ }
146
+ }
147
+ __decorate([
148
+ (0, test_utils_1.test)()
149
+ ], SpyMessageInterfaceTest, "knowsIfDidntPromp", null);
150
+ __decorate([
151
+ (0, test_utils_1.test)()
152
+ ], SpyMessageInterfaceTest, "holdsUntilPromptIsAnswered", null);
153
+ __decorate([
154
+ (0, test_utils_1.test)()
155
+ ], SpyMessageInterfaceTest, "tracksPrompts", null);
156
+ __decorate([
157
+ (0, test_utils_1.test)()
158
+ ], SpyMessageInterfaceTest, "throwsIfRenderedAfterPrompt", null);
159
+ __decorate([
160
+ (0, test_utils_1.test)()
161
+ ], SpyMessageInterfaceTest, "canAssertSelectChoices", null);
162
+ __decorate([
163
+ (0, test_utils_1.test)()
164
+ ], SpyMessageInterfaceTest, "canAssertDifferentSelectChoices", null);
165
+ __decorate([
166
+ (0, test_utils_1.test)()
167
+ ], SpyMessageInterfaceTest, "canAssertIfRequired", null);
168
+ exports.default = SpyMessageInterfaceTest;
@@ -0,0 +1,5 @@
1
+ import AbstractSpruceTest from '@sprucelabs/test-utils';
2
+ export default class SpyMessageBeforeAndAfterEachTest extends AbstractSpruceTest {
3
+ protected static throwsIfInstantiatingTwoWithoutCallingAfterEach(): Promise<void>;
4
+ protected static throwsIfDanglingPrompt(): Promise<void>;
5
+ }
@@ -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 { fake } from '@sprucelabs/spruce-test-fixtures';
17
+ import AbstractSpruceTest, { test, assert } from '@sprucelabs/test-utils';
18
+ import MockMessageInterface from '../../../interfaces/MockMessageInterface.js';
19
+ let SpyMessageBeforeAndAfterEachTest = class SpyMessageBeforeAndAfterEachTest extends AbstractSpruceTest {
20
+ static throwsIfInstantiatingTwoWithoutCallingAfterEach() {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ MockMessageInterface.Ui();
23
+ assert.doesThrow(() => MockMessageInterface.Ui());
24
+ MockMessageInterface.afterEach();
25
+ MockMessageInterface.Ui();
26
+ });
27
+ }
28
+ static throwsIfDanglingPrompt() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ MockMessageInterface.afterEach();
31
+ const ui = MockMessageInterface.Ui();
32
+ void ui.prompt({ type: 'number' });
33
+ ui.renderLine('Hey there!');
34
+ assert.doesThrow(() => MockMessageInterface.afterEach());
35
+ });
36
+ }
37
+ };
38
+ __decorate([
39
+ test()
40
+ ], SpyMessageBeforeAndAfterEachTest, "throwsIfInstantiatingTwoWithoutCallingAfterEach", null);
41
+ __decorate([
42
+ test()
43
+ ], SpyMessageBeforeAndAfterEachTest, "throwsIfDanglingPrompt", null);
44
+ SpyMessageBeforeAndAfterEachTest = __decorate([
45
+ fake.login()
46
+ ], SpyMessageBeforeAndAfterEachTest);
47
+ export default SpyMessageBeforeAndAfterEachTest;
@@ -0,0 +1,18 @@
1
+ import AbstractSpruceTest from '@sprucelabs/test-utils';
2
+ export default class SpyMessageInterfaceTest extends AbstractSpruceTest {
3
+ private static ui;
4
+ protected static beforeEach(): Promise<void>;
5
+ protected static afterEach(): Promise<void>;
6
+ protected static knowsIfDidntPromp(): Promise<void>;
7
+ protected static holdsUntilPromptIsAnswered(): Promise<void>;
8
+ protected static tracksPrompts(): Promise<void>;
9
+ protected static throwsIfRenderedAfterPrompt(): Promise<void>;
10
+ protected static canAssertSelectChoices(): Promise<void>;
11
+ protected static canAssertDifferentSelectChoices(): Promise<void>;
12
+ protected static canAssertIfRequired(): Promise<void>;
13
+ private static assertPromptedWithChoices;
14
+ private static promptWithChoices;
15
+ private static resetUi;
16
+ private static prompt;
17
+ private static assertNotJustPromptedFor;
18
+ }
@@ -0,0 +1,172 @@
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 AbstractSpruceTest, { test, assert, generateId, } from '@sprucelabs/test-utils';
17
+ import MockMessageInterface from '../../../interfaces/MockMessageInterface.js';
18
+ export default class SpyMessageInterfaceTest extends AbstractSpruceTest {
19
+ static beforeEach() {
20
+ const _super = Object.create(null, {
21
+ beforeEach: { get: () => super.beforeEach }
22
+ });
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ yield _super.beforeEach.call(this);
25
+ this.ui = MockMessageInterface.Ui();
26
+ });
27
+ }
28
+ static afterEach() {
29
+ const _super = Object.create(null, {
30
+ afterEach: { get: () => super.afterEach }
31
+ });
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ yield _super.afterEach.call(this);
34
+ MockMessageInterface.afterEach();
35
+ });
36
+ }
37
+ static knowsIfDidntPromp() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ this.assertNotJustPromptedFor('number');
40
+ });
41
+ }
42
+ static holdsUntilPromptIsAnswered() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const promise = this.prompt({ type: 'text' });
45
+ const expected = generateId();
46
+ this.ui.answerPrompt(expected);
47
+ const answer = yield promise;
48
+ assert.isEqual(answer, expected);
49
+ });
50
+ }
51
+ static tracksPrompts() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ void this.prompt({
54
+ type: 'number',
55
+ isRequired: true,
56
+ });
57
+ this.ui.assertJustPromptedFor('number');
58
+ this.assertNotJustPromptedFor('text');
59
+ this.resetUi();
60
+ });
61
+ }
62
+ static throwsIfRenderedAfterPrompt() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ void this.prompt({
65
+ type: 'number',
66
+ isRequired: true,
67
+ });
68
+ this.ui.renderLine('go dogs go!');
69
+ this.assertNotJustPromptedFor('number');
70
+ this.resetUi();
71
+ });
72
+ }
73
+ static canAssertSelectChoices() {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ this.promptWithChoices([
76
+ {
77
+ label: 'Hey',
78
+ value: 'hello',
79
+ },
80
+ ]);
81
+ assert.doesThrow(() => this.assertPromptedWithChoices([
82
+ {
83
+ value: 'what the!?',
84
+ },
85
+ ]));
86
+ this.assertPromptedWithChoices([
87
+ {
88
+ value: 'hello',
89
+ },
90
+ ]);
91
+ this.resetUi();
92
+ });
93
+ }
94
+ static canAssertDifferentSelectChoices() {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ const value = generateId();
97
+ this.promptWithChoices([
98
+ {
99
+ value,
100
+ label: 'What theee!!!!??',
101
+ },
102
+ { value: 'hello', label: 'Hello!' },
103
+ ]);
104
+ this.assertPromptedWithChoices([
105
+ {
106
+ value,
107
+ },
108
+ {
109
+ value: 'hello',
110
+ },
111
+ ]);
112
+ this.resetUi();
113
+ });
114
+ }
115
+ static canAssertIfRequired() {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ void this.prompt({
118
+ type: 'number',
119
+ options: {
120
+ min: 0,
121
+ max: 100,
122
+ },
123
+ });
124
+ assert.doesThrow(() => this.ui.assertJustPromptedFor('number', { min: 10, max: 20 }));
125
+ this.ui.assertJustPromptedFor('number', { min: 0, max: 100 });
126
+ this.resetUi();
127
+ });
128
+ }
129
+ static assertPromptedWithChoices(expected) {
130
+ return this.ui.assertJustPromptedFor('select', {
131
+ choices: expected,
132
+ });
133
+ }
134
+ static promptWithChoices(choices) {
135
+ void this.prompt({
136
+ type: 'select',
137
+ options: {
138
+ choices,
139
+ },
140
+ });
141
+ }
142
+ static resetUi() {
143
+ this.ui.reset();
144
+ }
145
+ static prompt(definition) {
146
+ return this.ui.prompt(definition);
147
+ }
148
+ static assertNotJustPromptedFor(type) {
149
+ assert.doesThrow(() => this.ui.assertJustPromptedFor(type));
150
+ }
151
+ }
152
+ __decorate([
153
+ test()
154
+ ], SpyMessageInterfaceTest, "knowsIfDidntPromp", null);
155
+ __decorate([
156
+ test()
157
+ ], SpyMessageInterfaceTest, "holdsUntilPromptIsAnswered", null);
158
+ __decorate([
159
+ test()
160
+ ], SpyMessageInterfaceTest, "tracksPrompts", null);
161
+ __decorate([
162
+ test()
163
+ ], SpyMessageInterfaceTest, "throwsIfRenderedAfterPrompt", null);
164
+ __decorate([
165
+ test()
166
+ ], SpyMessageInterfaceTest, "canAssertSelectChoices", null);
167
+ __decorate([
168
+ test()
169
+ ], SpyMessageInterfaceTest, "canAssertDifferentSelectChoices", null);
170
+ __decorate([
171
+ test()
172
+ ], SpyMessageInterfaceTest, "canAssertIfRequired", null);
@@ -1,4 +1,5 @@
1
1
  export * from './types/conversation.types';
2
2
  export { default as plugin } from './plugins/conversation.plugin';
3
3
  export { default as suggesterUtil } from './utilities/suggester.utility';
4
+ export { default as MockMessageInterface } from './interfaces/MockMessageInterface';
4
5
  import '@sprucelabs/mercury-core-events';
@@ -1,4 +1,5 @@
1
1
  export * from './types/conversation.types.js';
2
2
  export { default as plugin } from './plugins/conversation.plugin.js';
3
3
  export { default as suggesterUtil } from './utilities/suggester.utility.js';
4
+ export { default as MockMessageInterface } from './interfaces/MockMessageInterface.js';
4
5
  import '@sprucelabs/mercury-core-events';
@@ -0,0 +1,22 @@
1
+ import { FieldDefinitions, FieldDefinitionValueType } from '@sprucelabs/schema';
2
+ import MessageGraphicsInterface from './MessageGraphicsInterface';
3
+ export default class MockMessageInterface extends MessageGraphicsInterface {
4
+ private static alreadyExists;
5
+ private static lastPrompt;
6
+ private promptResolve?;
7
+ private static isPrompting;
8
+ private constructor();
9
+ static Ui(): MockMessageInterface;
10
+ static afterEach(): void;
11
+ reset(): void;
12
+ private clearLastPrompt;
13
+ prompt<T extends FieldDefinitions>(definition: T): Promise<FieldDefinitionValueType<T, false>>;
14
+ answerPrompt(value: string | number | null): void;
15
+ assertJustPromptedFor<T extends FieldDefinitions>(type: T['type'], options?: T['options']): any;
16
+ private assertValidChoices;
17
+ private get lastPrompt();
18
+ private set lastPrompt(value);
19
+ private get isPrompting();
20
+ private set isPrompting(value);
21
+ }
22
+ export type FieldType = FieldDefinitions['type'];
@@ -0,0 +1,87 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { selectAssert, } from '@sprucelabs/schema';
11
+ import { assert } from '@sprucelabs/test-utils';
12
+ import MessageGraphicsInterface from './MessageGraphicsInterface.js';
13
+ export default class MockMessageInterface extends MessageGraphicsInterface {
14
+ constructor() {
15
+ super({
16
+ sendMessageHandler: () => __awaiter(this, void 0, void 0, function* () {
17
+ this.clearLastPrompt();
18
+ }),
19
+ });
20
+ }
21
+ static Ui() {
22
+ assert.isFalse(this.alreadyExists, `You gotta call Ui.afterEach() after each test!`);
23
+ this.alreadyExists = true;
24
+ return new this();
25
+ }
26
+ static afterEach() {
27
+ if (this.isPrompting) {
28
+ assert.fail('You have a dangling prompt!! Send some input or call ui.reset()');
29
+ }
30
+ this.alreadyExists = false;
31
+ }
32
+ reset() {
33
+ this.clearLastPrompt();
34
+ this.isPrompting = false;
35
+ }
36
+ clearLastPrompt() {
37
+ this.lastPrompt = null;
38
+ }
39
+ prompt(definition) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ this.lastPrompt = definition;
42
+ this.isPrompting = true;
43
+ return new Promise((r) => {
44
+ this.promptResolve = r;
45
+ });
46
+ });
47
+ }
48
+ answerPrompt(value) {
49
+ var _a;
50
+ this.isPrompting = false;
51
+ this.clearLastPrompt();
52
+ (_a = this.promptResolve) === null || _a === void 0 ? void 0 : _a.call(this, value);
53
+ }
54
+ assertJustPromptedFor(type, options) {
55
+ var _a, _b;
56
+ assert.isEqual((_a = this.lastPrompt) === null || _a === void 0 ? void 0 : _a.type, type, `You did not prompt for a '${type}'!`);
57
+ if (options) {
58
+ if (!this.assertValidChoices(options)) {
59
+ assert.doesInclude((_b = this.lastPrompt) === null || _b === void 0 ? void 0 : _b.options, options, `Your prompt options are not what I expected!`);
60
+ }
61
+ }
62
+ }
63
+ assertValidChoices(options) {
64
+ var _a, _b;
65
+ const choices = (_b = (_a = this.lastPrompt) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.choices;
66
+ if (choices) {
67
+ selectAssert.assertSelectChoicesMatch(choices, options.choices.map((c) => c.value));
68
+ return true;
69
+ }
70
+ return false;
71
+ }
72
+ get lastPrompt() {
73
+ return MockMessageInterface.lastPrompt;
74
+ }
75
+ set lastPrompt(prompt) {
76
+ MockMessageInterface.lastPrompt = prompt;
77
+ }
78
+ get isPrompting() {
79
+ return MockMessageInterface.isPrompting;
80
+ }
81
+ set isPrompting(prompt) {
82
+ MockMessageInterface.isPrompting = prompt;
83
+ }
84
+ }
85
+ MockMessageInterface.alreadyExists = false;
86
+ MockMessageInterface.lastPrompt = null;
87
+ MockMessageInterface.isPrompting = false;
@@ -1,9 +1,5 @@
1
1
  import { PromptHandler } from '../interfaces/TestGraphicsInterface';
2
2
  import { LoadedTopicDefinition, Message } from '../types/conversation.types';
3
- type WriteHandler = (message: Pick<Message, 'body' | 'choices'>) => void;
4
- type SelectHandler = (message: Pick<Message, 'body' | 'choices'>) => Promise<string>;
5
- type SimplifiedTopic = LoadedTopicDefinition;
6
- export declare const END_OF_LINE = "END OF LINE \uD83D\uDC7E";
7
3
  export default class ScriptTester {
8
4
  private writeHandler;
9
5
  private player?;
@@ -28,4 +24,8 @@ export default class ScriptTester {
28
24
  }): Promise<ScriptTester>;
29
25
  }
30
26
  export declare function generateTransitionMessage(transitionConversationTo: string): string;
27
+ type WriteHandler = (message: Pick<Message, 'body' | 'choices'>) => void;
28
+ type SelectHandler = (message: Pick<Message, 'body' | 'choices'>) => Promise<string>;
29
+ type SimplifiedTopic = LoadedTopicDefinition;
30
+ export declare const END_OF_LINE = "END OF LINE \uD83D\uDC7E";
31
31
  export {};
@@ -14,25 +14,6 @@ import TestGraphicsInterface from '../interfaces/TestGraphicsInterface.js';
14
14
  import { TopicScriptPlayer } from '../topics/TopicScriptPlayer.js';
15
15
  import { TopicSuggester } from '../topics/TopicSuggester.js';
16
16
  import randomUtil from '../utilities/random.utility.js';
17
- const inquirerSelectPromptHandler = (message) => __awaiter(void 0, void 0, void 0, function* () {
18
- var _a;
19
- const answer = yield inquirer.prompt({
20
- type: 'list',
21
- name: 'select',
22
- message: message.body,
23
- choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({ name: c.label, value: c.value })),
24
- });
25
- return answer.select;
26
- });
27
- const inquirerPromptHandler = (message) => __awaiter(void 0, void 0, void 0, function* () {
28
- const answer = yield inquirer.prompt({
29
- type: 'input',
30
- name: 'input',
31
- message: message.body,
32
- });
33
- return answer.input;
34
- });
35
- export const END_OF_LINE = 'END OF LINE 👾';
36
17
  export default class ScriptTester {
37
18
  constructor(topics, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
38
19
  this.writeHandler = writeHandler !== null && writeHandler !== void 0 ? writeHandler : ((message) => console.log(message.body));
@@ -158,3 +139,22 @@ export default class ScriptTester {
158
139
  export function generateTransitionMessage(transitionConversationTo) {
159
140
  return `Conversation exited. Transitioning to ${transitionConversationTo}.`;
160
141
  }
142
+ const inquirerSelectPromptHandler = (message) => __awaiter(void 0, void 0, void 0, function* () {
143
+ var _a;
144
+ const answer = yield inquirer.prompt({
145
+ type: 'list',
146
+ name: 'select',
147
+ message: message.body,
148
+ choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({ name: c.label, value: c.value })),
149
+ });
150
+ return answer.select;
151
+ });
152
+ const inquirerPromptHandler = (message) => __awaiter(void 0, void 0, void 0, function* () {
153
+ const answer = yield inquirer.prompt({
154
+ type: 'input',
155
+ name: 'input',
156
+ message: message.body,
157
+ });
158
+ return answer.input;
159
+ });
160
+ export const END_OF_LINE = 'END OF LINE 👾';
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './types/conversation.types';
2
2
  export { default as plugin } from './plugins/conversation.plugin';
3
3
  export { default as suggesterUtil } from './utilities/suggester.utility';
4
+ export { default as MockMessageInterface } from './interfaces/MockMessageInterface';
4
5
  import '@sprucelabs/mercury-core-events';
package/build/index.js CHANGED
@@ -17,10 +17,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.suggesterUtil = exports.plugin = void 0;
20
+ exports.MockMessageInterface = exports.suggesterUtil = exports.plugin = void 0;
21
21
  __exportStar(require("./types/conversation.types"), exports);
22
22
  var conversation_plugin_1 = require("./plugins/conversation.plugin");
23
23
  Object.defineProperty(exports, "plugin", { enumerable: true, get: function () { return __importDefault(conversation_plugin_1).default; } });
24
24
  var suggester_utility_1 = require("./utilities/suggester.utility");
25
25
  Object.defineProperty(exports, "suggesterUtil", { enumerable: true, get: function () { return __importDefault(suggester_utility_1).default; } });
26
+ var MockMessageInterface_1 = require("./interfaces/MockMessageInterface");
27
+ Object.defineProperty(exports, "MockMessageInterface", { enumerable: true, get: function () { return __importDefault(MockMessageInterface_1).default; } });
26
28
  require("@sprucelabs/mercury-core-events");
@@ -0,0 +1,22 @@
1
+ import { FieldDefinitions, FieldDefinitionValueType } from '@sprucelabs/schema';
2
+ import MessageGraphicsInterface from './MessageGraphicsInterface';
3
+ export default class MockMessageInterface extends MessageGraphicsInterface {
4
+ private static alreadyExists;
5
+ private static lastPrompt;
6
+ private promptResolve?;
7
+ private static isPrompting;
8
+ private constructor();
9
+ static Ui(): MockMessageInterface;
10
+ static afterEach(): void;
11
+ reset(): void;
12
+ private clearLastPrompt;
13
+ prompt<T extends FieldDefinitions>(definition: T): Promise<FieldDefinitionValueType<T, false>>;
14
+ answerPrompt(value: string | number | null): void;
15
+ assertJustPromptedFor<T extends FieldDefinitions>(type: T['type'], options?: T['options']): any;
16
+ private assertValidChoices;
17
+ private get lastPrompt();
18
+ private set lastPrompt(value);
19
+ private get isPrompting();
20
+ private set isPrompting(value);
21
+ }
22
+ export type FieldType = FieldDefinitions['type'];
@@ -0,0 +1,82 @@
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 schema_1 = require("@sprucelabs/schema");
7
+ const test_utils_1 = require("@sprucelabs/test-utils");
8
+ const MessageGraphicsInterface_1 = __importDefault(require("./MessageGraphicsInterface"));
9
+ class MockMessageInterface extends MessageGraphicsInterface_1.default {
10
+ constructor() {
11
+ super({
12
+ sendMessageHandler: async () => {
13
+ this.clearLastPrompt();
14
+ },
15
+ });
16
+ }
17
+ static Ui() {
18
+ test_utils_1.assert.isFalse(this.alreadyExists, `You gotta call Ui.afterEach() after each test!`);
19
+ this.alreadyExists = true;
20
+ return new this();
21
+ }
22
+ static afterEach() {
23
+ if (this.isPrompting) {
24
+ test_utils_1.assert.fail('You have a dangling prompt!! Send some input or call ui.reset()');
25
+ }
26
+ this.alreadyExists = false;
27
+ }
28
+ reset() {
29
+ this.clearLastPrompt();
30
+ this.isPrompting = false;
31
+ }
32
+ clearLastPrompt() {
33
+ this.lastPrompt = null;
34
+ }
35
+ async prompt(definition) {
36
+ this.lastPrompt = definition;
37
+ this.isPrompting = true;
38
+ return new Promise((r) => {
39
+ this.promptResolve = r;
40
+ });
41
+ }
42
+ answerPrompt(value) {
43
+ var _a;
44
+ this.isPrompting = false;
45
+ this.clearLastPrompt();
46
+ (_a = this.promptResolve) === null || _a === void 0 ? void 0 : _a.call(this, value);
47
+ }
48
+ assertJustPromptedFor(type, options) {
49
+ var _a, _b;
50
+ test_utils_1.assert.isEqual((_a = this.lastPrompt) === null || _a === void 0 ? void 0 : _a.type, type, `You did not prompt for a '${type}'!`);
51
+ if (options) {
52
+ if (!this.assertValidChoices(options)) {
53
+ test_utils_1.assert.doesInclude((_b = this.lastPrompt) === null || _b === void 0 ? void 0 : _b.options, options, `Your prompt options are not what I expected!`);
54
+ }
55
+ }
56
+ }
57
+ assertValidChoices(options) {
58
+ var _a, _b;
59
+ const choices = (_b = (_a = this.lastPrompt) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.choices;
60
+ if (choices) {
61
+ schema_1.selectAssert.assertSelectChoicesMatch(choices, options.choices.map((c) => c.value));
62
+ return true;
63
+ }
64
+ return false;
65
+ }
66
+ get lastPrompt() {
67
+ return MockMessageInterface.lastPrompt;
68
+ }
69
+ set lastPrompt(prompt) {
70
+ MockMessageInterface.lastPrompt = prompt;
71
+ }
72
+ get isPrompting() {
73
+ return MockMessageInterface.isPrompting;
74
+ }
75
+ set isPrompting(prompt) {
76
+ MockMessageInterface.isPrompting = prompt;
77
+ }
78
+ }
79
+ exports.default = MockMessageInterface;
80
+ MockMessageInterface.alreadyExists = false;
81
+ MockMessageInterface.lastPrompt = null;
82
+ MockMessageInterface.isPrompting = false;
@@ -1,9 +1,5 @@
1
1
  import { PromptHandler } from '../interfaces/TestGraphicsInterface';
2
2
  import { LoadedTopicDefinition, Message } from '../types/conversation.types';
3
- type WriteHandler = (message: Pick<Message, 'body' | 'choices'>) => void;
4
- type SelectHandler = (message: Pick<Message, 'body' | 'choices'>) => Promise<string>;
5
- type SimplifiedTopic = LoadedTopicDefinition;
6
- export declare const END_OF_LINE = "END OF LINE \uD83D\uDC7E";
7
3
  export default class ScriptTester {
8
4
  private writeHandler;
9
5
  private player?;
@@ -28,4 +24,8 @@ export default class ScriptTester {
28
24
  }): Promise<ScriptTester>;
29
25
  }
30
26
  export declare function generateTransitionMessage(transitionConversationTo: string): string;
27
+ type WriteHandler = (message: Pick<Message, 'body' | 'choices'>) => void;
28
+ type SelectHandler = (message: Pick<Message, 'body' | 'choices'>) => Promise<string>;
29
+ type SimplifiedTopic = LoadedTopicDefinition;
30
+ export declare const END_OF_LINE = "END OF LINE \uD83D\uDC7E";
31
31
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateTransitionMessage = exports.END_OF_LINE = void 0;
6
+ exports.END_OF_LINE = exports.generateTransitionMessage = void 0;
7
7
  const schema_1 = require("@sprucelabs/schema");
8
8
  const inquirer_1 = __importDefault(require("inquirer"));
9
9
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
@@ -11,25 +11,6 @@ const TestGraphicsInterface_1 = __importDefault(require("../interfaces/TestGraph
11
11
  const TopicScriptPlayer_1 = require("../topics/TopicScriptPlayer");
12
12
  const TopicSuggester_1 = require("../topics/TopicSuggester");
13
13
  const random_utility_1 = __importDefault(require("../utilities/random.utility"));
14
- const inquirerSelectPromptHandler = async (message) => {
15
- var _a;
16
- const answer = await inquirer_1.default.prompt({
17
- type: 'list',
18
- name: 'select',
19
- message: message.body,
20
- choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({ name: c.label, value: c.value })),
21
- });
22
- return answer.select;
23
- };
24
- const inquirerPromptHandler = async (message) => {
25
- const answer = await inquirer_1.default.prompt({
26
- type: 'input',
27
- name: 'input',
28
- message: message.body,
29
- });
30
- return answer.input;
31
- };
32
- exports.END_OF_LINE = 'END OF LINE 👾';
33
14
  class ScriptTester {
34
15
  constructor(topics, writeHandler, selectPromptHandler, promptHandler, lineDelay, shouldPlayReplayAfterFinish) {
35
16
  this.writeHandler = writeHandler !== null && writeHandler !== void 0 ? writeHandler : ((message) => console.log(message.body));
@@ -147,3 +128,22 @@ function generateTransitionMessage(transitionConversationTo) {
147
128
  return `Conversation exited. Transitioning to ${transitionConversationTo}.`;
148
129
  }
149
130
  exports.generateTransitionMessage = generateTransitionMessage;
131
+ const inquirerSelectPromptHandler = async (message) => {
132
+ var _a;
133
+ const answer = await inquirer_1.default.prompt({
134
+ type: 'list',
135
+ name: 'select',
136
+ message: message.body,
137
+ choices: (_a = message.choices) === null || _a === void 0 ? void 0 : _a.map((c) => ({ name: c.label, value: c.value })),
138
+ });
139
+ return answer.select;
140
+ };
141
+ const inquirerPromptHandler = async (message) => {
142
+ const answer = await inquirer_1.default.prompt({
143
+ type: 'input',
144
+ name: 'input',
145
+ message: message.body,
146
+ });
147
+ return answer.input;
148
+ };
149
+ exports.END_OF_LINE = 'END OF LINE 👾';
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "@types/inquirer"
14
14
  ]
15
15
  },
16
- "version": "52.3.24",
16
+ "version": "52.4.0",
17
17
  "files": [
18
18
  "build/**/*",
19
19
  "!build/__tests__",
@@ -65,14 +65,14 @@
65
65
  "dependencies": {
66
66
  "@nlpjs/nlu": "^4.23.5",
67
67
  "@sprucelabs/error": "^5.0.554",
68
- "@sprucelabs/mercury-core-events": "^15.0.134",
68
+ "@sprucelabs/mercury-core-events": "^15.0.135",
69
69
  "@sprucelabs/schema": "^28.5.83",
70
- "@sprucelabs/spruce-core-schemas": "^35.1.85",
71
- "@sprucelabs/spruce-event-plugin": "^52.3.24",
72
- "@sprucelabs/spruce-event-utils": "^30.0.15",
73
- "@sprucelabs/spruce-skill-booter": "^52.3.24",
70
+ "@sprucelabs/spruce-core-schemas": "^35.1.86",
71
+ "@sprucelabs/spruce-event-plugin": "^52.4.0",
72
+ "@sprucelabs/spruce-event-utils": "^30.0.16",
73
+ "@sprucelabs/spruce-skill-booter": "^52.4.0",
74
74
  "@sprucelabs/spruce-skill-utils": "^28.1.13",
75
- "@sprucelabs/spruce-test-fixtures": "^52.3.24",
75
+ "@sprucelabs/spruce-test-fixtures": "^52.4.0",
76
76
  "fuzzyset": "^1.0.7",
77
77
  "globby": "^11.0.4",
78
78
  "inquirer": "^8.2.4",
@@ -82,7 +82,7 @@
82
82
  "devDependencies": {
83
83
  "@sprucelabs/esm-postbuild": "^2.0.48",
84
84
  "@sprucelabs/jest-json-reporter": "^6.0.534",
85
- "@sprucelabs/mercury-client": "^35.0.19",
85
+ "@sprucelabs/mercury-client": "^35.0.20",
86
86
  "@sprucelabs/resolve-path-aliases": "^1.1.144",
87
87
  "@sprucelabs/semantic-release": "^4.0.8",
88
88
  "@sprucelabs/test": "^7.7.398",
@@ -119,5 +119,5 @@
119
119
  "^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
120
120
  }
121
121
  },
122
- "gitHead": "a41e90fb0467ce6fabc03e7bcda9603f3996ce04"
122
+ "gitHead": "c99a131cf9100392da6fc5ce1dece954d14014e9"
123
123
  }