-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(middlewares/allowed-chat): Add test for allowWhiteListChat (#22)
- Loading branch information
1 parent
ffb40b0
commit 5d38be0
Showing
3 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import test from 'ava' | ||
import sinon from 'sinon' | ||
import { Context } from '../tests/telegraf' | ||
import { allowWhiteListChat } from './allowed-chat' | ||
|
||
/* eslint-disable no-param-reassign */ | ||
|
||
test.beforeEach((t) => { | ||
t.context.create = ({ inWhitelist }) => { | ||
const ctx = Context.create() | ||
const res = Math.random() | ||
const next = sinon.stub().returns(res) | ||
|
||
ctx.isChatInWhiteList = sinon.stub().returns(inWhitelist) | ||
|
||
return { ctx, res, next } | ||
} | ||
}) | ||
|
||
test('should pass in whitelist', async (t) => { | ||
const { ctx, res, next } = t.context.create({ inWhitelist: true }) | ||
const result = await allowWhiteListChat(ctx, next) | ||
|
||
t.true(next.called) | ||
t.is(result, res) | ||
t.true(ctx.isChatInWhiteList.calledWith(ctx.chat)) | ||
}) | ||
|
||
test('should stop not in whitelist', async (t) => { | ||
const { ctx, next } = t.context.create({ inWhitelist: false }) | ||
const result = await allowWhiteListChat(ctx, next) | ||
|
||
t.false(next.called) | ||
t.is(result, null) | ||
t.true(ctx.isChatInWhiteList.calledWith(ctx.chat)) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters