mirror of
https://github.com/outline/outline.git
synced 2026-12-01 01:14:11 +03:00
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.
73 lines
2.1 KiB
TypeScript
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();
|
|
});
|
|
});
|