Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Fixes #1849 - exclude conversation.properties field from key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrown committed Mar 11, 2020
1 parent 46f9120 commit f776ed5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/botkit/src/conversationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class BotkitConversationState extends ConversationState {

// create a combo key by sorting all the fields in the conversation address and combining them all
// mix in user id as well, because conversations are between the bot and a single user
const conversationId: string = Object.keys(activity.conversation).sort().map((key) => activity.conversation[key]).filter((val) => val !== '' && val !== null && typeof val !== 'undefined').join('-') + '-' + activity.from.id;
const conversationId: string = Object.keys(activity.conversation).filter((key) => { return key !== 'properties'; }).sort().map((key) => activity.conversation[key]).filter((val) => val !== '' && val !== null && typeof val !== 'undefined').join('-') + '-' + activity.from.id;

if (!channelId) {
throw new Error('missing activity.channelId');
Expand Down
56 changes: 56 additions & 0 deletions packages/botkit/tests/State.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const assert = require('assert');
const { BotkitConversationState } = require('../lib/conversationState');
const { MemoryStorage } = require('botbuilder');

const storage = new MemoryStorage();
const state = new BotkitConversationState(storage);

describe('BotkitConversationState', function() {
it('should generate appropriate state key', function() {
const key = state.getStorageKey({
activity: {
channelId: 'test',
from: {
id: 'foo'
},
conversation: {
id: 'bar'
}
}
});
assert(key === 'test/conversations/bar-foo/', 'failed key gen');
});
it('should generate appropriate state key excluding properties field', function() {
const key = state.getStorageKey({
activity: {
channelId: 'test',
from: {
id: 'foo'
},
conversation: {
properties: {
baz: true
},
id: 'bar'
}
}
});
assert(key === 'test/conversations/bar-foo/', 'failed key gen');
});
it('should generate appropriate state key including platform field', function() {
const key = state.getStorageKey({
activity: {
channelId: 'test',
from: {
id: 'foo'
},
conversation: {
threadId: '5',
channel: '9',
id: 'bar'
}
}
});
assert(key === 'test/conversations/9-bar-5-foo/', 'failed key gen');
});
});

1 comment on commit f776ed5

@etiennellipse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for test coverage!

Please sign in to comment.