require "rails_helper" RSpec.describe Youtube::BroadcastService do describe "#normalize_scheduled_start_time" do subject(:service) { described_class.allocate } it "usa tra ~90 secondi se scheduled_at è assente" do travel_to Time.zone.parse("2026-06-03 20:00:00 UTC") do t = service.send(:normalize_scheduled_start_time, nil) expect(t).to eq(Time.utc(2026, 6, 3, 20, 1, 30)) end end it "sposta nel futuro se scheduled_at è nel passato" do travel_to Time.zone.parse("2026-06-03 20:00:00 UTC") do past = Time.zone.parse("2026-06-03 10:00:00") t = service.send(:normalize_scheduled_start_time, past) expect(t).to eq(Time.utc(2026, 6, 3, 20, 1, 30)) end end it "mantiene scheduled_at se è nel futuro entro 7 giorni" do travel_to Time.zone.parse("2026-06-03 20:00:00 UTC") do future = Time.zone.parse("2026-06-05 18:00:00") t = service.send(:normalize_scheduled_start_time, future) expect(t).to eq(future.utc) end end end end