- Delete unused dataMerger, formatter, Device model, dead service exports, and the empty agents/ + .gitkeep placeholders. - Extract STORE_MODES and MDM device-type filters into a shared constants.js. - Anchor bot regexes (^help|^store|^analyze) so "analyze store 305" no longer fires both handlers; replace catch-all noise. - Hoist inline require() calls in integrations to top-of-file imports. - Harden WebSocket server: Authorization header support, single-agent enforcement, bounded pending requests, server-level error handler, coalesced cache refresh in Meraki client. - Wrap Meraki/MDM network calls with withRetry; add request timeouts. - Migrate all console.* calls onto utils/logger.js (LOG_LEVEL aware); drive Webex framework logLevel from env. - Refactor storeDetail.js: shared renderClientLine + buildMdmSection helpers cut duplication roughly in half. - Refresh README structure, document LOG_LEVEL, add npm run agent script, add jest testMatch + new tests (handlers, HealthReport, Store, ws). Verified: npm run lint clean, 7 suites / 31 tests passing. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
const { createHealthReport } = require('../models/HealthReport');
|
|
|
|
describe('HealthReport', () => {
|
|
it('starts at a perfect score of 100', () => {
|
|
const r = createHealthReport('305', 'Test Store').finalize();
|
|
expect(r.overallScore).toBe(100);
|
|
expect(r.summary).toContain('🟢 Good');
|
|
expect(r.summary).toContain('No major issues');
|
|
});
|
|
|
|
it('deducts points and floors at zero', () => {
|
|
const r = createHealthReport('305');
|
|
r.deduct(60, 'major outage');
|
|
r.deduct(80, 'second outage');
|
|
r.finalize();
|
|
expect(r.overallScore).toBe(0);
|
|
expect(r.summary).toContain('🔴 Needs Attention');
|
|
});
|
|
|
|
it('chooses the right status emoji at each threshold', () => {
|
|
const fair = createHealthReport('1');
|
|
fair.deduct(15, 'minor');
|
|
fair.finalize();
|
|
expect(fair.overallScore).toBe(85);
|
|
expect(fair.summary).toContain('🟡 Fair');
|
|
|
|
const bad = createHealthReport('1');
|
|
bad.deduct(35, 'big issue');
|
|
bad.finalize();
|
|
expect(bad.summary).toContain('🔴 Needs Attention');
|
|
});
|
|
|
|
it('deduplicates identical issues added via addIssue', () => {
|
|
const r = createHealthReport('1');
|
|
r.addIssue('same problem');
|
|
r.addIssue('same problem');
|
|
r.addIssue('different problem');
|
|
r.finalize();
|
|
const occurrences = (r.summary.match(/same problem/g) || []).length;
|
|
expect(occurrences).toBe(1);
|
|
expect(r.summary).toContain('different problem');
|
|
});
|
|
|
|
it('toJSON returns a serializable snapshot', () => {
|
|
const r = createHealthReport('305', 'Test').finalize();
|
|
const j = r.toJSON();
|
|
expect(j.storeNumber).toBe('305');
|
|
expect(j.storeName).toBe('Test');
|
|
expect(j.overallScore).toBe(100);
|
|
expect(typeof j.summary).toBe('string');
|
|
});
|
|
});
|