
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
botkit-mock
Advanced tools
npm install --save botkit-mock
botkit-mock
in your test: const Botmock = require('botkit-mock');
const fileBeingTested = require("./indexController")
Let's say you have a controller that looks something like this:
module.exports = function(controller) {
// simple answer
controller.hears(['help'], 'direct_message', function (bot, message) {
bot.reply(message, 'help message');
});
}
To use botkit-mock
, you can test your controller like below:
const Botmock = require('botkit-mock');
const yourController = require("./yourController");
describe("controller tests",()=>{
beforeEach(()=>{
this.controller = Botmock({});
// type can be ‘slack’, facebook’, or null
this.bot = this.controller.spawn({type: 'slack'});
yourController(this.controller);
});
});
In your it
statement, use the bot.usersInput
method to define the conversation.
it('should return `help message` if user types `help`', () => {
return this.bot.usersInput(
[
{
user: 'someUserId',
channel: 'someChannel',
messages: [
{
text: 'help', isAssertion: true
}
]
}
]
).then((message) => {
// In message, we receive a full object that includes params:
// {
// user: 'someUserId',
// channel: 'someChannel',
// text: 'help message',
// }
return assert.equal(message.text, 'help message');
})
});
botExtender
- allows developers to extend the bot and add custom functions to the bot
. This overrides functionality in BotmockWorker.js.
To use this, define botExtender
in your beforeEach
. It accepts three parameters (bot, botkit, config)
, which are passed in from Botmock.js and BotmockWorker.js. Pass botExtender
to your .spawn()
and you will have access to your custom functions in the it
.
beforeEach(()=>{
function botExtender(bot, botkit, config){
bot.customReply = function(message, text){
bot.reply(message, 'Something new...' + text)
}
}
this.bot = this.controller.spawn({type: 'slack', botExtender: botExtender});
});
user
user slackId (required) (string)channel
is a channel where user sends messages (required) (string)type
specify botkit message type. ie direct_message
, message_received
, interactive_message_callback
. (defaults to direct_message
) (string)messages
(array) that includes:
isAssertion
indicates which conversation response array to return in .then()
in multi-user testing. (required) (boolean)deep
indicates the index of the conversation response to return in .then()
. 0 (default) is the last response, 1 is the second-to-last, etc.. (integer)timeout
set timeout for message in milliseconds (integer)waitBefore
alias for timeout
, indicates how many milliseconds to wait before sending the message to the bot (integer)waitAfter
indicates how many milliseconds to wait for the bot response, useful for long-running commands (integer)text
the message's text (string)channel
indicates the channel the message was sent in. This overrides the channel defined in usersInput
for this current message. (string)attachments
, callback_id
, etc...botkit-mock
currently (and will always) support all of Botkit's core functionality by default. We also support extended Slack and Facebook functionality.
To add functionality to botkit-mock
, you can create platform-specific functions like seen in FacebookBotWorker. If you add functionality to support something we don't, please make a PR.
*mochaSpec.js
)*MochaSpec.js
or *JasmineSpec.js
)Built by the team at https://www.gratify.chat.
Like botkit-mock? Donate BTC to our team: 1KwpqzTvpLWiUST2V5wmPiT3twwc1pZ9tP
FAQs
Write tests for botkit.
The npm package botkit-mock receives a total of 35 weekly downloads. As such, botkit-mock popularity was classified as not popular.
We found that botkit-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.