Ops può correggere dati clienti errati (es. email titolare) dalla scheda società senza interventi manuali sul DB. Co-authored-by: Cursor <cursoragent@cursor.com>
105 lines
3.5 KiB
Ruby
105 lines
3.5 KiB
Ruby
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
|