Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Dialog Manager to work with skills #2343

Merged
merged 14 commits into from
Jul 9, 2020
Merged
55 changes: 50 additions & 5 deletions libraries/botbuilder-dialogs/tests/dialogManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const SKILL_BOT_ID = '00000000-0000-0000-0000-00000000000SKILL';
let _eocSent;
let _dmTurnResult;

function createTestFlow(dialog, testCase = FlowTestCase.RootBotOnly) {
function createTestFlow(dialog, testCase = FlowTestCase.RootBotOnly, enabledTrace = false) {
const conversationId = 'testFlowConversationId';
const storage = new MemoryStorage();
const convoState = new ConversationState(storage);
Expand All @@ -68,7 +68,8 @@ function createTestFlow(dialog, testCase = FlowTestCase.RootBotOnly) {
conversation: {
isGroup: false,
conversationType: conversationId,
id: conversationId },
id: conversationId
},
};

const dm = new DialogManager(dialog);
Expand All @@ -81,7 +82,7 @@ function createTestFlow(dialog, testCase = FlowTestCase.RootBotOnly) {
const claimsIdentity = new ClaimsIdentity();
claimsIdentity.addClaim({ type: 'ver', value: '2.0' }); // AuthenticationConstants.VersionClaim
claimsIdentity.addClaim({ type: 'aud', value: SKILL_BOT_ID }); // AuthenticationConstants.AudienceClaim
claimsIdentity.addClaim({ type: 'azp', value: PARENT_BOT_ID }); // AuthenticationConstants.AuthorizedParty
claimsIdentity.addClaim({ type: 'azp', value: PARENT_BOT_ID }); // AuthenticationConstants.AuthorizedParty
context.turnState.set(context.adapter.BotIdentityKey, claimsIdentity);

if (testCase === FlowTestCase.RootBotConsumingSkill) {
Expand Down Expand Up @@ -109,7 +110,7 @@ function createTestFlow(dialog, testCase = FlowTestCase.RootBotOnly) {
});

_dmTurnResult = await dm.onTurn(context);
}, convRef);
}, convRef, enabledTrace);
adapter.use(new AutoSaveStateMiddleware(userState, convoState));

return adapter;
Expand Down Expand Up @@ -170,7 +171,7 @@ describe('DialogManager', function() {
.assertReply('Hello SomeName, nice to meet you!')
.startTest();
strictEqual(_dmTurnResult.turnResult.status, DialogTurnStatus.complete);

strictEqual(dialog.endReason, DialogReason.endCalled);
if (shouldSendEoc) {
ok(_eocSent, 'Skills should send EndConversation to channel');
Expand Down Expand Up @@ -227,6 +228,50 @@ describe('DialogManager', function() {
strictEqual(_dmTurnResult.turnResult.status, DialogTurnStatus.empty);
});

it('Trace skill state', async () => {
stevengum marked this conversation as resolved.
Show resolved Hide resolved
const dialog = new SimpleComponentDialog();
const testFlow = createTestFlow(dialog, FlowTestCase.LeafSkill, true);
await testFlow.send('Hi')
.assertReply(reply => {
strictEqual(reply.type, ActivityTypes.Trace);
})
.assertReply('Hello, what is your name?')
.assertReply(reply => {
strictEqual(reply.type, ActivityTypes.Trace);
strictEqual(reply.label, 'Skill State');
})
.send('SomeName')
.assertReply('Hello SomeName, nice to meet you!')
.assertReply(reply => {
strictEqual(reply.type, ActivityTypes.Trace);
strictEqual(reply.label, 'Skill State');
})
.assertReply(reply => {
strictEqual(reply.type, ActivityTypes.Trace);
})
.startTest();
strictEqual(_dmTurnResult.turnResult.status, DialogTurnStatus.complete);
});

it('Trace bot state', async () => {
const dialog = new SimpleComponentDialog();
const testFlow = createTestFlow(dialog, FlowTestCase.RootBotOnly, true);
await testFlow.send('Hi')
.assertReply('Hello, what is your name?')
.assertReply(reply => {
strictEqual(reply.type, ActivityTypes.Trace);
strictEqual(reply.label, 'Bot State');
})
.send('SomeName')
.assertReply('Hello SomeName, nice to meet you!')
.assertReply(reply => {
strictEqual(reply.type, ActivityTypes.Trace);
strictEqual(reply.label, 'Bot State');
})
.startTest();
strictEqual(_dmTurnResult.turnResult.status, DialogTurnStatus.complete);
});

it('Gets or sets root dialog', () => {
const dm = new DialogManager();
const rootDialog = new SimpleComponentDialog();
Expand Down