44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
const test = require('node:test');
|
||
|
|
const assert = require('node:assert/strict');
|
||
|
|
|
||
|
|
const DashboardApi = require('../../src/specificClass.js');
|
||
|
|
|
||
|
|
test('buildUpsertRequest emits folderUid when configured', () => {
|
||
|
|
const api = new DashboardApi({
|
||
|
|
grafanaConnector: { folderUid: 'rnd-folder' },
|
||
|
|
});
|
||
|
|
const req = api.buildUpsertRequest({ dashboard: { uid: 'x', title: 'X' } });
|
||
|
|
assert.equal(req.folderUid, 'rnd-folder');
|
||
|
|
assert.equal(req.overwrite, true);
|
||
|
|
assert.ok(!('folderId' in req), 'should not emit folderId when folderUid is set');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('buildUpsertRequest omits folderUid when empty (Grafana defaults to General)', () => {
|
||
|
|
const api = new DashboardApi({});
|
||
|
|
const req = api.buildUpsertRequest({ dashboard: { uid: 'x' } });
|
||
|
|
assert.equal(req.folderUid, undefined);
|
||
|
|
// folderId fallback only when explicitly passed
|
||
|
|
assert.equal(req.folderId, undefined);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('buildUpsertRequest folderUid override at call-site wins over config', () => {
|
||
|
|
const api = new DashboardApi({ grafanaConnector: { folderUid: 'rnd-folder' } });
|
||
|
|
const req = api.buildUpsertRequest({ dashboard: { uid: 'x' }, folderUid: 'override-folder' });
|
||
|
|
assert.equal(req.folderUid, 'override-folder');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('bearerToken from config flows into specificClass config', () => {
|
||
|
|
const api = new DashboardApi({
|
||
|
|
grafanaConnector: { bearerToken: 'tok-xyz', folderUid: '' },
|
||
|
|
});
|
||
|
|
assert.equal(api.config.grafanaConnector.bearerToken, 'tok-xyz');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('default config has empty bearerToken and folderUid', () => {
|
||
|
|
const api = new DashboardApi({});
|
||
|
|
assert.equal(api.config.grafanaConnector.bearerToken, '');
|
||
|
|
assert.equal(api.config.grafanaConnector.folderUid, '');
|
||
|
|
});
|