56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { AutopilotSettings } from "@photoreport/contracts";
|
|
import { exportTargets, galleryReceivers, picksNeeded } from "../src/autopilot/targets.js";
|
|
|
|
const a = "11111111-1111-4111-8111-111111111111";
|
|
const b = "22222222-2222-4222-8222-222222222222";
|
|
const c = "33333333-3333-4333-8333-333333333333";
|
|
|
|
describe("exportTargets", () => {
|
|
it("prefers deliverTargetIds and dedupes", () => {
|
|
expect(exportTargets({ deliverTargetIds: [a, b, a], deliverTargetId: null, restTargetId: null })).toEqual([a, b]);
|
|
});
|
|
|
|
it("falls back to legacy deliver + rest", () => {
|
|
expect(exportTargets({ deliverTargetIds: [], deliverTargetId: a, restTargetId: b })).toEqual([a, b]);
|
|
expect(exportTargets({ deliverTargetIds: [], deliverTargetId: a, restTargetId: a })).toEqual([a]);
|
|
});
|
|
});
|
|
|
|
describe("picksNeeded", () => {
|
|
it("matches the number of exports when set", () => {
|
|
const s = AutopilotSettings.parse({ enabled: true, deliverTargetIds: [a, b, c] });
|
|
expect(picksNeeded(s)).toBe(3);
|
|
});
|
|
|
|
it("uses picksPerBurst when no exports", () => {
|
|
expect(picksNeeded(AutopilotSettings.parse({ enabled: true, picksPerBurst: 2 }))).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe("galleryReceivers", () => {
|
|
const zz = "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa";
|
|
const liga = "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb";
|
|
const galleries = [
|
|
{ targetId: zz, count: 30 },
|
|
{ targetId: liga, count: 100 },
|
|
];
|
|
|
|
it("sends a short-gallery frame to the short client and to the larger one", () => {
|
|
const chosen = new Map<string, Set<string>>([
|
|
[zz, new Set(["p1"])],
|
|
[liga, new Set(["p1", "p2"])],
|
|
]);
|
|
expect(galleryReceivers("p1", galleries, chosen).sort()).toEqual([liga, zz].sort());
|
|
expect(galleryReceivers("p2", galleries, chosen)).toEqual([liga]);
|
|
});
|
|
|
|
it("puts a frame only the short gallery picked into the larger gallery too", () => {
|
|
const chosen = new Map<string, Set<string>>([
|
|
[zz, new Set(["p1"])],
|
|
[liga, new Set()],
|
|
]);
|
|
expect(galleryReceivers("p1", galleries, chosen).sort()).toEqual([liga, zz].sort());
|
|
});
|
|
});
|