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>
78 lines
2.5 KiB
Ruby
78 lines
2.5 KiB
Ruby
# 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 la piattaforma" 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_android: true,
|
|
show_on_ios: true
|
|
)
|
|
AppAnnouncement.create!(
|
|
kind: "info",
|
|
status: "published",
|
|
title: "Solo sito",
|
|
body: "Non in app",
|
|
show_on_android: false,
|
|
show_on_ios: false,
|
|
show_on_web_public: true
|
|
)
|
|
AppAnnouncement.create!(
|
|
kind: "info",
|
|
status: "draft",
|
|
title: "Bozza",
|
|
body: "Non deve uscire"
|
|
)
|
|
AppAnnouncement.create!(
|
|
kind: "update",
|
|
status: "published",
|
|
title: "Aggiorna Android",
|
|
body: "Versione nuova",
|
|
show_on_android: true,
|
|
show_on_ios: false
|
|
)
|
|
|
|
get "/api/v1/announcements", params: { platform: "android" }
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
android_body = JSON.parse(response.body)
|
|
expect(android_body.map { |row| row["title"] }).to contain_exactly("Manutenzione stasera", "Aggiorna Android")
|
|
|
|
get "/api/v1/announcements", params: { platform: "ios" }
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
ios_body = JSON.parse(response.body)
|
|
expect(ios_body.map { |row| row["title"] }).to eq(["Manutenzione stasera"])
|
|
end
|
|
|
|
it "GET /api/v1/announcements localizza il testo da Accept-Language" do
|
|
AppAnnouncement.create!(
|
|
kind: "info",
|
|
status: "published",
|
|
title: "Manutenzione stasera",
|
|
body: "Dalle 23:00 il servizio sarà offline.",
|
|
show_on_android: true,
|
|
show_on_ios: true,
|
|
translations: {
|
|
"en" => { "title" => "Maintenance tonight", "body" => "The service will be offline from 23:00." }
|
|
}
|
|
)
|
|
|
|
get "/api/v1/announcements", params: { platform: "android" }, headers: { "Accept-Language" => "en-US,en;q=0.9" }
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
payload = JSON.parse(response.body)
|
|
expect(payload.first["title"]).to eq("Maintenance tonight")
|
|
expect(payload.first["body"]).to include("offline")
|
|
|
|
get "/api/v1/announcements", params: { platform: "android" }, headers: { "Accept-Language" => "fr" }
|
|
|
|
expect(JSON.parse(response.body).first["title"]).to eq("Maintenance tonight")
|
|
end
|
|
end
|