Release v2.10.3
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const { refreshApiSource, refreshRssFeed } = require('../src/web/lib/data-source-refresh');
|
||||
const { refreshApiSource, refreshRssFeed, refreshWeatherLocation } = require('../src/web/lib/data-source-refresh');
|
||||
|
||||
function createConnection(options) {
|
||||
const state = Object.assign({
|
||||
@@ -178,3 +178,86 @@ test('refreshRssFeed skips notifications when the RSS items are unchanged', asyn
|
||||
|
||||
assert.deepEqual(notifyCalls, []);
|
||||
});
|
||||
|
||||
test('refreshWeatherLocation notifies players when the forecast changes', async () => {
|
||||
const connection = createConnection({
|
||||
slideRows: [{ id: 12, content_json: JSON.stringify({ weather_location_id: 4 }) }],
|
||||
screenRows: [{ slug: 'screen-c' }]
|
||||
});
|
||||
const notifyCalls = [];
|
||||
const pool = { async getConnection() { return connection; } };
|
||||
const common = {
|
||||
async fetchWeatherLocationForecast() {
|
||||
return { responseJson: JSON.stringify({ temperature: 21 }) };
|
||||
},
|
||||
parseJsonSafe(value) {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
};
|
||||
|
||||
await refreshWeatherLocation(pool, common, {
|
||||
id: 4,
|
||||
last_pulled_at: new Date(),
|
||||
last_response_json: JSON.stringify({ temperature: 20 })
|
||||
}, 42, async function (slugs, payload) {
|
||||
notifyCalls.push({ slugs, payload });
|
||||
});
|
||||
|
||||
assert.deepEqual(notifyCalls, [{ slugs: ['screen-c'], payload: 'refresh' }]);
|
||||
});
|
||||
|
||||
test('refreshWeatherLocation skips notifications when the forecast is unchanged within the hour', async () => {
|
||||
const connection = createConnection({
|
||||
slideRows: [{ id: 12, content_json: JSON.stringify({ weather_location_id: 4 }) }],
|
||||
screenRows: [{ slug: 'screen-c' }]
|
||||
});
|
||||
const notifyCalls = [];
|
||||
const pool = { async getConnection() { return connection; } };
|
||||
const snapshot = JSON.stringify({ temperature: 20 });
|
||||
const common = {
|
||||
async fetchWeatherLocationForecast() {
|
||||
return { responseJson: snapshot };
|
||||
},
|
||||
parseJsonSafe(value) {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
};
|
||||
|
||||
await refreshWeatherLocation(pool, common, {
|
||||
id: 4,
|
||||
last_pulled_at: new Date(),
|
||||
last_response_json: snapshot
|
||||
}, 42, async function (slugs, payload) {
|
||||
notifyCalls.push({ slugs, payload });
|
||||
});
|
||||
|
||||
assert.deepEqual(notifyCalls, []);
|
||||
});
|
||||
|
||||
test('refreshWeatherLocation notifies when an unchanged forecast crosses into a new hour', async () => {
|
||||
const connection = createConnection({
|
||||
slideRows: [{ id: 12, content_json: JSON.stringify({ weather_location_id: 4 }) }],
|
||||
screenRows: [{ slug: 'screen-c' }]
|
||||
});
|
||||
const notifyCalls = [];
|
||||
const pool = { async getConnection() { return connection; } };
|
||||
const snapshot = JSON.stringify({ temperature: 20 });
|
||||
const common = {
|
||||
async fetchWeatherLocationForecast() {
|
||||
return { responseJson: snapshot };
|
||||
},
|
||||
parseJsonSafe(value) {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
};
|
||||
|
||||
await refreshWeatherLocation(pool, common, {
|
||||
id: 4,
|
||||
last_pulled_at: new Date('2000-01-01T00:00:00.000Z'),
|
||||
last_response_json: snapshot
|
||||
}, 42, async function (slugs, payload) {
|
||||
notifyCalls.push({ slugs, payload });
|
||||
});
|
||||
|
||||
assert.deepEqual(notifyCalls, [{ slugs: ['screen-c'], payload: 'refresh' }]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user