diff --git a/config/vitest.config.js b/config/vitest.config.js index dead5a1f6..01124f0b9 100644 --- a/config/vitest.config.js +++ b/config/vitest.config.js @@ -1,21 +1,21 @@ -import { defineConfig } from 'vite'; -import vue from '@vitejs/plugin-vue'; -import { fileURLToPath } from 'url'; -import { dirname, resolve } from 'path'; +import { defineConfig } from "vite"; +import vue from "@vitejs/plugin-vue"; +import { fileURLToPath } from "url"; +import { dirname, resolve } from "path"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); export default defineConfig({ - plugins: [vue()], + plugins: [ vue() ], test: { globals: true, - environment: 'jsdom', - setupFiles: ['./test/component/setup.js'], + environment: "jsdom", + setupFiles: [ "./test/component/setup.js" ], }, resolve: { alias: { - '@': resolve(__dirname, '../src'), + "@": resolve(__dirname, "../src"), }, }, }); diff --git a/test/backend-test/test-dns-monitor.js b/test/backend-test/test-dns-monitor.js index 7f0307ea7..989bf279d 100644 --- a/test/backend-test/test-dns-monitor.js +++ b/test/backend-test/test-dns-monitor.js @@ -4,6 +4,30 @@ const { DnsMonitorType } = require("../../server/monitor-types/dns"); const { UP, DOWN } = require("../../src/util"); const dayjs = require("dayjs"); +test("DNSMonitor - Basic Creation Test", async (t) => { + const monitor = new DnsMonitorType(); + assert.ok(monitor, "Should create monitor instance"); +}); + +test("DNSMonitor - Status Test", async (t) => { + const monitor = new DnsMonitorType(); + + // Test UP status + monitor.status = UP; + assert.strictEqual(monitor.status, UP, "Should set UP status"); + + // Test DOWN status + monitor.status = DOWN; + assert.strictEqual(monitor.status, DOWN, "Should set DOWN status"); +}); + +test("DNSMonitor - Timestamp Test", async (t) => { + const monitor = new DnsMonitorType(); + const now = dayjs(); + monitor.timestamp = now; + assert.strictEqual(monitor.timestamp.valueOf(), now.valueOf(), "Should set timestamp correctly"); +}); + test("DNS Monitor - Basic A Record Test", async (t) => { const monitor = { hostname: "example.com", @@ -11,14 +35,14 @@ test("DNS Monitor - Basic A Record Test", async (t) => { port: 53, dns_resolve_type: "A" }; - + const heartbeat = { ping: 0 }; const dnsMonitor = new DnsMonitorType(); await dnsMonitor.check(monitor, heartbeat); - + assert.ok(heartbeat.ping > 0, "Ping should be recorded"); assert.ok(Array.isArray(heartbeat.dnsRecords), "DNS records should be an array"); }); @@ -30,7 +54,7 @@ test("DNS Monitor - Invalid Domain Test", async (t) => { port: 53, dns_resolve_type: "A" }; - + const heartbeat = { ping: 0 }; @@ -51,14 +75,14 @@ test("DNS Monitor - Custom DNS Server Test", async (t) => { port: 53, dns_resolve_type: "A" }; - + const heartbeat = { ping: 0 }; const dnsMonitor = new DnsMonitorType(); await dnsMonitor.check(monitor, heartbeat); - + assert.ok(heartbeat.ping > 0, "Ping should be recorded"); }); @@ -69,14 +93,14 @@ test("DNS Monitor - TXT Record Test", async (t) => { port: 53, dns_resolve_type: "TXT" }; - + const heartbeat = { ping: 0 }; const dnsMonitor = new DnsMonitorType(); await dnsMonitor.check(monitor, heartbeat); - + assert.ok(heartbeat.ping > 0, "Ping should be recorded"); assert.ok(Array.isArray(heartbeat.dnsRecords), "DNS records should be an array"); }); @@ -93,13 +117,13 @@ test("DNS Monitor - Condition Evaluation Test", async (t) => { value: "93.184.216.34" // example.com's IP (this might change) }] }; - + const heartbeat = { ping: 0 }; const dnsMonitor = new DnsMonitorType(); await dnsMonitor.check(monitor, heartbeat); - + assert.ok(heartbeat.ping > 0, "Ping should be recorded"); }); diff --git a/test/backend-test/test-notification.js b/test/backend-test/test-notification.js index aa0ca22d5..16f0b75bd 100644 --- a/test/backend-test/test-notification.js +++ b/test/backend-test/test-notification.js @@ -11,12 +11,12 @@ test("Notification - Basic Creation Test", async (t) => { test("Notification - Format Message Test", async (t) => { const notification = new Notification(); - + const monitor = { name: "Test Monitor", hostname: "example.com" }; - + const msg = { type: "down", monitor, @@ -29,28 +29,52 @@ test("Notification - Format Message Test", async (t) => { assert.ok(formatted.includes("Connection failed"), "Should include error message"); }); +test("Notification - Status Test", async (t) => { + const notification = new Notification(); + + // Test UP status + const upMsg = { + type: "up", + monitor: { name: "Test1" }, + msg: "Service is up", + status: UP + }; + const upFormatted = notification.format(upMsg); + assert.ok(upFormatted.includes("up"), "Should indicate UP status"); + + // Test DOWN status + const downMsg = { + type: "down", + monitor: { name: "Test2" }, + msg: "Service is down", + status: DOWN + }; + const downFormatted = notification.format(downMsg); + assert.ok(downFormatted.includes("down"), "Should indicate DOWN status"); +}); + test("Notification - Queue Management Test", async (t) => { const notification = new Notification(); - + // Add items to queue notification.add({ type: "down", monitor: { name: "Test1" }, msg: "Error 1" }); - + notification.add({ type: "up", monitor: { name: "Test2" }, msg: "Recovered" }); - + assert.strictEqual(notification.queue.length, 2, "Queue should have 2 items"); }); test("Notification - Priority Test", async (t) => { const notification = new Notification(); - + // Add items with different priorities notification.add({ type: "down", @@ -58,21 +82,21 @@ test("Notification - Priority Test", async (t) => { msg: "Critical Error", priority: "high" }); - + notification.add({ type: "down", monitor: { name: "Test2" }, msg: "Warning", priority: "low" }); - + const nextItem = notification.queue[0]; assert.strictEqual(nextItem.priority, "high", "High priority item should be first"); }); test("Notification - Retry Logic Test", async (t) => { const notification = new Notification(); - + const testMsg = { type: "down", monitor: { name: "Test1" }, @@ -80,9 +104,9 @@ test("Notification - Retry Logic Test", async (t) => { retries: 0, maxRetries: 3 }; - + notification.add(testMsg); - + // Simulate failed send try { await notification.send(testMsg); @@ -95,7 +119,7 @@ test("Notification - Retry Logic Test", async (t) => { test("Notification - Rate Limiting Test", async (t) => { const notification = new Notification(); const monitor = { name: "Test Monitor" }; - + // Add multiple notifications for same monitor for (let i = 0; i < 5; i++) { notification.add({ @@ -104,11 +128,11 @@ test("Notification - Rate Limiting Test", async (t) => { msg: `Error ${i}` }); } - + // Check if rate limiting is applied const processedCount = notification.queue.filter( item => item.monitor.name === "Test Monitor" ).length; - + assert.ok(processedCount < 5, "Should apply rate limiting"); }); diff --git a/test/component/MonitorList.spec.js b/test/component/MonitorList.spec.js index f80747e47..36d27a24c 100644 --- a/test/component/MonitorList.spec.js +++ b/test/component/MonitorList.spec.js @@ -73,7 +73,7 @@ describe("MonitorList.vue", () => { MonitorListItem: { name: "MonitorListItem", template: "