Skip to content

Commit

Permalink
refactor: Do not pass brain and config to Dialog constructor
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Do not pass brain and config to Dialog
constructor because the bot is already passed.
  • Loading branch information
Michel Blancard committed Apr 18, 2018
1 parent 988e025 commit b2eec6f
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 45 deletions.
2 changes: 1 addition & 1 deletion packages/botfuel-dialog/src/dialog-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DialogManager extends Resolver {

/** @inheritdoc */
resolutionSucceeded(Resolved) {
return new Resolved(this.bot, this.config, this.brain, Resolved.params);
return new Resolved(this.bot, Resolved.params);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/botfuel-dialog/src/dialogs/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ class Dialog {
* @param {Object} characteristics - the characteristics of the dialog
* @param {Object} [parameters={}] - the optional dialog parameters
*/
constructor(bot, config, brain, characteristics = { reentrant: false }, parameters = {}) {
constructor(bot, characteristics = { reentrant: false }, parameters = {}) {
logger.debug('constructor', parameters);
const { config, brain } = bot;
this.bot = bot;
this.brain = brain;
this.characteristics = characteristics;
Expand Down
4 changes: 2 additions & 2 deletions packages/botfuel-dialog/src/dialogs/prompt-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class PromptDialog extends Dialog {
* @param {Object} parameters - the dialog parameters,
* parameters.entities is a map mapping entities to optional parameters
*/
constructor(bot, config, brain, parameters) {
super(bot, config, brain, { reentrant: true }, parameters);
constructor(bot, parameters) {
super(bot, { reentrant: true }, parameters);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ const TEST_CONFIG = require('../../src/config').getConfiguration({

describe('ClassificationDisambiguationDialog', () => {
const bot = new Bot(TEST_CONFIG);
const { brain } = bot;

test('should complete', async () => {
const dialog = new ClassificationDisambiguationDialog(bot, TEST_CONFIG, brain);
const dialog = new ClassificationDisambiguationDialog(bot);
const classificationResults = [
new ClassificationResult({
type: ClassificationResult.TYPE_INTENT,
Expand Down
16 changes: 10 additions & 6 deletions packages/botfuel-dialog/tests/dialogs/confirmation-dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@
* limitations under the License.
*/

const Bot = require('../../src/bot');
const ConfirmationDialog = require('../../src/dialogs/confirmation-dialog');
const MemoryBrain = require('../../src/brains/memory-brain');
const UserTextMessage = require('../../src/messages/user-text-message');
const TEST_CONFIG = require('../../src/config').getConfiguration({});
const TEST_CONFIG = require('../../src/config').getConfiguration({
brain: {
name: 'memory',
},
});

const USER_ID = 'USER';
const TEST_BOT = null;

describe('ConfirmationDialog', () => {
const brain = new MemoryBrain(TEST_CONFIG);
const bot = new Bot(TEST_CONFIG);
const { brain } = bot;

beforeEach(async () => {
await brain.addUser(USER_ID);
Expand All @@ -34,7 +38,7 @@ describe('ConfirmationDialog', () => {
});

test('should return the complete action', async () => {
const dialog = new ConfirmationDialog(TEST_BOT, TEST_CONFIG, brain, {
const dialog = new ConfirmationDialog(bot, {
namespace: 'confirmation-dialog',
});
const action = await dialog.dialogWillComplete(new UserTextMessage('message').toJson(USER_ID), {
Expand All @@ -46,7 +50,7 @@ describe('ConfirmationDialog', () => {
});

test('should return the cancel action', async () => {
const dialog = new ConfirmationDialog(TEST_BOT, TEST_CONFIG, brain, {
const dialog = new ConfirmationDialog(bot, {
namespace: 'confirmation-dialog',
});
const action = await dialog.dialogWillComplete(new UserTextMessage('message').toJson(USER_ID), {
Expand Down
14 changes: 8 additions & 6 deletions packages/botfuel-dialog/tests/dialogs/dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
* limitations under the License.
*/

const Bot = require('../../src/bot');
const Dialog = require('../../src/dialogs/dialog');
const MemoryBrain = require('../../src/brains/memory-brain');
const DialogError = require('../../src/errors/dialog-error');
const TEST_CONFIG = require('../../src/config').getConfiguration({});

const TEST_BOT = null;
const TEST_CONFIG = require('../../src/config').getConfiguration({
brain: {
name: 'memory',
},
});

describe('Dialog', () => {
const brain = new MemoryBrain(TEST_CONFIG);
const dialog = new Dialog(TEST_BOT, TEST_CONFIG, brain, {
const bot = new Bot(TEST_CONFIG);
const dialog = new Dialog(bot, {
namespace: 'testdialog',
entities: {},
});
Expand Down
28 changes: 13 additions & 15 deletions packages/botfuel-dialog/tests/dialogs/prompt-dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@
* limitations under the License.
*/

const PromptDialog = require('../../src/dialogs/prompt-dialog');
const MemoryBrain = require('../../src/brains/memory-brain');
const Bot = require('../../src/bot');
const PromptDialog = require('../../src/dialogs/prompt-dialog');
const Config = require('../../src/config');

const TEST_CONFIG = Config.getConfiguration({});
const TEST_CONFIG = Config.getConfiguration({
adapter: {
name: 'test',
},
brain: {
name: 'memory',
},
});

const TEST_BOT = null;
const bot = new Bot(TEST_CONFIG);

describe('PromptDialog', () => {
describe('computeEntities', () => {
const brain = new MemoryBrain(TEST_CONFIG);
const prompt = new PromptDialog(TEST_BOT, TEST_CONFIG, brain, {
const prompt = new PromptDialog(bot, {
namespace: 'testdialog',
entities: {},
});
Expand Down Expand Up @@ -851,8 +856,7 @@ describe('PromptDialog', () => {
});

describe('sort missing entities', () => {
const brain = new MemoryBrain(TEST_CONFIG);
const prompt = new PromptDialog(TEST_BOT, TEST_CONFIG, brain, {
const prompt = new PromptDialog(bot, {
namespace: 'testdialog',
entities: {},
});
Expand All @@ -879,16 +883,10 @@ describe('PromptDialog', () => {
});

describe('excecute', () => {
const config = Config.getConfiguration({
adapter: {
name: 'test',
},
});
const bot = new Bot(config);
const { adapter } = bot;
const { userId } = adapter;

const prompt = new PromptDialog(bot, TEST_CONFIG, bot.brain, {
const prompt = new PromptDialog(bot, {
namespace: 'testdialog',
entities: {
a: {
Expand Down
11 changes: 5 additions & 6 deletions packages/botfuel-dialog/tests/dialogs/qnas-dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

const Bot = require('../../src/bot');
const QnasDialog = require('../../src/dialogs/qnas-dialog');
const MemoryBrain = require('../../src/brains/memory-brain');
const TEST_CONFIG = require('../../src/config').getConfiguration({
adapter: { name: 'shell' },
adapter: {
name: 'shell',
},
});

const TEST_BOT = new Bot(TEST_CONFIG);

describe('QnasDialog', () => {
const brain = new MemoryBrain(TEST_CONFIG);
const dialog = new QnasDialog(TEST_BOT, TEST_CONFIG, brain);
const bot = new Bot(TEST_CONFIG);
const dialog = new QnasDialog(bot);
const answers = [[{ value: 'answer' }]];

test('should return the complete action', async () => {
Expand Down
14 changes: 8 additions & 6 deletions packages/botfuel-dialog/tests/dialogs/void-dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
* limitations under the License.
*/

const Bot = require('../../src/bot');
const VoidDialog = require('../../src/dialogs/void-dialog');
const MemoryBrain = require('../../src/brains/memory-brain');
const TEST_CONFIG = require('../../src/config').getConfiguration({});

const TEST_BOT = null;
const TEST_CONFIG = require('../../src/config').getConfiguration({
brain: {
name: 'memory',
},
});

describe('VoidDialog', () => {
const brain = new MemoryBrain(TEST_CONFIG);
const dialog = new VoidDialog(TEST_BOT, TEST_CONFIG, brain, {
const bot = new Bot(TEST_CONFIG);
const dialog = new VoidDialog(bot, {
namespace: 'void-dialog',
});

Expand Down

0 comments on commit b2eec6f

Please sign in to comment.