2024-12-06 00:14:29 +03:00
|
|
|
import { after, before, describe, it } from 'node:test'
|
2024-12-03 09:55:37 +03:00
|
|
|
import { expect } from 'chai'
|
2024-12-06 00:14:29 +03:00
|
|
|
import { TelegramClient } from 'mtcute'
|
2023-12-23 22:00:20 +03:00
|
|
|
|
2024-12-06 00:14:29 +03:00
|
|
|
import { getApiParams } from './_utils.js'
|
2023-12-23 22:00:20 +03:00
|
|
|
|
2024-12-06 00:14:29 +03:00
|
|
|
describe('2. calling methods', () => {
|
2023-12-23 22:00:20 +03:00
|
|
|
const tg = new TelegramClient(getApiParams('dc2.session'))
|
|
|
|
|
2024-12-06 00:14:29 +03:00
|
|
|
before(() => tg.connect())
|
|
|
|
after(() => tg.close())
|
2023-12-23 22:00:20 +03:00
|
|
|
|
|
|
|
it('getUsers(@BotFather)', async () => {
|
|
|
|
const [user] = await tg.getUsers('botfather')
|
|
|
|
|
2024-08-13 04:53:07 +03:00
|
|
|
expect(user?.isBot).to.eq(true)
|
2023-12-23 22:00:20 +03:00
|
|
|
expect(user?.displayName).to.equal('BotFather')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('getUsers(@BotFather) - cached', async () => {
|
|
|
|
const [user] = await tg.getUsers('botfather')
|
|
|
|
|
2024-08-13 04:53:07 +03:00
|
|
|
expect(user?.isBot).to.eq(true)
|
2023-12-23 22:00:20 +03:00
|
|
|
expect(user?.displayName).to.equal('BotFather')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('getHistory(777000)', async () => {
|
2024-12-06 00:14:29 +03:00
|
|
|
await tg.findDialogs(777000) // ensure it's cached
|
2024-06-26 00:09:40 +03:00
|
|
|
|
2023-12-23 22:00:20 +03:00
|
|
|
const history = await tg.getHistory(777000, { limit: 5 })
|
|
|
|
|
2024-12-09 21:15:10 +03:00
|
|
|
expect(history[0].chat.type).to.equal('user')
|
2023-12-23 22:00:20 +03:00
|
|
|
expect(history[0].chat.id).to.equal(777000)
|
2024-12-11 07:37:19 +03:00
|
|
|
expect(history[0].chat.displayName).to.match(/^Telegram(?: Notifications)?$/)
|
2023-12-23 22:00:20 +03:00
|
|
|
})
|
|
|
|
})
|