forked from Yara724/api
74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
import { Types } from "mongoose";
|
|
import {
|
|
ExpertFileActivityType,
|
|
} from "src/users/entities/schema/expert-file-activity.schema";
|
|
import { expertPortfolioFileIdsFromActivityEvents } from "./expert-portfolio";
|
|
|
|
describe("expertPortfolioFileIdsFromActivityEvents", () => {
|
|
const fid = new Types.ObjectId();
|
|
|
|
it("includes handled files after HANDLED", () => {
|
|
const ids = expertPortfolioFileIdsFromActivityEvents([
|
|
{
|
|
fileId: fid,
|
|
eventType: ExpertFileActivityType.CHECKED,
|
|
occurredAt: new Date("2026-01-01T10:00:00Z"),
|
|
},
|
|
{
|
|
fileId: fid,
|
|
eventType: ExpertFileActivityType.HANDLED,
|
|
occurredAt: new Date("2026-01-01T11:00:00Z"),
|
|
},
|
|
]);
|
|
expect(ids.has(String(fid))).toBe(true);
|
|
});
|
|
|
|
it("includes currently checked files", () => {
|
|
const ids = expertPortfolioFileIdsFromActivityEvents([
|
|
{
|
|
fileId: fid,
|
|
eventType: ExpertFileActivityType.CHECKED,
|
|
occurredAt: new Date("2026-01-01T10:00:00Z"),
|
|
},
|
|
]);
|
|
expect(ids.has(String(fid))).toBe(true);
|
|
});
|
|
|
|
it("keeps handled files after a later UNCHECKED (e.g. resend unlock)", () => {
|
|
const ids = expertPortfolioFileIdsFromActivityEvents([
|
|
{
|
|
fileId: fid,
|
|
eventType: ExpertFileActivityType.CHECKED,
|
|
occurredAt: new Date("2026-01-01T10:00:00Z"),
|
|
},
|
|
{
|
|
fileId: fid,
|
|
eventType: ExpertFileActivityType.HANDLED,
|
|
occurredAt: new Date("2026-01-01T10:30:00Z"),
|
|
},
|
|
{
|
|
fileId: fid,
|
|
eventType: ExpertFileActivityType.UNCHECKED,
|
|
occurredAt: new Date("2026-01-01T11:00:00Z"),
|
|
},
|
|
]);
|
|
expect(ids.has(String(fid))).toBe(true);
|
|
});
|
|
|
|
it("excludes files after UNCHECKED without HANDLED", () => {
|
|
const ids = expertPortfolioFileIdsFromActivityEvents([
|
|
{
|
|
fileId: fid,
|
|
eventType: ExpertFileActivityType.CHECKED,
|
|
occurredAt: new Date("2026-01-01T10:00:00Z"),
|
|
},
|
|
{
|
|
fileId: fid,
|
|
eventType: ExpertFileActivityType.UNCHECKED,
|
|
occurredAt: new Date("2026-01-01T10:30:00Z"),
|
|
},
|
|
]);
|
|
expect(ids.has(String(fid))).toBe(false);
|
|
});
|
|
});
|