Error in initialUserMessage() and storage missing
opened this issue · comments
-
You messed up the initialUserMessage() method in line 146 of BotMock, so it does not work with actual regular expressions. You take a RegEx, convert it into a String and then convert it back to a RegEx. So if I use a RegEx: /someRegEx/ it is converted to //someRegEx//i.
So I solved it like this:let p = obj.pattern; if (Array.isArray(obj.pattern)) { for (let i = 0;i < p.length;i++) { if ((message.text || message).match(new RegExp(p[i], 'i'))) { message.match = (message.text || message).match(p); return (message.text || message).match(new RegExp(p[i], 'i')); } } } else { if ((message.text || message).match(new RegExp(p, 'i'))) { message.match = (message.text || message).match(new RegExp(p, 'i')) } } return (message.text || message).match(new RegExp(p, 'i'));
-
BotMock.js does not support simple_storage:
If you want to support that just add the simple_storage.js to your requirements, then you only have to add:memory_store: { users: { }, channels: { }, teams: { }, }
to line 11:
line 11:this.botkit = { tasks: [], log: function(){} };
Additionally, if you want to access the storage with your Bot you have to add the team_id or user_id to the call back:
See this example:
addthis.convo.sourceMessage.username = message.username;
to
this.convo.sourceMessage.user = message.user; this.convo.sourceMessage.channel = message.user;
in line line 77, 78
and
to line 245
channel: this.sourceMessage.channel
add:
user: this.sourceMessage.username
Thank you. Looking into this and making changes to BotMock master. Will close this issue and comment our changes to this issue when master is updated.
@amplicity I'm working on tests that will involve simple_storage. I was just curious why you didn't address item 2 above in @TabeaSpahn's issue. Is there another way to approach testing with storage?
Slipped past us. Reopening and will push the simple storage mods soon.
@amplicity thanks!
@nsbingham see 2a24d01