const { RuleTester } = require("eslint");
const rule = require("./no-node-fetch");
const { getRuleTester } = require("./testHelper");

getRuleTester().run("no-node-fetch", rule, {
    valid: [
        "const axios = require('axios');",
        "import axios from 'axios';",
        "const result = await axios.get('http://example.com');",
        "function fetchData() { return 'data'; }",
        "const obj = { fetch: () => {} };",
        "import { fetch } from '@insite/client-framework/ServerSideRendering';",
        `import { fetch } from '@insite/client-framework/ServerSideRendering';
        fetch('http://example.com');
        `,
    ],

    invalid: [
        {
            code: "fetch('http://example.com');",
            errors: [{ messageId: "noFetch" }],
        },
        {
            code: "const response = await fetch('http://example.com');",
            errors: [{ messageId: "noFetch" }],
        },
        {
            code: "global.fetch('http://example.com');",
            errors: [{ messageId: "noFetch" }],
        },
        {
            code: "globalThis.fetch('http://example.com');",
            errors: [{ messageId: "noFetch" }],
        },
        {
            code: "import fetch from 'node-fetch';",
            errors: [{ messageId: "noFetch" }],
        },
        {
            code: "import { fetch } from 'some-other-library';",
            errors: [{ messageId: "noFetch" }],
        },
        {
            code: "const fetch = require('node-fetch');",
            errors: [{ messageId: "noFetch" }],
        },
    ],
});
