I nodi cloud restano in provisioning finché :9997 risponde; retry su create_path e 503 retryable se l’ingest è ancora irraggiungibile. Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
2.2 KiB
Ruby
53 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
RSpec.describe "API session create ingest unavailable", type: :request do
|
|
let!(:user) do
|
|
User.create!(email: "ingest-#{SecureRandom.hex(4)}@example.com", name: "Coach", password: "Password123", role: "coach")
|
|
end
|
|
let!(:club) { Club.create!(name: "IngestClub", sport: "volleyball") }
|
|
let!(:membership) { club.club_memberships.create!(user: user, role: "owner") }
|
|
let!(:team) { club.teams.create!(name: "Tigers", sport: "volleyball", slug: "ingest-tigers-#{SecureRandom.hex(3)}") }
|
|
let!(:match) { team.matches.create!(opponent_name: "Opp", scheduled_at: 1.hour.from_now) }
|
|
|
|
def auth_headers
|
|
post "/api/v1/auth/login", params: { email: user.email, password: "Password123" }
|
|
token = response.parsed_body["access_token"]
|
|
{ "Authorization" => "Bearer #{token}", "Content-Type" => "application/json" }
|
|
end
|
|
|
|
before do
|
|
plan = Plan.find_or_initialize_by(slug: "premium_full")
|
|
plan.name ||= "Premium Full"
|
|
plan.features = (plan.features || {}).merge(
|
|
"platforms" => %w[matchlivetv youtube],
|
|
"youtube_enabled" => true,
|
|
"concurrent_streams_limit" => 10,
|
|
"recordings_enabled" => true,
|
|
"recording_days" => 90
|
|
)
|
|
plan.save!
|
|
club.create_subscription!(plan: plan, status: "active") if club.subscription.blank?
|
|
|
|
allow_any_instance_of(Teams::Entitlements).to receive(:assert_can_stream_on!)
|
|
allow_any_instance_of(Teams::Entitlements).to receive(:assert_concurrent_stream!)
|
|
allow(Streams::CoverSlateEnsurer).to receive(:ensure_for!)
|
|
allow(Streams::SlateDistributor).to receive(:ensure_for!)
|
|
Streams::NodeRegistry.ensure_home_from_env!
|
|
end
|
|
|
|
it "returns 503 when MediaMTX connection fails after retries" do
|
|
allow_any_instance_of(Mediamtx::Client).to receive(:create_path)
|
|
.and_raise(Faraday::ConnectionFailed.new("Connection refused"))
|
|
|
|
post "/api/v1/matches/#{match.id}/sessions",
|
|
params: { platform: "matchlivetv", privacy_status: "private" }.to_json,
|
|
headers: auth_headers
|
|
|
|
expect(response).to have_http_status(:service_unavailable)
|
|
body = response.parsed_body
|
|
expect(body["error_code"]).to eq("stream_ingest_unavailable")
|
|
end
|
|
end
|