2016-08-02 16:52:55 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-21 16:32:02 -04:00
|
|
|
describe API::NotificationSettings do
|
2016-08-02 16:52:55 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:group) { create(:group) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project) { create(:project, :public, creator_id: user.id, namespace: group) }
|
2016-08-02 16:52:55 -04:00
|
|
|
|
|
|
|
describe "GET /notification_settings" do
|
|
|
|
it "returns global notification settings for the current user" do
|
|
|
|
get api("/notification_settings", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-02 16:52:55 -04:00
|
|
|
expect(json_response).to be_a Hash
|
|
|
|
expect(json_response['notification_email']).to eq(user.notification_email)
|
|
|
|
expect(json_response['level']).to eq(user.global_notification_setting.level)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /notification_settings" do
|
|
|
|
let(:email) { create(:email, user: user) }
|
|
|
|
|
|
|
|
it "updates global notification settings for the current user" do
|
2018-12-17 17:52:17 -05:00
|
|
|
put api("/notification_settings", user), params: { level: 'watch', notification_email: email.email }
|
2016-08-02 16:52:55 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-02 16:52:55 -04:00
|
|
|
expect(json_response['notification_email']).to eq(email.email)
|
|
|
|
expect(user.reload.notification_email).to eq(email.email)
|
|
|
|
expect(json_response['level']).to eq(user.reload.global_notification_setting.level)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /notification_settings" do
|
|
|
|
it "fails on non-user email address" do
|
2018-12-17 17:52:17 -05:00
|
|
|
put api("/notification_settings", user), params: { notification_email: 'invalid@example.com' }
|
2016-08-02 16:52:55 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(400)
|
2016-08-02 16:52:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /groups/:id/notification_settings" do
|
|
|
|
it "returns group level notification settings for the current user" do
|
|
|
|
get api("/groups/#{group.id}/notification_settings", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-02 16:52:55 -04:00
|
|
|
expect(json_response).to be_a Hash
|
|
|
|
expect(json_response['level']).to eq(user.notification_settings_for(group).level)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /groups/:id/notification_settings" do
|
|
|
|
it "updates group level notification settings for the current user" do
|
2018-12-17 17:52:17 -05:00
|
|
|
put api("/groups/#{group.id}/notification_settings", user), params: { level: 'watch' }
|
2016-08-02 16:52:55 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-02 16:52:55 -04:00
|
|
|
expect(json_response['level']).to eq(user.reload.notification_settings_for(group).level)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/notification_settings" do
|
|
|
|
it "returns project level notification settings for the current user" do
|
|
|
|
get api("/projects/#{project.id}/notification_settings", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-02 16:52:55 -04:00
|
|
|
expect(json_response).to be_a Hash
|
|
|
|
expect(json_response['level']).to eq(user.notification_settings_for(project).level)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /projects/:id/notification_settings" do
|
|
|
|
it "updates project level notification settings for the current user" do
|
2018-12-17 17:52:17 -05:00
|
|
|
put api("/projects/#{project.id}/notification_settings", user), params: { level: 'custom', new_note: true }
|
2016-08-02 16:52:55 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-02 16:52:55 -04:00
|
|
|
expect(json_response['level']).to eq(user.reload.notification_settings_for(project).level)
|
2017-07-28 05:44:33 -04:00
|
|
|
expect(json_response['events']['new_note']).to be_truthy
|
|
|
|
expect(json_response['events']['new_issue']).to be_falsey
|
2016-08-02 16:52:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /projects/:id/notification_settings" do
|
|
|
|
it "fails on invalid level" do
|
2018-12-17 17:52:17 -05:00
|
|
|
put api("/projects/#{project.id}/notification_settings", user), params: { level: 'invalid' }
|
2016-08-02 16:52:55 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(400)
|
2016-08-02 16:52:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|