diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-01 21:08:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-01 21:08:33 +0300 |
commit | 24d67ec55454fc6f4e8e80bf7c8dc5bc677e8514 (patch) | |
tree | 6ce73c2fd8ec96c6f043c4a1403c0991fd448b81 /spec | |
parent | a0fdcfcdd514c2af98f18cadfa75f8a6a85b4d2c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
18 files changed, 349 insertions, 266 deletions
diff --git a/spec/controllers/import/bitbucket_controller_spec.rb b/spec/controllers/import/bitbucket_controller_spec.rb index 8f11ab86efa..af220e2d515 100644 --- a/spec/controllers/import/bitbucket_controller_spec.rb +++ b/spec/controllers/import/bitbucket_controller_spec.rb @@ -65,7 +65,7 @@ RSpec.describe Import::BitbucketController do .with(hash_including( 'grant_type' => 'authorization_code', 'code' => code, - redirect_uri: users_import_bitbucket_callback_url), + 'redirect_uri' => users_import_bitbucket_callback_url), {}) .and_return(access_token) stub_omniauth_provider('bitbucket') diff --git a/spec/features/profiles/oauth_applications_spec.rb b/spec/features/profiles/oauth_applications_spec.rb index 86cc761d790..7d8cd2dc6ca 100644 --- a/spec/features/profiles/oauth_applications_spec.rb +++ b/spec/features/profiles/oauth_applications_spec.rb @@ -45,10 +45,12 @@ RSpec.describe 'Profile > Applications' do let(:anonymous_token) { create(:oauth_access_token, resource_owner: user) } context 'with multiple access token types and multiple owners' do + let!(:token2) { create(:oauth_access_token, application: application, resource_owner: user) } let!(:other_user_token) { create(:oauth_access_token, application: application, resource_owner: other_user) } before do token.update_column(:created_at, created_at) + token2.update_column(:created_at, created_at - 1.day) anonymous_token.update_columns(application_id: nil, created_at: 1.day.ago) end diff --git a/spec/frontend/pages/projects/learn_gitlab/components/__snapshots__/learn_gitlab_spec.js.snap b/spec/frontend/pages/projects/learn_gitlab/components/__snapshots__/learn_gitlab_spec.js.snap index 005b8968383..aab78c99190 100644 --- a/spec/frontend/pages/projects/learn_gitlab/components/__snapshots__/learn_gitlab_spec.js.snap +++ b/spec/frontend/pages/projects/learn_gitlab/components/__snapshots__/learn_gitlab_spec.js.snap @@ -85,8 +85,6 @@ exports[`Learn GitLab renders correctly 1`] = ` <div class="gl-mb-4" > - <!----> - <div class="flex align-items-center" > @@ -105,7 +103,8 @@ exports[`Learn GitLab renders correctly 1`] = ` </svg> Invite your colleagues - + + <!----> </span> <!----> @@ -114,8 +113,6 @@ exports[`Learn GitLab renders correctly 1`] = ` <div class="gl-mb-4" > - <!----> - <div class="flex align-items-center" > @@ -133,8 +130,9 @@ exports[`Learn GitLab renders correctly 1`] = ` /> </svg> - Create or import a repository - + Create a repository + + <!----> </span> <!----> @@ -143,23 +141,23 @@ exports[`Learn GitLab renders correctly 1`] = ` <div class="gl-mb-4" > - <!----> - <div class="flex align-items-center" > - <a - class="gl-link" - data-testid="uncompleted-learn-gitlab-link" - data-track-action="click_link" - data-track-label="Set up CI/CD" - href="http://example.com/" - target="_self" - > - - Set up CI/CD - - </a> + <div> + <a + class="gl-link" + data-testid="uncompleted-learn-gitlab-link" + data-track-action="click_link" + data-track-label="set_up_your_first_project_s_ci_cd" + href="http://example.com/" + target="_self" + > + Set up your first project's CI/CD + </a> + + <!----> + </div> <!----> </div> @@ -167,24 +165,24 @@ exports[`Learn GitLab renders correctly 1`] = ` <div class="gl-mb-4" > - <!----> - <div class="flex align-items-center" > - <a - class="gl-link" - data-testid="uncompleted-learn-gitlab-link" - data-track-action="click_link" - data-track-label="Start a free Ultimate trial" - href="http://example.com/" - rel="noopener noreferrer" - target="_blank" - > - - Start a free Ultimate trial - - </a> + <div> + <a + class="gl-link" + data-testid="uncompleted-learn-gitlab-link" + data-track-action="click_link" + data-track-label="start_a_free_trial_of_gitlab_ultimate" + href="http://example.com/" + rel="noopener noreferrer" + target="_blank" + > + Start a free trial of GitLab Ultimate + </a> + + <!----> + </div> <!----> </div> @@ -193,30 +191,30 @@ exports[`Learn GitLab renders correctly 1`] = ` class="gl-mb-4" > <div - class="gl-font-style-italic gl-text-gray-500" - data-testid="trial-only" - > - - Trial only - - </div> - - <div class="flex align-items-center" > - <a - class="gl-link" - data-testid="uncompleted-learn-gitlab-link" - data-track-action="click_link" - data-track-label="Add code owners" - href="http://example.com/" - rel="noopener noreferrer" - target="_blank" - > - - Add code owners - - </a> + <div> + <a + class="gl-link" + data-testid="uncompleted-learn-gitlab-link" + data-track-action="click_link" + data-track-label="add_code_owners" + href="http://example.com/" + rel="noopener noreferrer" + target="_blank" + > + Add code owners + </a> + + <span + class="gl-font-style-italic gl-text-gray-500" + data-testid="trial-only" + > + + - Included in trial + + </span> + </div> <!----> </div> @@ -225,30 +223,30 @@ exports[`Learn GitLab renders correctly 1`] = ` class="gl-mb-4" > <div - class="gl-font-style-italic gl-text-gray-500" - data-testid="trial-only" - > - - Trial only - - </div> - - <div class="flex align-items-center" > - <a - class="gl-link" - data-testid="uncompleted-learn-gitlab-link" - data-track-action="click_link" - data-track-label="Add merge request approval" - href="http://example.com/" - rel="noopener noreferrer" - target="_blank" - > - - Add merge request approval - - </a> + <div> + <a + class="gl-link" + data-testid="uncompleted-learn-gitlab-link" + data-track-action="click_link" + data-track-label="enable_require_merge_approvals" + href="http://example.com/" + rel="noopener noreferrer" + target="_blank" + > + Enable require merge approvals + </a> + + <span + class="gl-font-style-italic gl-text-gray-500" + data-testid="trial-only" + > + + - Included in trial + + </span> + </div> <!----> </div> @@ -290,23 +288,23 @@ exports[`Learn GitLab renders correctly 1`] = ` <div class="gl-mb-4" > - <!----> - <div class="flex align-items-center" > - <a - class="gl-link" - data-testid="uncompleted-learn-gitlab-link" - data-track-action="click_link" - data-track-label="Create an issue" - href="http://example.com/" - target="_self" - > - - Create an issue - - </a> + <div> + <a + class="gl-link" + data-testid="uncompleted-learn-gitlab-link" + data-track-action="click_link" + data-track-label="create_an_issue" + href="http://example.com/" + target="_self" + > + Create an issue + </a> + + <!----> + </div> <!----> </div> @@ -314,23 +312,23 @@ exports[`Learn GitLab renders correctly 1`] = ` <div class="gl-mb-4" > - <!----> - <div class="flex align-items-center" > - <a - class="gl-link" - data-testid="uncompleted-learn-gitlab-link" - data-track-action="click_link" - data-track-label="Submit a merge request" - href="http://example.com/" - target="_self" - > - - Submit a merge request - - </a> + <div> + <a + class="gl-link" + data-testid="uncompleted-learn-gitlab-link" + data-track-action="click_link" + data-track-label="submit_a_merge_request_mr" + href="http://example.com/" + target="_self" + > + Submit a merge request (MR) + </a> + + <!----> + </div> <!----> </div> @@ -372,24 +370,24 @@ exports[`Learn GitLab renders correctly 1`] = ` <div class="gl-mb-4" > - <!----> - <div class="flex align-items-center" > - <a - class="gl-link" - data-testid="uncompleted-learn-gitlab-link" - data-track-action="click_link" - data-track-label="Run a Security scan using CI/CD" - href="https://docs.gitlab.com/ee/foobar/" - rel="noopener noreferrer" - target="_blank" - > - - Run a Security scan using CI/CD - - </a> + <div> + <a + class="gl-link" + data-testid="uncompleted-learn-gitlab-link" + data-track-action="click_link" + data-track-label="run_a_security_scan_using_ci_cd" + href="https://docs.gitlab.com/ee/foobar/" + rel="noopener noreferrer" + target="_blank" + > + Run a Security scan using CI/CD + </a> + + <!----> + </div> <!----> </div> diff --git a/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_info_card_spec.js b/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_info_card_spec.js deleted file mode 100644 index ad4bc826a9d..00000000000 --- a/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_info_card_spec.js +++ /dev/null @@ -1,57 +0,0 @@ -import { shallowMount } from '@vue/test-utils'; -import LearnGitlabInfoCard from '~/pages/projects/learn_gitlab/components/learn_gitlab_info_card.vue'; - -const defaultProps = { - title: 'Create Repository', - description: 'Some description', - actionLabel: 'Create Repository now', - url: 'https://example.com', - completed: false, - svg: 'https://example.com/illustration.svg', -}; - -describe('Learn GitLab Info Card', () => { - let wrapper; - - afterEach(() => { - wrapper.destroy(); - wrapper = null; - }); - - const createWrapper = (props = {}) => { - wrapper = shallowMount(LearnGitlabInfoCard, { - propsData: { ...defaultProps, ...props }, - }); - }; - - it('renders no icon when not completed', () => { - createWrapper({ completed: false }); - - expect(wrapper.find('[data-testid="completed-icon"]').exists()).toBe(false); - }); - - it('renders the completion icon when completed', () => { - createWrapper({ completed: true }); - - expect(wrapper.find('[data-testid="completed-icon"]').exists()).toBe(true); - }); - - it('renders no trial only when it is not required', () => { - createWrapper(); - - expect(wrapper.find('[data-testid="trial-only"]').exists()).toBe(false); - }); - - it('renders trial only when trial is required', () => { - createWrapper({ trialRequired: true }); - - expect(wrapper.find('[data-testid="trial-only"]').exists()).toBe(true); - }); - - it('renders completion icon when completed a trial-only feature', () => { - createWrapper({ trialRequired: true, completed: true }); - - expect(wrapper.find('[data-testid="trial-only"]').exists()).toBe(false); - expect(wrapper.find('[data-testid="completed-icon"]').exists()).toBe(true); - }); -}); diff --git a/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_section_link_spec.js b/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_section_link_spec.js index d9aff37f703..897cbf5eaa4 100644 --- a/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_section_link_spec.js +++ b/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_section_link_spec.js @@ -119,7 +119,7 @@ describe('Learn GitLab Section Link', () => { findUncompletedLink().trigger('click'); expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_link', { - label: 'Run a Security scan using CI/CD', + label: 'run_a_security_scan_using_ci_cd', }); unmockTracking(); @@ -164,7 +164,7 @@ describe('Learn GitLab Section Link', () => { triggerEvent(openInviteMembesrModalLink().element); expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_link', { - label: 'Invite your colleagues', + label: 'invite_your_colleagues', property: 'Growth::Activation::Experiment::InviteForHelpContinuousOnboarding', }); @@ -203,7 +203,7 @@ describe('Learn GitLab Section Link', () => { videoTutorialLink().trigger('click'); expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_video_link', { - label: 'Add code owners', + label: 'add_code_owners', property: 'Growth::Conversion::Experiment::LearnGitLab', context: { data: { diff --git a/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_trial_card_spec.js b/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_trial_card_spec.js new file mode 100644 index 00000000000..6ab57e31fed --- /dev/null +++ b/spec/frontend/pages/projects/learn_gitlab/components/learn_gitlab_trial_card_spec.js @@ -0,0 +1,12 @@ +import { shallowMount } from '@vue/test-utils'; +import IncludedInTrialIndicator from '~/pages/projects/learn_gitlab/components/included_in_trial_indicator.vue'; + +describe('Learn GitLab Trial Card', () => { + it('renders correctly', () => { + const wrapper = shallowMount(IncludedInTrialIndicator); + + expect(wrapper.text()).toEqual('- Included in trial'); + + wrapper.destroy(); + }); +}); diff --git a/spec/frontend/pipelines/test_reports/test_reports_spec.js b/spec/frontend/pipelines/test_reports/test_reports_spec.js index e0daf8cb4b5..3c3143b1865 100644 --- a/spec/frontend/pipelines/test_reports/test_reports_spec.js +++ b/spec/frontend/pipelines/test_reports/test_reports_spec.js @@ -31,18 +31,30 @@ describe('Test reports app', () => { const createComponent = ({ state = {} } = {}) => { store = new Vuex.Store({ - state: { - isLoading: false, - selectedSuiteIndex: null, - testReports, - ...state, + modules: { + testReports: { + namespaced: true, + state: { + isLoading: false, + selectedSuiteIndex: null, + testReports, + ...state, + }, + actions: actionSpies, + getters, + }, }, - actions: actionSpies, - getters, }); + jest.spyOn(store, 'registerModule').mockReturnValue(null); + wrapper = extendedWrapper( shallowMount(TestReports, { + provide: { + blobPath: '/blob/path', + summaryEndpoint: '/summary.json', + suiteEndpoint: '/suite.json', + }, store, }), ); diff --git a/spec/frontend/pipelines/test_reports/test_suite_table_spec.js b/spec/frontend/pipelines/test_reports/test_suite_table_spec.js index 25650b24705..c372ac06c35 100644 --- a/spec/frontend/pipelines/test_reports/test_suite_table_spec.js +++ b/spec/frontend/pipelines/test_reports/test_suite_table_spec.js @@ -34,22 +34,32 @@ describe('Test reports suite table', () => { const createComponent = ({ suite = testSuite, perPage = 20, errorMessage } = {}) => { store = new Vuex.Store({ - state: { - blobPath, + modules: { testReports: { - test_suites: [suite], + namespaced: true, + state: { + blobPath, + testReports: { + test_suites: [suite], + }, + selectedSuiteIndex: 0, + pageInfo: { + page: 1, + perPage, + }, + errorMessage, + }, + getters, }, - selectedSuiteIndex: 0, - pageInfo: { - page: 1, - perPage, - }, - errorMessage, }, - getters, }); wrapper = shallowMountExtended(SuiteTable, { + provide: { + blobPath: '/blob/path', + summaryEndpoint: '/summary.json', + suiteEndpoint: '/suite.json', + }, store, stubs: { GlFriendlyWrap }, }); diff --git a/spec/frontend/pipelines/test_reports/test_summary_table_spec.js b/spec/frontend/pipelines/test_reports/test_summary_table_spec.js index 1598d5c337f..0e1229f7067 100644 --- a/spec/frontend/pipelines/test_reports/test_summary_table_spec.js +++ b/spec/frontend/pipelines/test_reports/test_summary_table_spec.js @@ -20,13 +20,23 @@ describe('Test reports summary table', () => { const createComponent = (reports = null) => { store = new Vuex.Store({ - state: { - testReports: reports || testReports, + modules: { + testReports: { + namespaced: true, + state: { + testReports: reports || testReports, + }, + getters, + }, }, - getters, }); wrapper = mount(SummaryTable, { + provide: { + blobPath: '/blob/path', + summaryEndpoint: '/summary.json', + suiteEndpoint: '/suite.json', + }, propsData: defaultProps, store, }); diff --git a/spec/helpers/learn_gitlab_helper_spec.rb b/spec/helpers/learn_gitlab_helper_spec.rb index 9fce7495b5a..7c9dfd6b5be 100644 --- a/spec/helpers/learn_gitlab_helper_spec.rb +++ b/spec/helpers/learn_gitlab_helper_spec.rb @@ -92,38 +92,6 @@ RSpec.describe LearnGitlabHelper do it_behaves_like 'has all data' - it 'sets correct paths' do - expect(onboarding_actions_data).to match({ - trial_started: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/2\z}) - ), - pipeline_created: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/7\z}) - ), - code_owners_enabled: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/10\z}) - ), - required_mr_approvals_enabled: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/11\z}) - ), - issue_created: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues\z}) - ), - git_write: a_hash_including( - url: a_string_matching(%r{/learn_gitlab\z}) - ), - user_added: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/project_members\z}) - ), - merge_request_created: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/merge_requests\z}) - ), - security_scan_enabled: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/security/configuration\z}) - ) - }) - end - it 'sets correct completion statuses' do expect(onboarding_actions_data).to match({ issue_created: a_hash_including(completed: false), @@ -137,5 +105,58 @@ RSpec.describe LearnGitlabHelper do security_scan_enabled: a_hash_including(completed: false) }) end + + describe 'security_actions_continuous_onboarding experiment' do + let(:base_paths) do + { + trial_started: a_hash_including(url: %r{/learn_gitlab/-/issues/2\z}), + pipeline_created: a_hash_including(url: %r{/learn_gitlab/-/issues/7\z}), + code_owners_enabled: a_hash_including(url: %r{/learn_gitlab/-/issues/10\z}), + required_mr_approvals_enabled: a_hash_including(url: %r{/learn_gitlab/-/issues/11\z}), + issue_created: a_hash_including(url: %r{/learn_gitlab/-/issues\z}), + git_write: a_hash_including(url: %r{/learn_gitlab\z}), + user_added: a_hash_including(url: %r{/learn_gitlab/-/project_members\z}), + merge_request_created: a_hash_including(url: %r{/learn_gitlab/-/merge_requests\z}) + } + end + + context 'when control' do + before do + stub_experiments(security_actions_continuous_onboarding: :control) + end + + it 'sets correct paths' do + expect(onboarding_actions_data).to match( + base_paths.merge( + security_scan_enabled: a_hash_including( + url: %r{/learn_gitlab/-/security/configuration\z} + ) + ) + ) + end + end + + context 'when candidate' do + before do + stub_experiments(security_actions_continuous_onboarding: :candidate) + end + + it 'sets correct paths' do + expect(onboarding_actions_data).to match( + base_paths.merge( + license_scanning_run: a_hash_including( + url: described_class::LICENSE_SCANNING_RUN_URL + ), + secure_dependency_scanning_run: a_hash_including( + url: project_security_configuration_path(project, anchor: 'dependency-scanning') + ), + secure_dast_run: a_hash_including( + url: project_security_configuration_path(project, anchor: 'dast') + ) + ) + ) + end + end + end end end diff --git a/spec/lib/gitlab/gitlab_import/importer_spec.rb b/spec/lib/gitlab/gitlab_import/importer_spec.rb index eb4c404e454..984c690add6 100644 --- a/spec/lib/gitlab/gitlab_import/importer_spec.rb +++ b/spec/lib/gitlab/gitlab_import/importer_spec.rb @@ -21,8 +21,8 @@ RSpec.describe Gitlab::GitlabImport::Importer do 'name' => 'John Doe' } } - ]) - stub_request('issues/3/notes', []) + ].to_json) + stub_request('issues/3/notes', [].to_json) end it 'persists issues' do diff --git a/spec/lib/learn_gitlab/onboarding_spec.rb b/spec/lib/learn_gitlab/onboarding_spec.rb index 8c7284ed7f5..3e22ce59091 100644 --- a/spec/lib/learn_gitlab/onboarding_spec.rb +++ b/spec/lib/learn_gitlab/onboarding_spec.rb @@ -6,11 +6,14 @@ RSpec.describe LearnGitlab::Onboarding do describe '#completed_percentage' do let(:completed_actions) { {} } let(:onboarding_progress) { build(:onboarding_progress, namespace: namespace, **completed_actions) } - let(:namespace) { build(:namespace) } + let(:namespace) { create(:namespace) } let_it_be(:tracked_action_columns) do - tracked_actions = described_class::ACTION_ISSUE_IDS.keys + described_class::ACTION_PATHS - tracked_actions.map { |key| OnboardingProgress.column_name(key) } + [ + *described_class::ACTION_ISSUE_IDS.keys, + *described_class::ACTION_PATHS, + :security_scan_enabled + ].map { |key| OnboardingProgress.column_name(key) } end before do @@ -29,12 +32,6 @@ RSpec.describe LearnGitlab::Onboarding do it { is_expected.to eq(0) } end - context 'when one action has been completed' do - let(:completed_actions) { Hash[tracked_action_columns.first, Time.current] } - - it { is_expected.to eq(11) } - end - context 'when all tracked actions have been completed' do let(:completed_actions) do tracked_action_columns.to_h { |action| [action, Time.current] } @@ -42,5 +39,25 @@ RSpec.describe LearnGitlab::Onboarding do it { is_expected.to eq(100) } end + + describe 'security_actions_continuous_onboarding experiment' do + let(:completed_actions) { Hash[tracked_action_columns.first, Time.current] } + + context 'when control' do + before do + stub_experiments(security_actions_continuous_onboarding: :control) + end + + it { is_expected.to eq(11) } + end + + context 'when candidate' do + before do + stub_experiments(security_actions_continuous_onboarding: :candidate) + end + + it { is_expected.to eq(9) } + end + end end end diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb index 39fde0c9b77..86074765c7b 100644 --- a/spec/models/integration_spec.rb +++ b/spec/models/integration_spec.rb @@ -799,7 +799,7 @@ RSpec.describe Integration do shared_examples '#api_field_names' do it 'filters out secret fields' do - safe_fields = %w[some_safe_field safe_field url trojan_gift] + safe_fields = %w[some_safe_field safe_field url trojan_gift api_only_field] expect(fake_integration.new).to have_attributes( api_field_names: match_array(safe_fields) @@ -807,6 +807,12 @@ RSpec.describe Integration do end end + shared_examples '#form_fields' do + it 'filters out API only fields' do + expect(fake_integration.new.form_fields.pluck(:name)).not_to include('api_only_field') + end + end + context 'when the class overrides #fields' do let(:fake_integration) do Class.new(Integration) do @@ -824,7 +830,8 @@ RSpec.describe Integration do { name: 'safe_field' }, { name: 'url' }, { name: 'trojan_horse', type: 'password' }, - { name: 'trojan_gift', type: 'text' } + { name: 'trojan_gift', type: 'text' }, + { name: 'api_only_field', api_only: true } ].shuffle end end @@ -832,6 +839,7 @@ RSpec.describe Integration do it_behaves_like '#fields' it_behaves_like '#api_field_names' + it_behaves_like '#form_fields' end context 'when the class uses the field DSL' do @@ -850,11 +858,13 @@ RSpec.describe Integration do field :url field :trojan_horse, type: 'password' field :trojan_gift, type: 'text' + field :api_only_field, api_only: true end end it_behaves_like '#fields' it_behaves_like '#api_field_names' + it_behaves_like '#form_fields' end end diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index 28d97b74adb..2a994540bd3 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -164,7 +164,7 @@ RSpec.describe Integrations::Jira do subject(:fields) { integration.fields } it 'returns custom fields' do - expect(fields.pluck(:name)).to eq(%w[url api_url username password]) + expect(fields.pluck(:name)).to eq(%w[url api_url username password jira_issue_transition_id]) end end diff --git a/spec/models/oauth_access_token_spec.rb b/spec/models/oauth_access_token_spec.rb index 65a7f6410cf..2b47da1ebe1 100644 --- a/spec/models/oauth_access_token_spec.rb +++ b/spec/models/oauth_access_token_spec.rb @@ -7,22 +7,40 @@ RSpec.describe OauthAccessToken do let(:app_one) { create(:oauth_application) } let(:app_two) { create(:oauth_application) } let(:app_three) { create(:oauth_application) } - let(:tokens) { described_class.all } + let(:token) { create(:oauth_access_token, application_id: app_one.id) } - before do - create(:oauth_access_token, application_id: app_one.id) - create_list(:oauth_access_token, 2, resource_owner: user, application_id: app_two.id) - end + describe 'scopes' do + describe '.distinct_resource_owner_counts' do + let(:tokens) { described_class.all } + + before do + token + create_list(:oauth_access_token, 2, resource_owner: user, application_id: app_two.id) + end + + it 'returns unique owners' do + expect(tokens.count).to eq(3) + expect(tokens.distinct_resource_owner_counts([app_one])).to eq({ app_one.id => 1 }) + expect(tokens.distinct_resource_owner_counts([app_two])).to eq({ app_two.id => 1 }) + expect(tokens.distinct_resource_owner_counts([app_three])).to eq({}) + expect(tokens.distinct_resource_owner_counts([app_one, app_two])) + .to eq({ + app_one.id => 1, + app_two.id => 1 + }) + end + end + + describe '.latest_per_application' do + let!(:app_two_token1) { create(:oauth_access_token, application: app_two) } + let!(:app_two_token2) { create(:oauth_access_token, application: app_two) } + let!(:app_three_token1) { create(:oauth_access_token, application: app_three) } + let!(:app_three_token2) { create(:oauth_access_token, application: app_three) } - it 'returns unique owners' do - expect(tokens.count).to eq(3) - expect(tokens.distinct_resource_owner_counts([app_one])).to eq({ app_one.id => 1 }) - expect(tokens.distinct_resource_owner_counts([app_two])).to eq({ app_two.id => 1 }) - expect(tokens.distinct_resource_owner_counts([app_three])).to eq({}) - expect(tokens.distinct_resource_owner_counts([app_one, app_two])) - .to eq({ - app_one.id => 1, - app_two.id => 1 - }) + it 'returns only the latest token for each application' do + expect(described_class.latest_per_application.map(&:id)) + .to match_array([app_two_token2.id, app_three_token2.id]) + end + end end end diff --git a/spec/requests/api/integrations_spec.rb b/spec/requests/api/integrations_spec.rb index a23c9b9f2ba..b2db7f7caef 100644 --- a/spec/requests/api/integrations_spec.rb +++ b/spec/requests/api/integrations_spec.rb @@ -363,6 +363,31 @@ RSpec.describe API::Integrations do end end + describe 'Jira integration' do + let(:integration_name) { 'jira' } + let(:params) do + { url: 'https://jira.example.com', username: 'username', password: 'password' } + end + + before do + project.create_jira_integration(active: true, properties: params) + end + + it 'returns the jira_issue_transition_id for get request' do + get api("/projects/#{project.id}/#{endpoint}/#{integration_name}", user) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['properties']).to include('jira_issue_transition_id' => nil) + end + + it 'returns the jira_issue_transition_id for put request' do + put api("/projects/#{project.id}/#{endpoint}/#{integration_name}", user), params: params.merge(jira_issue_transition_id: '1') + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['properties']['jira_issue_transition_id']).to eq('1') + end + end + describe 'Pipelines Email Integration' do let(:integration_name) { 'pipelines-email' } diff --git a/spec/serializers/integrations/field_entity_spec.rb b/spec/serializers/integrations/field_entity_spec.rb index e75dc051f5e..7af17cf6df6 100644 --- a/spec/serializers/integrations/field_entity_spec.rb +++ b/spec/serializers/integrations/field_entity_spec.rb @@ -114,6 +114,6 @@ RSpec.describe Integrations::FieldEntity do end def integration_field(name) - integration.global_fields.find { |f| f[:name] == name } + integration.form_fields.find { |f| f[:name] == name } end end diff --git a/spec/support/shared_examples/integrations/integration_settings_form.rb b/spec/support/shared_examples/integrations/integration_settings_form.rb index dfe5a071f91..5041ac4a660 100644 --- a/spec/support/shared_examples/integrations/integration_settings_form.rb +++ b/spec/support/shared_examples/integrations/integration_settings_form.rb @@ -20,6 +20,11 @@ RSpec.shared_examples 'integration settings form' do "#{integration.title} field #{field_name} not present" end + api_only_fields = integration.fields.select { _1[:api_only] } + api_only_fields.each do |field| + expect(page).not_to have_field("service[#{field.name}]", wait: 0) + end + sections = integration.sections events = parse_json(trigger_events_for_integration(integration)) |