netxops/test/alarm-push.test.mjs
oliver a4993b2407 Add Netx Ops i18n and promote settings to a dedicated section.
Localize alarm prompts and UI reason codes for zh/en, and restyle the settings page like uds-auth as its own settings.section.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-09 22:09:47 +08:00

55 lines
1.7 KiB
JavaScript

import assert from 'node:assert/strict'
import { test } from 'node:test'
import {
alarmSubscribeUrl,
formatAlarmPrompt,
} from '../src/netx/alarm-push.ts'
test('alarmSubscribeUrl maps http(s) REST roots to the hub path', () => {
assert.equal(
alarmSubscribeUrl('http://192.168.1.10:8890'),
'ws://192.168.1.10:8890/v1/integrations/dsh-alarm/ws',
)
assert.equal(
alarmSubscribeUrl('https://netx.example/'),
'wss://netx.example/v1/integrations/dsh-alarm/ws',
)
assert.equal(alarmSubscribeUrl(''), '')
})
test('formatAlarmPrompt keeps human fields without raw sockets', () => {
const text = formatAlarmPrompt({
action: 'inserted',
rule_label: 'Power Down',
object_name: 'PORT-1',
perceived_severity: 'critical',
native_probable_cause: 'LOS',
time_created: '2026-01-01T00:00:00Z',
notification_id: 'n1',
alarm_key: 'k1',
ne: { host_name: 'PE1', ip_address: '10.0.0.1' },
}, 'zh')
assert.match(text, /告警产生/)
assert.match(text, /\[NMS /)
assert.match(text, /PE1 \(10\.0\.0\.1\)/)
assert.match(text, /请分析这条关键告警/)
})
test('formatAlarmPrompt switches to English when lang starts with en', () => {
const text = formatAlarmPrompt({
action: 'deleted',
rule_label: 'Power Down',
object_name: 'PORT-1',
perceived_severity: 'critical',
native_probable_cause: 'LOS',
time_created: '2026-01-01T00:00:00Z',
notification_id: 'n1',
alarm_key: 'k1',
ne: { host_name: 'PE1', ip_address: '10.0.0.1' },
}, 'en-US')
assert.match(text, /Alarm Cleared/)
assert.match(text, /Device: PE1 \(10\.0\.0\.1\)/)
assert.match(text, /Please analyze this key alarm/)
assert.doesNotMatch(text, /告警/)
})