Files
outline/server/queues/tasks/CleanupPermanentlyDeletedDocumentsTask.test.ts
T
Tom Moor 750c30b470 feat: Customizable document retention periods
Two-phase retention: configurable trash retention (TrashRetentionDays)
and data retention (DataRetentionDays) per team, with a destroyedAt
column and background tasks to expire and permanently delete documents.
2026-08-16 14:36:00 -04:00

73 lines
2.1 KiB
TypeScript

import { buildTeam } from "@server/test/factories";
import { TeamPreferenceDefaults } from "@shared/constants";
import { TeamPreference } from "@shared/types";
import CleanupPermanentlyDeletedDocumentsTask from "./CleanupPermanentlyDeletedDocumentsTask";
import CleanupPermanentlyDeletedDocumentsByRetentionTask from "./CleanupPermanentlyDeletedDocumentsByRetentionTask";
const props = {
limit: 10000,
partition: {
partitionIndex: 0,
partitionCount: 1,
},
};
const defaultRetentionDays = TeamPreferenceDefaults[
TeamPreference.DataRetentionDays
] as number;
describe("CleanupPermanentlyDeletedDocumentsTask", () => {
it("should schedule worker tasks for default and custom retention periods", async () => {
const scheduleSpy = vi.spyOn(
CleanupPermanentlyDeletedDocumentsByRetentionTask.prototype,
"schedule"
);
// Team with custom retention
const teamCustom = await buildTeam();
const customDays = 7;
teamCustom.setPreference(TeamPreference.DataRetentionDays, customDays);
await teamCustom.save();
const task = new CleanupPermanentlyDeletedDocumentsTask();
await task.perform(props);
// Verify that the default retention task was scheduled
expect(scheduleSpy).toHaveBeenCalledWith(
expect.objectContaining({
retentionDays: defaultRetentionDays,
partition: props.partition,
})
);
// Verify that the custom retention task was scheduled
expect(scheduleSpy).toHaveBeenCalledWith(
expect.objectContaining({
retentionDays: customDays,
partition: props.partition,
})
);
scheduleSpy.mockRestore();
});
it("should always schedule a worker for the default retention period", async () => {
const scheduleSpy = vi.spyOn(
CleanupPermanentlyDeletedDocumentsByRetentionTask.prototype,
"schedule"
);
const task = new CleanupPermanentlyDeletedDocumentsTask();
await task.perform(props);
expect(scheduleSpy).toHaveBeenCalledWith(
expect.objectContaining({
retentionDays: defaultRetentionDays,
partition: props.partition,
})
);
scheduleSpy.mockRestore();
});
});