/
notifications_controller_spec.rb
148 lines (113 loc) · 4.08 KB
/
notifications_controller_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
require 'rails_helper'
RSpec.describe Person::NotificationsController do
let(:user) { create(:confirmed_user, :with_home, :in_beta) }
render_views
describe 'Check if feature flag is enabled' do
before do
toggle_notifications_redesign
login user
get :index, format: :xml
end
context 'Feature :notifications_redesign is enabled' do
let(:toggle_notifications_redesign) { Flipper[:notifications_redesign].enable }
it { expect(response).to have_http_status(:success) }
end
context 'Feature :notifications_redesign is disabled' do
let(:toggle_notifications_redesign) { Flipper[:notifications_redesign].disable }
it { expect(response).to have_http_status(:not_found) }
end
end
describe 'filter check' do
before do
Flipper[:notifications_redesign].enable
login user
get :index, params: params
end
context 'default filter' do
let(:params) { { format: :xml } }
it { expect(response).to have_http_status(:success) }
end
context 'bad filter' do
let(:params) { { format: :xml, notifications_type: 'foobar' } }
it { expect(response).to have_http_status(:bad_request) }
end
end
describe 'index' do
context 'called by authorized user' do
let!(:notifications) { create_list(:web_notification, 2, :request_state_change, subscriber: user) }
before do
Flipper[:notifications_redesign].enable
login user
get :index, format: :xml
notifications.each do |notification|
notification.projects << user.home_project
notification.save
end
end
it { expect(response).to have_http_status(:success) }
it { expect(response.body).to include('<notifications count="2">') }
context 'filter by notifications_type' do
let!(:notifications) { create_list(:web_notification, 2, :request_state_change, subscriber: user, delivered: true) }
before do
login user
get :index, params: { format: :xml, notifications_type: 'read' }
end
it { expect(response).to have_http_status(:success) }
it { expect(response.body).to include('<notifications count="2">') }
end
context 'filter by project finds results' do
before do
login user
get :index, params: { format: :xml, project: user.home_project_name }
end
it { expect(response).to have_http_status(:success) }
it { expect(response.body).to include('<notifications count="2">') }
end
context 'filter by project does not find results' do
before do
login user
get :index, params: { format: :xml, project: 'home:hans' }
end
it { expect(response).to have_http_status(:success) }
it { expect(response.body).to include('<notifications count="0"/>') }
end
end
context 'called by unauthorized user' do
before do
get :index, format: :xml
end
it { expect(response).to have_http_status(:unauthorized) }
end
end
describe '#update' do
let!(:notification) { create(:web_notification, :comment_for_package, subscriber: user) }
before do
Flipper[:notifications_redesign].enable
end
context 'called by an unauthorized user' do
let(:other_user) { create(:confirmed_user, :in_beta) }
before do
login other_user
put :update, params: { format: :xml, id: notification.id }
end
it { expect(response).to have_http_status(:forbidden) }
end
context 'called by an authorized user' do
before do
login user
put :update, params: { format: :xml, id: notification.id }
end
it 'toggles the delivered attribute' do
expect(notification.reload.delivered).to be(true)
end
it { expect(response).to have_http_status(:success) }
end
context "notification doesn't exist" do
before do
login user
put :update, params: { format: :xml, id: notification.id + 1 }
end
it { expect(response).to have_http_status(:not_found) }
end
end
end