fix: tests

This commit is contained in:
alina sireneva
2025-03-01 10:11:49 +03:00
parent 5f990bcbe7
commit 2f3d08fd94
5 changed files with 30 additions and 11 deletions

View File

@@ -18,6 +18,7 @@
"@mtcute/tl": "./tests/deno-shims/tl.js",
"@mtcute/tl/binary/rsa-keys.js": "./tests/deno-shims/tl-rsa.js",
"@mtcute/tl/binary/reader.js": "./tests/deno-shims/tl-reader.js",
"@mtcute/tl/compat/reader.js": "./tests/deno-shims/tl-reader-compat.js",
"@mtcute/tl/binary/writer.js": "./tests/deno-shims/tl-writer.js"
},
"tasks": {

View File

@@ -0,0 +1,5 @@
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
export const { __tlReaderMapCompat } = require('../../../packages/tl/compat/reader.js')

View File

@@ -271,13 +271,12 @@ export class PeersService extends BaseService {
if (cached) return cached.peer
const dto = await this._peers.getById(id)
if (!dto) return null
if (!dto.isMin) {
if (dto && !dto.isMin) {
return this._returnCaching(id, dto)
}
if (dto.isMin && allowRefs) {
if ((!dto || dto.isMin) && allowRefs) {
const ref = await this._refs.getForPeer(id)
if (!ref) return null

View File

@@ -52,7 +52,7 @@ export function testPeersRepository(repo: IPeersRepository, driver: IStorageDriv
describe('peers', () => {
it('should be empty by default', async () => {
expect(await repo.getById(123123, false)).toEqual(null)
expect(await repo.getById(123123)).toEqual(null)
expect(await repo.getByUsername('some_user')).toEqual(null)
expect(await repo.getByPhone('phone')).toEqual(null)
})
@@ -62,11 +62,11 @@ export function testPeersRepository(repo: IPeersRepository, driver: IStorageDriv
await repo.store(stubPeerChannel)
await driver.save?.()
expect(fixPeerInfo(await repo.getById(123123, false))).toEqual(stubPeerUser)
expect(fixPeerInfo(await repo.getById(123123))).toEqual(stubPeerUser)
expect(fixPeerInfo(await repo.getByUsername('some_user'))).toEqual(stubPeerUser)
expect(fixPeerInfo(await repo.getByPhone('78005553535'))).toEqual(stubPeerUser)
expect(fixPeerInfo(await repo.getById(-1001183945448, false))).toEqual(stubPeerChannel)
expect(fixPeerInfo(await repo.getById(-1001183945448))).toEqual(stubPeerChannel)
expect(fixPeerInfo(await repo.getByUsername('some_channel'))).toEqual(stubPeerChannel)
})
@@ -78,21 +78,20 @@ export function testPeersRepository(repo: IPeersRepository, driver: IStorageDriv
await repo.store(modUser)
await driver.save?.()
expect(fixPeerInfo(await repo.getById(123123, false))).toEqual(modUser)
expect(fixPeerInfo(await repo.getById(123123))).toEqual(modUser)
expect(await repo.getByUsername('some_user')).toEqual(null)
expect(fixPeerInfo(await repo.getByUsername('some_user2'))).toEqual(modUser)
})
it('should not return min peers by default', async () => {
it('only getById should return min peers', async () => {
await repo.deleteAll()
await repo.store(stupPeerMinUser)
await driver.save?.()
expect(await repo.getById(123123, false)).toEqual(null)
expect(await repo.getByUsername('some_user')).toEqual(null)
expect(await repo.getByPhone('78005553535')).toEqual(null)
expect(fixPeerInfo(await repo.getById(123123, true))).toEqual(stupPeerMinUser)
expect(fixPeerInfo(await repo.getById(123123))).toEqual(stupPeerMinUser)
})
})
}

View File

@@ -24,6 +24,10 @@ const files = [
'binary/rsa-keys.js',
'binary/writer.d.ts',
'binary/writer.js',
'compat/reader.js',
'compat/index.d.ts',
'compat/reader.d.ts',
'compat/reader.js',
'index.d.ts',
'index.js',
'raw-errors.json',
@@ -34,6 +38,7 @@ const files = [
]
await fsp.mkdir(resolve(outDir, 'binary'), { recursive: true })
await fsp.mkdir(resolve(outDir, 'compat'), { recursive: true })
for (const f of files) {
await fsp.copyFile(resolve(packageDir, f), resolve(outDir, f))
@@ -83,6 +88,14 @@ if (process.env.JSR) {
'export const __publicKeyIndex = exports.__publicKeyIndex;',
].join('\n')
})
await transformFile(resolve(outDir, 'compat/reader.js'), (content) => {
return [
'/// <reference types="./reader.d.ts" />',
'const exports = {};',
content,
'export const __tlReaderMapCompat = exports.__tlReaderMapCompat;',
].join('\n')
})
// patch deno.json to add some export maps
const denoJson = packageJsonToDeno({
@@ -91,7 +104,9 @@ if (process.env.JSR) {
workspaceVersions: {},
buildDirName: 'dist',
})
denoJson.exports = {}
denoJson.exports = {
'./compat': './compat/index.d.ts',
}
for (const f of files) {
if (!f.match(/\.js(?:on)?$/)) continue