Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
850 changes: 209 additions & 641 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"test:e2e": "npm run build && cypress open",
"test:db": "node ./test/shared/setupDatabase.js",
"test:server": "npm run test:db && cross-env NODE_ENV=test node server/index.js",
"test:ui": "vitest run --coverage --watch --ui",
"migrate": "node ./scripts/migrate_manual.js",
"dev:prepare": "husky",
"preview": "vite preview",
Expand All @@ -42,12 +43,12 @@
"@dnd-kit/sortable": "10.0.0",
"@dnd-kit/utilities": "3.2.2",
"@lunalytics/ui": "0.1.19",
"axios": "^1.12.2",
"axios": "1.12.2",
"bcryptjs": "3.0.2",
"better-sqlite3": "11.10.0",
"classnames": "2.5.1",
"compare-versions": "6.1.1",
"compression": "1.8.0",
"compression": "1.8.1",
"cookie-parser": "1.4.7",
"cors": "2.8.5",
"cron": "4.3.1",
Expand Down Expand Up @@ -90,7 +91,8 @@
"@types/react-dom": "19.1.7",
"@types/react-window": "1.8.8",
"@vitejs/plugin-react-swc": "4.0.0",
"@vitest/coverage-v8": "3.2.4",
"@vitest/coverage-v8": "4.0.4",
"@vitest/ui": "4.0.4",
"concurrently": "9.2.0",
"cypress": "14.4.1",
"eslint": "9.33.0",
Expand All @@ -107,8 +109,8 @@
"sass": "1.89.2",
"typescript": "5.9.2",
"typescript-eslint": "8.39.1",
"vite": "7.1.11",
"vite": "7.1.12",
"vite-plugin-compression2": "2.2.0",
"vitest": "3.2.4"
"vitest": "4.0.4"
}
}
10 changes: 5 additions & 5 deletions server/middleware/notifications/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { UnprocessableError } from '../../../shared/utils/errors.js';
import { deleteNotification } from '../../database/queries/notification.js';

