Release 2.6.7
This commit is contained in:
+93
-37
@@ -5,7 +5,7 @@ require('../src/common');
|
||||
|
||||
const { createPlayerActionService } = require('../src/web/lib/player-actions');
|
||||
|
||||
test('player actions prefer the exact configured player registration over a remote FQDN row', async () => {
|
||||
test('player actions use the configured bridge url for commands', async () => {
|
||||
const fetchCalls = [];
|
||||
const originalFetch = global.fetch;
|
||||
global.fetch = async function (url, init) {
|
||||
@@ -29,20 +29,7 @@ test('player actions prefer the exact configured player registration over a remo
|
||||
|
||||
const playerActionService = createPlayerActionService({
|
||||
common: {},
|
||||
pool: {
|
||||
async query() {
|
||||
return [[
|
||||
{
|
||||
identifier: 'player-local',
|
||||
internal_base_url: 'http://player:8081'
|
||||
},
|
||||
{
|
||||
identifier: 'player-remote',
|
||||
internal_base_url: 'https://pulse-dev-bridge.lzstealth.com'
|
||||
}
|
||||
]];
|
||||
}
|
||||
}
|
||||
playerInternalBaseUrl: 'http://player:8081'
|
||||
});
|
||||
|
||||
const originalIdentifier = process.env.PLAYER_IDENTIFIER;
|
||||
@@ -60,12 +47,57 @@ test('player actions prefer the exact configured player registration over a remo
|
||||
}
|
||||
});
|
||||
|
||||
test('player actions merge screen connections from every recent player registration', async () => {
|
||||
test('player actions read screen connections from the bridge base url', async () => {
|
||||
const fetchCalls = [];
|
||||
const originalFetch = global.fetch;
|
||||
global.fetch = async function (url, init) {
|
||||
fetchCalls.push({ url, init });
|
||||
if (String(url).includes('player-a.example')) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: { get() { return null; } },
|
||||
async json() {
|
||||
return {
|
||||
screenSlug: 'demo',
|
||||
connections: [
|
||||
{ id: 'bridge-1', playerPublicBaseUrl: 'http://bridge.example' }
|
||||
]
|
||||
};
|
||||
},
|
||||
async text() {
|
||||
return JSON.stringify({ ok: true });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const playerActionService = createPlayerActionService({
|
||||
common: {},
|
||||
pool: {
|
||||
async query() {
|
||||
return [[[]]];
|
||||
}
|
||||
},
|
||||
playerInternalBaseUrl: 'http://bridge.example'
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await playerActionService.getScreenConnections('demo');
|
||||
|
||||
assert.equal(response.count, 1);
|
||||
assert.deepEqual(response.connections.map(function (connection) { return connection.id; }), ['bridge-1']);
|
||||
assert.equal(fetchCalls.length, 1);
|
||||
assert.equal(fetchCalls[0].url, 'http://bridge.example/api/screens/demo/connections');
|
||||
} finally {
|
||||
global.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test('player actions merge bridge and player screen connections', async () => {
|
||||
const fetchCalls = [];
|
||||
const originalFetch = global.fetch;
|
||||
global.fetch = async function (url, init) {
|
||||
fetchCalls.push({ url, init });
|
||||
if (String(url).indexOf('player-bridge:8090') !== -1) {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
@@ -74,7 +106,7 @@ test('player actions merge screen connections from every recent player registrat
|
||||
return {
|
||||
screenSlug: 'demo',
|
||||
connections: [
|
||||
{ id: 'a-1', playerPublicBaseUrl: 'http://player-a.example' }
|
||||
{ id: 'bridge-1', playerPublicBaseUrl: 'http://bridge.example' }
|
||||
]
|
||||
};
|
||||
},
|
||||
@@ -92,7 +124,7 @@ test('player actions merge screen connections from every recent player registrat
|
||||
return {
|
||||
screenSlug: 'demo',
|
||||
connections: [
|
||||
{ id: 'b-1', playerPublicBaseUrl: 'http://player-b.example' }
|
||||
{ id: 'player-1', playerPublicBaseUrl: 'http://player.example' }
|
||||
]
|
||||
};
|
||||
},
|
||||
@@ -104,30 +136,54 @@ test('player actions merge screen connections from every recent player registrat
|
||||
|
||||
const playerActionService = createPlayerActionService({
|
||||
common: {},
|
||||
pool: {
|
||||
async query() {
|
||||
return [[
|
||||
{
|
||||
identifier: 'player-a',
|
||||
public_base_url: 'http://player-a.example',
|
||||
last_seen_at: new Date().toISOString()
|
||||
},
|
||||
{
|
||||
identifier: 'player-b',
|
||||
public_base_url: 'http://player-b.example',
|
||||
last_seen_at: new Date().toISOString()
|
||||
}
|
||||
]];
|
||||
}
|
||||
}
|
||||
playerInternalBaseUrl: 'http://player:8081',
|
||||
bridgeInternalBaseUrl: 'http://player-bridge:8090'
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await playerActionService.getScreenConnections('demo');
|
||||
|
||||
assert.equal(response.count, 2);
|
||||
assert.deepEqual(response.connections.map(function (connection) { return connection.id; }), ['a-1', 'b-1']);
|
||||
assert.equal(fetchCalls.length, 2);
|
||||
assert.deepEqual(fetchCalls.map(function (call) { return call.url; }).sort(), [
|
||||
'http://player-bridge:8090/api/screens/demo/connections',
|
||||
'http://player:8081/api/screens/demo/connections'
|
||||
]);
|
||||
assert.equal(response.count, 2);
|
||||
assert.deepEqual(response.connections.map(function (connection) { return connection.id; }).sort(), ['bridge-1', 'player-1']);
|
||||
} finally {
|
||||
global.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test('player actions send device commands through the bridge base url', async () => {
|
||||
const fetchCalls = [];
|
||||
const originalFetch = global.fetch;
|
||||
global.fetch = async function (url, init) {
|
||||
fetchCalls.push({ url, init });
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: { get() { return null; } },
|
||||
async json() {
|
||||
return { ok: true, sent: true };
|
||||
},
|
||||
async text() {
|
||||
return JSON.stringify({ ok: true, sent: true });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const playerActionService = createPlayerActionService({
|
||||
common: {},
|
||||
bridgeInternalBaseUrl: 'http://player-bridge:8090'
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await playerActionService.forwardPlayerCommandToDevice('device-123', { command: 'pause' });
|
||||
|
||||
assert.deepEqual(response, { ok: true, sent: true });
|
||||
assert.equal(fetchCalls.length, 1);
|
||||
assert.equal(fetchCalls[0].url, 'http://player-bridge:8090/api/players/device-123/commands');
|
||||
} finally {
|
||||
global.fetch = originalFetch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user