diff options
Diffstat (limited to 'spec')
25 files changed, 259 insertions, 126 deletions
diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index 2808b6181f3..1f43caf37e7 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -649,6 +649,8 @@ RSpec.describe 'Admin updates settings', feature_category: :shared do end it 'loads togglable usage ping payload on click', :js do + allow(Gitlab::Usage::ServicePingReport).to receive(:for).and_return({ uuid: '12345678', hostname: '127.0.0.1' }) + stub_usage_data_connections stub_database_flavor_check diff --git a/spec/frontend/blob/line_highlighter_spec.js b/spec/frontend/blob/line_highlighter_spec.js index 21d4e8db503..b2e1a29b84f 100644 --- a/spec/frontend/blob/line_highlighter_spec.js +++ b/spec/frontend/blob/line_highlighter_spec.js @@ -1,7 +1,7 @@ /* eslint-disable no-return-assign, no-new, no-underscore-dangle */ - import $ from 'jquery'; -import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import htmlStaticLineHighlighter from 'test_fixtures_static/line_highlighter.html'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import LineHighlighter from '~/blob/line_highlighter'; import * as utils from '~/lib/utils/common_utils'; @@ -17,7 +17,7 @@ describe('LineHighlighter', () => { }; beforeEach(() => { - loadHTMLFixture('static/line_highlighter.html'); + setHTMLFixture(htmlStaticLineHighlighter); testContext.class = new LineHighlighter(); testContext.css = testContext.class.highlightLineClass; return (testContext.spies = { diff --git a/spec/frontend/diffs/components/compare_versions_spec.js b/spec/frontend/diffs/components/compare_versions_spec.js index 23da1a3601b..47a266c2e36 100644 --- a/spec/frontend/diffs/components/compare_versions_spec.js +++ b/spec/frontend/diffs/components/compare_versions_spec.js @@ -21,6 +21,7 @@ beforeEach(() => { describe('CompareVersions', () => { let wrapper; let store; + let dispatchMock; const targetBranchName = 'tmp-wine-dev'; const { commit } = getDiffWithCommit; @@ -29,6 +30,8 @@ describe('CompareVersions', () => { store.state.diffs.commit = { ...store.state.diffs.commit, ...commitArgs }; } + dispatchMock = jest.spyOn(store, 'dispatch'); + wrapper = mount(CompareVersionsComponent, { store, propsData: { @@ -146,7 +149,7 @@ describe('CompareVersions', () => { it('renders short commit ID', () => { expect(wrapper.text()).toContain('Viewing commit'); - expect(wrapper.text()).toContain(wrapper.vm.commit.short_id); + expect(wrapper.text()).toContain(commit.short_id); }); }); @@ -204,10 +207,6 @@ describe('CompareVersions', () => { setWindowLocation(`?commit_id=${mrCommit.id}`); }); - beforeEach(() => { - jest.spyOn(wrapper.vm, 'moveToNeighboringCommit').mockImplementation(() => {}); - }); - it('uses the correct href', () => { const link = getPrevCommitNavElement(); @@ -219,7 +218,7 @@ describe('CompareVersions', () => { link.trigger('click'); await nextTick(); - expect(wrapper.vm.moveToNeighboringCommit).toHaveBeenCalledWith({ + expect(dispatchMock).toHaveBeenCalledWith('diffs/moveToNeighboringCommit', { direction: 'previous', }); }); @@ -238,10 +237,6 @@ describe('CompareVersions', () => { setWindowLocation(`?commit_id=${mrCommit.id}`); }); - beforeEach(() => { - jest.spyOn(wrapper.vm, 'moveToNeighboringCommit').mockImplementation(() => {}); - }); - it('uses the correct href', () => { const link = getNextCommitNavElement(); @@ -253,7 +248,9 @@ describe('CompareVersions', () => { link.trigger('click'); await nextTick(); - expect(wrapper.vm.moveToNeighboringCommit).toHaveBeenCalledWith({ direction: 'next' }); + expect(dispatchMock).toHaveBeenCalledWith('diffs/moveToNeighboringCommit', { + direction: 'next', + }); }); it('renders a disabled button when there is no next commit', () => { diff --git a/spec/frontend/prometheus_metrics/custom_metrics_spec.js b/spec/frontend/prometheus_metrics/custom_metrics_spec.js index 823caec0211..706f932aa8d 100644 --- a/spec/frontend/prometheus_metrics/custom_metrics_spec.js +++ b/spec/frontend/prometheus_metrics/custom_metrics_spec.js @@ -1,5 +1,5 @@ -import prometheusIntegration from 'test_fixtures/integrations/prometheus/prometheus_integration.html'; import MockAdapter from 'axios-mock-adapter'; +import prometheusIntegration from 'test_fixtures/integrations/prometheus/prometheus_integration.html'; import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import axios from '~/lib/utils/axios_utils'; import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; diff --git a/spec/frontend/prometheus_metrics/prometheus_metrics_spec.js b/spec/frontend/prometheus_metrics/prometheus_metrics_spec.js index bc796ac53ca..64cf69b7f5b 100644 --- a/spec/frontend/prometheus_metrics/prometheus_metrics_spec.js +++ b/spec/frontend/prometheus_metrics/prometheus_metrics_spec.js @@ -1,5 +1,5 @@ -import prometheusIntegration from 'test_fixtures/integrations/prometheus/prometheus_integration.html'; import MockAdapter from 'axios-mock-adapter'; +import prometheusIntegration from 'test_fixtures/integrations/prometheus/prometheus_integration.html'; import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import waitForPromises from 'helpers/wait_for_promises'; import axios from '~/lib/utils/axios_utils'; diff --git a/spec/frontend/super_sidebar/components/menu_section_spec.js b/spec/frontend/super_sidebar/components/menu_section_spec.js index 203a65d6a0d..556e07a2e31 100644 --- a/spec/frontend/super_sidebar/components/menu_section_spec.js +++ b/spec/frontend/super_sidebar/components/menu_section_spec.js @@ -10,8 +10,6 @@ describe('MenuSection component', () => { const findButton = () => wrapper.find('button'); const findCollapse = () => wrapper.getComponent(GlCollapse); const findNavItems = () => wrapper.findAllComponents(NavItem); - const findSectionTitle = () => wrapper.findByTestId('section-title'); - const createWrapper = (item, otherProps) => { wrapper = shallowMountExtended(MenuSection, { propsData: { item, ...otherProps }, @@ -70,17 +68,6 @@ describe('MenuSection component', () => { }); }); - describe('`collectionStyle` prop', () => { - const newClasses = 'gl-font-sm gl-font-weight-semibold'.split(' '); - - it('applies new classes when using new styles', () => { - createWrapper({ title: 'Asdf' }, { collectionStyle: true }); - const classes = findSectionTitle().classes(); - - newClasses.forEach((newClass) => expect(classes).toContain(newClass)); - }); - }); - describe('`separated` prop', () => { describe('by default (false)', () => { it('does not render a separator', () => { diff --git a/spec/frontend/super_sidebar/components/sidebar_menu_spec.js b/spec/frontend/super_sidebar/components/sidebar_menu_spec.js index 55483c46732..26b146f0c8b 100644 --- a/spec/frontend/super_sidebar/components/sidebar_menu_spec.js +++ b/spec/frontend/super_sidebar/components/sidebar_menu_spec.js @@ -1,6 +1,5 @@ import { mountExtended } from 'helpers/vue_test_utils_helper'; import SidebarMenu from '~/super_sidebar/components/sidebar_menu.vue'; -import MenuSection from '~/super_sidebar/components/menu_section.vue'; import { PANELS_WITH_PINS } from '~/super_sidebar/constants'; import { sidebarData } from '../mock_data'; @@ -102,10 +101,6 @@ describe('SidebarMenu component', () => { 'Also with subitems', ]); }); - - it('passes `supportsPin` to menu sections', () => { - expect(wrapper.findAllComponents(MenuSection).at(1).props('collectionStyle')).toBe(true); - }); }); describe('when the sidebar does not support pins', () => { @@ -120,10 +115,6 @@ describe('SidebarMenu component', () => { it('keeps all items as non-static', () => { expect(wrapper.vm.nonStaticItems).toEqual(menuItems); }); - - it('passes `supportsPin` to menu sections', () => { - expect(wrapper.findAllComponents(MenuSection).at(1).props('collectionStyle')).toBe(false); - }); }); }); diff --git a/spec/frontend/vue3migration/compiler_spec.js b/spec/frontend/vue3migration/compiler_spec.js new file mode 100644 index 00000000000..3623f69fe07 --- /dev/null +++ b/spec/frontend/vue3migration/compiler_spec.js @@ -0,0 +1,38 @@ +import { mount } from '@vue/test-utils'; + +import SlotsWithSameName from './components/slots_with_same_name.vue'; +import VOnceInsideVIf from './components/v_once_inside_v_if.vue'; +import KeyInsideTemplate from './components/key_inside_template.vue'; +import CommentsOnRootLevel from './components/comments_on_root_level.vue'; +import SlotWithComment from './components/slot_with_comment.vue'; +import DefaultSlotWithComment from './components/default_slot_with_comment.vue'; + +describe('Vue.js 3 compiler edge cases', () => { + it('workarounds issue #6063 when same slot is used with whitespace preserve', () => { + expect(() => mount(SlotsWithSameName)).not.toThrow(); + }); + + it('workarounds issue #7725 when v-once is used inside v-if', () => { + expect(() => mount(VOnceInsideVIf)).not.toThrow(); + }); + + it('renders vue.js 2 component when key is inside template', () => { + const wrapper = mount(KeyInsideTemplate); + expect(wrapper.text()).toBe('12345'); + }); + + it('passes attributes to component with trailing comments on root level', () => { + const wrapper = mount(CommentsOnRootLevel, { propsData: { 'data-testid': 'test' } }); + expect(wrapper.html()).toBe('<div data-testid="test"></div>'); + }); + + it('treats empty slots with comments as empty', () => { + const wrapper = mount(SlotWithComment); + expect(wrapper.html()).toBe('<div>Simple</div>'); + }); + + it('treats empty default slot with comments as empty', () => { + const wrapper = mount(DefaultSlotWithComment); + expect(wrapper.html()).toBe('<div>Simple</div>'); + }); +}); diff --git a/spec/frontend/vue3migration/components/comments_on_root_level.vue b/spec/frontend/vue3migration/components/comments_on_root_level.vue new file mode 100644 index 00000000000..78222c059d5 --- /dev/null +++ b/spec/frontend/vue3migration/components/comments_on_root_level.vue @@ -0,0 +1,5 @@ +<template> + <!-- root level comment --> + <div><slot></slot></div> + <!-- root level comment --> +</template> diff --git a/spec/frontend/vue3migration/components/default_slot_with_comment.vue b/spec/frontend/vue3migration/components/default_slot_with_comment.vue new file mode 100644 index 00000000000..d2589104a5d --- /dev/null +++ b/spec/frontend/vue3migration/components/default_slot_with_comment.vue @@ -0,0 +1,18 @@ +<script> +import Simple from './simple.vue'; + +export default { + components: { + Simple, + }, +}; +</script> +<template> + <simple> + <!-- slot comment typical for gitlab-ui, for example --> + <!-- slot comment typical for gitlab-ui, for example --> + <slot></slot> + <!-- slot comment typical for gitlab-ui, for example --> + <!-- slot comment typical for gitlab-ui, for example --> + </simple> +</template> diff --git a/spec/frontend/vue3migration/components/key_inside_template.vue b/spec/frontend/vue3migration/components/key_inside_template.vue new file mode 100644 index 00000000000..af1f46c44e6 --- /dev/null +++ b/spec/frontend/vue3migration/components/key_inside_template.vue @@ -0,0 +1,7 @@ +<template> + <div> + <template v-for="count in 5" + ><span :key="count">{{ count }}</span></template + > + </div> +</template> diff --git a/spec/frontend/vue3migration/components/simple.vue b/spec/frontend/vue3migration/components/simple.vue new file mode 100644 index 00000000000..1d9854b5b4d --- /dev/null +++ b/spec/frontend/vue3migration/components/simple.vue @@ -0,0 +1,10 @@ +<script> +export default { + name: 'Simple', +}; +</script> +<template> + <div> + <slot>{{ $options.name }}</slot> + </div> +</template> diff --git a/spec/frontend/vue3migration/components/slot_with_comment.vue b/spec/frontend/vue3migration/components/slot_with_comment.vue new file mode 100644 index 00000000000..56bb41e432f --- /dev/null +++ b/spec/frontend/vue3migration/components/slot_with_comment.vue @@ -0,0 +1,20 @@ +<script> +import Simple from './simple.vue'; + +export default { + components: { + Simple, + }, +}; +</script> +<template> + <simple> + <template #default> + <!-- slot comment typical for gitlab-ui, for example --> + <!-- slot comment typical for gitlab-ui, for example --> + <slot></slot> + <!-- slot comment typical for gitlab-ui, for example --> + <!-- slot comment typical for gitlab-ui, for example --> + </template> + </simple> +</template> diff --git a/spec/frontend/vue3migration/components/slots_with_same_name.vue b/spec/frontend/vue3migration/components/slots_with_same_name.vue new file mode 100644 index 00000000000..37604cd9f6e --- /dev/null +++ b/spec/frontend/vue3migration/components/slots_with_same_name.vue @@ -0,0 +1,14 @@ +<script> +import Simple from './simple.vue'; + +export default { + name: 'SlotsWithSameName', + components: { Simple }, +}; +</script> +<template> + <simple> + <template v-if="true" #default>{{ $options.name }}</template> + <template v-else #default>{{ $options.name }}</template> + </simple> +</template> diff --git a/spec/frontend/vue3migration/components/v_once_inside_v_if.vue b/spec/frontend/vue3migration/components/v_once_inside_v_if.vue new file mode 100644 index 00000000000..708aa7a96c2 --- /dev/null +++ b/spec/frontend/vue3migration/components/v_once_inside_v_if.vue @@ -0,0 +1,12 @@ +<script> +export default { + name: 'VOnceInsideVIf', +}; +</script> +<template> + <div> + <template v-if="true"> + <div v-once>{{ $options.name }}</div> + </template> + </div> +</template> diff --git a/spec/frontend/vue_compat_test_setup.js b/spec/frontend/vue_compat_test_setup.js index 8c0346e6198..6eba9465c80 100644 --- a/spec/frontend/vue_compat_test_setup.js +++ b/spec/frontend/vue_compat_test_setup.js @@ -63,7 +63,7 @@ if (global.document) { }; let compatH; - Vue.config.compilerOptions.whitespace = 'condense'; + Vue.config.compilerOptions.whitespace = 'preserve'; Vue.createApp({ compatConfig: { MODE: 3, diff --git a/spec/initializers/doorkeeper_openid_connect_patch_spec.rb b/spec/initializers/doorkeeper_openid_connect_patch_spec.rb deleted file mode 100644 index c04d7d95de6..00000000000 --- a/spec/initializers/doorkeeper_openid_connect_patch_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require_relative '../../config/initializers/doorkeeper_openid_connect_patch' - -RSpec.describe 'doorkeeper_openid_connect_patch', feature_category: :integrations do - describe '.signing_key' do - let(:config) { Doorkeeper::OpenidConnect::Config.new } - - before do - allow(config).to receive(:signing_key).and_return(key) - allow(config).to receive(:signing_algorithm).and_return(algorithm) - allow(Doorkeeper::OpenidConnect).to receive(:configuration).and_return(config) - end - - context 'with RS256 algorithm' do - let(:algorithm) { :RS256 } - # Taken from https://github.com/doorkeeper-gem/doorkeeper-openid_connect/blob/01903c81a2b6237a3bf576ed45864f69ef20184e/spec/dummy/config/initializers/doorkeeper_openid_connect.rb#L6-L34 - let(:key) do - <<~KEY - -----BEGIN RSA PRIVATE KEY----- - MIIEpgIBAAKCAQEAsjdnSA6UWUQQHf6BLIkIEUhMRNBJC1NN/pFt1EJmEiI88GS0 - ceROO5B5Ooo9Y3QOWJ/n+u1uwTHBz0HCTN4wgArWd1TcqB5GQzQRP4eYnWyPfi4C - feqAHzQp+v4VwbcK0LW4FqtW5D0dtrFtI281FDxLhARzkhU2y7fuYhL8fVw5rUhE - 8uwvHRZ5CEZyxf7BSHxIvOZAAymhuzNLATt2DGkDInU1BmF75tEtBJAVLzWG/j4L - PZh1EpSdfezqaXQlcy9PJi916UzTl0P7Yy+ulOdUsMlB6yo8qKTY1+AbZ5jzneHb - GDU/O8QjYvii1WDmJ60t0jXicmOkGrOhruOptwIDAQABAoIBAQChYNwMeu9IugJi - NsEf4+JDTBWMRpOuRrwcpfIvQAUPrKNEB90COPvCoju0j9OxCDmpdPtq1K/zD6xx - khlw485FVAsKufSp4+g6GJ75yT6gZtq1JtKo1L06BFFzb7uh069eeP7+wB6JxPHw - KlAqwxvsfADhxeolQUKCTMb3Vjv/Aw2cO/nn6RAOeftw2aDmFy8Xl+oTUtSxyib0 - YCdU9cK8MxsxDdmowwHp04xRTm/wfG5hLEn7HMz1PP86iP9BiFsCqTId9dxEUTS1 - K+VAt9FbxRAq5JlBocxUMHNxLigb94Ca2FOMR7F6l/tronLfHD801YoObF0fN9qW - Cgw4aTO5AoGBAOR79hiZVM7/l1cBid7hKSeMWKUZ/nrwJsVfNpu1H9xt9uDu+79U - mcGfM7pm7L2qCNGg7eeWBHq2CVg/XQacRNtcTlomFrw4tDXUkFN1hE56t1iaTs9m - dN9IDr6jFgf6UaoOxxoPT9Q1ZtO46l043Nzrkoz8cBEBaBY20bUDwCYjAoGBAMet - tt1ImGF1cx153KbOfjl8v54VYUVkmRNZTa1E821nL/EMpoONSqJmRVsX7grLyPL1 - QyZe245NOvn63YM0ng0rn2osoKsMVJwYBEYjHL61iF6dPtW5p8FIs7auRnC3NrG0 - XxHATZ4xhHD0iIn14iXh0XIhUVk+nGktHU1gbmVdAoGBANniwKdqqS6RHKBTDkgm - Dhnxw6MGa+CO3VpA1xGboxuRHeoY3KfzpIC5MhojBsZDvQ8zWUwMio7+w2CNZEfm - g99wYiOjyPCLXocrAssj+Rzh97AdzuQHf5Jh4/W2Dk9jTbdPSl02ltj2Z+2lnJFz - pWNjnqimHrSI09rDQi5NulJjAoGBAImquujVpDmNQFCSNA7NTzlTSMk09FtjgCZW - 67cKUsqa2fLXRfZs84gD+s1TMks/NMxNTH6n57e0h3TSAOb04AM0kDQjkKJdXfhA - lrHEg4z4m4yf3TJ9Tat09HJ+tRIBPzRFp0YVz23Btg4qifiUDdcQWdbWIb/l6vCY - qhsu4O4BAoGBANbceYSDYRdT7a5QjJGibkC90Z3vFe4rDTBgZWg7xG0cpSU4JNg7 - SFR3PjWQyCg7aGGXiooCM38YQruACTj0IFub24MFRA4ZTXvrACvpsVokJlQiG0Z4 - tuQKYki41JvYqPobcq/rLE/AM7PKJftW35nqFuj0MrsUwPacaVwKBf5J - -----END RSA PRIVATE KEY----- - KEY - end - - it 'returns the private key as JWK instance' do - expect(Doorkeeper::OpenidConnect.signing_key).to be_a ::JWT::JWK::KeyBase - expect(Doorkeeper::OpenidConnect.signing_key.kid).to eq 'IqYwZo2cE6hsyhs48cU8QHH4GanKIx0S4Dc99kgTIMA' - end - - it 'matches json-jwt implementation' do - json_jwt_key = OpenSSL::PKey::RSA.new(key).public_key.to_jwk.slice(:kty, :kid, :e, :n) - expect(Doorkeeper::OpenidConnect.signing_key.export.sort.to_json).to eq(json_jwt_key.sort.to_json) - end - end - - context 'with HS512 algorithm' do - let(:algorithm) { :HS512 } - let(:key) { 'the_greatest_secret_key' } - - it 'returns the HMAC public key parameters' do - expect(Doorkeeper::OpenidConnect.signing_key_normalized).to eq( - kty: 'oct', - kid: 'lyAW7LdxryFWQtLdgxZpOrI87APHrzJKgWLT0BkWVog' - ) - end - end - end -end diff --git a/spec/lib/gitlab/github_import/importer/pull_requests_merged_by_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests/all_merged_by_importer_spec.rb index b6c162aafa9..8e13b35eb6b 100644 --- a/spec/lib/gitlab/github_import/importer/pull_requests_merged_by_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_requests/all_merged_by_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Importer::PullRequestsMergedByImporter do +RSpec.describe Gitlab::GithubImport::Importer::PullRequests::AllMergedByImporter, feature_category: :importers do let(:client) { double } let_it_be(:project) { create(:project, import_source: 'http://somegithub.com') } @@ -16,7 +16,11 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsMergedByImporter do end describe '#importer_class' do - it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequestMergedByImporter) } + it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequests::MergedByImporter) } + end + + describe '#sidekiq_worker_class' do + it { expect(subject.sidekiq_worker_class).to eq(Gitlab::GithubImport::PullRequests::ImportMergedByWorker) } end describe '#collection_method' do @@ -24,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsMergedByImporter do end describe '#id_for_already_imported_cache' do - it { expect(subject.id_for_already_imported_cache(double(id: 1))).to eq(1) } + it { expect(subject.id_for_already_imported_cache(instance_double(MergeRequest, id: 1))).to eq(1) } end describe '#each_object_to_import', :clean_gitlab_redis_cache do @@ -44,7 +48,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsMergedByImporter do expect { |b| subject.each_object_to_import(&b) } .to yield_with_args(pull_request) - subject.each_object_to_import {} + subject.each_object_to_import end it 'skips cached merge requests' do @@ -55,7 +59,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsMergedByImporter do expect(client).not_to receive(:pull_request) - subject.each_object_to_import {} + subject.each_object_to_import end end end diff --git a/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests/merged_by_importer_spec.rb index 01d706beea2..25381594632 100644 --- a/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/pull_requests/merged_by_importer_spec.rb @@ -2,12 +2,16 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Importer::PullRequestMergedByImporter, :clean_gitlab_redis_cache do +RSpec.describe Gitlab::GithubImport::Importer::PullRequests::MergedByImporter, + :clean_gitlab_redis_cache, feature_category: :importers do let_it_be(:merge_request) { create(:merged_merge_request) } let(:project) { merge_request.project } - let(:merged_at) { Time.new(2017, 1, 1, 12, 00).utc } - let(:client_double) { double(user: { id: 999, login: 'merger', email: 'merger@email.com' } ) } + let(:merged_at) { Time.utc(2017, 1, 1, 12) } + let(:client_double) do + instance_double(Gitlab::GithubImport::Client, user: { id: 999, login: 'merger', email: 'merger@email.com' }) + end + let(:merger_user) { { id: 999, login: 'merger' } } let(:pull_request) do @@ -25,7 +29,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestMergedByImporter, :cle shared_examples 'adds a note referencing the merger user' do it 'adds a note referencing the merger user' do expect { subject.execute } - .to change(Note, :count).by(1) + .to change { Note.count }.by(1) .and not_change(merge_request, :updated_at) metrics = merge_request.metrics.reload @@ -68,7 +72,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestMergedByImporter, :cle it 'adds a note referencing the merger user' do expect { subject.execute } - .to change(Note, :count).by(1) + .to change { Note.count }.by(1) .and not_change(merge_request, :updated_at) metrics = merge_request.metrics.reload diff --git a/spec/requests/groups/achievements_controller_spec.rb b/spec/requests/groups/achievements_controller_spec.rb new file mode 100644 index 00000000000..26ca0039984 --- /dev/null +++ b/spec/requests/groups/achievements_controller_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::AchievementsController, feature_category: :user_profile do + let_it_be(:user) { create(:user) } + + shared_examples 'response with 404 status' do + it 'returns 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + shared_examples 'ok response with index template' do + it 'renders the index template' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:index) + end + end + + shared_examples 'ok response with index template if authorized' do + context 'with a private group' do + let(:group) { create(:group, :private) } + + context 'with authorized user' do + before do + group.add_guest(user) + sign_in(user) + end + + it_behaves_like 'ok response with index template' + + context 'when achievements ff is disabled' do + before do + stub_feature_flags(achievements: false) + end + + it_behaves_like 'response with 404 status' + end + end + + context 'with unauthorized user' do + before do + sign_in(user) + end + + it_behaves_like 'response with 404 status' + end + + context 'with anonymous user' do + it 'redirects to sign_in page' do + subject + + expect(response).to have_gitlab_http_status(:found) + expect(response).to redirect_to(new_user_session_path) + end + end + end + + context 'with a public group' do + let(:group) { create(:group, :public) } + + context 'with anonymous user' do + it_behaves_like 'ok response with index template' + end + end + end + + describe 'GET #index' do + subject { get group_achievements_path(group) } + + it_behaves_like 'ok response with index template if authorized' + end +end diff --git a/spec/serializers/import/github_failure_entity_spec.rb b/spec/serializers/import/github_failure_entity_spec.rb index 357eae91b28..0de710f22cc 100644 --- a/spec/serializers/import/github_failure_entity_spec.rb +++ b/spec/serializers/import/github_failure_entity_spec.rb @@ -62,7 +62,7 @@ RSpec.describe Import::GithubFailureEntity, feature_category: :importers do end it_behaves_like 'import failure entity' do - let(:source) { 'Gitlab::GithubImport::Importer::PullRequestMergedByImporter' } + let(:source) { 'Gitlab::GithubImport::Importer::PullRequests::MergedByImporter' } let(:title) { 'Pull request 2 merger' } let(:provider_url) { 'https://github.com/example/repo/pull/2' } end diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb index 2c2cd7e9960..9fada09263c 100644 --- a/spec/workers/every_sidekiq_worker_spec.rb +++ b/spec/workers/every_sidekiq_worker_spec.rb @@ -277,6 +277,7 @@ RSpec.describe 'Every Sidekiq worker', feature_category: :shared do 'Gitlab::GithubImport::ImportPullRequestReviewWorker' => 5, 'Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker' => 5, 'Gitlab::GithubImport::PullRequests::ImportReviewWorker' => 5, + 'Gitlab::GithubImport::PullRequests::ImportMergedByWorker' => 5, 'Gitlab::GithubImport::ImportPullRequestWorker' => 5, 'Gitlab::GithubImport::RefreshImportJidWorker' => 5, 'Gitlab::GithubImport::Stage::FinishImportWorker' => 5, diff --git a/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb index 6f771a1b79d..4fbdfb1903f 100644 --- a/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb @@ -10,6 +10,6 @@ RSpec.describe Gitlab::GithubImport::ImportPullRequestMergedByWorker, feature_ca end describe '#importer_class' do - it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequestMergedByImporter) } + it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequests::MergedByImporter) } end end diff --git a/spec/workers/gitlab/github_import/pull_requests/import_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/pull_requests/import_merged_by_worker_spec.rb new file mode 100644 index 00000000000..23631c76a61 --- /dev/null +++ b/spec/workers/gitlab/github_import/pull_requests/import_merged_by_worker_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::PullRequests::ImportMergedByWorker, feature_category: :importers do + it { is_expected.to include_module(Gitlab::GithubImport::ObjectImporter) } + + describe '#representation_class' do + it { expect(subject.representation_class).to eq(Gitlab::GithubImport::Representation::PullRequest) } + end + + describe '#importer_class' do + it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequests::MergedByImporter) } + end + + describe '#object_type' do + it { expect(subject.object_type).to eq(:pull_request_merged_by) } + end +end diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb index 4ffc5a956a3..0debabda0cc 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker, fe client = double(:client) waiter = Gitlab::JobWaiter.new(2, '123') - expect(Gitlab::GithubImport::Importer::PullRequestsMergedByImporter) + expect(Gitlab::GithubImport::Importer::PullRequests::AllMergedByImporter) .to receive(:new) .with(project, client) .and_return(importer) |