11require "rails_helper"
22
33RSpec . describe "NotificationsIndex" , type : :request do
4- let ( :dev_account ) { create ( :user ) }
5- let ( :user ) { create ( :user ) }
4+ let_it_be ( :dev_account ) { create ( :user ) }
5+ let_it_be ( :user ) { create ( :user ) }
66
77 before do
88 allow ( User ) . to receive ( :dev_account ) . and_return ( dev_account )
@@ -71,9 +71,9 @@ def mock_follow_notifications(amount)
7171 end
7272
7373 context "when a user has new reaction notifications" do
74- let ( :article1 ) { create ( :article , user_id : user . id ) }
75- let ( :article2 ) { create ( :article , user_id : user . id ) }
76- let ( :special_characters_article ) { create ( :article , user_id : user . id , title : "What's Become of Waring" ) }
74+ let_it_be ( :article1 ) { create ( :article , user_id : user . id ) }
75+ let_it_be ( :article2 ) { create ( :article , user_id : user . id ) }
76+ let_it_be ( :special_characters_article ) { create ( :article , user_id : user . id , title : "What's Become of Waring" ) }
7777
7878 before { sign_in user }
7979
@@ -141,29 +141,32 @@ def mock_heart_reaction_notifications(amount, categories, reactable = article1)
141141 end
142142
143143 context "when a user has a new comment notification" do
144- let ( :user2 ) { create ( :user ) }
145- let ( :article ) { create ( :article , user_id : user . id ) }
146- let ( :comment ) { create ( :comment , user_id : user2 . id , commentable_id : article . id , commentable_type : "Article" ) }
144+ let_it_be ( :user2 ) { create ( :user ) }
145+ let_it_be ( :article ) { create ( :article , user_id : user . id ) }
146+ let_it_be ( :comment ) { create ( :comment , user_id : user2 . id , commentable_id : article . id , commentable_type : "Article" ) }
147147
148148 before do
149149 sign_in user
150150 Notification . send_new_comment_notifications_without_delay ( comment )
151- get "/notifications"
152151 end
153152
154153 it "renders the correct message" do
154+ get "/notifications"
155155 expect ( response . body ) . to include "commented on"
156156 end
157157
158158 it "does not render the moderation message" do
159+ get "/notifications"
159160 expect ( response . body ) . not_to include "As a trusted member"
160161 end
161162
162163 it "renders the article's path" do
164+ get "/notifications"
163165 expect ( response . body ) . to include article . path
164166 end
165167
166168 it "renders the comment's processed HTML" do
169+ get "/notifications"
167170 expect ( response . body ) . to include comment . processed_html
168171 end
169172
@@ -174,22 +177,26 @@ def mock_heart_reaction_notifications(amount, categories, reactable = article1)
174177 end
175178
176179 it "does not render the reaction as reacted if it was not reacted on" do
180+ get "/notifications"
177181 expect ( response . body ) . not_to include "reaction-button reacted"
178182 end
179183 end
180184
181185 context "when a user has a new moderation notification" do
182- let ( :user2 ) { create ( :user ) }
183- let ( :article ) { create ( :article , user_id : user . id ) }
184- let ( :comment ) { create ( :comment , user_id : user2 . id , commentable_id : article . id , commentable_type : "Article" ) }
186+ let_it_be ( :user2 ) { create ( :user ) }
187+ let_it_be ( :article ) { create ( :article , user_id : user . id ) }
188+ let_it_be ( :comment ) { create ( :comment , user_id : user2 . id , commentable_id : article . id , commentable_type : "Article" ) }
185189
186190 before do
187- user . add_role :trusted
188191 sign_in user
189192 Notification . send_moderation_notification_without_delay ( comment )
190193 get "/notifications"
191194 end
192195
196+ before_all do
197+ user . add_role :trusted
198+ end
199+
193200 it "renders the proper message" do
194201 expect ( response . body ) . to include "As a trusted member"
195202 end
@@ -204,23 +211,25 @@ def mock_heart_reaction_notifications(amount, categories, reactable = article1)
204211 end
205212
206213 context "when a user has a new welcome notification" do
214+ let_it_be ( :broadcast ) { create ( :broadcast , :onboarding ) }
215+
207216 before do
208217 sign_in user
218+ Notification . send_welcome_notification_without_delay ( user . id )
219+ get "/notifications"
209220 end
210221
211222 it "renders the welcome notification" do
212- broadcast = create ( :broadcast , :onboarding )
213- Notification . send_welcome_notification_without_delay ( user . id )
214- get "/notifications"
215223 expect ( response . body ) . to include broadcast . processed_html
216224 end
217225 end
218226
219227 context "when a user has a new badge notification" do
228+ let_it_be ( :badge ) { create ( :badge ) }
229+ let_it_be ( :badge_achievement ) { create ( :badge_achievement , user : user , badge : badge ) }
230+
220231 before do
221232 sign_in user
222- badge = create ( :badge )
223- badge_achievement = create ( :badge_achievement , user : user , badge : badge )
224233 Notification . send_new_badge_notification_without_delay ( badge_achievement )
225234 get "/notifications"
226235 end
@@ -243,9 +252,9 @@ def mock_heart_reaction_notifications(amount, categories, reactable = article1)
243252 end
244253
245254 context "when a user has a new mention notification" do
246- let ( :user2 ) { create ( :user ) }
247- let ( :article ) { create ( :article , user_id : user . id ) }
248- let ( :comment ) do
255+ let_it_be ( :user2 ) { create ( :user ) }
256+ let_it_be ( :article ) { create ( :article , user_id : user . id ) }
257+ let_it_be ( :comment ) do
249258 create (
250259 :comment ,
251260 user_id : user2 . id ,
@@ -256,13 +265,15 @@ def mock_heart_reaction_notifications(amount, categories, reactable = article1)
256265 end
257266
258267 before do
259- comment
260- Mention . create_all_without_delay ( comment )
261- Notification . send_mention_notification_without_delay ( Mention . first )
262268 sign_in user
269+ Notification . send_mention_notification_without_delay ( Mention . first )
263270 get "/notifications"
264271 end
265272
273+ before_all do
274+ Mention . create_all_without_delay ( comment )
275+ end
276+
266277 it "renders the proper message" do
267278 expect ( response . body ) . to include "mentioned you in a comment"
268279 end
@@ -273,16 +284,19 @@ def mock_heart_reaction_notifications(amount, categories, reactable = article1)
273284 end
274285
275286 context "when a user has a new article notification" do
276- let ( :user2 ) { create ( :user ) }
277- let ( :article ) { create ( :article , user_id : user . id ) }
287+ let_it_be ( :user2 ) { create ( :user ) }
288+ let_it_be ( :article ) { create ( :article , user_id : user . id ) }
278289
279290 before do
280- user2 . follow ( user )
281- Notification . send_to_followers_without_delay ( article , "Published" )
282291 sign_in user2
292+ Notification . send_to_followers_without_delay ( article , "Published" )
283293 get "/notifications"
284294 end
285295
296+ before_all do
297+ user2 . follow ( user )
298+ end
299+
286300 it "renders the proper message" do
287301 expect ( response . body ) . to include "made a new post:"
288302 end
0 commit comments