80 lines
2.1 KiB
JavaScript
80 lines
2.1 KiB
JavaScript
/**
|
|
* Basic ScheduleService Tests
|
|
* Tests for core functionality
|
|
*/
|
|
|
|
const fs = require("fs");
|
|
const ScheduleService = require("../../../src/tui/services/ScheduleService");
|
|
|
|
describe("ScheduleService Basic Tests", () => {
|
|
let scheduleService;
|
|
const testSchedulesFile = "test-schedules-basic.json";
|
|
|
|
beforeEach(() => {
|
|
scheduleService = new ScheduleService();
|
|
scheduleService.schedulesFile = testSchedulesFile;
|
|
scheduleService.lockFile = `${testSchedulesFile}.lock`;
|
|
|
|
// Clean up any existing test files
|
|
try {
|
|
fs.unlinkSync(testSchedulesFile);
|
|
} catch (error) {
|
|
// File doesn't exist, which is fine
|
|
}
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Remove test files
|
|
try {
|
|
fs.unlinkSync(testSchedulesFile);
|
|
} catch (error) {
|
|
// File doesn't exist, which is fine
|
|
}
|
|
});
|
|
|
|
test("should validate schedule data", () => {
|
|
const validSchedule = {
|
|
operationType: "update",
|
|
scheduledTime: new Date(Date.now() + 86400000).toISOString(),
|
|
recurrence: "once",
|
|
description: "Test schedule",
|
|
};
|
|
|
|
expect(() =>
|
|
scheduleService.validateScheduleData(validSchedule)
|
|
).not.toThrow();
|
|
});
|
|
|
|
test("should reject invalid operation types", () => {
|
|
const invalidSchedule = {
|
|
operationType: "invalid",
|
|
scheduledTime: new Date(Date.now() + 86400000).toISOString(),
|
|
recurrence: "once",
|
|
};
|
|
|
|
expect(() =>
|
|
scheduleService.validateScheduleData(invalidSchedule)
|
|
).toThrow();
|
|
});
|
|
|
|
test("should calculate checksum correctly", () => {
|
|
const data = [{ id: "1", name: "test" }];
|
|
const checksum1 = scheduleService.calculateChecksum(data);
|
|
const checksum2 = scheduleService.calculateChecksum(data);
|
|
|
|
expect(checksum1).toBe(checksum2);
|
|
expect(typeof checksum1).toBe("string");
|
|
expect(checksum1.length).toBe(32); // MD5 hash length
|
|
});
|
|
|
|
test("should provide service statistics", () => {
|
|
const stats = scheduleService.getServiceStats();
|
|
|
|
expect(stats).toHaveProperty("schedulesLoaded");
|
|
expect(stats).toHaveProperty("schedulesCount");
|
|
expect(stats).toHaveProperty("activeSchedules");
|
|
expect(stats).toHaveProperty("pendingOperations");
|
|
expect(stats).toHaveProperty("memoryUsage");
|
|
});
|
|
});
|