diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-24 15:11:29 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-24 15:11:29 +0000 |
commit | cb9b55e662d4164d913ef7031adc135d3ea4d9f0 (patch) | |
tree | 0da3d639eb5f981cc73f3c72648351e56fedd971 /spec | |
parent | d5f67e75b6ef8ebc1b304589005ccd91ea6674ff (diff) | |
download | gitlab-ce-cb9b55e662d4164d913ef7031adc135d3ea4d9f0.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
11 files changed, 151 insertions, 29 deletions
diff --git a/spec/frontend/analytics/shared/components/daterange_spec.js b/spec/frontend/analytics/shared/components/daterange_spec.js index 7a09fe3319d..562e86529ee 100644 --- a/spec/frontend/analytics/shared/components/daterange_spec.js +++ b/spec/frontend/analytics/shared/components/daterange_spec.js @@ -77,7 +77,7 @@ describe('Daterange component', () => { it('sets the tooltip', () => { const tooltip = findDaterangePicker().props('tooltip'); expect(tooltip).toBe( - 'Showing data for workflow items created in this date range. Date range limited to 30 days.', + 'Showing data for workflow items completed in this date range. Date range limited to 30 days.', ); }); }); diff --git a/spec/frontend/projects/settings/repository/branch_rules/app_spec.js b/spec/frontend/projects/settings/repository/branch_rules/app_spec.js index 4603436c40a..6369f04781f 100644 --- a/spec/frontend/projects/settings/repository/branch_rules/app_spec.js +++ b/spec/frontend/projects/settings/repository/branch_rules/app_spec.js @@ -52,6 +52,10 @@ describe('Branch rules app', () => { expect(findAllBranchRules().at(0).props('name')).toBe(nodes[0].name); + expect(findAllBranchRules().at(0).props('branchProtection')).toEqual(nodes[0].branchProtection); + expect(findAllBranchRules().at(1).props('name')).toBe(nodes[1].name); + + expect(findAllBranchRules().at(1).props('branchProtection')).toEqual(nodes[1].branchProtection); }); }); diff --git a/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js b/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js index 2bc705f538b..ab29189489e 100644 --- a/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js +++ b/spec/frontend/projects/settings/repository/branch_rules/components/branch_rule_spec.js @@ -2,7 +2,11 @@ import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import BranchRule, { i18n, } from '~/projects/settings/repository/branch_rules/components/branch_rule.vue'; -import { branchRuleProvideMock, branchRulePropsMock } from '../mock_data'; +import { + branchRuleProvideMock, + branchRulePropsMock, + branchRuleWithoutDetailsPropsMock, +} from '../mock_data'; describe('Branch rule', () => { let wrapper; @@ -45,17 +49,13 @@ describe('Branch rule', () => { }); it('does not render the protection details list of no details are present', () => { - createComponent({ approvalDetails: null }); + createComponent(branchRuleWithoutDetailsPropsMock); expect(findProtectionDetailsList().exists()).toBe(false); }); it('renders the protection details list items', () => { - expect(findProtectionDetailsListItems().at(0).text()).toBe( - branchRulePropsMock.approvalDetails[0], - ); - expect(findProtectionDetailsListItems().at(1).text()).toBe( - branchRulePropsMock.approvalDetails[1], - ); + expect(findProtectionDetailsListItems().at(0).text()).toBe(wrapper.vm.approvalDetails[0]); + expect(findProtectionDetailsListItems().at(1).text()).toBe(wrapper.vm.approvalDetails[1]); }); it('renders a detail button with the correct href', () => { diff --git a/spec/frontend/projects/settings/repository/branch_rules/mock_data.js b/spec/frontend/projects/settings/repository/branch_rules/mock_data.js index bac82992c4d..2a55dd7e835 100644 --- a/spec/frontend/projects/settings/repository/branch_rules/mock_data.js +++ b/spec/frontend/projects/settings/repository/branch_rules/mock_data.js @@ -8,10 +8,18 @@ export const branchRulesMockResponse = { nodes: [ { name: 'main', + branchProtection: { + allowForcePush: true, + codeOwnerApprovalRequired: true, + }, __typename: 'BranchRule', }, { name: 'test-*', + branchProtection: { + allowForcePush: false, + codeOwnerApprovalRequired: false, + }, __typename: 'BranchRule', }, ], @@ -32,5 +40,18 @@ export const branchRulePropsMock = { name: 'main', isDefault: true, isProtected: true, - approvalDetails: ['requires approval from TEST', '2 status checks'], + branchProtection: { + allowForcePush: true, + codeOwnerApprovalRequired: true, + }, +}; + +export const branchRuleWithoutDetailsPropsMock = { + name: 'main', + isDefault: false, + isProtected: false, + branchProtection: { + allowForcePush: false, + codeOwnerApprovalRequired: false, + }, }; diff --git a/spec/requests/groups/settings/access_tokens_controller_spec.rb b/spec/requests/groups/settings/access_tokens_controller_spec.rb index cf728b3935f..0d3f0dbe6e0 100644 --- a/spec/requests/groups/settings/access_tokens_controller_spec.rb +++ b/spec/requests/groups/settings/access_tokens_controller_spec.rb @@ -27,11 +27,21 @@ RSpec.describe Groups::Settings::AccessTokensController do end describe 'GET /:namespace/-/settings/access_tokens' do - subject do + let(:get_access_tokens) do get group_settings_access_tokens_path(resource) response end + let(:get_access_tokens_json) do + get group_settings_access_tokens_path(resource), params: { format: :json } + response + end + + subject(:get_access_tokens_with_page) do + get group_settings_access_tokens_path(resource), params: { page: 1 } + response + end + it_behaves_like 'feature unavailable' it_behaves_like 'GET resource access tokens available' end diff --git a/spec/requests/projects/settings/access_tokens_controller_spec.rb b/spec/requests/projects/settings/access_tokens_controller_spec.rb index 48114834c65..5fe97ef8ebc 100644 --- a/spec/requests/projects/settings/access_tokens_controller_spec.rb +++ b/spec/requests/projects/settings/access_tokens_controller_spec.rb @@ -28,11 +28,21 @@ RSpec.describe Projects::Settings::AccessTokensController do end describe 'GET /:namespace/:project/-/settings/access_tokens' do - subject do + let(:get_access_tokens) do get project_settings_access_tokens_path(resource) response end + let(:get_access_tokens_json) do + get project_settings_access_tokens_path(resource), params: { format: :json } + response + end + + subject(:get_access_tokens_with_page) do + get project_settings_access_tokens_path(resource), params: { page: 1 } + response + end + it_behaves_like 'feature unavailable' it_behaves_like 'GET resource access tokens available' end diff --git a/spec/scripts/lib/glfm/update_specification_spec.rb b/spec/scripts/lib/glfm/update_specification_spec.rb index 852b2b580e6..83af7cc7ca9 100644 --- a/spec/scripts/lib/glfm/update_specification_spec.rb +++ b/spec/scripts/lib/glfm/update_specification_spec.rb @@ -113,8 +113,7 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do before do # Mock default ENV var values - allow(ENV).to receive(:[]).with('UPDATE_GHFM_SPEC_MD').and_return(nil) - allow(ENV).to receive(:[]).and_call_original + stub_env('UPDATE_GHFM_SPEC_MD') # We mock out the URI and local file IO objects with real StringIO, instead of just mock # objects. This gives better and more realistic coverage, while still avoiding @@ -166,7 +165,7 @@ RSpec.describe Glfm::UpdateSpecification, '#process' do let(:ghfm_spec_txt_local_io) { StringIO.new } before do - allow(ENV).to receive(:[]).with('UPDATE_GHFM_SPEC_MD').and_return('true') + stub_env('UPDATE_GHFM_SPEC_MD', 'true') allow(File).to receive(:open).with(ghfm_spec_md_path, 'w') { ghfm_spec_txt_local_io } end diff --git a/spec/support/database/multiple_databases.rb b/spec/support/database/multiple_databases.rb index b863767b5df..b6341c2caec 100644 --- a/spec/support/database/multiple_databases.rb +++ b/spec/support/database/multiple_databases.rb @@ -2,15 +2,6 @@ module Database module MultipleDatabases - def run_and_cleanup(example) - # Each example may call `migrate!`, so we must ensure we are migrated down every time - schema_migrate_down! - - example.run - - delete_from_all_tables!(except: deletion_except_tables) - end - def skip_if_multiple_databases_not_setup skip 'Skipping because multiple databases not set up' unless Gitlab::Database.has_config?(:ci) end @@ -40,10 +31,15 @@ module Database config_model: base_model ) - schema_migrate_up! delete_from_all_tables!(except: deletion_except_tables) + schema_migrate_up! end end + + # ActiveRecord::Base.clear_all_connections! disconnects and clears attribute methods + # Force a refresh to avoid schema failures. + reset_column_in_all_models + refresh_attribute_methods end # The usage of this method switches temporarily used `connection_handler` @@ -152,10 +148,10 @@ RSpec.configure do |config| config_model: base_model ) - run_and_cleanup(example) + example.run end else - run_and_cleanup(example) + example.run end self.class.use_transactional_tests = true diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 7bd1f0c5dfa..222cbe9feeb 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -22,4 +22,14 @@ RSpec.configure do |config| self.class.use_transactional_tests = true end + + config.around(:each, :migration) do |example| + self.class.use_transactional_tests = false + + example.run + + delete_from_all_tables!(except: deletion_except_tables) + + self.class.use_transactional_tests = true + end end diff --git a/spec/support/migration.rb b/spec/support/migration.rb index 24e2fc2ff31..490aa836d74 100644 --- a/spec/support/migration.rb +++ b/spec/support/migration.rb @@ -19,6 +19,8 @@ RSpec.configure do |config| # Each example may call `migrate!`, so we must ensure we are migrated down every time config.before(:each, :migration) do use_fake_application_settings + + schema_migrate_down! end config.after(:context, :migration) do diff --git a/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb b/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb index 59e641e2af6..c83abdea0eb 100644 --- a/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb +++ b/spec/support/shared_examples/requests/access_tokens_controller_shared_examples.rb @@ -4,7 +4,7 @@ RSpec.shared_examples 'GET resource access tokens available' do let_it_be(:active_resource_access_token) { create(:personal_access_token, user: bot_user) } it 'retrieves active resource access tokens' do - subject + get_access_tokens token_entities = assigns(:active_resource_access_tokens) expect(token_entities.length).to eq(1) @@ -12,10 +12,80 @@ RSpec.shared_examples 'GET resource access tokens available' do end it 'lists all available scopes' do - subject + get_access_tokens expect(assigns(:scopes)).to eq(Gitlab::Auth.resource_bot_scopes) end + + it 'returns for json response' do + get_access_tokens_json + + expect(json_response.count).to eq(1) + end + + context "when access_tokens are paginated" do + before do + allow(Kaminari.config).to receive(:default_per_page).and_return(1) + create(:personal_access_token, user: bot_user) + end + + it "returns paginated response", :aggregate_failures do + get_access_tokens_with_page + expect(assigns(:active_resource_access_tokens).count).to eq(1) + + expect_header('X-Per-Page', '1') + expect_header('X-Page', '1') + expect_header('X-Next-Page', '2') + expect_header('X-Total', '2') + end + end + + context "when access_token_pagination feature flag is disabled" do + before do + stub_feature_flags(access_token_pagination: false) + create(:personal_access_token, user: bot_user) + end + + it "returns all tokens in system" do + get_access_tokens_with_page + expect(assigns(:active_resource_access_tokens).count).to eq(2) + end + end + + context "as tokens returned are ordered" do + let(:expires_1_day_from_now) { 1.day.from_now.to_date } + let(:expires_2_day_from_now) { 2.days.from_now.to_date } + + before do + create(:personal_access_token, user: bot_user, name: "Token1", expires_at: expires_1_day_from_now) + create(:personal_access_token, user: bot_user, name: "Token2", expires_at: expires_2_day_from_now) + end + + it "orders token list ascending on expires_at" do + get_access_tokens + + first_token = assigns(:active_resource_access_tokens).first.as_json + expect(first_token['name']).to eq("Token1") + expect(first_token['expires_at']).to eq(expires_1_day_from_now.strftime("%Y-%m-%d")) + end + + it "orders tokens on id in case token has same expires_at" do + create(:personal_access_token, user: bot_user, name: "Token3", expires_at: expires_1_day_from_now) + get_access_tokens + + first_token = assigns(:active_resource_access_tokens).first.as_json + expect(first_token['name']).to eq("Token3") + expect(first_token['expires_at']).to eq(expires_1_day_from_now.strftime("%Y-%m-%d")) + + second_token = assigns(:active_resource_access_tokens).second.as_json + expect(second_token['name']).to eq("Token1") + expect(second_token['expires_at']).to eq(expires_1_day_from_now.strftime("%Y-%m-%d")) + end + end + + def expect_header(header_name, header_val) + expect(response.headers[header_name]).to eq(header_val) + end end RSpec.shared_examples 'POST resource access tokens available' do |