const NotificationDeleteMiddleware = async (request, response) => {
const { notificationId } = request.query;
try {
const { notificationId } = request.query;

if (!notificationId) {
throw new UnprocessableError('No notificationId provided');
}
if (!notificationId) {
throw new UnprocessableError('No notificationId provided');
}

try {
await deleteNotification(notificationId);
return response.status(200).send('Notification deleted');
} catch (error) {
Expand Down
14 changes: 7 additions & 7 deletions server/middleware/notifications/disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { toggleNotification } from '../../database/queries/notification.js';
const NotificationToggleMiddleware = async (request, response) => {
const { notificationId, isEnabled } = request.query;

if (!notificationId) {
throw new UnprocessableError('No notificationId provided');
}
try {
if (!notificationId) {
throw new UnprocessableError('No notificationId provided');
}

if (isEnabled !== 'true' && isEnabled !== 'false') {
throw new UnprocessableError('isEnabled is not a boolean');
}
if (isEnabled !== 'true' && isEnabled !== 'false') {
throw new UnprocessableError('isEnabled is not a boolean');
}

try {
await toggleNotification(notificationId, isEnabled === 'true');
return response.sendStatus(200);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion server/middleware/status/defaultPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const defaultPageMiddleware = async (request, response, next) => {
}
}

next();
return next();
} catch {
return response.redirect('/home');
}
Expand Down
1 change: 1 addition & 0 deletions shared/utils/authenication.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const getAuthCallbackUrl = (
}

if (provider === 'custom') {
return [];
}

return null;
Expand Down
83 changes: 83 additions & 0 deletions test/server/class/incident.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { cleanIncident } from '../../../server/class/incident.js';

describe('cleanIncident', () => {
it('should clean and parse monitorIds and messages if they are JSON strings', () => {
const incident = {
incidentId: 'abc123',
title: 'Test Incident',
monitorIds: '["monitor1","monitor2"]',
messages: '[{"msg":"down"},{"msg":"up"}]',
affect: 'partial',
status: 'investigating',
createdAt: '2025-10-25T10:00:00Z',
completedAt: null,
isClosed: '1',
};
const result = cleanIncident(incident);
expect(result.incidentId).toBe('abc123');
expect(result.title).toBe('Test Incident');
expect(result.monitorIds).toEqual(['monitor1', 'monitor2']);
expect(result.messages).toEqual([{ msg: 'down' }, { msg: 'up' }]);
expect(result.affect).toBe('partial');
expect(result.status).toBe('investigating');
expect(result.createdAt).toBe('2025-10-25T10:00:00Z');
expect(result.completedAt).toBeNull();
expect(result.isClosed).toBe(true);
});

it('should not parse monitorIds/messages if already objects', () => {
const incident = {
incidentId: 'id2',
title: 'Already Parsed',
monitorIds: ['m1', 'm2'],
messages: [{ msg: 'ok' }],
affect: 'none',
status: 'resolved',
createdAt: '2025-10-25T11:00:00Z',
completedAt: '2025-10-25T12:00:00Z',
isClosed: '0',
};
const result = cleanIncident(incident);
expect(result.monitorIds).toEqual(['m1', 'm2']);
expect(result.messages).toEqual([{ msg: 'ok' }]);
expect(result.isClosed).toBe(false);
});

it('should handle malformed JSON gracefully', () => {
const incident = {
incidentId: 'id3',
title: 'Malformed',
monitorIds: '[malformed',
messages: '{bad:json}',
affect: 'major',
status: 'error',
createdAt: '2025-10-25T13:00:00Z',
completedAt: null,
isClosed: '1',
};
const result = cleanIncident(incident);
expect(result.monitorIds).toBe('[malformed');
expect(result.messages).toBe('{bad:json}');
expect(result.isClosed).toBe(true);
});

it('should handle missing optional fields', () => {
const incident = {
incidentId: 'id4',
title: 'Missing Fields',
monitorIds: '[]',
messages: '[]',
affect: undefined,
status: undefined,
createdAt: undefined,
completedAt: undefined,
isClosed: undefined,
};
const result = cleanIncident(incident);
expect(result.affect).toBeUndefined();
expect(result.status).toBeUndefined();
expect(result.createdAt).toBeUndefined();
expect(result.completedAt).toBeUndefined();
expect(result.isClosed).toBe(false);
});
});
File renamed without changes.
75 changes: 75 additions & 0 deletions test/server/class/monitor/docker.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import clean from '../../../../server/class/monitor/docker.js';

describe('docker clean', () => {
it('should parse and convert fields correctly', () => {
const monitor = {
monitorId: 'm1',
name: 'Docker Monitor',
url: 'http://localhost',
retry: '3',
interval: '60',
retryInterval: '10',
requestTimeout: '5000',
email: 'test@example.com',
type: 'docker',
notificationId: 'nid',
notificationType: 'email',
uptimePercentage: 99.9,
averageHeartbeatLatency: 100,
showFilters: true,
paused: '1',
ignoreTls: '1',
createdAt: '2025-10-25T10:00:00Z',
icon: '["icon1"]',
heartbeats: [{ status: 'ok' }],
};
const result = clean(monitor);
expect(result.monitorId).toBe('m1');
expect(result.retry).toBe(3);
expect(result.interval).toBe(60);
expect(result.retryInterval).toBe(10);
expect(result.requestTimeout).toBe(5000);
expect(result.paused).toBe(true);
expect(result.ignoreTls).toBe(true);
expect(result.icon).toEqual(['icon1']);
expect(result.heartbeats).toEqual([{ status: 'ok' }]);
});

it('should handle missing heartbeats and parse booleans', () => {
const monitor = {
monitorId: 'm2',
name: 'No Heartbeats',
url: 'http://localhost',
retry: '1',
interval: '30',
retryInterval: '5',
requestTimeout: '1000',
paused: '0',
ignoreTls: '0',
icon: '[]',
};
const result = clean(monitor);
expect(result.paused).toBe(false);
expect(result.ignoreTls).toBe(false);
expect(result.heartbeats).toEqual([]);
expect(result.icon).toEqual([]);
});

it('should omit heartbeats if includeHeartbeats is false', () => {
const monitor = {
monitorId: 'm3',
name: 'No Heartbeats',
url: 'http://localhost',
retry: '1',
interval: '30',
retryInterval: '5',
requestTimeout: '1000',
paused: '0',
ignoreTls: '0',
icon: '[]',
heartbeats: [{ status: 'ok' }],
};
const result = clean(monitor, false);
expect(result.heartbeats).toBeUndefined();
});
});
87 changes: 87 additions & 0 deletions test/server/class/monitor/http.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import clean from '../../../../server/class/monitor/http.js';

describe('http clean', () => {
it('should parse and convert fields correctly', () => {
const monitor = {
monitorId: 'h1',
name: 'HTTP Monitor',
url: 'http://localhost',
retry: '2',
interval: '30',
retryInterval: '5',
requestTimeout: '1000',
method: 'GET',
headers: '{"Accept":"*/*"}',
body: '{"data":1}',
valid_status_codes: '["200-299"]',
email: 'test@example.com',
type: 'http',
notificationId: 'nid',
notificationType: 'email',
uptimePercentage: 100,
averageHeartbeatLatency: 50,
showFilters: false,
paused: '1',
ignoreTls: '1',
createdAt: '2025-10-25T10:00:00Z',
icon: '["icon1"]',
heartbeats: [{ status: 'ok' }],
cert: { valid: true },
};
const result = clean(monitor);
expect(result.monitorId).toBe('h1');
expect(result.retry).toBe(2);
expect(result.interval).toBe(30);
expect(result.retryInterval).toBe(5);
expect(result.requestTimeout).toBe(1000);
expect(result.method).toBe('GET');
expect(result.headers).toEqual({ Accept: '*/*' });
expect(result.body).toEqual({ data: 1 });
expect(result.valid_status_codes).toEqual(['200-299']);
expect(result.paused).toBe(true);
expect(result.ignoreTls).toBe(true);
expect(result.icon).toEqual(['icon1']);
expect(result.heartbeats).toEqual([{ status: 'ok' }]);
});

it('should handle missing heartbeats and cert, and parse booleans', () => {
const monitor = {
monitorId: 'h2',
name: 'No Heartbeats',
url: 'http://localhost',
retry: '1',
interval: '10',
retryInterval: '2',
requestTimeout: '500',
paused: '0',
ignoreTls: '0',
icon: '[]',
};
const result = clean(monitor);
expect(result.paused).toBe(false);
expect(result.ignoreTls).toBe(false);
expect(result.heartbeats).toEqual([]);
expect(result.icon).toEqual([]);
expect(result.cert).toEqual({ isValid: false });
});

it('should omit heartbeats/cert if includeHeartbeats/includeCert is false', () => {
const monitor = {
monitorId: 'h3',
name: 'No Heartbeats',
url: 'http://localhost',
retry: '1',
interval: '10',
retryInterval: '2',
requestTimeout: '500',
paused: '0',
ignoreTls: '0',
icon: '[]',
heartbeats: [{ status: 'ok' }],
cert: { valid: true },
};
const result = clean(monitor, false, false);
expect(result.heartbeats).toBeUndefined();
expect(result.cert).toBeUndefined();
});
});
Loading