Complete room UI and protocol integration, move game definitions and resources behind bundle entries, publish authoritative version XML, and document single-game builds. Include all current resource changes and experiment artifacts.
39 lines
2.1 KiB
TypeScript
39 lines
2.1 KiB
TypeScript
import {test} from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {readFileSync} from 'node:fs';
|
|
import {parseCreateRoomResponse,parseSelfJoinRoomResponse} from '../../YouleNexus/assets/framework/protocol/contracts/room-contracts.ts';
|
|
import {parseLoginResponse} from '../../YouleNexus/assets/framework/protocol/contracts/login-contract.ts';
|
|
import {PlatformStore} from '../../YouleNexus/assets/framework/platform/stores/platform-store.ts';
|
|
|
|
const fixture=(name:string)=>JSON.parse(readFileSync(new URL('../fixtures/contracts/'+name,import.meta.url),'utf8')).data;
|
|
test('Store verifies numeric raw identity without permitting forged parsed room IDs',()=>{
|
|
const store=new PlatformStore();store.applyLoginSuccess(parseLoginResponse(fixture('player-login-success.json')));
|
|
const before=store.getState();
|
|
const parsed=parseSelfJoinRoomResponse({...fixture('self-join-room.json'),roomcode:123456});
|
|
assert.ok(parsed.room);
|
|
const room=parsed.room;
|
|
assert.throws(()=>store.replaceRoom({...parsed,room:{...room,roomcode:'different'}}),/roomcode/);
|
|
assert.equal(store.getState(),before);
|
|
store.replaceRoom(parsed);
|
|
assert.equal(store.getState().room.kind,'inside');
|
|
});
|
|
const cases=[
|
|
{name:'create',parse:parseCreateRoomResponse,data:()=>({state:0,seat:0,roomtype:'11011000000'})},
|
|
{name:'join',parse:parseSelfJoinRoomResponse,data:()=>fixture('self-join-room.json')},
|
|
{name:'login restore',parse:parseLoginResponse,data:()=>fixture('player-login-room.json')},
|
|
];
|
|
for(const entry of cases){
|
|
test(entry.name+' normalizes numeric room codes without changing wire data or string identity',()=>{
|
|
for(const roomcode of [123456,'123456','001234']){
|
|
const data={...entry.data(),roomcode};const parsed=entry.parse(data);
|
|
assert.equal(parsed.room?.roomcode,String(roomcode));
|
|
assert.equal(parsed.raw,data);assert.equal(data.roomcode,roomcode);
|
|
}
|
|
});
|
|
test(entry.name+' rejects invalid numeric room codes and unrelated types at ingress',()=>{
|
|
for(const roomcode of [NaN,Infinity,-1,1.5,Number.MAX_SAFE_INTEGER+1,null,true,{},[]]){
|
|
assert.throws(()=>entry.parse({...entry.data(),roomcode}),/roomcode/);
|
|
}
|
|
});
|
|
}
|