test(core): fixed resolvePeer tests
This commit is contained in:
parent
9e218e3457
commit
9622d2c0a2
1 changed files with 76 additions and 2 deletions
|
@ -140,9 +140,44 @@ describe('resolvePeer', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw if not in storage', async () => {
|
it('should return with zero hash for bots if not in storage', async () => {
|
||||||
|
const client = StubTelegramClient.offline()
|
||||||
|
|
||||||
|
await client.storage.self.storeFrom(createStub('user', {
|
||||||
|
bot: true,
|
||||||
|
}))
|
||||||
|
|
||||||
|
expect(await resolvePeer(client, 123)).toEqual({
|
||||||
|
_: 'inputPeerUser',
|
||||||
|
userId: 123,
|
||||||
|
accessHash: Long.ZERO,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should try fetching with zero hash for users if not in storage', async () => {
|
||||||
const client = new StubTelegramClient()
|
const client = new StubTelegramClient()
|
||||||
|
|
||||||
|
const handler = vi.fn().mockResolvedValue([
|
||||||
|
createStub('user', {
|
||||||
|
id: 123,
|
||||||
|
accessHash: Long.fromBits(456, 789),
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
client.respondWith('users.getUsers', handler)
|
||||||
|
|
||||||
|
expect(await resolvePeer(client, 123)).toEqual({
|
||||||
|
_: 'inputPeerUser',
|
||||||
|
userId: 123,
|
||||||
|
accessHash: Long.fromBits(456, 789),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should throw if zero hash fetch failed', async () => {
|
||||||
|
const client = new StubTelegramClient()
|
||||||
|
|
||||||
|
const handler = vi.fn().mockResolvedValue([])
|
||||||
|
client.respondWith('users.getUsers', handler)
|
||||||
|
|
||||||
await expect(resolvePeer(client, 123)).rejects.toThrow(MtPeerNotFoundError)
|
await expect(resolvePeer(client, 123)).rejects.toThrow(MtPeerNotFoundError)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -192,9 +227,48 @@ describe('resolvePeer', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw if not in storage', async () => {
|
it('should return with zero hash for bots if not in storage', async () => {
|
||||||
|
const client = StubTelegramClient.offline()
|
||||||
|
|
||||||
|
await client.storage.self.storeFrom(createStub('user', {
|
||||||
|
bot: true,
|
||||||
|
}))
|
||||||
|
|
||||||
|
expect(await resolvePeer(client, -1000000000123)).toEqual({
|
||||||
|
_: 'inputPeerChannel',
|
||||||
|
channelId: 123,
|
||||||
|
accessHash: Long.ZERO,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should try fetching with zero hash for users if not in storage', async () => {
|
||||||
const client = new StubTelegramClient()
|
const client = new StubTelegramClient()
|
||||||
|
|
||||||
|
const handler = vi.fn().mockResolvedValue({
|
||||||
|
chats: [
|
||||||
|
createStub('channel', {
|
||||||
|
id: 123,
|
||||||
|
accessHash: Long.fromBits(456, 789),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
client.respondWith('channels.getChannels', handler)
|
||||||
|
|
||||||
|
expect(await resolvePeer(client, -1000000000123)).toEqual({
|
||||||
|
_: 'inputPeerChannel',
|
||||||
|
channelId: 123,
|
||||||
|
accessHash: Long.fromBits(456, 789),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should throw if zero hash fetch failed', async () => {
|
||||||
|
const client = new StubTelegramClient()
|
||||||
|
|
||||||
|
const handler = vi.fn().mockResolvedValue({
|
||||||
|
chats: [],
|
||||||
|
})
|
||||||
|
client.respondWith('channels.getChannels', handler)
|
||||||
|
|
||||||
await expect(resolvePeer(client, -1000000000123)).rejects.toThrow(MtPeerNotFoundError)
|
await expect(resolvePeer(client, -1000000000123)).rejects.toThrow(MtPeerNotFoundError)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue