mtcute/e2e/tests/02.methods.e2e.ts
alina sireneva b5bf02fc72
chore(core)!: extract user-specific fields from (Full)Chat to (Full)User
breaking:
 - `getChat`, `getFullChat` now only work for chats (channels/supergroups/basic groups)
 - for users, use `getUser` and `getFullUser`
 - many fields that previously had type `Chat` now have type `User | Chat`
2024-12-09 21:19:41 +03:00

36 lines
1.1 KiB
TypeScript

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
const history = await tg.getHistory(777000, { limit: 5 })
expect(history[0].chat.type).to.equal('user')
expect(history[0].chat.id).to.equal(777000)
expect(history[0].chat.displayName).to.equal('Telegram')
})
})