// packages/core-eslint/rules/no-realtime-handler-reexport.test.js
import { RuleTester } from "eslint";
import rule from "./no-realtime-handler-reexport.js";

const tester = new RuleTester({
  languageOptions: { ecmaVersion: 2022, sourceType: "module" },
});

tester.run("no-realtime-handler-reexport", rule, {
  valid: [
    // Importing a handler from inside a feature's bind-* file is allowed.
    {
      code: 'import { onPingHandler } from "../realtime/handlers/on-ping.handler";',
      filename: "/repo/packages/blog/src/di/bind-production.ts",
    },
    // Re-exporting a channel descriptor is allowed.
    {
      code: 'export { presenceChannel } from "./realtime/presence.channel";',
      filename: "/repo/packages/blog/src/index.ts",
    },
  ],
  invalid: [
    // Re-exporting a handler from any non-bind file is forbidden.
    {
      code: 'export { onPingHandler } from "./realtime/handlers/on-ping.handler";',
      filename: "/repo/packages/blog/src/index.ts",
      errors: [{ messageId: "noRealtimeHandlerReexport" }],
    },
    {
      code: 'export * from "./handlers/on-ping.handler";',
      filename: "/repo/packages/blog/src/realtime/index.ts",
      errors: [{ messageId: "noRealtimeHandlerReexport" }],
    },
  ],
});
