// packages/core-eslint/rules/no-direct-socket-io.test.js
import { RuleTester } from "eslint";
import rule from "./no-direct-socket-io.js";

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

tester.run("no-direct-socket-io", rule, {
  valid: [
    // Allowed inside core-realtime
    { code: 'import { Server } from "socket.io";', filename: "/repo/packages/core-realtime/src/socket-io-realtime-server.ts" },
    // Allowed in app servers
    { code: 'import { Server } from "socket.io";', filename: "/repo/apps/web-next/server.ts" },
    // Allowed in app integration tests (e.g. realtime-ping e2e)
    { code: 'import { Server } from "socket.io";', filename: "/repo/apps/web-next/src/__tests__/realtime-ping.test.ts" },
    { code: 'import { io } from "socket.io-client";', filename: "/repo/apps/web-next/src/__tests__/realtime-ping.test.ts" },
    // Allowed elsewhere when not importing socket.io
    { code: 'import { foo } from "bar";', filename: "/repo/packages/blog/src/foo.ts" },
  ],
  invalid: [
    {
      code: 'import { Server } from "socket.io";',
      filename: "/repo/packages/blog/src/foo.ts",
      errors: [{ messageId: "noDirectSocketIO" }],
    },
    {
      code: 'import { io } from "socket.io-client";',
      filename: "/repo/packages/blog/src/ui/Component.tsx",
      errors: [{ messageId: "noDirectSocketIOClient" }],
    },
  ],
});
