diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/support/shared_contexts | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/support/shared_contexts')
7 files changed, 209 insertions, 24 deletions
diff --git a/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb b/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb index 3ea6658c0c1..3d3b8c2207d 100644 --- a/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb +++ b/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb @@ -2,14 +2,42 @@ Integration.available_integration_names.each do |integration| RSpec.shared_context integration do - include JiraServiceHelper if integration == 'jira' + include JiraIntegrationHelpers if integration == 'jira' let(:dashed_integration) { integration.dasherize } let(:integration_method) { Project.integration_association_name(integration) } let(:integration_klass) { Integration.integration_name_to_model(integration) } let(:integration_instance) { integration_klass.new } - let(:integration_fields) { integration_instance.fields } - let(:integration_attrs_list) { integration_fields.inject([]) {|arr, hash| arr << hash[:name].to_sym } } + + # Build a list of all attributes that an integration supports. + let(:integration_attrs_list) do + integration_fields + integration_events + custom_attributes.fetch(integration.to_sym, []) + end + + # Attributes defined as fields. + let(:integration_fields) do + integration_instance.fields.map { _1[:name].to_sym } + end + + # Attributes for configurable event triggers. + let(:integration_events) do + integration_instance.configurable_events.map { IntegrationsHelper.integration_event_field_name(_1).to_sym } + end + + # Other special cases, this list might be incomplete. + # + # Some of these won't be needed anymore after we've converted them to use the field DSL + # in https://gitlab.com/gitlab-org/gitlab/-/issues/354899. + # + # Others like `comment_on_event_disabled` are actual columns on `integrations`, maybe we should migrate + # these to fields as well. + let(:custom_attributes) do + { + jira: %i[comment_on_event_enabled jira_issue_transition_automatic jira_issue_transition_id project_key + issues_enabled vulnerabilities_enabled vulnerabilities_issuetype] + } + end + let(:integration_attrs) do integration_attrs_list.inject({}) do |hash, k| if k =~ /^(token*|.*_token|.*_key)/ @@ -32,9 +60,11 @@ Integration.available_integration_names.each do |integration| hash.merge!(k => 1234) elsif integration == 'jira' && k == :jira_issue_transition_id hash.merge!(k => '1,2,3') + elsif integration == 'jira' && k == :jira_issue_transition_automatic + hash.merge!(k => true) elsif integration == 'emails_on_push' && k == :recipients hash.merge!(k => 'foo@bar.com') - elsif integration == 'slack' || integration == 'mattermost' && k == :labels_to_be_notified_behavior + elsif (integration == 'slack' || integration == 'mattermost') && k == :labels_to_be_notified_behavior hash.merge!(k => "match_any") else hash.merge!(k => "someword") @@ -44,7 +74,7 @@ Integration.available_integration_names.each do |integration| let(:licensed_features) do { - 'github' => :github_project_service_integration + 'github' => :github_integration } end diff --git a/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb b/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb index d9cbea58406..afb3976e3b8 100644 --- a/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb +++ b/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb @@ -12,7 +12,7 @@ RSpec.shared_context 'IssuesFinder context' do let_it_be(:milestone) { create(:milestone, project: project1, releases: [release]) } let_it_be(:label) { create(:label, project: project2) } let_it_be(:label2) { create(:label, project: project2) } - let_it_be(:issue1, reload: true) do + let_it_be(:item1, reload: true) do create(:issue, author: user, assignees: [user], @@ -23,7 +23,7 @@ RSpec.shared_context 'IssuesFinder context' do updated_at: 1.week.ago) end - let_it_be(:issue2, reload: true) do + let_it_be(:item2, reload: true) do create(:issue, author: user, assignees: [user], @@ -33,7 +33,7 @@ RSpec.shared_context 'IssuesFinder context' do updated_at: 1.week.from_now) end - let_it_be(:issue3, reload: true) do + let_it_be(:item3, reload: true) do create(:issue, author: user2, assignees: [user2], @@ -44,8 +44,8 @@ RSpec.shared_context 'IssuesFinder context' do updated_at: 2.weeks.from_now) end - let_it_be(:issue4, reload: true) { create(:issue, project: project3) } - let_it_be(:issue5, reload: true) do + let_it_be(:item4, reload: true) { create(:issue, project: project3) } + let_it_be(:item5, reload: true) do create(:issue, author: user, assignees: [user], @@ -55,18 +55,20 @@ RSpec.shared_context 'IssuesFinder context' do updated_at: 3.days.ago) end - let_it_be(:award_emoji1) { create(:award_emoji, name: 'thumbsup', user: user, awardable: issue1) } - let_it_be(:award_emoji2) { create(:award_emoji, name: 'thumbsup', user: user2, awardable: issue2) } - let_it_be(:award_emoji3) { create(:award_emoji, name: 'thumbsdown', user: user, awardable: issue3) } + let_it_be(:award_emoji1) { create(:award_emoji, name: 'thumbsup', user: user, awardable: item1) } + let_it_be(:award_emoji2) { create(:award_emoji, name: 'thumbsup', user: user2, awardable: item2) } + let_it_be(:award_emoji3) { create(:award_emoji, name: 'thumbsdown', user: user, awardable: item3) } + + let(:items_model) { Issue } end RSpec.shared_context 'IssuesFinder#execute context' do - let!(:closed_issue) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') } - let!(:label_link) { create(:label_link, label: label, target: issue2) } - let!(:label_link2) { create(:label_link, label: label2, target: issue3) } + let!(:closed_item) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') } + let!(:label_link) { create(:label_link, label: label, target: item2) } + let!(:label_link2) { create(:label_link, label: label2, target: item3) } let(:search_user) { user } let(:params) { {} } - let(:issues) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute } + let(:items) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute } before_all do project1.add_maintainer(user) diff --git a/spec/support/shared_contexts/finders/work_items_finder_shared_contexts.rb b/spec/support/shared_contexts/finders/work_items_finder_shared_contexts.rb new file mode 100644 index 00000000000..8c5bc339db5 --- /dev/null +++ b/spec/support/shared_contexts/finders/work_items_finder_shared_contexts.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +RSpec.shared_context 'WorkItemsFinder context' do + let_it_be(:user) { create(:user) } + let_it_be(:user2) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:subgroup) { create(:group, parent: group) } + let_it_be(:project1, reload: true) { create(:project, group: group) } + let_it_be(:project2, reload: true) { create(:project) } + let_it_be(:project3, reload: true) { create(:project, group: subgroup) } + let_it_be(:release) { create(:release, project: project1, tag: 'v1.0.0') } + let_it_be(:milestone) { create(:milestone, project: project1, releases: [release]) } + let_it_be(:label) { create(:label, project: project2) } + let_it_be(:label2) { create(:label, project: project2) } + let_it_be(:item1, reload: true) do + create(:work_item, + author: user, + assignees: [user], + project: project1, + milestone: milestone, + title: 'gitlab', + created_at: 1.week.ago, + updated_at: 1.week.ago) + end + + let_it_be(:item2, reload: true) do + create(:work_item, + author: user, + assignees: [user], + project: project2, + description: 'gitlab', + created_at: 1.week.from_now, + updated_at: 1.week.from_now) + end + + let_it_be(:item3, reload: true) do + create(:work_item, + author: user2, + assignees: [user2], + project: project2, + title: 'tanuki', + description: 'tanuki', + created_at: 2.weeks.from_now, + updated_at: 2.weeks.from_now) + end + + let_it_be(:item4, reload: true) { create(:work_item, project: project3) } + let_it_be(:item5, reload: true) do + create(:work_item, + author: user, + assignees: [user], + project: project1, + title: 'wotnot', + created_at: 3.days.ago, + updated_at: 3.days.ago) + end + + let_it_be(:award_emoji1) { create(:award_emoji, name: 'thumbsup', user: user, awardable: item1) } + let_it_be(:award_emoji2) { create(:award_emoji, name: 'thumbsup', user: user2, awardable: item2) } + let_it_be(:award_emoji3) { create(:award_emoji, name: 'thumbsdown', user: user, awardable: item3) } + + let(:items_model) { WorkItem } +end + +RSpec.shared_context 'WorkItemsFinder#execute context' do + let!(:closed_item) { create(:work_item, author: user2, assignees: [user2], project: project2, state: 'closed') } + let!(:label_link) { create(:label_link, label: label, target: item2) } + let!(:label_link2) { create(:label_link, label: label2, target: item3) } + let(:search_user) { user } + let(:params) { {} } + let(:items) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute } + + before_all do + project1.add_maintainer(user) + project2.add_developer(user) + project2.add_developer(user2) + project3.add_developer(user) + end +end diff --git a/spec/support/shared_contexts/lib/gitlab/sidekiq_logging/structured_logger_shared_context.rb b/spec/support/shared_contexts/lib/gitlab/sidekiq_logging/structured_logger_shared_context.rb index 7d51c90522a..aa8bc6fa79f 100644 --- a/spec/support/shared_contexts/lib/gitlab/sidekiq_logging/structured_logger_shared_context.rb +++ b/spec/support/shared_contexts/lib/gitlab/sidekiq_logging/structured_logger_shared_context.rb @@ -18,7 +18,10 @@ RSpec.shared_context 'structured_logger' do "correlation_id" => 'cid', "error_message" => "wrong number of arguments (2 for 3)", "error_class" => "ArgumentError", - "error_backtrace" => [] + "error_backtrace" => [], + "exception.message" => "wrong number of arguments (2 for 3)", + "exception.class" => "ArgumentError", + "exception.backtrace" => [] } end @@ -28,7 +31,10 @@ RSpec.shared_context 'structured_logger' do let(:clock_thread_cputime_start) { 0.222222299 } let(:clock_thread_cputime_end) { 1.333333799 } let(:start_payload) do - job.except('error_backtrace', 'error_class', 'error_message').merge( + job.except( + 'error_message', 'error_class', 'error_backtrace', + 'exception.backtrace', 'exception.class', 'exception.message' + ).merge( 'message' => 'TestWorker JID-da883554ee4fe414012f5f42: start', 'job_status' => 'start', 'pid' => Process.pid, @@ -58,7 +64,8 @@ RSpec.shared_context 'structured_logger' do 'duration_s' => 0.0, 'completed_at' => timestamp.to_f, 'cpu_s' => 1.111112, - 'rate_limiting_gates' => [] + 'rate_limiting_gates' => [], + 'worker_id' => "process_#{Process.pid}" ) end @@ -68,7 +75,10 @@ RSpec.shared_context 'structured_logger' do 'job_status' => 'fail', 'error_class' => 'ArgumentError', 'error_message' => 'Something went wrong', - 'error_backtrace' => be_a(Array).and(be_present) + 'error_backtrace' => be_a(Array).and(be_present), + 'exception.class' => 'ArgumentError', + 'exception.message' => 'Something went wrong', + 'exception.backtrace' => be_a(Array).and(be_present) ) end diff --git a/spec/support/shared_contexts/markdown_snapshot_shared_examples.rb b/spec/support/shared_contexts/markdown_snapshot_shared_examples.rb new file mode 100644 index 00000000000..de52b58982e --- /dev/null +++ b/spec/support/shared_contexts/markdown_snapshot_shared_examples.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' + +# See https://docs.gitlab.com/ee/development/gitlab_flavored_markdown/specification_guide/#markdown-snapshot-testing +# for documentation on this spec. +# rubocop:disable Layout/LineLength +RSpec.shared_context 'with API::Markdown Snapshot shared context' do |glfm_specification_dir, glfm_example_snapshots_dir| + # rubocop:enable Layout/LineLength + include ApiHelpers + + markdown_examples, html_examples = %w[markdown.yml html.yml].map do |file_name| + yaml = File.read("#{glfm_example_snapshots_dir}/#{file_name}") + YAML.safe_load(yaml, symbolize_names: true, aliases: true) + end + + normalizations_yaml = File.read( + "#{glfm_specification_dir}/input/gitlab_flavored_markdown/glfm_example_normalizations.yml") + normalizations_by_example_name = YAML.safe_load(normalizations_yaml, symbolize_names: true, aliases: true) + + if (focused_markdown_examples_string = ENV['FOCUSED_MARKDOWN_EXAMPLES']) + focused_markdown_examples = focused_markdown_examples_string.split(',').map(&:strip).map(&:to_sym) + markdown_examples.select! { |example_name| focused_markdown_examples.include?(example_name) } + end + + markdown_examples.each do |name, markdown| + context "for #{name}" do + let(:html) { html_examples.fetch(name).fetch(:static) } + let(:normalizations) { normalizations_by_example_name.dig(name, :html, :static, :snapshot) } + + it "verifies conversion of GLFM to HTML", :unlimited_max_formatted_output_length do + api_url = api "/markdown" + + # noinspection RubyResolve + normalized_html = normalize_html(html, normalizations) + + post api_url, params: { text: markdown, gfm: true } + expect(response).to be_successful + response_body = Gitlab::Json.parse(response.body) + # Some requests have the HTML in the `html` key, others in the `body` key. + response_html = response_body['body'] ? response_body.fetch('body') : response_body.fetch('html') + # noinspection RubyResolve + normalized_response_html = normalize_html(response_html, normalizations) + + expect(normalized_response_html).to eq(normalized_html) + end + + def normalize_html(html, normalizations) + return html unless normalizations + + normalized_html = html.dup + normalizations.each_value do |normalization_entry| + normalization_entry.each do |normalization| + regex = normalization.fetch(:regex) + replacement = normalization.fetch(:replacement) + normalized_html.gsub!(%r{#{regex}}, replacement) + end + end + + normalized_html + end + end + end +end diff --git a/spec/support/shared_contexts/navbar_structure_context.rb b/spec/support/shared_contexts/navbar_structure_context.rb index ef6ff7be840..d277a45584d 100644 --- a/spec/support/shared_contexts/navbar_structure_context.rb +++ b/spec/support/shared_contexts/navbar_structure_context.rb @@ -134,13 +134,13 @@ RSpec.shared_context 'group navbar structure' do nav_sub_items: [ _('General'), _('Integrations'), + _('Webhooks'), _('Access Tokens'), _('Projects'), _('Repository'), _('CI/CD'), _('Applications'), - _('Packages & Registries'), - _('Webhooks') + _('Packages & Registries') ] } end diff --git a/spec/support/shared_contexts/policies/project_policy_shared_context.rb b/spec/support/shared_contexts/policies/project_policy_shared_context.rb index e50083a10e7..7396643823c 100644 --- a/spec/support/shared_contexts/policies/project_policy_shared_context.rb +++ b/spec/support/shared_contexts/policies/project_policy_shared_context.rb @@ -75,7 +75,7 @@ RSpec.shared_context 'ProjectPolicy context' do let(:base_owner_permissions) do %i[ archive_project change_namespace change_visibility_level destroy_issue - destroy_merge_request remove_fork_project remove_project rename_project + destroy_merge_request manage_owners remove_fork_project remove_project rename_project set_issue_created_at set_issue_iid set_issue_updated_at set_note_created_at ] |