Spaces:
Sleeping
Sleeping
File size: 2,765 Bytes
097eaf0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | import { trackMonitorTargetInterest } from "../../lib/tracking";
import {
getRemovedMonitorTargets,
trackMonitorCheckStartedInterest,
trackMonitorConfiguredInterest,
trackMonitorDeactivatedInterest,
} from "./interest";
import type { MonitorCheckRow, MonitorRow, MonitorTarget } from "./types";
jest.mock("../../lib/tracking", () => ({
trackMonitorTargetInterest: jest.fn(),
}));
const scrapeTarget: MonitorTarget = {
id: "scrape-target",
type: "scrape",
urls: ["https://example.com/a"],
scrapeOptions: {},
};
const crawlTarget: MonitorTarget = {
id: "crawl-target",
type: "crawl",
url: "https://example.com/docs",
crawlOptions: { limit: 50, maxDiscoveryDepth: 2 },
scrapeOptions: {},
};
const monitor = {
id: "monitor-1",
team_id: "team-1",
status: "active",
schedule_cron: "0 * * * *",
schedule_timezone: "UTC",
targets: [scrapeTarget, crawlTarget],
} as MonitorRow;
describe("monitor interest emit helpers", () => {
beforeEach(() => {
jest.clearAllMocks();
(trackMonitorTargetInterest as jest.Mock).mockResolvedValue(undefined);
});
it("finds configured targets removed by an update", () => {
expect(
getRemovedMonitorTargets({
before: monitor,
after: { ...monitor, targets: [crawlTarget] },
}),
).toEqual([scrapeTarget]);
});
it("emits configured interest for all monitor targets", async () => {
await trackMonitorConfiguredInterest({
monitor,
intervalMs: 60 * 60 * 1000,
});
expect(trackMonitorTargetInterest).toHaveBeenCalledWith(
expect.objectContaining({
eventType: "configured",
teamId: "team-1",
monitorId: "monitor-1",
monitorStatus: "active",
intervalMs: 60 * 60 * 1000,
targets: [scrapeTarget, crawlTarget],
zeroDataRetention: false,
}),
);
});
it("emits deactivated interest for a target subset", async () => {
await trackMonitorDeactivatedInterest({
monitor: { ...monitor, status: "paused" },
targets: [scrapeTarget],
intervalMs: 60 * 60 * 1000,
});
expect(trackMonitorTargetInterest).toHaveBeenCalledWith(
expect.objectContaining({
eventType: "deactivated",
monitorStatus: "paused",
targets: [scrapeTarget],
}),
);
});
it("emits check_started interest with a check id", async () => {
await trackMonitorCheckStartedInterest({
monitor,
check: { id: "check-1" } as MonitorCheckRow,
});
expect(trackMonitorTargetInterest).toHaveBeenCalledWith(
expect.objectContaining({
eventType: "check_started",
checkId: "check-1",
intervalMs: 60 * 60 * 1000,
targets: [scrapeTarget, crawlTarget],
}),
);
});
});
|