mtcute/packages/test/src/stub.test.ts

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-11-08 17:28:45 +03:00
import Long from 'long'
import { describe, expect, it } from 'vitest'
2023-11-08 17:28:45 +03:00
import { createStub } from './index.js'
2023-11-08 17:28:45 +03:00
describe('stub', () => {
it('should correctly generate simple stubs', () => {
expect(createStub('inputUser', { userId: 123 })).toEqual({
2023-11-08 17:28:45 +03:00
_: 'inputUser',
userId: 123,
accessHash: Long.ZERO,
})
})
it('should correctly generate stubs for optional fields', () => {
expect(createStub('updateChannelTooLong')).toEqual({
2023-11-08 17:28:45 +03:00
_: 'updateChannelTooLong',
channelId: 0,
pts: undefined,
})
})
it('should correctly generate stubs for boolean flags', () => {
expect(createStub('account.finishTakeoutSession')).toEqual({
2023-11-08 17:28:45 +03:00
_: 'account.finishTakeoutSession',
success: false,
})
})
it('should correctly generate stubs for vectors', () => {
expect(createStub('messageActionChatAddUser')).toEqual({
2023-11-08 17:28:45 +03:00
_: 'messageActionChatAddUser',
users: [],
})
})
2023-11-11 18:34:33 +03:00
it('should correctly generate stubs for optional vectors', () => {
expect(createStub('updateChannelPinnedTopics')).toEqual({
_: 'updateChannelPinnedTopics',
channelId: 0,
order: [],
})
})
2023-11-08 17:28:45 +03:00
it('should correctly generate stubs for nested types', () => {
expect(createStub('messageActionGroupCallScheduled', { scheduleDate: 123 })).toEqual({
2023-11-08 17:28:45 +03:00
_: 'messageActionGroupCallScheduled',
call: {
_: 'inputGroupCall',
id: Long.ZERO,
accessHash: Long.ZERO,
},
scheduleDate: 123,
})
})
})