debian-mirror-gitlab/spec/requests/api/notification_settings_spec.rb

88 lines
3.4 KiB
Ruby
Raw Normal View History

2016-09-29 09:46:39 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
describe API::NotificationSettings do
2016-09-29 09:46:39 +05:30
let(:user) { create(:user) }
let!(:group) { create(:group) }
2017-09-10 17:25:29 +05:30
let!(:project) { create(:project, :public, creator_id: user.id, namespace: group) }
2016-09-29 09:46:39 +05:30
describe "GET /notification_settings" do
it "returns global notification settings for the current user" do
get api("/notification_settings", user)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-29 09:46:39 +05:30
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
2019-02-15 15:39:39 +05:30
put api("/notification_settings", user), params: { level: 'watch', notification_email: email.email }
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-29 09:46:39 +05:30
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
2019-02-15 15:39:39 +05:30
put api("/notification_settings", user), params: { notification_email: 'invalid@example.com' }
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(400)
2016-09-29 09:46:39 +05:30
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)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-29 09:46:39 +05:30
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
2019-02-15 15:39:39 +05:30
put api("/groups/#{group.id}/notification_settings", user), params: { level: 'watch' }
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-29 09:46:39 +05:30
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)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-29 09:46:39 +05:30
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
2019-02-15 15:39:39 +05:30
put api("/projects/#{project.id}/notification_settings", user), params: { level: 'custom', new_note: true }
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2016-09-29 09:46:39 +05:30
expect(json_response['level']).to eq(user.reload.notification_settings_for(project).level)
2017-09-10 17:25:29 +05:30
expect(json_response['events']['new_note']).to be_truthy
expect(json_response['events']['new_issue']).to be_falsey
2016-09-29 09:46:39 +05:30
end
end
describe "PUT /projects/:id/notification_settings" do
it "fails on invalid level" do
2019-02-15 15:39:39 +05:30
put api("/projects/#{project.id}/notification_settings", user), params: { level: 'invalid' }
2016-09-29 09:46:39 +05:30
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(400)
2016-09-29 09:46:39 +05:30
end
end
end