flip status on create

This commit is contained in:
Alex Holliday committed 2026-05-21 10:50:53 -07:00
1 parent 0470eab782
commit fbfb861447
2 files changed
+25 -1

No files matched your search

@@ -107,7 +107,7 @@ export class MaintenanceWindowService implements IMaintenanceWindowService {
});
}
await this.maintenanceWindowsRepository.create({
const created = await this.maintenanceWindowsRepository.create({
teamId,
monitorIds: monitorIDs,
name: name,
@@ -118,6 +118,10 @@ export class MaintenanceWindowService implements IMaintenanceWindowService {
start: start,
end: end,
});
if (isWindowActive(created)) {
await this.monitorsRepository.updateByIds(created.monitorIds, teamId, { status: "maintenance" });
}
};
getMaintenanceWindowById = async ({ id, teamId }: { id: string; teamId: string }) => {
@@ -149,6 +149,26 @@ describe("MaintenanceWindowService", () => {
expect(maintenanceWindowsRepository.create).toHaveBeenCalledTimes(1);
expect(maintenanceWindowsRepository.create).toHaveBeenCalledWith(expect.objectContaining({ monitorIds: ["mon-1"] }));
});
it("flips monitors to maintenance when the created window is active", async () => {
const maintenanceWindowsRepository = createMaintenanceWindowsRepo();
(maintenanceWindowsRepository.create as jest.Mock).mockResolvedValue(makeActiveWindow({ monitorIds: ["mon-1", "mon-2"] }));
const { service, monitorsRepository } = createService({ maintenanceWindowsRepository });
await service.createMaintenanceWindow(defaultCreateParams);
expect(monitorsRepository.updateByIds).toHaveBeenCalledTimes(1);
expect(monitorsRepository.updateByIds).toHaveBeenCalledWith(["mon-1", "mon-2"], "team-1", { status: "maintenance" });
});
it("does not touch monitor status when the created window is inactive", async () => {
// default mock returns makeWindow() with past dates → inactive
const { service, monitorsRepository } = createService();
await service.createMaintenanceWindow(defaultCreateParams);
expect(monitorsRepository.updateByIds).not.toHaveBeenCalled();
});
});
// ── getMaintenanceWindowById ─────────────────────────────────────────────