Skip to content

Commit

Permalink
Done test and remove expectjs
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoDanin committed Sep 20, 2018
1 parent c60b5ae commit dd9ff6f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 13 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ Set environment variables `DEBUG=telgraf:test`
## Dev Dependencies

- [telegraf](https://ghub.io/telegraf): 📡 Modern Telegram bot framework
- [expect.js](https://ghub.io/expect.js): BDD style assertions for node and the browser.
- [mocha](https://ghub.io/mocha): simple, flexible, fun test framework

## License
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
},
"devDependencies": {
"telegraf": "3.23.1",
"expect.js": "0.3.1",
"mocha": "5.2.0"
},
"scripts": {
Expand Down
110 changes: 99 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Telegraf = require('telegraf')
const TelegrafTest = require('.')
const expect = require('expect.js')
const assert = require('assert')

const port = 3000
const secretPath = 'secret-path'
Expand All @@ -10,23 +10,111 @@ const test = new TelegrafTest({
url: `http://127.0.0.1:${port}/${secretPath}`
})

test.setUser({
id: 1234,
username: '@Jack'
//...//
})

bot.hears(/ping/i, (ctx) => {
console.log('------')
ctx.reply('Pong!')
})

bot.on('inline_query', (ctx) => {
ctx.answerInlineQuery([{
type: 'article',
title: 'TITLE',
id: 'TEST',
input_message_content: {
message_text: 'TEST'
}
}], {
cache_time: 0
})
})

bot.on('callback_query', (ctx) => {
ctx.answerCbQuery(
'Test‼️',
true
)
})

bot.startWebhook(`/${secretPath}`, null, port)

describe('Telegraf Test', function() {
it('/ping', async function() {
it('setUser()', async function() {
var user = test.setUser({
id: 1234,
username: '@Jack'
})
assert.equal(user.id, 1234)
assert.equal(user.username, '@Jack')
})

it('setChat()', async function() {
var chat = test.setChat({
id: 6655465,
type: 'supergroup'
})
assert.equal(chat.id, 6655465)
assert.equal(chat.type, 'supergroup')
})

it('setMessage()', async function() {
var message = test.setMessage({})
assert.equal(message.message_id, 2)
assert.equal(message.from.username, '@Jack')
})

it('setMessage()', async function() {
var message = test.setMessage({})
assert.equal(message.from.username, '@Jack')
})

it('setInlineQuery()', async function() {
var inline = test.setInlineQuery({})
assert.equal(inline.from.username, '@Jack')
})

it('setCallbackQuery()', async function() {
var callback = test.setCallbackQuery({})
assert.equal(callback.from.username, '@Jack')
})

it('setUpdateId()', async function() {
var id = test.setUpdateId(6)
assert.equal(id, 6)
})

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

it('sendMessage()', async function() {
var r = await test.sendMessage({
text: '/ping'
})
assert.equal(r.data.text, 'Pong!')
})

it('sendMessageWithText()', async function() {
var r = await test.sendMessageWithText('/ping')
expect(r.data.text).to.be.a('string')
expect(r.data.text).to.contain('Pong!')
assert.equal(r.data.text, 'Pong!')
})

it('sendInlineQuery()', async function() {
var r = await test.sendInlineQuery('hi!')
assert.equal(r.data.method, 'answerInlineQuery')
assert.equal(r.data.cache_time, 0)
})

it('sendCallbackQuery()', async function() {
var r = await test.sendCallbackQueryWithData({
data: 'test'
})
assert.equal(r.data.method, 'answerCallbackQuery')
assert.equal(r.data.text, 'Test‼️')
})

it('sendCallbackQueryWithData()', async function() {
var r = await test.sendCallbackQueryWithData('test')
assert.equal(r.data.method, 'answerCallbackQuery')
assert.equal(r.data.text, 'Test‼️')
})
})

0 comments on commit dd9ff6f

Please sign in to comment.