2023-12-23 22:00:20 +03:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { describe, it } from 'mocha'
|
2024-06-26 00:09:40 +03:00
|
|
|
import { MtPeerNotFoundError } from '@mtcute/core'
|
2024-03-01 18:16:07 +03:00
|
|
|
import { TelegramClient } from '@mtcute/core/client.js'
|
2023-12-23 22:00:20 +03:00
|
|
|
|
|
|
|
import { getApiParams } from '../utils.js'
|
|
|
|
|
|
|
|
describe('2. calling methods', function () {
|
|
|
|
this.timeout(300_000)
|
|
|
|
const tg = new TelegramClient(getApiParams('dc2.session'))
|
|
|
|
|
|
|
|
this.beforeAll(() => tg.connect())
|
|
|
|
this.afterAll(() => tg.close())
|
|
|
|
|
|
|
|
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-06-26 00:09:40 +03:00
|
|
|
try {
|
|
|
|
await tg.findDialogs(777000) // ensure it's cached
|
|
|
|
} catch (e) {
|
|
|
|
if (e instanceof MtPeerNotFoundError) {
|
|
|
|
// this happens sometimes :D gracefully skip
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
throw e
|
|
|
|
}
|
|
|
|
|
2023-12-23 22:00:20 +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')
|
|
|
|
})
|
|
|
|
})
|