-
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(private-greetings): Add tests for /start in private
- Loading branch information
1 parent
2196cfb
commit d8180d9
Showing
4 changed files
with
120 additions
and
3 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
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,85 @@ | ||
import test from 'ava' | ||
|
||
import { Context } from '../../tests/telegraf' | ||
import installFeature from './index' | ||
|
||
/* eslint-disable no-magic-numbers */ | ||
|
||
test('/start reply with greet in private', async (t) => { | ||
let testFn = null | ||
const bot = { | ||
command(cmd, fn) { | ||
t.is(cmd, 'start', 'command is start') | ||
t.true(typeof fn === 'function', 'callback is function') | ||
testFn = fn | ||
}, | ||
} | ||
const context = Context.create() | ||
|
||
context.message.$from() | ||
|
||
installFeature(bot) | ||
|
||
testFn(context) | ||
t.regex(context.reply.getCall(0).args[0], new RegExp(`${context.message.from.first_name}`)) | ||
}) | ||
|
||
test('/start not reply in supergroup', async (t) => { | ||
let testFn = null | ||
const bot = { | ||
command(cmd, fn) { | ||
t.is(cmd, 'start', 'command is start') | ||
t.true(typeof fn === 'function', 'callback is function') | ||
testFn = fn | ||
}, | ||
} | ||
const context = Context.create() | ||
|
||
context.message.$from() | ||
context.chat.$type('supergroup') | ||
|
||
installFeature(bot) | ||
|
||
testFn(context) | ||
t.true(context.reply.notCalled) | ||
}) | ||
|
||
test('/start not reply in group', async (t) => { | ||
let testFn = null | ||
const bot = { | ||
command(cmd, fn) { | ||
t.is(cmd, 'start', 'command is start') | ||
t.true(typeof fn === 'function', 'callback is function') | ||
testFn = fn | ||
}, | ||
} | ||
const context = Context.create() | ||
|
||
context.message.$from() | ||
context.chat.$type('group') | ||
|
||
installFeature(bot) | ||
|
||
testFn(context) | ||
t.true(context.reply.notCalled) | ||
}) | ||
|
||
test('/start not reply in channel', async (t) => { | ||
let testFn = null | ||
const bot = { | ||
command(cmd, fn) { | ||
t.is(cmd, 'start', 'command is start') | ||
t.true(typeof fn === 'function', 'callback is function') | ||
testFn = fn | ||
}, | ||
} | ||
const context = Context.create() | ||
|
||
context.message.$from() | ||
context.chat.$type('channel') | ||
|
||
installFeature(bot) | ||
|
||
testFn(context) | ||
t.true(context.reply.notCalled) | ||
}) |
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