import { describe, expect, it } from "vitest";
import { WidgetsController } from "./widgets.controller";

const THROTTLER_SKIP_DEFAULT_KEY = "THROTTLER:SKIPdefault";

describe("WidgetsController throttler metadata", () => {
  it("marks widget data polling endpoints to skip throttling", () => {
    const pollingHandlers = [
      WidgetsController.prototype.getStatCardData,
      WidgetsController.prototype.getChartData,
      WidgetsController.prototype.getListData,
      WidgetsController.prototype.getCalendarPreviewData,
      WidgetsController.prototype.getActiveProjectsData,
      WidgetsController.prototype.getAgentChainsData,
    ];

    for (const handler of pollingHandlers) {
      expect(Reflect.getMetadata(THROTTLER_SKIP_DEFAULT_KEY, handler)).toBe(true);
    }
  });

  it("does not skip throttling for non-polling widget routes", () => {
    expect(
      Reflect.getMetadata(THROTTLER_SKIP_DEFAULT_KEY, WidgetsController.prototype.findAll)
    ).toBe(undefined);

    expect(
      Reflect.getMetadata(THROTTLER_SKIP_DEFAULT_KEY, WidgetsController.prototype.findByName)
    ).toBe(undefined);
  });
});
