summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-03 15:12:58 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-03 15:12:58 +0000
commit27a5080c34c64a84219d855d652b994c5e344a0a (patch)
tree1f6bcb68378e4965b4e93a846d8a939af18aeec6 /spec/support/shared_examples
parent2c01907a1ab4b328e2f20ddf9e10dfe6dc17105a (diff)
downloadgitlab-ce-27a5080c34c64a84219d855d652b994c5e344a0a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_examples')
-rw-r--r--spec/support/shared_examples/lib/menus_shared_examples.rb31
-rw-r--r--spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb69
-rw-r--r--spec/support/shared_examples/serializers/note_entity_shared_examples.rb3
3 files changed, 102 insertions, 1 deletions
diff --git a/spec/support/shared_examples/lib/menus_shared_examples.rb b/spec/support/shared_examples/lib/menus_shared_examples.rb
index ed3165079fb..0aa98517444 100644
--- a/spec/support/shared_examples/lib/menus_shared_examples.rb
+++ b/spec/support/shared_examples/lib/menus_shared_examples.rb
@@ -61,3 +61,34 @@ RSpec.shared_examples_for 'not serializable as super_sidebar_menu_args' do
expect(menu.serialize_as_menu_item_args).to be_nil
end
end
+
+RSpec.shared_examples_for 'a panel with uniquely identifiable menu items' do
+ let(:menu_items) do
+ subject.instance_variable_get(:@menus)
+ .flat_map { |menu| menu.instance_variable_get(:@items) }
+ end
+
+ it 'all menu_items have unique item_id' do
+ duplicated_ids = menu_items.group_by(&:item_id).reject { |_, v| (v.size < 2) }
+
+ expect(duplicated_ids).to eq({})
+ end
+
+ it 'all menu_items have an item_id' do
+ items_with_nil_id = menu_items.select { |item| item.item_id.nil? }
+
+ expect(items_with_nil_id).to match_array([])
+ end
+end
+
+RSpec.shared_examples_for 'a panel with all menu_items categorized' do
+ let(:uncategorized_menu) do
+ subject.instance_variable_get(:@menus)
+ .find { |menu| menu.instance_of?(::Sidebars::UncategorizedMenu) }
+ end
+
+ it 'has no uncategorized menu_items' do
+ uncategorized_menu_items = uncategorized_menu.instance_variable_get(:@items)
+ expect(uncategorized_menu_items).to eq([])
+ end
+end
diff --git a/spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb b/spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb
new file mode 100644
index 00000000000..2ca62698daf
--- /dev/null
+++ b/spec/support/shared_examples/requests/api/ml/mlflow/mlflow_shared_examples.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'MLflow|Not Found - Resource Does Not Exist' do
+ it "is Resource Does Not Exist", :aggregate_failures do
+ is_expected.to have_gitlab_http_status(:not_found)
+
+ expect(json_response).to include({ "error_code" => 'RESOURCE_DOES_NOT_EXIST' })
+ end
+end
+
+RSpec.shared_examples 'MLflow|Requires api scope' do
+ context 'when user has access but token has wrong scope' do
+ let(:access_token) { tokens[:read] }
+
+ it { is_expected.to have_gitlab_http_status(:forbidden) }
+ end
+end
+
+RSpec.shared_examples 'MLflow|Requires read_api scope' do
+ context 'when user has access but token has wrong scope' do
+ let(:access_token) { tokens[:no_access] }
+
+ it { is_expected.to have_gitlab_http_status(:forbidden) }
+ end
+end
+
+RSpec.shared_examples 'MLflow|Bad Request' do
+ it "is Bad Request" do
+ is_expected.to have_gitlab_http_status(:bad_request)
+ end
+end
+
+RSpec.shared_examples 'MLflow|shared error cases' do
+ context 'when not authenticated' do
+ let(:headers) { {} }
+
+ it "is Unauthorized" do
+ is_expected.to have_gitlab_http_status(:unauthorized)
+ end
+ end
+
+ context 'when user does not have access' do
+ let(:access_token) { tokens[:different_user] }
+
+ it "is Not Found" do
+ is_expected.to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'when ff is disabled' do
+ let(:ff_value) { false }
+
+ it "is Not Found" do
+ is_expected.to have_gitlab_http_status(:not_found)
+ end
+ end
+end
+
+RSpec.shared_examples 'MLflow|Bad Request on missing required' do |keys|
+ keys.each do |key|
+ context "when \"#{key}\" is missing" do
+ let(:params) { default_params.tap { |p| p.delete(key) } }
+
+ it "is Bad Request" do
+ is_expected.to have_gitlab_http_status(:bad_request)
+ end
+ end
+ end
+end
diff --git a/spec/support/shared_examples/serializers/note_entity_shared_examples.rb b/spec/support/shared_examples/serializers/note_entity_shared_examples.rb
index b5e3a407b53..e8238480ced 100644
--- a/spec/support/shared_examples/serializers/note_entity_shared_examples.rb
+++ b/spec/support/shared_examples/serializers/note_entity_shared_examples.rb
@@ -18,7 +18,8 @@ RSpec.shared_examples 'note entity' do
:noteable_note_url,
:report_abuse_path,
:resolvable,
- :type
+ :type,
+ :external_author
)
end