import test from 'node:test'; import assert from 'node:assert/strict'; import {parseVipRooms} from '../../YouleNexus/assets/framework/protocol/contracts/vip-room.ts'; import {orderedVipRooms,occupiedSeats} from '../../YouleNexus/assets/framework/presentation/vip-room-model.ts'; import {VipRoomHistory} from '../../YouleNexus/assets/framework/adapters/native/vip-room-history.ts'; import {PlatformStore} from '../../YouleNexus/assets/framework/platform/stores/platform-store.ts'; test('VIP response follows saved short codes and counts occupied seats, without mutating source',()=>{ const one={shortCode:'200001',owner:'房主',playerList:[[0,2,null,4]],roomcodes:{roomtype:[1,2],roomlist:['800001']},deskState:[1],seatCount:[4]}; const two={shortCode:'200002',destwo:'另一间',owner:123456,playerList:[]}; const rooms=parseVipRooms({roomInfo:[one,two]}); assert.deepEqual(orderedVipRooms(rooms,['200002','missing','200001']).map(r=>r.shortCode),['200002','200001']); assert.equal(rooms[0].title,'vip房间');assert.equal(rooms[1].roomcodes,null); assert.equal(orderedVipRooms(rooms,[200001])[0],rooms[0]); assert.equal(occupiedSeats(rooms[0].playerList[0]),2); assert.deepEqual(one.deskState,[1]); const store=new PlatformStore();store.applyVipRooms({roomInfo:[one]});const before=store.getState(); assert.throws(()=>store.applyVipRooms({roomInfo:[{...one,seatCount:[]}]}),/matching lengths/); assert.equal(store.getState(),before); store.applyVipRooms({roomInfo:[]});assert.deepEqual(store.getState().vipRooms,[]); }); test('VIP history preserves legacy storage key and most recent first ordering',()=>{ const data=new Map();const h=new VipRoomHistory({getItem:k=>data.get(k)??null,setItem:(k,v)=>{data.set(k,v);}},'g','a'); assert.deepEqual(h.read(),[]);assert.equal(data.get('tsgame_vipRoom_ga'),'{"data":[]}'); h.add('1');h.add('2');h.add('1');assert.deepEqual(h.read(),['1','2']); data.set('tsgame_vipRoom_ga','{"data":false}');assert.throws(()=>h.read(),/Invalid/); });