mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { subMinutes } from "date-fns";
|
|
import { buildAttachment } from "@server/test/factories";
|
|
import Attachment from "./Attachment";
|
|
|
|
describe("#Attachment", () => {
|
|
describe("updateAccessedAt", () => {
|
|
it("should set lastAccessedAt when it is empty", async () => {
|
|
const attachment = await buildAttachment();
|
|
await attachment.updateAccessedAt();
|
|
|
|
const reloaded = await Attachment.findByPk(attachment.id, {
|
|
rejectOnEmpty: true,
|
|
});
|
|
expect(reloaded.lastAccessedAt).toBeTruthy();
|
|
});
|
|
|
|
it("should not write when accessed within the last five minutes", async () => {
|
|
const recent = subMinutes(new Date(), 1);
|
|
const attachment = await buildAttachment({ lastAccessedAt: recent });
|
|
await attachment.updateAccessedAt();
|
|
|
|
const reloaded = await Attachment.findByPk(attachment.id, {
|
|
rejectOnEmpty: true,
|
|
});
|
|
expect(reloaded.lastAccessedAt).toEqual(recent);
|
|
});
|
|
|
|
it("should write when last accessed more than five minutes ago", async () => {
|
|
const old = subMinutes(new Date(), 10);
|
|
const attachment = await buildAttachment({ lastAccessedAt: old });
|
|
await attachment.updateAccessedAt();
|
|
|
|
const reloaded = await Attachment.findByPk(attachment.id, {
|
|
rejectOnEmpty: true,
|
|
});
|
|
expect(reloaded.lastAccessedAt!.getTime()).toBeGreaterThan(old.getTime());
|
|
});
|
|
});
|
|
});
|