Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}, {})
app
.init()
.event('message', (msg) => {
t.deepEqual(msg, message)
})
._handle(message, (err, handled) => {
t.is(err, null)
t.true(handled)
t.end()
})
})
test.cb('SlackApp.ignoreBotsMiddleware() with bot message', t => {
let app = new SlackApp()
let mw = app.ignoreBotsMiddleware()
let message = new Message('event', {}, {
bot_id: 'asdf'
})
// this callback is synchronous
mw(message, () => {
t.fail()
})
t.pass()
t.end()
})
test.cb('SlackApp.ignoreBotsMiddleware() w/o bot message', t => {
let app = new SlackApp()
let mw = app.ignoreBotsMiddleware()
let message = new Message('event', {}, {
bot_id: 'asdf'
})
// this callback is synchronous
mw(message, () => {
t.fail()
})
t.pass()
t.end()
})
test.cb('SlackApp.ignoreBotsMiddleware() w/o bot message', t => {
let app = new SlackApp()
let mw = app.ignoreBotsMiddleware()
let message = new Message('event', {}, {})
// this callback is synchronous
mw(message, () => {
t.pass()
t.end()
})
})
test.serial("performs well on small scenario", t => {
t.true(smallScenario(10).elapsed < TOO_SLOW_MS)
})
test.serial("performs well on medium scenario", t => {
t.true(mediumScenario(10).elapsed < TOO_SLOW_MS)
})
test.serial("performs well on large scenario", t => {
t.true(largeScenario(10, 0, 0).elapsed < TOO_SLOW_MS)
t.true(largeScenario(10, 10, 0).elapsed < TOO_SLOW_MS)
t.true(largeScenario(10, 0, 10).elapsed < TOO_SLOW_MS)
t.true(largeScenario(10, 10, 10).elapsed < TOO_SLOW_MS)
})
test.cb("timer", t => {
const go = start()
setTimeout(function() {
const lap = go(true)
setTimeout(function() {
const done = go()
t.not(lap, 0)
t.not(done, 0)
t.not(lap, done)
t.end()
}, 2)
}, 2)
})
next()
})
.match((msg) => {
return true
})
app._handle(message, (err, handled) => {
t.true(attachSlackAppStub.calledOnce)
t.is(err, null)
t.true(handled)
t.end()
})
})
test.cb('SlackApp._handle() no mw, with override, no matchers', t => {
t.plan(5)
let app = new SlackApp()
let message = {
override: (msg) => {
t.deepEqual(msg, message)
},
conversation_id: 'asdf',
attachSlackApp: () => {}
}
let attachSlackAppStub = sinon.stub(message, 'attachSlackApp')
let delSpy = sinon.spy(app.convoStore, 'del')
app._handle(message, (err, handled) => {
t.true(attachSlackAppStub.calledOnce)
t.is(err, null)
test.cb("can handle async actions", t => {
testCoffeeTodo(
t,
self =>
function* fetchData(this: any, kind: string) {
self.title = "getting coffee " + kind
self.title = yield delay(100, "drinking coffee")
return "awake"
},
false,
"awake",
["getting coffee black", "drinking coffee"]
)
})
test.cb("can handle erroring actions", t => {
testCoffeeTodo(
t,
self =>
function* fetchData(this: any, kind: string) {
throw kind
},
true,
"black",
[]
)
})
test.cb("can handle try catch", t => {
testCoffeeTodo(
t,
self =>
command: 'test'
}
}
app
.command(message.body.command, (msg) => {
t.deepEqual(msg, message)
})
._handle(message, (err, handled) => {
t.is(err, null)
t.true(handled)
t.end()
})
})
test.cb('SlackApp.command() w/ criteria string', t => {
t.plan(3)
let app = new SlackApp()
let message = {
attachSlackApp () {},
type: 'command',
body: {
command: 'test',
text: 'hello'
}
}
app
.command(message.body.command, 'hel', (msg) => {
t.deepEqual(msg, message)
})
bot_user_id: 'asdf',
channel_id: 'qwertyg'
})
app
.message('beep', 'ambient', (msg) => {
t.deepEqual(msg, message)
})
._handle(message, (err, handled) => {
t.is(err, null)
t.true(handled)
t.end()
})
})
test.cb('SlackApp.event() w/ string criteria', t => {
t.plan(3)
let app = new SlackApp()
let message = new Message('event', {
event: {
type: 'message',
text: 'beep boop'
}
}, {})
app
.event('message', (msg) => {
t.deepEqual(msg, message)
})
._handle(message, (err, handled) => {
t.is(err, null)
],
callback_id: 'my_callback',
command: 'test'
}
}
app
.action(message.body.callback_id, 'boop', () => {})
._handle(message, (err, handled) => {
t.is(err, null)
t.false(handled)
t.end()
})
})
test.cb('SlackApp.message() w/o filter', t => {
t.plan(3)
let app = new SlackApp()
let message = new Message('event', {
event: {
type: 'message',
text: 'beep boop'
}
}, {})
app
.message('beep', (msg) => {
t.deepEqual(msg, message)
})
._handle(message, (err, handled) => {
t.is(err, null)
text: 'hello'
}
}
app
.command(message.body.command, 'hel', (msg) => {
t.deepEqual(msg, message)
})
._handle(message, (err, handled) => {
t.is(err, null)
t.true(handled)
t.end()
})
})
test.cb('SlackApp.command() w/ criteria regex', t => {
t.plan(3)
let app = new SlackApp()
let message = {
attachSlackApp () {},
type: 'command',
body: {
command: 'test',
text: 'hello'
}
}
app
.command(message.body.command, /llo$/, (msg) => {
t.deepEqual(msg, message)
})
attachSlackApp: () => {}
}
let attachSlackAppStub = sinon.stub(message, 'attachSlackApp')
let delSpy = sinon.spy(app.convoStore, 'del')
app._handle(message, (err, handled) => {
t.true(attachSlackAppStub.calledOnce)
t.is(err, null)
t.true(handled)
t.true(delSpy.calledWith(message.conversation_id))
t.end()
})
})
test.cb('SlackApp._handle() with override and del error', t => {
t.plan(6)
let app = new SlackApp()
let message = {
onError: () => {},
override: (msg) => {
t.deepEqual(msg, message)
},
conversation_id: 'asdf',
attachSlackApp: () => {}
}
let attachSlackAppStub = sinon.stub(message, 'attachSlackApp')
let onErrorSpy = sinon.stub(app, 'onError')
let delStub = sinon.stub(app.convoStore, 'del', (id, cb) => {
cb(new Error('kaboom'))
})