mtcute/e2e/cjs/tests/tl-schema.js
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* feat: moved tl-runtime to esm and native ArrayBuffers

* feat: migration to esm

* fix(core): web-related fixes

* test: finally, some good fucking e2e

* chore: fixed linters etc

* ci: added e2e to ci

* build(tl): fixed gen-code on node 20

* fix: codegen Uint8Array, not Buffer

never `git reset --hard` kids

* build: only do type-aware linting for `packages/*`

* build: ignore no-unresolved in ci for e2e

* fix: node 16 doesn't have subtle crypto apparently?

* fix(tests): use Uint8Array

for gods sake please can i just merge this already

* ci: don't parallel tasks in ci

because machines are utter garbage and it may just randomly break

* ci: pass secrets to e2e tests

* ci: separate cli command for ci

apparently im retarded

* fix: run codegen in e2e

im actually retarded

* ci: more fixes for e2e

* ci: debugging stuff

* ci: still debugging

* ci: hopefully fix ci???
2023-10-16 19:23:53 +03:00

39 lines
1.3 KiB
JavaScript

const Long = require('long')
const {
TlBinaryReader,
TlBinaryWriter,
hexEncode,
} = require('@mtcute/tl-runtime')
const { tl } = require('@mtcute/tl')
const { __tlReaderMap } = require('@mtcute/tl/binary/reader')
const { __tlWriterMap } = require('@mtcute/tl/binary/writer')
const { describe, it } = require('mocha')
const { expect } = require('chai')
// here we primarily want to check that @mtcute/tl correctly works with @mtcute/tl-runtime
describe('@mtcute/tl', () => {
it('writers map works with TlBinaryWriter', () => {
const obj = {
_: 'inputPeerUser',
userId: 123,
accessHash: Long.fromNumber(456),
}
expect(hexEncode(TlBinaryWriter.serializeObject(__tlWriterMap, obj))).to.equal('4ca5e8dd7b00000000000000c801000000000000')
})
it('readers map works with TlBinaryReader', () => {
const buf = Buffer.from('4ca5e8dd7b00000000000000c801000000000000', 'hex')
const obj = TlBinaryReader.deserializeObject(__tlReaderMap, buf)
expect(obj._).equal('inputPeerUser')
expect(obj.userId).equal(123)
expect(obj.accessHash.toString()).equal('456')
})
it('correctly checks for combinator types', () => {
expect(tl.isAnyInputUser({ _: 'inputUserEmpty' })).to.be.true
})
})