Files
youle_cocos/cocoscreator_projects/framework-tests/config/identity.test.ts
T

40 lines
1.5 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 { resolveIdentity } from '../../YouleNexus/assets/framework/config/identity.ts';
import { BUILD_IDENTITY } from '../../YouleNexus/assets/framework/config/sources/defaults.ts';
test('BUILD_IDENTITY 含全部字段且 gameid 为固定 token', () => {
assert.ok(BUILD_IDENTITY.gameid.length > 0);
assert.ok('agentid' in BUILD_IDENTITY);
assert.ok('channelid' in BUILD_IDENTITY);
assert.ok('marketid' in BUILD_IDENTITY);
assert.equal(typeof BUILD_IDENTITY.version, 'string');
assert.equal(typeof BUILD_IDENTITY.versionCode, 'number');
});
test('resolveIdentity:后面的 source 覆盖前面的', () => {
const id = resolveIdentity([
() => BUILD_IDENTITY,
() => ({ agentid: 'A2' }),
() => ({ agentid: 'A3', channelid: 'C3' }),
]);
assert.equal(id.agentid, 'A3');
assert.equal(id.channelid, 'C3');
assert.equal(id.gameid, BUILD_IDENTITY.gameid); // 未被覆盖
});
test('resolveIdentity:undefined / null / 空串 不覆盖', () => {
const id = resolveIdentity([
() => BUILD_IDENTITY,
() => ({ agentid: undefined as any, channelid: '' , marketid: null as any }),
]);
assert.equal(id.agentid, BUILD_IDENTITY.agentid);
assert.equal(id.channelid, BUILD_IDENTITY.channelid);
assert.equal(id.marketid, BUILD_IDENTITY.marketid);
});
test('resolveIdentity:marketid=0 是有效值,应覆盖', () => {
const id = resolveIdentity([() => BUILD_IDENTITY, () => ({ marketid: 0 })]);
assert.equal(id.marketid, 0);
});