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

Code before:
        const rabbitMQMonitor = new RabbitMqMonitorType();
        const monitor = {
            rabbitmqNodes: JSON.stringify([ "http://node1:15672", "http://node2:15672" ]),
            rabbitmqUsername: "guest",
            rabbitmqPassword: "guest",
            timeout: 10,
        };

        const heartbeat = {
            msg: "",
            status: PENDING,
        };

        // Mock checkSingleNode to fail first, succeed second
        let callCount = 0;
        rabbitMQMonitor.checkSingleNode = async (mon, url, nodeInfo) => {
            callCount++;
            if (callCount === 1) {
                throw new Error("Node 1 connection failed");
            }
            // Second call succeeds - don't throw
        };

        await rabbitMQMonitor.check(monitor, heartbeat, {});
        assert.strictEqual(heartbeat.status, UP);
        assert.strictEqual(heartbeat.msg, "OK");
        assert.strictEqual(callCount, 2, "Should check both nodes");
    });

    test("check() fails with consolidated error when all nodes are down", async () => {
        const rabbitMQMonitor = new RabbitMqMonitorType();
        const monitor = {
            rabbitmqNodes: JSON.stringify([
                "http://node1:15672",
                "http://node2:15672",
                "http://node3:15672"
            ]),
            rabbitmqUsername: "guest",
            rabbitmqPassword: "guest",
            timeout: 10,
        };

        const heartbeat = {
            msg: "",
            status: PENDING,
        };

        // Mock checkSingleNode to always fail
        let callCount = 0;
        rabbitMQMonitor.checkSingleNode = async (mon, url, nodeInfo) => {
            callCount++;

Review comment (suggestion):
```suggestion
        assert.strictEqual(heartbeat.msg, "One of the 2 nodes is reachable and there are no alerts in the cluster");
```

Code after:
        const rabbitMQMonitor = new RabbitMqMonitorType();
        const monitor = {
            rabbitmqNodes: JSON.stringify([ "http://node1:15672", "http://node2:15672" ]),
            rabbitmqUsername: "guest",
            rabbitmqPassword: "guest",
            timeout: 10,
        };

        const heartbeat = {
            msg: "",
            status: PENDING,
        };

        // Mock checkSingleNode to fail first, succeed second
        let callCount = 0;
        rabbitMQMonitor.checkSingleNode = async (mon, url, nodeInfo) => {
            callCount++;
            if (callCount === 1) {
                throw new Error("Node 1 connection failed");
            }
            // Second call succeeds - don't throw
        };

        await rabbitMQMonitor.check(monitor, heartbeat, {});
        assert.strictEqual(heartbeat.status, UP);
        assert.strictEqual(heartbeat.msg, "One of the 2 nodes is reachable and there are no alerts in the cluster");
        assert.strictEqual(callCount, 2, "Should check both nodes");
    });

    test("check() fails with consolidated error when all nodes are down", async () => {
        const rabbitMQMonitor = new RabbitMqMonitorType();
        const monitor = {
            rabbitmqNodes: JSON.stringify([
                "http://node1:15672",
                "http://node2:15672",
                "http://node3:15672"
            ]),
            rabbitmqUsername: "guest",
            rabbitmqPassword: "guest",
            timeout: 10,
        };

        const heartbeat = {
            msg: "",
            status: PENDING,
        };

        // Mock checkSingleNode to always fail
        let callCount = 0;
        rabbitMQMonitor.checkSingleNode = async (mon, url, nodeInfo) => {
            callCount++;