mtcute/e2e/tests/02.methods.e2e.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

import { after, before, describe, it } from 'node:test'
import { expect } from 'chai'
import { TelegramClient } from 'mtcute'
import { getApiParams } from './_utils.js'
describe('2. calling methods', () => {
const tg = new TelegramClient(getApiParams('dc2.session'))
before(() => tg.connect())
after(() => tg.close())
it('getUsers(@BotFather)', async () => {
const [user] = await tg.getUsers('botfather')
expect(user?.isBot).to.eq(true)
expect(user?.displayName).to.equal('BotFather')
})
it('getUsers(@BotFather) - cached', async () => {
const [user] = await tg.getUsers('botfather')
expect(user?.isBot).to.eq(true)
expect(user?.displayName).to.equal('BotFather')
})
it('getHistory(777000)', async () => {
await tg.findDialogs(777000) // ensure it's cached
2024-06-26 00:09:40 +03:00
const history = await tg.getHistory(777000, { limit: 5 })
expect(history[0].chat.chatType).to.equal('private')
expect(history[0].chat.id).to.equal(777000)
expect(history[0].chat.firstName).to.equal('Telegram')
})
})