mtcute/packages/file-id/src/serialize-unique.test.ts

36 lines
1.4 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from 'vitest'
import { defaultPlatform } from '@mtcute/test'
import { parseFileId } from './parse.js'
import { toUniqueFileId } from './serialize-unique.js'
// test file IDs are partially taken from https://github.com/luckydonald/telegram_file_id
describe('serializing unique file ids', () => {
const test = (id: string, expected: string) => {
expect(toUniqueFileId(defaultPlatform, parseFileId(defaultPlatform, id))).eql(expected)
}
it('serializes unique ids for old file ids', () => {
test('CAADAQADegAD997LEUiQZafDlhIeAg', 'AgADegAD997LEQ')
})
it('serializes unique ids for common file ids', () => {
2023-09-24 01:32:22 +03:00
test('CAACAgEAAx0CVgtngQACAuFfU1GY9wiRG7A7jlIBbP2yvAostAACegAD997LEUiQZafDlhIeGwQ', 'AgADegAD997LEQ')
test('BQACAgIAAxkBAAEJnzNgit00IDsKd07OdSeanwz8osecYAACdAwAAueoWEicaPvNdOYEwB8E', 'AgADdAwAAueoWEg')
test(
'AAMCAgADGQEAAQmfM2CK3TQgOwp3Ts51J5qfDPyix5xgAAJ0DAAC56hYSJxo-8105gTAT_bYoy4AAwEAB20AA0JBAAIfBA',
'AQADdAwAAueoWEhy',
)
2023-09-24 01:32:22 +03:00
test('CAACAgIAAxkBAAEJny9gituz1_V_uSKBUuG_nhtzEtFOeQACXFoAAuCjggfYjw_KAAGSnkgfBA', 'AgADXFoAAuCjggc')
})
it('serializes unique ids for profile pictures', () => {
// big
2023-09-24 01:32:22 +03:00
test('AQADAgATySHBDgAEAwAD0npI3Bb___-wfxjpg7QCPf8pBQABHwQ', 'AQADySHBDgAE_ykFAAE')
// small
2023-09-24 01:32:22 +03:00
test('AQADAgATySHBDgAEAgAD0npI3Bb___-wfxjpg7QCPf0pBQABHwQ', 'AQADySHBDgAE_SkFAAE')
})
})