Files
mtusi2026lab6/student-tests/grafana-provisioning.test.ts
T

6 lines
1.2 KiB
TypeScript

import{test,expect}from'bun:test';import{dashboardMatches,rulesMatch}from'../scripts/lib/grafana-provisioning';
const expected={uid:'messenger',panels:[{id:1,title:'RPS'},{id:2,title:'API p95'}]};
test('accepts the actual configured dashboard and exact rule UID set',()=>{expect(dashboardMatches({dashboard:expected},expected)).toBe(true);expect(rulesMatch([{uid:'b'},{uid:'a'}],['a','b'])).toBe(true)});
test('rejects empty or mismatched dashboard payload despite successful HTTP status',()=>{expect(dashboardMatches({},expected)).toBe(false);expect(dashboardMatches({dashboard:{uid:'other',panels:expected.panels}},expected)).toBe(false);expect(dashboardMatches({dashboard:{...expected,panels:[]}},expected)).toBe(false);expect(dashboardMatches({dashboard:{...expected,panels:[expected.panels[0],expected.panels[0]]}},expected)).toBe(false);expect(dashboardMatches({dashboard:{...expected,panels:[expected.panels[0],{id:2,title:'Wrong signal'}]}},expected)).toBe(false)});
test('rejects absent, duplicated or wrong rule UIDs even when counts match',()=>{expect(rulesMatch([],['a','b'])).toBe(false);expect(rulesMatch([{uid:'a'},{uid:'a'}],['a','b'])).toBe(false);expect(rulesMatch([{uid:'a'},{uid:'c'}],['a','b'])).toBe(false);expect(rulesMatch([],[])).toBe(false)});