Release v2.10.3
This commit is contained in:
@@ -4,6 +4,7 @@ const crypto = require('node:crypto');
|
||||
|
||||
const {
|
||||
collectLiveConnections,
|
||||
findAvailableClientName,
|
||||
isClientNameAvailable,
|
||||
normalizeClientName,
|
||||
normalizeDeviceId,
|
||||
@@ -22,7 +23,7 @@ test('collectLiveConnections returns an array safely', () => {
|
||||
assert.deepEqual(collectLiveConnections([{ clientName: 'A' }]), [{ clientName: 'A' }]);
|
||||
});
|
||||
|
||||
test('isClientNameAvailable rejects matching db rows and live connections', async () => {
|
||||
test('isClientNameAvailable ignores stored names for offline devices', async () => {
|
||||
const pool = {
|
||||
async query(sql, params) {
|
||||
assert.match(sql, /FROM d_onboarding_devices/);
|
||||
@@ -31,12 +32,28 @@ test('isClientNameAvailable rejects matching db rows and live connections', asyn
|
||||
}
|
||||
};
|
||||
|
||||
assert.equal(await isClientNameAvailable(pool, ' Screen A ', 'device-01', []), false);
|
||||
assert.equal(await isClientNameAvailable(pool, ' Screen A ', 'device-01', []), true);
|
||||
assert.equal(await isClientNameAvailable(pool, 'Screen A', 'device-01', [{ clientName: 'screen a', deviceId: 'device-99' }]), false);
|
||||
assert.equal(await isClientNameAvailable(null, 'Screen A', 'device-01', [{ clientName: 'screen a', clientId: 'device-99' }]), false);
|
||||
assert.equal(await isClientNameAvailable(null, 'Screen A', 'device-01', [{ clientName: 'screen a', clientId: 'device-01' }]), true);
|
||||
assert.equal(await isClientNameAvailable(null, ' ', 'device-01', []), false);
|
||||
});
|
||||
|
||||
test('findAvailableClientName adds the first free numeric suffix', async () => {
|
||||
const occupiedNames = new Set(['Lobby', 'Lobby (1)']);
|
||||
const pool = {
|
||||
async query(_sql, params) {
|
||||
const name = params[0];
|
||||
return [[occupiedNames.has(name) ? { device_id: 'active-device' } : undefined].filter(Boolean)];
|
||||
}
|
||||
};
|
||||
|
||||
assert.equal(
|
||||
await findAvailableClientName(pool, 'Lobby', 'new-device', [{ deviceId: 'active-device' }]),
|
||||
'Lobby (2)'
|
||||
);
|
||||
});
|
||||
|
||||
test('withClientNameReservation acquires and releases locks around the handler', async () => {
|
||||
const calls = [];
|
||||
const lockName = `ps_client_name_${crypto.createHash('sha1').update('screen a').digest('hex')}`;
|
||||
|
||||
Reference in New Issue
Block a user