require "rails_helper" RSpec.describe Ops::Notifier do let(:incident) do Ops::Incident.create!( kind: "test", severity: "critical", status: "open", title: "Test alert", message: "Messaggio di prova", metadata: {}, fingerprint: "test:#{SecureRandom.hex(4)}", occurrence_count: 1, first_seen_at: Time.current, last_seen_at: Time.current ) end describe "#notify" do it "invia POST a ntfy quando configurato" do conn = instance_double(Faraday::Connection) response = instance_double(Faraday::Response, success?: true, status: 200, body: "") allow(Faraday).to receive(:new).and_return(conn) allow(conn).to receive(:post).and_return(response) allow(ENV).to receive(:[]).and_call_original allow(ENV).to receive(:[]).with("OPS_NTFY_URL").and_return("https://ntfy.example/ops") described_class.new.notify(incident) expect(conn).to have_received(:post).with("https://ntfy.example/ops", anything, hash_including("Title")) end end describe ".notify_severity?" do it "rispetta OPS_NOTIFY_SEVERITIES" do allow(ENV).to receive(:fetch).and_call_original allow(ENV).to receive(:fetch).with("OPS_NOTIFY_SEVERITIES", "critical").and_return("critical,warning") expect(described_class.notify_severity?("critical")).to be(true) expect(described_class.notify_severity?("info")).to be(false) end end end