Repository: louislam/uptime-kuma
File: test/backend-test/test-domain.js (JavaScript)

Code before:
                const monitor = {
                    type: "http",
                    url: "https://127.0.0.1",
                    domainExpiryNotification: true,
                };
                await assert.rejects(
                    async () => await DomainExpiry.checkSupport(monitor),
                    (error) => {
                        assert.strictEqual(error.constructor.name, "TranslatableError");
                        assert.strictEqual(error.message, "domain_expiry_unsupported_is_icann");
                        return true;
                    }
                );
            });
        });

        describe("Edge Cases & RDAP Support", () => {
            test("handles subdomain correctly", async () => {
                const monitor = {
                    type: "http",
                    url: "https://api.staging.example.com/v1/users",
                    domainExpiryNotification: true,
                };
                const supportInfo = await DomainExpiry.checkSupport(monitor);
                assert.strictEqual(supportInfo.domain, "example.com");
                assert.strictEqual(supportInfo.tld, "com");
            });

            test("handles complex subdomain correctly", async () => {
                const monitor = {
                    type: "http",
                    url: "https://mail.subdomain.example.org",
                    domainExpiryNotification: true,
                };
                const supportInfo = await DomainExpiry.checkSupport(monitor);
                assert.strictEqual(supportInfo.domain, "example.org");
                assert.strictEqual(supportInfo.tld, "org");
            });

            test("handles URL with port correctly", async () => {
                const monitor = {
                    type: "http",
                    url: "https://example.com:8080/api",
                    domainExpiryNotification: true,
                };
                const supportInfo = await DomainExpiry.checkSupport(monitor);
                assert.strictEqual(supportInfo.domain, "example.com");
                assert.strictEqual(supportInfo.tld, "com");
            });

            test("handles URL with query parameters correctly", async () => {

Review comment (suggestion):
this should trigger the `domain_expiry_unsupported_is_ip` error instead.
-> Please reorder accoringly

Code after:
                const monitor = {
                    type: "http",
                    url: "https://example.a",
                    domainExpiryNotification: true,
                };
                await assert.rejects(
                    async () => await DomainExpiry.checkSupport(monitor),
                    (error) => {
                        assert.strictEqual(error.constructor.name, "TranslatableError");
                        assert.strictEqual(error.message, "domain_expiry_public_suffix_too_short");
                        return true;
                    }
                );
            });

            test("throws error for non-ICANN TLD (e.g. .local)", async () => {
                const monitor = {
                    type: "http",
                    url: "https://example.local",
                    domainExpiryNotification: true,
                };
                await assert.rejects(
                    async () => await DomainExpiry.checkSupport(monitor),
                    (error) => {
                        assert.strictEqual(error.constructor.name, "TranslatableError");
                        assert.strictEqual(error.message, "domain_expiry_unsupported_is_icann");
                        return true;
                    }
                );
            });
        });

        describe("Edge Cases & RDAP Support", () => {
            test("handles subdomain correctly", async () => {
                const monitor = {
                    type: "http",
                    url: "https://api.staging.example.com/v1/users",
                    domainExpiryNotification: true,
                };
                const supportInfo = await DomainExpiry.checkSupport(monitor);
                assert.strictEqual(supportInfo.domain, "example.com");
                assert.strictEqual(supportInfo.tld, "com");
            });

            test("handles complex subdomain correctly", async () => {
                const monitor = {
                    type: "http",
                    url: "https://mail.subdomain.example.org",
                    domainExpiryNotification: true,
                };
                const supportInfo = await DomainExpiry.checkSupport(monitor);