// An Instagram channel is synced seldom, whatever the global default // (syncScheduler.ts resolveIntervalMinutes). Every other channel's interval is // what it was. import { test } from "node:test"; import assert from "node:assert/strict"; import type { ChannelConfig } from "../lib/channelConfig"; import { defaultSyncScheduler } from "../lib/settings"; import { INSTAGRAM_DEFAULT_SYNC_MINUTES, INSTAGRAM_MIN_SYNC_MINUTES, resolveIntervalMinutes } from "./syncScheduler"; const sched = (defaultIntervalMinutes: number) => ({ ...defaultSyncScheduler(), defaultIntervalMinutes }); const ig = (syncIntervalMinutes?: number) => ({ sourceKind: "social", platform: "instagram", ...(syncIntervalMinutes !== undefined ? { syncIntervalMinutes } : {}) }) as ChannelConfig; const x = (syncIntervalMinutes?: number) => ({ sourceKind: "social", platform: "twitter", ...(syncIntervalMinutes !== undefined ? { syncIntervalMinutes } : {}) }) as ChannelConfig; test("an Instagram channel with no interval of its own: every 12 hours at the most often", () => { assert.equal(INSTAGRAM_DEFAULT_SYNC_MINUTES, 720); assert.equal(resolveIntervalMinutes(ig(), sched(60)), 720); assert.equal(resolveIntervalMinutes(ig(), sched(1440)), 1440); // A global default of 0 (no default cadence) is still none. assert.equal(resolveIntervalMinutes(ig(), sched(0)), 0); }); test("its own interval is never under 4 hours, and 0 turns its auto-sync off", () => { assert.equal(INSTAGRAM_MIN_SYNC_MINUTES, 240); assert.equal(resolveIntervalMinutes(ig(30), sched(60)), 240); assert.equal(resolveIntervalMinutes(ig(480), sched(60)), 480); assert.equal(resolveIntervalMinutes(ig(0), sched(60)), 0); }); test("every other channel's interval is what it was", () => { assert.equal(resolveIntervalMinutes(x(), sched(60)), 60); assert.equal(resolveIntervalMinutes(x(30), sched(60)), 30); assert.equal(resolveIntervalMinutes({ platform: "instagram" } as ChannelConfig, sched(60)), 60, "a video channel is not an Instagram posts channel"); });