# frozen_string_literal: true require "rails_helper" RSpec.describe Streams::NodeHealth do let!(:node) do StreamNode.create!( slug: "ingest-health-01", hostname: "ingest-health-01.mltv-stream.net", role: "cloud", status: "provisioning", provider: "hetzner", rtmp_base_url: "rtmp://h:1935", hls_base_url: "https://h/hls", api_base_url: "http://203.0.113.10:9997", max_publishers: 4, max_relays: 4 ) end after { node.destroy } it "promotes provisioning node when MediaMTX is reachable" do client = instance_double(Mediamtx::Client, reachable?: true) allow(Mediamtx::Client).to receive(:new).with(base_url: node.api_base_url).and_return(client) expect(described_class.promote_if_healthy!(node)).to eq(true) expect(node.reload.status).to eq("ready") expect(node.last_health_at).to be_present end it "does not promote when MediaMTX is down" do client = instance_double(Mediamtx::Client, reachable?: false) allow(Mediamtx::Client).to receive(:new).with(base_url: node.api_base_url).and_return(client) expect(described_class.promote_if_healthy!(node)).to eq(false) expect(node.reload.status).to eq("provisioning") end end