Merge branch 'main' into collaudo
Porta in collaudo l'invito trasmissione con email automatica.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# Anteprima: http://localhost:3000/rails/mailers/teams/invitation_mailer/transmission_invite
|
||||
module Teams
|
||||
class InvitationMailerPreview < ActionMailer::Preview
|
||||
def transmission_invite
|
||||
team = Team.includes(:club).order(:created_at).first
|
||||
raise "Nessuna squadra in DB: esegui seed" unless team
|
||||
|
||||
invited_by = User.order(:created_at).first || User.new(name: "Coach Demo", email: "coach@matchlivetv.test")
|
||||
invitation = TeamInvitation.new(
|
||||
email: "demo.streamer@example.com",
|
||||
expires_at: 7.days.from_now,
|
||||
role: "member",
|
||||
staff_kind: "transmission"
|
||||
)
|
||||
invite_url = "http://localhost:3000/join/anteprima-token-esempio"
|
||||
|
||||
::Teams::InvitationMailer.transmission_invite(
|
||||
team: team,
|
||||
invitation: invitation,
|
||||
invite_url: invite_url,
|
||||
invited_by: invited_by
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Teams::InvitationMailer, type: :mailer do
|
||||
let!(:club) { Club.create!(name: "Mail Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
|
||||
let!(:team) { club.teams.create!(name: "U16", sport: "volleyball") }
|
||||
let!(:inviter) { User.create!(name: "Coach", email: "coach-mail@test.it", password: "Password123", role: "coach") }
|
||||
let(:invitation) do
|
||||
TeamInvitation.new(
|
||||
email: "streamer@test.it",
|
||||
expires_at: 7.days.from_now,
|
||||
role: "member",
|
||||
staff_kind: "transmission"
|
||||
)
|
||||
end
|
||||
|
||||
it "invia l'invito con link e oggetto corretti" do
|
||||
mail = described_class.transmission_invite(
|
||||
team: team,
|
||||
invitation: invitation,
|
||||
invite_url: "http://www.example.com/join/token-demo",
|
||||
invited_by: inviter
|
||||
)
|
||||
|
||||
expect(mail.to).to eq(["streamer@test.it"])
|
||||
expect(mail.subject).to include("U16")
|
||||
expect(mail.subject).to include("Mail Club")
|
||||
expect(mail.body.encoded).to include("http://www.example.com/join/token-demo")
|
||||
expect(mail.body.encoded).to include("Coach")
|
||||
end
|
||||
end
|
||||
@@ -4,11 +4,11 @@ RSpec.describe "Api::V1::Invitations", type: :request do
|
||||
let(:club) { Club.create!(name: "FC Test", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
|
||||
let(:team) { club.teams.create!(name: "Squadra A", sport: "volleyball") }
|
||||
let(:owner) do
|
||||
User.create!(email: "owner@test.it", name: "Owner", password: "password123", role: "coach").tap do |u|
|
||||
User.create!(email: "owner@test.it", name: "Owner", password: "Password123", role: "coach").tap do |u|
|
||||
ClubMembership.create!(user: u, club: club, role: "owner")
|
||||
end
|
||||
end
|
||||
let(:invitee) { User.create!(email: "streamer@test.it", name: "Streamer", password: "password123", role: "coach") }
|
||||
let(:invitee) { User.create!(email: "streamer@test.it", name: "Streamer", password: "Password123", role: "coach") }
|
||||
let(:token) { TeamInvitation.generate_token }
|
||||
let!(:invitation) do
|
||||
team.team_invitations.create!(
|
||||
@@ -31,7 +31,7 @@ RSpec.describe "Api::V1::Invitations", type: :request do
|
||||
|
||||
describe "POST /api/v1/invitations/:token/accept" do
|
||||
it "accetta con email corretta" do
|
||||
post "/api/v1/auth/login", params: { email: invitee.email, password: "password123" }
|
||||
post "/api/v1/auth/login", params: { email: invitee.email, password: "Password123" }
|
||||
access = response.parsed_body["access_token"]
|
||||
|
||||
post "/api/v1/invitations/#{token}/accept",
|
||||
@@ -42,7 +42,7 @@ RSpec.describe "Api::V1::Invitations", type: :request do
|
||||
end
|
||||
|
||||
it "rifiuta email diversa" do
|
||||
post "/api/v1/auth/login", params: { email: owner.email, password: "password123" }
|
||||
post "/api/v1/auth/login", params: { email: owner.email, password: "Password123" }
|
||||
access = response.parsed_body["access_token"]
|
||||
|
||||
post "/api/v1/invitations/#{token}/accept",
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Public team transmission invite", type: :request do
|
||||
let!(:coach) do
|
||||
User.create!(email: "invite-owner@test.it", name: "Owner", password: "Password123", role: "coach")
|
||||
end
|
||||
let!(:club) do
|
||||
c = Club.create!(name: "Invite Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff")
|
||||
ClubMembership.create!(user: coach, club: c, role: "owner")
|
||||
load Rails.root.join("db/seeds/plans.rb")
|
||||
Billing::AssignPlan.call(club: c, plan_slug: "premium_light")
|
||||
c
|
||||
end
|
||||
let!(:team) { club.teams.create!(name: "U13 Black", sport: "volleyball") }
|
||||
|
||||
def login!
|
||||
post public_login_path, params: { email: coach.email, password: "Password123" }
|
||||
end
|
||||
|
||||
it "mostra il form invito sulla pagina dettagli squadra" do
|
||||
login!
|
||||
get public_team_details_path(team)
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("Invita un account a trasmettere")
|
||||
expect(response.body).to include('id="invita-trasmissione"')
|
||||
expect(response.body).to include("#responsabili-trasmissione")
|
||||
end
|
||||
|
||||
it "GET /teams/:id/invite reindirizza ai dettagli con ancora" do
|
||||
login!
|
||||
get public_team_invite_path(team)
|
||||
|
||||
expect(response).to redirect_to(public_team_details_path(team, anchor: "invita-trasmissione"))
|
||||
end
|
||||
|
||||
it "genera il link, invia l'email e li mostra sui dettagli dopo il POST" do
|
||||
login!
|
||||
expect {
|
||||
post public_team_invite_path(team), params: { email: "streamer@test.it", staff_kind: "transmission" }
|
||||
}.to change { team.team_invitations.count }.by(1)
|
||||
.and change { ActionMailer::Base.deliveries.size }.by(1)
|
||||
|
||||
expect(response).to redirect_to(public_team_details_path(team, anchor: "invito-generato"))
|
||||
follow_redirect!
|
||||
|
||||
expect(response.body).to include("Invito inviato a streamer@test.it")
|
||||
expect(response.body).to include("id=\"invito-generato\"")
|
||||
expect(response.body).to include("/join/")
|
||||
expect(response.body).to include("streamer@test.it")
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
expect(mail.to).to eq(["streamer@test.it"])
|
||||
expect(mail.subject).to include("U13 Black")
|
||||
expect(mail.body.encoded).to include("/join/")
|
||||
end
|
||||
end
|
||||
@@ -1,10 +1,10 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Teams::StaffAssignment do
|
||||
let!(:owner) { User.create!(name: "Owner", email: "owner@test.com", password: "password123", role: "coach") }
|
||||
let!(:owner) { User.create!(name: "Owner", email: "owner@test.com", password: "Password123", role: "coach") }
|
||||
let!(:club) { Club.create!(name: "Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
|
||||
let!(:team) { club.teams.create!(name: "Team", sport: "volleyball") }
|
||||
let!(:other) { User.create!(name: "Other", email: "other@test.com", password: "password123", role: "coach") }
|
||||
let!(:other) { User.create!(name: "Other", email: "other@test.com", password: "Password123", role: "coach") }
|
||||
|
||||
before do
|
||||
ClubMembership.create!(user: owner, club: club, role: "owner")
|
||||
|
||||
Reference in New Issue
Block a user