2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.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)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response).to be_a Hash
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(json_response['notification_email']).to eq(user.notification_email_or_default)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response['level']).to eq(user.global_notification_setting.level)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /notification_settings" do
|
2020-05-30 21:06:31 +05:30
|
|
|
let(:email) { create(:email, :confirmed, user: user) }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
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)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
2020-10-24 23:57:45 +05:30
|
|
|
put api("/projects/#{project.id}/notification_settings", user), params: { level: 'custom', new_note: true, moved_project: true }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(json_response['events']['moved_project']).to be_truthy
|
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
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|