Aggiunge annunci in-app/sito, contatti e migliora UI copertina sul portale.
Include admin/API/banner nativi, form contatti e reset copertina standard con layout edit più ampio. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
# 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_app: 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_app: false, show_on_web_public: true
|
||||
)
|
||||
private_item = create_notice!(
|
||||
title: "Privato", show_on_app: false, show_on_web_private: true
|
||||
)
|
||||
app_item = create_notice!(title: "App")
|
||||
|
||||
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_app).to contain_exactly(app_item)
|
||||
end
|
||||
|
||||
it "requires at least one channel" do
|
||||
item = described_class.new(
|
||||
kind: "info", status: "draft", title: "X", body: "Y",
|
||||
show_on_app: 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
|
||||
@@ -0,0 +1,50 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Admin announcements", type: :request do
|
||||
let!(:admin) { AdminAccount.create!(username: "ops-news", password: "Password123") }
|
||||
|
||||
before do
|
||||
post admin_login_path, params: { username: "ops-news", password: "Password123" }
|
||||
end
|
||||
|
||||
it "crea e pubblica un avviso visibile alle app e al sito" do
|
||||
post admin_announcements_path, params: {
|
||||
app_announcement: {
|
||||
kind: "update",
|
||||
severity: "info",
|
||||
status: "published",
|
||||
title: "Nuova versione",
|
||||
body: "Aggiorna l'app dallo store.",
|
||||
dismissible: "1",
|
||||
show_on_app: "1",
|
||||
show_on_web_public: "1",
|
||||
show_on_web_private: "0"
|
||||
}
|
||||
}
|
||||
|
||||
expect(response).to redirect_to(admin_announcements_path)
|
||||
notice = AppAnnouncement.last
|
||||
expect(notice.title).to eq("Nuova versione")
|
||||
expect(notice).to be_published
|
||||
expect(notice.show_on_app).to be(true)
|
||||
expect(notice.show_on_web_public).to be(true)
|
||||
expect(notice.show_on_web_private).to be(false)
|
||||
|
||||
get admin_announcements_path
|
||||
expect(response.body).to include("Nuova versione")
|
||||
expect(response.body).to include(I18n.t("admin.announcements.channels.web_public"))
|
||||
end
|
||||
|
||||
it "elimina un avviso" do
|
||||
item = AppAnnouncement.create!(
|
||||
kind: "info", status: "published", title: "Da togliere", body: "Test"
|
||||
)
|
||||
|
||||
delete admin_announcement_path(item)
|
||||
|
||||
expect(response).to redirect_to(admin_announcements_path)
|
||||
expect(AppAnnouncement.find_by(id: item.id)).to be_nil
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Api::V1::Announcements", type: :request do
|
||||
it "GET /api/v1/announcements senza autenticazione restituisce solo gli avvisi attivi per l'app" do
|
||||
AppAnnouncement.create!(
|
||||
kind: "maintenance",
|
||||
severity: "warning",
|
||||
status: "published",
|
||||
title: "Manutenzione stasera",
|
||||
body: "Dalle 23:00 alle 01:00 il servizio sarà offline.",
|
||||
show_on_app: true
|
||||
)
|
||||
AppAnnouncement.create!(
|
||||
kind: "info",
|
||||
status: "published",
|
||||
title: "Solo sito",
|
||||
body: "Non in app",
|
||||
show_on_app: false,
|
||||
show_on_web_public: true
|
||||
)
|
||||
AppAnnouncement.create!(
|
||||
kind: "info",
|
||||
status: "draft",
|
||||
title: "Bozza",
|
||||
body: "Non deve uscire"
|
||||
)
|
||||
|
||||
get "/api/v1/announcements", params: { platform: "android" }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
body = JSON.parse(response.body)
|
||||
expect(body.length).to eq(1)
|
||||
expect(body.first["title"]).to eq("Manutenzione stasera")
|
||||
expect(body.first["kind"]).to eq("maintenance")
|
||||
expect(body.first["dismissible"]).to eq(true)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,48 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Public site announcements", type: :request do
|
||||
let!(:coach) do
|
||||
User.create!(email: "news-coach@test.it", name: "Coach", password: "Password123", role: "coach")
|
||||
end
|
||||
|
||||
it "mostra gli avvisi pubblici in home e non quelli privati" do
|
||||
AppAnnouncement.create!(
|
||||
kind: "maintenance", status: "published", title: "Manutenzione sito",
|
||||
body: "Stasera il sito sarà offline.",
|
||||
show_on_app: false, show_on_web_public: true, show_on_web_private: false
|
||||
)
|
||||
AppAnnouncement.create!(
|
||||
kind: "info", status: "published", title: "Solo soci",
|
||||
body: "Messaggio interno.",
|
||||
show_on_app: false, show_on_web_public: false, show_on_web_private: true
|
||||
)
|
||||
|
||||
get root_path
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("Manutenzione sito")
|
||||
expect(response.body).not_to include("Solo soci")
|
||||
end
|
||||
|
||||
it "mostra gli avvisi privati nell'area account dopo il login" do
|
||||
AppAnnouncement.create!(
|
||||
kind: "info", status: "published", title: "Solo soci",
|
||||
body: "Messaggio interno.",
|
||||
show_on_app: false, show_on_web_public: false, show_on_web_private: true
|
||||
)
|
||||
AppAnnouncement.create!(
|
||||
kind: "info", status: "published", title: "Manutenzione sito",
|
||||
body: "Stasera il sito sarà offline.",
|
||||
show_on_app: false, show_on_web_public: true, show_on_web_private: false
|
||||
)
|
||||
|
||||
post public_login_path, params: { email: coach.email, password: "Password123" }
|
||||
get public_account_path
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("Solo soci")
|
||||
expect(response.body).not_to include("Manutenzione sito")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user