Skip to content

Commit

Permalink
New tests and Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoDanin committed Oct 4, 2018
1 parent 045f8c5 commit 08f7352
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ test.sendMessageWithText('/ping')
- **setUpdateId(id: Number)**
> Update id.</br>
> Default value: Start in `0`
- **setWebhook({**[params](https://core.telegram.org/bots/api#setwebhook)**})**
- **setAllowedUpdates({**[params](https://core.telegram.org/bots/api#update)**})**

### Get Objects

Expand All @@ -103,10 +105,12 @@ test.sendMessageWithText('/ping')
- **getInlineQuery()**
- **getCallbackQuery()**
- **getUpdateId()**
- **getWebhook()**
- **getAllowedUpdates()**

#### Send Requests

Return request of [axios](https://github.com/axios/axios).
Return request of [axios](https://github.com/axios/axios) or `false` in updates ignored.

- **sendUpdate({**[params](https://core.telegram.org/bots/api#update)**})**
- **sendMessage({**[params](https://core.telegram.org/bots/api#message)**})**
Expand All @@ -119,12 +123,13 @@ Return request of [axios](https://github.com/axios/axios).

Telegram Bot Api Server Emulator. Start with `startServer()`.

- [ ] [getMe](https://core.telegram.org/bots/api#getme)
- [x] [getMe](https://core.telegram.org/bots/api#getme)
- [x] [setWebhook](https://core.telegram.org/bots/api#setwebhook)
- [x] [getWebhookInfo](https://core.telegram.org/bots/api#deletewebhook)
- [x] [setWebhook](https://core.telegram.org/bots/api#getwebhookinfo)

<!--
- [ ] [getMe](https://core.telegram.org/bots/api#getme)
- [ ] [getUpdates](https://core.telegram.org/bots/api#getupdates)
- [ ] [setWebhook](https://core.telegram.org/bots/api#setwebhook)
- [ ] [sendMessage](https://core.telegram.org/bots/api#sendmessage)
- [ ] [forwardMessage](https://core.telegram.org/bots/api#forwardmessage)
- [ ] [sendPhoto](https://core.telegram.org/bots/api#sendphoto)
Expand Down
35 changes: 32 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const bot = new Telegraf('ABCD:1234567890')
const test = new TelegrafTest({
url: `http://127.0.0.1:${port}/${secretPath}`
})
test.startServer()

bot.hears(/ping/i, (ctx) => {
ctx.reply('Pong!')
Expand Down Expand Up @@ -39,9 +40,9 @@ bot.startWebhook(`/${secretPath}`, null, port)
describe('Telegraf Test', function() {
it('setBot()', async function() {
var bot = test.setBot({
username: '@Tiagobot'
username: 'Tiagobot'
})
assert.equal(bot.username, '@Tiagobot')
assert.equal(bot.username, 'Tiagobot')
})

it('setUser()', async function() {
Expand Down Expand Up @@ -88,6 +89,26 @@ describe('Telegraf Test', function() {
assert.equal(id, 6)
})

it('setWebhook()', async function() {
var webhook = test.setWebhook()
assert.equal(webhook.url, test.webhook.url)
assert.equal(webhook.allowed_updates.toString(), test.getAllowedUpdates().toString())
})

it('setAllowedUpdates()', async function() {
var updatesType = test.setAllowedUpdates()
assert.equal(updatesType.toString(), [
'message',
'channel_post',
'edited_channel_post',
'inline_query',
'chosen_inline_result',
'callback_query',
'shipping_query',
'pre_checkout_query'
].toString())
})

it('getBot', async function() {
assert.equal(test.getBot(), test.bot)
})
Expand Down Expand Up @@ -116,9 +137,17 @@ describe('Telegraf Test', function() {
assert.equal(test.getUpdateId(), test.updateId)
})

it('getWebhook', async function() {
assert.equal(test.getWebhook(), test.webhook)
})

it('getAllowedUpdates', async function() {
assert.equal(test.getAllowedUpdates(), test.allowedUpdates)
})

it('sendUpdate()', async function() {
var r = await test.sendUpdate({})
assert.equal(r.data, '')
assert.equal(r, false)
})

it('sendMessage()', async function() {
Expand Down

0 comments on commit 08f7352

Please sign in to comment.