Files
MatchLiveTv/backend/spec/models/app_announcement_spec.rb
eminuxandCursor f02782d0f0 Aggiunge traduzioni it/en/fr/de/es agli avvisi e toglie gli override Android/iOS.
Un avviso ha un testo per lingua; per differenziare le piattaforme si creano due avvisi. L'app riceve già il copy risolto da Accept-Language.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 16:26:30 +02:00

82 lines
3.2 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
RSpec.describe AppAnnouncement do
def create_notice!(**attrs)
described_class.create!({
kind: "info",
severity: "info",
status: "published",
title: "Avviso",
body: "Testo",
show_on_android: true,
show_on_ios: true,
show_on_web_public: false,
show_on_web_private: false
}.merge(attrs))
end
it "is active on the app when published without a time window" do
item = create_notice!(kind: "maintenance", severity: "warning", title: "Manutenzione", body: "Domani dalle 2 alle 4.")
expect(described_class.for_app).to include(item)
expect(described_class.for_channel(:web_public)).not_to include(item)
end
it "hides drafts and expired notices" do
create_notice!(status: "draft", title: "Bozza", body: "Non visibile")
create_notice!(title: "Scaduto", body: "Fine", ends_at: 1.hour.ago)
live = create_notice!(kind: "update", title: "Aggiornamento", body: "Nuova versione")
expect(described_class.for_app.map(&:title)).to eq(["Aggiornamento"])
expect(live.as_api_json(platform: "android")[:action_url]).to eq(MatchLiveTv.play_store_url)
expect(live.as_api_json(platform: "ios")[:action_url]).to eq(MatchLiveTv.app_store_url)
end
it "filters by selected channels" do
public_item = create_notice!(
title: "Pubblico", show_on_android: false, show_on_ios: false, show_on_web_public: true
)
private_item = create_notice!(
title: "Privato", show_on_android: false, show_on_ios: false, show_on_web_private: true
)
android_item = create_notice!(title: "Android", show_on_ios: false)
ios_item = create_notice!(title: "iOS", show_on_android: false, show_on_ios: true)
expect(described_class.for_channel(:web_public)).to contain_exactly(public_item)
expect(described_class.for_channel(:web_private)).to contain_exactly(private_item)
expect(described_class.for_platform("android")).to contain_exactly(android_item)
expect(described_class.for_platform("ios")).to contain_exactly(ios_item)
expect(described_class.for_app).to contain_exactly(android_item, ios_item)
end
it "serves translated copy and falls back to English then Italian" do
item = create_notice!(
title: "Titolo IT",
body: "Testo IT",
translations: {
"en" => { "title" => "EN title", "body" => "EN body" },
"de" => { "title" => "DE title", "body" => "DE body" }
}
)
expect(item.as_api_json(locale: :en)[:title]).to eq("EN title")
expect(item.as_api_json(locale: :de)[:title]).to eq("DE title")
expect(item.as_api_json(locale: :fr)[:title]).to eq("EN title")
expect(item.as_api_json(locale: :it)[:title]).to eq("Titolo IT")
expect(item.filled_locale_codes).to include("it", "en", "de")
expect(item.filled_locale_codes).not_to include("fr")
end
it "requires at least one channel" do
item = described_class.new(
kind: "info", status: "draft", title: "X", body: "Y",
show_on_android: false, show_on_ios: false,
show_on_web_public: false, show_on_web_private: false
)
expect(item).not_to be_valid
expect(item.errors[:base]).to be_present
end
end