Permette all’admin di forzare anagrafica, fiscali, owner, staff e inviti.

Ops può correggere dati clienti errati (es. email titolare) dalla scheda società senza interventi manuali sul DB.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-10 18:18:18 +02:00
co-authored by Cursor
parent d7dd744c32
commit cc95fcacbf
15 changed files with 739 additions and 8 deletions
@@ -0,0 +1,104 @@
require "rails_helper"
RSpec.describe "Admin club data edit", type: :request do
let!(:admin) { AdminAccount.create!(username: "ops-club-edit", password: "Password123") }
let!(:club) do
Club.create!(
name: "Edit Club",
sport: "pallavolo",
primary_color: "#e53935",
secondary_color: "#ffffff",
billing_entity_type: "company",
billing_legal_name: "ASD Edit",
billing_email: "old-bill@test.it",
billing_address_line: "Via 1",
billing_city: "Milano",
billing_province: "MI",
billing_postal_code: "20100",
billing_country: "IT",
billing_vat_number: "12345678901",
billing_recipient_code: "ABCDEFG"
)
end
let!(:owner) do
user = User.create!(email: "owner-typo@test.it", name: "Owner Old", password: "Password123", role: "coach")
ClubMembership.create!(user: user, club: club, role: "owner")
user
end
let!(:team) { club.teams.create!(name: "U14", sport: "pallavolo") }
let!(:staff) do
user = User.create!(email: "staff@test.it", name: "Staff Old", password: "Password123", role: "coach")
UserTeam.create!(user: user, team: team, role: "member", staff_kind: "transmission")
user
end
let!(:invitation) do
token = TeamInvitation.generate_token
TeamInvitation.create!(
team: team,
email: "invite-old@test.it",
token_digest: Digest::SHA256.hexdigest(token),
role: "member",
staff_kind: "transmission",
expires_at: 3.days.from_now
)
end
before do
post admin_login_path, params: { username: "ops-club-edit", password: "Password123" }
end
it "mostra il form di modifica" do
get edit_admin_club_path(club)
expect(response).to have_http_status(:ok)
expect(response.body).to include("Modifica Edit Club")
expect(response.body).to include("owner-typo@test.it")
expect(response.body).to include("invite-old@test.it")
end
it "forza anagrafica, billing, owner, staff, invito e squadra" do
patch admin_club_path(club), params: {
club: {
name: "Edit Club Nuovo",
sport: "pallavolo",
primary_color: "#112233",
secondary_color: "#ffffff",
billing_entity_type: "company",
billing_legal_name: "ASD Edit Nuova",
billing_email: "amministrazione@test.it",
billing_vat_number: "12345678901",
billing_address_line: "Via Roma 10",
billing_city: "Milano",
billing_province: "mi",
billing_postal_code: "20121",
billing_country: "it",
billing_recipient_code: "ABCDEFG"
},
owner: { name: "Owner Fixed", email: "amministrazione@test.it" },
staff_users: {
staff.id => { name: "Staff Fixed", email: "staff-fixed@test.it" }
},
invitations: {
invitation.id => { email: "invite-fixed@test.it" }
},
teams: {
team.id => { name: "U15", sport: "pallavolo" }
}
}
expect(response).to redirect_to(admin_club_path(club))
follow_redirect!
expect(response.body).to include("Dati aggiornati per Edit Club Nuovo")
club.reload
expect(club.name).to eq("Edit Club Nuovo")
expect(club.billing_email).to eq("amministrazione@test.it")
expect(club.billing_province).to eq("MI")
expect(club.billing_legal_name).to eq("ASD Edit Nuova")
expect(owner.reload.email).to eq("amministrazione@test.it")
expect(owner.name).to eq("Owner Fixed")
expect(staff.reload.email).to eq("staff-fixed@test.it")
expect(invitation.reload.email).to eq("invite-fixed@test.it")
expect(team.reload.name).to eq("U15")
end
end
@@ -0,0 +1,46 @@
require "rails_helper"
RSpec.describe Admin::UpdateClubData do
let!(:club) do
Club.create!(
name: "Svc Club",
sport: "pallavolo",
primary_color: "#e53935",
secondary_color: "#ffffff"
)
end
let!(:owner) do
user = User.create!(email: "svc-owner@test.it", name: "Owner", password: "Password123", role: "coach")
ClubMembership.create!(user: user, club: club, role: "owner")
user
end
it "updates club and owner email" do
described_class.call(
club: club,
club_attrs: {
name: "Svc Club Updated",
billing_email: "bill@test.it",
billing_province: "bz"
},
owner_attrs: { email: "owner-fixed@test.it", name: "Owner Fixed" }
)
expect(club.reload.name).to eq("Svc Club Updated")
expect(club.billing_email).to eq("bill@test.it")
expect(club.billing_province).to eq("BZ")
expect(owner.reload.email).to eq("owner-fixed@test.it")
end
it "raises when email is already taken" do
User.create!(email: "taken@test.it", name: "Other", password: "Password123", role: "coach")
expect do
described_class.call(
club: club,
club_attrs: {},
owner_attrs: { email: "taken@test.it" }
)
end.to raise_error(Admin::UpdateClubData::Error)
end
end