mtsmfm / hubot-test-helper

Helper for testing hubot script
MIT License
115 stars 40 forks source link

support testing one robot (shared brain) present in multiple rooms #32

Open MatthewMazaika opened 8 years ago

MatthewMazaika commented 8 years ago

not sure about other implementations, but in slack, hubot can be in multiple rooms (channels), but there is only one instance of the robot and brain

is there a way to test this functionality with the current test-helper and I'm missing it?

if not, can we add on this functionality? i'd be glad to implement and PR with some guidance, but at this point I don't quite have a lot of background on test-helper or hubot architecture.

thanks! Matt

mtsmfm commented 8 years ago

@MatthewMazaika

At this time, there is no way to share brain :cry: But I wonder why do you want to share the brain :dizzy: Could you tell me the context and ideal test code? (the code won't work at the time but I want to know how do you want to write test :wink: )

IAmPatrickB commented 8 years ago

This is something I do as well, but I haven't written tests for my custom scripts yet - in an Enterprise level organization, we have hundreds of rooms our Hubot is in. I've written a few custom scripts to support Authentication based on level of user in a Room, the room a user is in, or the room a request comes from. Ours also provides the ability to message users across rooms by mentioning a nick that's designated to the hubot "i.e. @Hubot this room belongs to Perf", then anyone who mentions @perf the bot will transmit the message to their private room.

I'm looking at implementing some custom test scripts this week, I'll let you know what challenges I run into.

timkinnane commented 7 years ago

Would also like to do this. I'm testing scripts for a platform with many rooms, where use cases need hubot to remember past interactions and context with a user across rooms. Ran into a wall trying to test some uncommon behaviour for fairly specific interactions. e.g. it should respond to a given user in any room, but not other users - or - it will respond to any user in a given room, but not other rooms.

I have similar requirements to this example from Hubot-Conversation but would prefer to find an approach consistent with my other tests using hubot-test-helper.

e.g.

@room1 = helper.createRoom name: 'room1'
@room2 = helper.createRoom name: 'room2'
@room1.user.say 'user1', 'hello its me'
@room2.user.say 'user1', 'its me again'

I discovered one easy tip for anyone trying this, that the httpd: false option will prevent EADDRINUSE 0.0.0.0:8080 errors from trying to setup multiple concurrent listeners.

yozlet commented 7 years ago

Here's a really simple test case: I have a hubot script which can be triggered in any room that the bot is in, and the result is that it should emit a message to a configured target room.

Here's the script: https://github.com/18F/18f-bot/blob/master/scripts/love.coffee Here's the test case I wrote: https://github.com/18F/18f-bot/blob/master/test/scripts/love_test.coffee

However, this test case only works because hubot-test-helper doesn't differentiate between rooms in which the message is being emitted. Ideally, the test case should involve two rooms, emit the trigger message in the first room, and assert that the result message is emitted in the second room.

EDITED TO ADD: @timkinnane, I only just noticed hubot-pretend. Nice! I'll try rewriting the test with that when I get a moment.

timkinnane commented 7 years ago

@yozlet - Cool! You'll be the first user afaik. I think it's pretty good and have used it extensively in my own project. I tried to write clear and comprehensive tests, but I'd be really interested to get your feedback - it's easy to miss things when you're the creator and only user.

Have a look here for multi-room test examples.

ummaycoc commented 6 years ago

Did anything come of this?

timkinnane commented 6 years ago

@ummaycoc I'm working on a new framework of the whole stack I developed based on hubot, nubot/playbook/pretend - it will provide multi room testing tools, but is still a little way off. If you'd like to get early access please email me: timkinnane@gmail.com

For now, here's the updated link from above, for using Pretend to do multi-room tests...

https://github.com/timkinnane/hubot-pretend/blob/master/test/usage/02-rooms_test.js