Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
112 lines
8.3 KiB
JavaScript
112 lines
8.3 KiB
JavaScript
'use strict';
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { SnapshotOperation, validate, crc32 } = require('../app/main/server-snapshot-codec');
|
|
|
|
function operation(call, extras = {}) {
|
|
return new SnapshotOperation({ call, context: { generation: 7, server_uid: 'server-uid', permissions_catalog: [{ id: 1, name: 'i_icon_id' }] }, check() {}, progress() {}, icons: { collect: async () => [], upload: async () => 4000 }, ...extras });
|
|
}
|
|
const doc = entry => ({ type: 'teamspeak.server.snapshot', schemaVersion: '0.0.1', meta: { createdAt: '2026-11-01T00:00:00.000Z', createdBy: 'Unknown' }, catalog: [{ id: 'default', ...entry }] });
|
|
|
|
test('official JSON export includes options, permanent hierarchy, named permissions and UID members', async () => {
|
|
const op = operation(async (command, args) => {
|
|
const rows = {
|
|
server_info: [{ virtualserver_name: 'Example Server', virtualserver_version: '6.0', virtualserver_platform: 'Linux', virtualserver_default_server_group: '9' }],
|
|
channel_list: [{ cid: '10', cpid: '0', channel_order: '0', channel_flag_permanent: '1', channel_name: 'Example Lobby' }, { cid: '11', cpid: '10', channel_order: '0', channel_flag_permanent: '1', channel_name: 'Child' }, { cid: '12', cpid: '0', channel_order: '10', channel_flag_permanent: '0', channel_name: 'Temporary' }],
|
|
channel_info: [{ channel_description: args.channel_id === 10 ? 'Example description' : '' }],
|
|
channel_perm_list: [{ permid: '1', permvalue: '-1' }],
|
|
server_group_list: [{ sgid: '5', type: '1', sortid: '0', name: 'Example Admin' }, { sgid: '1', type: '0', name: 'Template' }],
|
|
server_group_perm_list: [{ permid: '1', permvalue: '100', permskip: '1', permnegated: '1' }],
|
|
server_group_client_list: [{ client_nickname: 'Alice', client_unique_identifier: 'alice-uid' }],
|
|
channel_group_list: [{ cgid: '3', type: '1', sortid: '0', name: 'Channel Admin' }],
|
|
channel_group_perm_list: [],
|
|
};
|
|
assert.ok(Object.hasOwn(rows, command), command); return { rows: rows[command] };
|
|
});
|
|
const exported = await op.create({ includeServerSettings: true, includeChannels: true, includeServerGroups: true, includeServerGroupMembers: true, includeChannelGroups: true, includeIcons: true, snapshotDescription: 'Backup', vars: { brand: 'Example' } });
|
|
assert.equal(exported.type, 'teamspeak.server.snapshot'); assert.equal(exported.schemaVersion, '0.0.1'); assert.equal(exported.meta.createdBy, 'Unknown');
|
|
assert.equal(exported.meta.description, 'Backup'); assert.deepEqual(exported.meta.source, { serverVersion: '6.0', platform: 'Linux' });
|
|
const entry = exported.catalog[0]; assert.equal(entry.server.name, '${brand} Server'); assert.equal(entry.channels.length, 1);
|
|
assert.equal(entry.channels[0].description, '${brand} description'); assert.equal(entry.channels[0].channels[0].name, 'Child');
|
|
assert.deepEqual(entry.channels[0].permissions, [{ id: 'i_icon_id', value: 4294967295 }]);
|
|
assert.deepEqual(entry.serverGroups[0].members, [{ nickname: 'Alice', uid: 'alice-uid' }]);
|
|
assert.deepEqual(entry.serverGroups[0].permissions, [{ id: 'i_icon_id', value: 100, skip: true, negate: true }]);
|
|
assert.equal(op.errors.length, 0); assert.deepEqual(validate(JSON.parse(JSON.stringify(exported))), exported);
|
|
});
|
|
|
|
test('apply maps icon/channel/group IDs, variables, defaults and UID membership through typed commands', async () => {
|
|
const calls = []; let channel = 20, group = 30;
|
|
const op = operation(async (command, args) => {
|
|
calls.push([command, args]);
|
|
if (command.endsWith('_list')) return { rows: [] };
|
|
if (command === 'channel_create') return { channel_id: channel++ };
|
|
if (command === 'group_add') return { group_id: group++ };
|
|
return {};
|
|
});
|
|
const permission = { id: 'i_icon_id', value: 9000 };
|
|
await op.apply({ server: { name: '${brand} Server', iconId: 9000 }, icons: [{ id: '9000' }], channels: [{ name: '${brand}', permissions: [permission], channels: [{ name: 'Child' }] }], serverGroups: [{ name: 'Admins', default: true, permissions: [permission], members: [{ uid: 'alice' }] }], channelGroups: [{ name: 'Operators', default: true, defaultChannelAdmin: true, permissions: [permission] }] }, { brand: 'New' }, 'rename_new');
|
|
assert.equal(op.errors.length, 0);
|
|
assert.equal(calls.find(([cmd]) => cmd === 'channel_create')[1].properties.channel_name, 'New');
|
|
assert.equal(calls.filter(([cmd]) => cmd === 'channel_create')[1][1].parent_id, 20);
|
|
assert.deepEqual(calls.find(([cmd]) => cmd === 'channel_set_permissions')[1].permissions, [{ id: 'i_icon_id', value: 4000 }]);
|
|
assert.deepEqual(calls.filter(([cmd]) => cmd === 'group_set_permissions').map(([, args]) => args.kind), ['server', 'channel']);
|
|
assert.ok(calls.some(([cmd, args]) => cmd === 'server_edit' && args.properties.virtualserver_default_channel_group === 31 && args.confirm === 'server-uid'));
|
|
assert.deepEqual(calls.find(([cmd]) => cmd === 'server_group_member_add_uid')[1], { generation: 7, group_id: 30, uid: 'alice' });
|
|
assert.deepEqual(op.created.channels, [20, 21]); assert.deepEqual(op.created.icons, [4000]);
|
|
});
|
|
|
|
test('missing icons, unsupported settings and denied members remain partial without redirecting references', async () => {
|
|
const calls = [];
|
|
const op = operation(async (command, args) => {
|
|
calls.push([command, args]);
|
|
if (command === 'server_edit') throw new Error('Unsupported property');
|
|
if (command === 'group_add') return { group_id: 4 };
|
|
if (command.endsWith('_list')) return { rows: [] };
|
|
if (command === 'server_group_member_add_uid') throw new Error('Membership denied');
|
|
return {};
|
|
}, { icons: { upload: async () => { throw new Error('Upload denied'); } } });
|
|
await op.apply({ icons: [{ id: '5000' }], server: { iconId: 5000, sfuEndpoint: 'https://example.invalid' }, serverGroups: [{ name: 'Group', permissions: [{ id: 'i_icon_id', value: 5000 }], members: [{ uid: 'unknown' }] }] }, {}, 'skip');
|
|
assert.equal(op.errors.length, 5);
|
|
assert.ok(!calls.some(([cmd]) => cmd === 'group_set_permissions'));
|
|
assert.deepEqual(op.created.members, []);
|
|
assert.deepEqual(op.created.serverGroups, [4]);
|
|
});
|
|
|
|
test('cancellation retains acknowledged parent and prevents subsequent child creation', async () => {
|
|
let cancelled = false, calls = 0;
|
|
const op = operation(async command => {
|
|
if (command === 'channel_list') return { rows: [] };
|
|
if (command === 'channel_create') { calls++; cancelled = true; return { channel_id: 8 }; }
|
|
throw new Error(command);
|
|
}, { check() { if (cancelled) throw Object.assign(new Error('cancelled'), { code: 'cancelled' }); } });
|
|
await assert.rejects(op.apply({ channels: [{ name: 'Parent', channels: [{ name: 'Child' }] }] }, {}, 'rename_new'), /cancelled/);
|
|
assert.equal(calls, 1); assert.deepEqual(op.created.channels, [8]);
|
|
});
|
|
|
|
test('all official conflict modes keep channel parent ownership and report skipped names', async () => {
|
|
for (const mode of ['skip', 'rename_new', 'rename_existing']) {
|
|
const calls = [];
|
|
const op = operation(async (command, args) => {
|
|
calls.push([command, args]);
|
|
if (command === 'channel_list') return { rows: [{ cid: '5', cpid: '0', channel_name: 'Lobby' }] };
|
|
if (command === 'channel_create') return { channel_id: 6 };
|
|
return {};
|
|
});
|
|
await op.apply({ channels: [{ name: 'Lobby' }] }, {}, mode);
|
|
const creation = calls.find(([command]) => command === 'channel_create');
|
|
if (mode === 'skip') { assert.equal(creation, undefined); assert.equal(op.errors[0].type, 'conflict'); }
|
|
if (mode === 'rename_new') { assert.equal(creation[1].properties.channel_name, 'Lobby (1)'); assert.equal(op.errors.length, 0); }
|
|
if (mode === 'rename_existing') {
|
|
assert.equal(calls.find(([command]) => command === 'channel_edit')[1].properties.channel_name, 'OLD Lobby');
|
|
assert.equal(creation[1].properties.channel_name, 'Lobby'); assert.equal(op.created.renamed.length, 1);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('validation rejects server-query data, malformed nested fields and duplicate catalogs', () => {
|
|
assert.throws(() => validate({ type: 'serverquery' }));
|
|
assert.throws(() => validate(doc({ channels: [{ name: 'A', channels: {} }] })), /tree/);
|
|
const duplicate = doc({}); duplicate.catalog.push({ id: 'default' }); assert.throws(() => validate(duplicate), /duplicate/);
|
|
assert.equal(crc32(Buffer.from('123456789')), 0xcbf43926);
|
|
});
|