2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-26 16:49:20 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-12-10 13:14:42 -05:00
|
|
|
RSpec.describe Users::CalloutsController do
|
2021-09-14 20:09:30 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
2018-01-26 16:49:20 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2018-02-02 16:23:26 -05:00
|
|
|
describe "POST #create" do
|
2021-09-14 20:09:30 -04:00
|
|
|
let(:params) { { feature_name: feature_name } }
|
|
|
|
|
|
|
|
subject { post :create, params: params, format: :json }
|
2018-01-26 16:49:20 -05:00
|
|
|
|
2018-02-02 18:16:24 -05:00
|
|
|
context 'with valid feature name' do
|
2021-12-10 13:14:42 -05:00
|
|
|
let(:feature_name) { Users::Callout.feature_names.each_key.first }
|
2018-02-02 18:16:24 -05:00
|
|
|
|
|
|
|
context 'when callout entry does not exist' do
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'creates a callout entry with dismissed state' do
|
2021-12-10 13:14:42 -05:00
|
|
|
expect { subject }.to change { Users::Callout.count }.by(1)
|
2018-02-02 18:16:24 -05:00
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'returns success' do
|
2018-02-02 18:16:24 -05:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
2018-01-26 16:49:20 -05:00
|
|
|
end
|
|
|
|
|
2018-02-02 18:16:24 -05:00
|
|
|
context 'when callout entry already exists' do
|
2021-12-10 13:14:42 -05:00
|
|
|
let!(:callout) { create(:callout, feature_name: Users::Callout.feature_names.each_key.first, user: user) }
|
2018-02-02 18:16:24 -05:00
|
|
|
|
2021-09-14 20:09:30 -04:00
|
|
|
it 'returns success', :aggregate_failures do
|
2021-12-10 13:14:42 -05:00
|
|
|
expect { subject }.not_to change { Users::Callout.count }
|
2018-02-02 18:16:24 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
end
|
2018-01-26 16:49:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-02 18:16:24 -05:00
|
|
|
context 'with invalid feature name' do
|
|
|
|
let(:feature_name) { 'bogus_feature_name' }
|
2018-01-26 16:49:20 -05:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'returns bad request' do
|
2018-01-26 16:49:20 -05:00
|
|
|
subject
|
|
|
|
|
2018-02-02 18:16:24 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-01-26 16:49:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|