Release v2.19.0: indexed content references
This commit is contained in:
1 parent
24f1603b43
commit
b59fe08298
31 files changed
+663
-237
No files matched your search
@@ -1,6 +1,6 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { buildApiGroupPayload, saveApiGroup, fetchApiGroupById } = require('../src/data/api-source-groups');
|
||||
const { buildApiGroupPayload, saveApiGroup, fetchApiGroupById, fetchApiGroupsPage } = require('../src/data/api-source-groups');
|
||||
const { getPendingMigrations } = require('../src/db/migrations');
|
||||
const { fetchApiSourcesData, fetchApiSourceById, testApiSourceAuthentication } = require('../src/data/api-sources');
|
||||
|
||||
@@ -20,8 +20,18 @@ function createPool(existing, slides, groupEnabled = 1, templateDefaults = []) {
|
||||
if (sql.includes('SELECT id, enabled FROM i_api_source_groups WHERE id')) return [[{ id: 5, enabled: groupEnabled }]];
|
||||
if (sql.includes('SELECT id FROM i_api_source_groups WHERE name')) return [[]];
|
||||
if (sql.includes('SELECT id FROM i_api_sources')) return [existing.map(id => ({ id }))];
|
||||
if (sql.includes('SELECT default_content_json FROM c_template_regions')) return [templateDefaults.map(value => ({ default_content_json: value }))];
|
||||
if (sql.includes('SELECT content_json')) return [(slides || []).map(value => ({ content_json: value }))];
|
||||
if (sql.includes('FROM c_content_references')) {
|
||||
const ids = new Set();
|
||||
function walk(value) {
|
||||
if (!value || typeof value !== 'object') return;
|
||||
if (Array.isArray(value)) return value.forEach(walk);
|
||||
if (value.source_id !== undefined && value.source_id !== null && value.source_id !== '') ids.add(String(Number(value.source_id)));
|
||||
Object.values(value).forEach(walk);
|
||||
}
|
||||
(slides || []).forEach(value => walk(JSON.parse(value)));
|
||||
(templateDefaults || []).forEach(value => walk(typeof value === 'string' ? JSON.parse(value) : value));
|
||||
return [[...ids].map(reference_value => ({ reference_value }))];
|
||||
}
|
||||
if (sql.startsWith('INSERT INTO i_api_sources')) return [{ insertId: 99 }];
|
||||
if (sql.startsWith('INSERT INTO i_api_source_groups')) return [{ insertId: 10 }];
|
||||
return [{}];
|
||||
@@ -30,6 +40,23 @@ function createPool(existing, slides, groupEnabled = 1, templateDefaults = []) {
|
||||
return { calls, async getConnection() { return connection; } };
|
||||
}
|
||||
|
||||
test('API source list marks groups with indexed request usage', async () => {
|
||||
const queries = [];
|
||||
const pool = {
|
||||
async query(sql) {
|
||||
queries.push(sql);
|
||||
if (sql.includes('SELECT COUNT(*) AS count FROM i_api_source_groups')) return [[{ count: 1 }]];
|
||||
if (sql.includes('FROM i_api_source_groups auth')) return [[{ id: 4, name: 'Product Metrics', request_count: 1, inUse: 1 }]];
|
||||
return [[]];
|
||||
}
|
||||
};
|
||||
const result = await fetchApiGroupsPage(pool, 1, 25, '', '', '');
|
||||
const listQuery = queries.find(sql => sql.includes('AS inUse'));
|
||||
assert.ok(listQuery);
|
||||
assert.match(listQuery, /c_content_references/);
|
||||
assert.equal(result.apiSources[0].inUse, 1);
|
||||
});
|
||||
|
||||
test('group payload supports public requests and independent request settings', () => {
|
||||
const group = payload([{ id: 5, name: 'Event', api_url: 'https://example.com/event', update_interval_value: 2, update_interval_unit: 'hours' }, { name: 'Donors', api_url: 'https://example.com/donors', items_path: 'data', update_interval_value: 30, update_interval_unit: 'seconds', enabled: false }]);
|
||||
assert.equal(group.auth.auth_method, 'none');
|
||||
|
||||
Reference in new issue
Block a user