Files

26 lines
1.3 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { PlatformStore } from '../../YouleNexus/assets/framework/platform/stores/platform-store.ts';
import { parseLoginResponse } from '../../YouleNexus/assets/framework/protocol/contracts/login-contract.ts';
const response = () => JSON.parse(readFileSync(new URL('../fixtures/contracts/player-login-success.json', import.meta.url), 'utf8')).data;
test('login publishes server assets and task status, including subsequent login changes', () => {
const store = new PlatformStore();
const data = response();
store.applyLoginSuccess(parseLoginResponse(data));
const self = () => store.getState().players.entities[data.playerid] as any;
assert.equal(self().roomcard, 3);
assert.equal(self().taskstate, 1);
assert.equal(self().score, 0);
assert.equal(self().sign, null);
store.applyLoginSuccess(parseLoginResponse({...data, roomcard:8, taskstate:0}));
assert.equal(self().roomcard, 8);
assert.equal(self().taskstate, 0);
});
test('invalid supplied asset fields reject the complete login without publishing partial state', () => {
const store = new PlatformStore(), before = store.getState();
assert.throws(() => store.applyLoginSuccess(parseLoginResponse({...response(), roomcard:'3'})), /roomcard/);
assert.equal(store.getState(), before);
});