forked from hackorum-dev/hackorum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteams_profile_spec.rb
More file actions
110 lines (87 loc) · 3.88 KB
/
teams_profile_spec.rb
File metadata and controls
110 lines (87 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require "rails_helper"
RSpec.describe "TeamsProfile", type: :request do
def sign_in(email:, password: "secret")
post session_path, params: { email: email, password: password }
expect(response).to redirect_to(root_path)
end
def attach_verified_alias(user, email:, primary: true)
al = create(:alias, user: user, email: email)
if primary && user.person&.default_alias_id.nil?
user.person.update!(default_alias_id: al.id)
end
Alias.by_email(email).update_all(verified_at: Time.current)
al
end
describe "GET /team/:name" do
let!(:team) { create(:team, name: "test-team") }
let!(:admin) { create(:user, password: "secret", password_confirmation: "secret") }
let!(:member) { create(:user, password: "secret", password_confirmation: "secret") }
let!(:non_member) { create(:user, password: "secret", password_confirmation: "secret") }
before do
create(:team_member, team: team, user: admin, role: "admin")
create(:team_member, team: team, user: member, role: "member")
end
context "with private team (default)" do
it "redirects guests to sign in" do
get team_profile_path("test-team")
expect(response).to redirect_to(new_session_path)
end
it "returns 404 for signed-in non-members" do
attach_verified_alias(non_member, email: "non-member@example.com")
sign_in(email: "non-member@example.com")
get team_profile_path("test-team")
expect(response).to have_http_status(:not_found)
end
it "allows signed-in team members" do
attach_verified_alias(member, email: "member@example.com")
sign_in(email: "member@example.com")
get team_profile_path("test-team")
expect(response).to have_http_status(:success)
end
end
context "with visible team" do
before { team.update!(visibility: :visible) }
it "allows guests to view" do
get team_profile_path("test-team")
expect(response).to have_http_status(:success)
end
it "allows non-members to view" do
attach_verified_alias(non_member, email: "non-member@example.com")
sign_in(email: "non-member@example.com")
get team_profile_path("test-team")
expect(response).to have_http_status(:success)
end
end
context "with open team" do
before { team.update!(visibility: :open) }
it "allows guests to view" do
get team_profile_path("test-team")
expect(response).to have_http_status(:success)
end
it "allows non-members to view" do
attach_verified_alias(non_member, email: "non-member@example.com")
sign_in(email: "non-member@example.com")
get team_profile_path("test-team")
expect(response).to have_http_status(:success)
end
end
it "returns 404 for non-existent teams" do
get team_profile_path("non-existent")
expect(response).to have_http_status(:not_found)
end
it "shows the sender column and links team activity rows to the sender profile" do
team.update!(visibility: :visible)
member_alias = attach_verified_alias(member, email: "member@example.com")
create(:team_member, team: team, user: non_member, role: "member")
sender_alias = attach_verified_alias(non_member, email: "sender@example.com")
topic = create(:topic, creator_alias: member_alias, title: "Sender activity thread")
create(:message, topic: topic, sender: sender_alias, sender_person_id: non_member.person.id, created_at: 2.days.ago, updated_at: 2.days.ago)
get team_profile_path("test-team")
expect(response).to have_http_status(:success)
expect(response.body).to include("<th>Sender</th>")
expect(response.body).to include("sender@example.com")
expect(response.body).to include(person_path("sender@example.com"))
expect(response.body).to include("Sender activity thread")
end
end
end