2019-10-28 20:06:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-02 16:52:55 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.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)
|
|
|
|
|
2020-02-26 10:08:56 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-08-02 16:52:55 -04:00
|
|
|
expect(json_response).to be_a Hash
|
2021-09-16 11:12:47 -04:00
|
|
|
expect(json_response['notification_email']).to eq(user.notification_email_or_default)
|
2016-08-02 16:52:55 -04:00
|
|
|
expect(json_response['level']).to eq(user.global_notification_setting.level)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /notification_settings" do
|
2020-05-27 17:08:05 -04:00
|
|
|
let(:email) { create(:email, :confirmed, user: user) }
|
2016-08-02 16:52:55 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-02-26 10:08:56 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
|
|
|
2020-02-26 10:08:56 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
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)
|
|
|
|
|
2020-02-26 10:08:56 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
|
|
|
2020-02-26 10:08:56 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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)
|
|
|
|
|
2020-02-26 10:08:56 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
2020-07-27 23:09:35 -04:00
|
|
|
put api("/projects/#{project.id}/notification_settings", user), params: { level: 'custom', new_note: true, moved_project: true }
|
2016-08-02 16:52:55 -04:00
|
|
|
|
2020-02-26 10:08:56 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
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
|
2020-07-27 23:09:35 -04:00
|
|
|
expect(json_response['events']['moved_project']).to be_truthy
|
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
|
|
|
|
2020-02-26 10:08:56 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2016-08-02 16:52:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|