-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
update_channel_spec.rb
153 lines (128 loc) · 4.22 KB
/
update_channel_spec.rb
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# frozen_string_literal: true
RSpec.describe Chat::UpdateChannel do
subject(:result) { described_class.call(guardian: guardian, channel_id: channel.id, **params) }
fab!(:channel) { Fabricate(:chat_channel) }
fab!(:current_user) { Fabricate(:admin) }
let(:guardian) { Guardian.new(current_user) }
let(:params) do
{
name: "cool channel",
description: "a channel description",
slug: "snail",
allow_channel_wide_mentions: true,
auto_join_users: false,
}
end
context "when the user cannot edit the channel" do
fab!(:current_user) { Fabricate(:user) }
it { is_expected.to fail_a_policy(:check_channel_permission) }
end
context "when the user tries to edit a DM channel" do
fab!(:channel) { Fabricate(:direct_message_channel, users: [current_user, Fabricate(:user)]) }
it { is_expected.to fail_a_policy(:no_direct_message_channel) }
end
context "when channel is a category one" do
context "when a valid user provides valid params" do
let(:message) do
MessageBus
.track_publish(Chat::Publisher::CHANNEL_EDITS_MESSAGE_BUS_CHANNEL) { result }
.first
end
it "sets the service result as successful" do
expect(result).to be_a_success
end
it "updates the channel accordingly" do
result
expect(channel.reload).to have_attributes(
name: "cool channel",
slug: "snail",
description: "a channel description",
allow_channel_wide_mentions: true,
auto_join_users: false,
)
end
it "publishes a MessageBus message" do
expect(message.data).to eq(
{
chat_channel_id: channel.id,
name: "cool channel",
description: "a channel description",
slug: "snail",
},
)
end
describe "name" do
context "when blank" do
before { params[:name] = "" }
it "nils out the name" do
result
expect(channel.reload.name).to be_nil
end
end
end
describe "description" do
context "when blank" do
before do
channel.update!(description: "something")
params[:description] = ""
end
it "nils out the description" do
result
expect(channel.reload.description).to be_nil
end
end
end
describe "#auto_join_users" do
context "when set to 'true'" do
before do
channel.update!(auto_join_users: false)
params[:auto_join_users] = true
end
it "updates the model accordingly" do
result
expect(channel.reload).to have_attributes(auto_join_users: true)
end
it "auto joins users" do
expect_enqueued_with(
job: Jobs::Chat::AutoJoinChannelMemberships,
args: {
chat_channel_id: channel.id,
},
) { result }
end
end
end
describe "threading_enabled" do
context "when true" do
before { params[:threading_enabled] = true }
it "changes the value to true" do
expect { result }.to change { channel.reload.threading_enabled }.from(false).to(true)
end
it "enqueues a job to mark all threads in the channel as read" do
expect_enqueued_with(
job: Jobs::Chat::MarkAllChannelThreadsRead,
args: {
channel_id: channel.id,
},
) { result }
end
end
context "when false" do
before { params[:threading_enabled] = false }
it "changes the value to false" do
channel.update!(threading_enabled: true)
expect { result }.to change { channel.reload.threading_enabled }.from(true).to(false)
end
it "does not enqueue a job to mark all threads in the channel as read" do
expect_not_enqueued_with(
job: Jobs::Chat::MarkAllChannelThreadsRead,
args: {
channel_id: channel.id,
},
) { result }
end
end
end
end
end
end