Files
youle_cocos/cocoscreator_projects/framework-tests/protocol/login.test.ts
T
2026-06-28 14:25:29 +08:00

33 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { buildLoginRequest, parseLoginResponse } from '../../YouleNexus/assets/framework/protocol/login.ts';
const IDENTITY = { agentid: 1, gameid: 2, openid: 'o', nickname: 'n', avatar: 'a', sex: 1, province: 'p', city: 'c', unionid: 'u', version: '1.0', channelid: 7, marketid: 9 };
test('buildLoginRequest 透传必备身份字段', () => {
const d = buildLoginRequest(IDENTITY);
assert.equal(d.agentid, 1);
assert.equal(d.openid, 'o');
assert.equal(d.marketid, 9);
});
test('parseLoginResponse 提取核心字段 + 房间恢复标志', () => {
const r = parseLoginResponse({ state: 0, playerid: 9, bean: 100, roomcode: 'ABCD', isbattle: 1, deskinfo: { x: 1 } });
assert.equal(r.ok, true);
assert.equal(r.playerid, 9);
assert.equal(r.inRoom, true);
assert.equal(r.hasBattle, true);
assert.deepEqual(r.deskinfo, { x: 1 });
});
test('parseLoginResponse:无 roomcode 时不在房间', () => {
const r = parseLoginResponse({ state: 0, playerid: 9 });
assert.equal(r.inRoom, false);
assert.equal(r.hasBattle, false);
});
test('parseLoginResponse:state!=0 视为失败', () => {
const r = parseLoginResponse({ state: 1, playerid: -1 });
assert.equal(r.ok, false);
});