diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 12:09:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 12:09:42 +0000 |
commit | 403678e00406edc8094f087ec70e00aa29e49bef (patch) | |
tree | 447d6d4967e9a11895683b27e637a50bd9fc0602 /spec | |
parent | f5050253469fc0961c02deec0e698ad62bdd9de5 (diff) | |
download | gitlab-ce-403678e00406edc8094f087ec70e00aa29e49bef.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
15 files changed, 234 insertions, 21 deletions
diff --git a/spec/frontend/static_site_editor/components/static_site_editor_spec.js b/spec/frontend/static_site_editor/components/static_site_editor_spec.js index 919763ce9fe..cde95d0a21e 100644 --- a/spec/frontend/static_site_editor/components/static_site_editor_spec.js +++ b/spec/frontend/static_site_editor/components/static_site_editor_spec.js @@ -17,11 +17,15 @@ describe('StaticSiteEditor', () => { let store; let loadContentActionMock; - const buildStore = (initialState = {}) => { + const buildStore = ({ initialState, getters } = {}) => { loadContentActionMock = jest.fn(); store = new Vuex.Store({ state: createState(initialState), + getters: { + isContentLoaded: () => false, + ...getters, + }, actions: { loadContent: loadContentActionMock, }, @@ -56,7 +60,7 @@ describe('StaticSiteEditor', () => { const content = 'edit area content'; beforeEach(() => { - buildStore({ content, isContentLoaded: true }); + buildStore({ initialState: { content }, getters: { isContentLoaded: () => true } }); buildWrapper(); }); @@ -70,7 +74,7 @@ describe('StaticSiteEditor', () => { }); it('displays skeleton loader while loading content', () => { - buildStore({ isLoadingContent: true }); + buildStore({ initialState: { isLoadingContent: true } }); buildWrapper(); expect(wrapper.find(GlSkeletonLoader).exists()).toBe(true); diff --git a/spec/frontend/static_site_editor/store/actions_spec.js b/spec/frontend/static_site_editor/store/actions_spec.js new file mode 100644 index 00000000000..98d7d0d2c2d --- /dev/null +++ b/spec/frontend/static_site_editor/store/actions_spec.js @@ -0,0 +1,76 @@ +import testAction from 'helpers/vuex_action_helper'; +import createState from '~/static_site_editor/store/state'; +import * as actions from '~/static_site_editor/store/actions'; +import * as mutationTypes from '~/static_site_editor/store/mutation_types'; +import loadSourceContent from '~/static_site_editor/services/load_source_content'; + +import createFlash from '~/flash'; + +import { + projectId, + sourcePath, + sourceContentTitle as title, + sourceContent as content, +} from '../mock_data'; + +jest.mock('~/flash'); +jest.mock('~/static_site_editor/services/load_source_content', () => jest.fn()); + +describe('Static Site Editor Store actions', () => { + let state; + + beforeEach(() => { + state = createState({ + projectId, + sourcePath, + }); + }); + + describe('loadContent', () => { + describe('on success', () => { + const payload = { title, content }; + + beforeEach(() => { + loadSourceContent.mockResolvedValueOnce(payload); + }); + + it('commits receiveContentSuccess', () => { + testAction( + actions.loadContent, + null, + state, + [ + { type: mutationTypes.LOAD_CONTENT }, + { type: mutationTypes.RECEIVE_CONTENT_SUCCESS, payload }, + ], + [], + ); + + expect(loadSourceContent).toHaveBeenCalledWith({ projectId, sourcePath }); + }); + }); + + describe('on error', () => { + const expectedMutations = [ + { type: mutationTypes.LOAD_CONTENT }, + { type: mutationTypes.RECEIVE_CONTENT_ERROR }, + ]; + + beforeEach(() => { + loadSourceContent.mockRejectedValueOnce(); + }); + + it('commits receiveContentError', () => { + testAction(actions.loadContent, null, state, expectedMutations); + }); + + it('displays flash communicating error', () => { + return testAction(actions.loadContent, null, state, expectedMutations).then(() => { + expect(createFlash).toHaveBeenCalledWith( + 'An error ocurred while loading your content. Please try again.', + ); + }); + }); + }); + }); +}); diff --git a/spec/frontend/static_site_editor/store/getters_spec.js b/spec/frontend/static_site_editor/store/getters_spec.js new file mode 100644 index 00000000000..8800216f3b0 --- /dev/null +++ b/spec/frontend/static_site_editor/store/getters_spec.js @@ -0,0 +1,15 @@ +import createState from '~/static_site_editor/store/state'; +import { isContentLoaded } from '~/static_site_editor/store/getters'; +import { sourceContent as content } from '../mock_data'; + +describe('Static Site Editor Store getters', () => { + describe('isContentLoaded', () => { + it('returns true when content is not empty', () => { + expect(isContentLoaded(createState({ content }))).toBe(true); + }); + + it('returns false when content is empty', () => { + expect(isContentLoaded(createState({ content: '' }))).toBe(false); + }); + }); +}); diff --git a/spec/frontend/static_site_editor/store/mutations_spec.js b/spec/frontend/static_site_editor/store/mutations_spec.js new file mode 100644 index 00000000000..c7055fbb2f0 --- /dev/null +++ b/spec/frontend/static_site_editor/store/mutations_spec.js @@ -0,0 +1,52 @@ +import createState from '~/static_site_editor/store/state'; +import mutations from '~/static_site_editor/store/mutations'; +import * as types from '~/static_site_editor/store/mutation_types'; +import { sourceContentTitle as title, sourceContent as content } from '../mock_data'; + +describe('Static Site Editor Store mutations', () => { + let state; + + beforeEach(() => { + state = createState(); + }); + + describe('loadContent', () => { + beforeEach(() => { + mutations[types.LOAD_CONTENT](state); + }); + + it('sets isLoadingContent to true', () => { + expect(state.isLoadingContent).toBe(true); + }); + }); + + describe('receiveContentSuccess', () => { + const payload = { title, content }; + + beforeEach(() => { + mutations[types.RECEIVE_CONTENT_SUCCESS](state, payload); + }); + + it('sets current state to LOADING', () => { + expect(state.isLoadingContent).toBe(false); + }); + + it('sets title', () => { + expect(state.title).toBe(payload.title); + }); + + it('sets content', () => { + expect(state.content).toBe(payload.content); + }); + }); + + describe('receiveContentError', () => { + beforeEach(() => { + mutations[types.RECEIVE_CONTENT_ERROR](state); + }); + + it('sets current state to LOADING_ERROR', () => { + expect(state.isLoadingContent).toBe(false); + }); + }); +}); diff --git a/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js b/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js index b53e30b6896..a1377564073 100644 --- a/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js +++ b/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js @@ -224,7 +224,7 @@ describe('AjaxFormVariableList', () => { describe('maskableRegex', () => { it('takes in the regex provided by the data attribute', () => { - expect(container.dataset.maskableRegex).toBe('^[a-zA-Z0-9_+=/@:-]{8,}$'); + expect(container.dataset.maskableRegex).toBe('^[a-zA-Z0-9_+=/@:.-]{8,}$'); expect(ajaxVariableList.maskableRegex).toBe(container.dataset.maskableRegex); }); }); diff --git a/spec/javascripts/ci_variable_list/ci_variable_list_spec.js b/spec/javascripts/ci_variable_list/ci_variable_list_spec.js index 180ba979325..c0c3a83a44b 100644 --- a/spec/javascripts/ci_variable_list/ci_variable_list_spec.js +++ b/spec/javascripts/ci_variable_list/ci_variable_list_spec.js @@ -162,7 +162,7 @@ describe('VariableList', () => { }); it('has a regex provided via a data attribute', () => { - expect($wrapper.attr('data-maskable-regex')).toBe('^[a-zA-Z0-9_+=/@:-]{8,}$'); + expect($wrapper.attr('data-maskable-regex')).toBe('^[a-zA-Z0-9_+=/@:.-]{8,}$'); }); it('allows values that are 8 characters long', done => { diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb index dcc4d277f5c..ce60a19a7b3 100644 --- a/spec/lib/gitlab/auth_spec.rb +++ b/spec/lib/gitlab/auth_spec.rb @@ -8,7 +8,7 @@ describe Gitlab::Auth, :use_clean_rails_memory_store_caching do describe 'constants' do it 'API_SCOPES contains all scopes for API access' do - expect(subject::API_SCOPES).to eq %i[api read_user] + expect(subject::API_SCOPES).to eq %i[api read_user read_api] end it 'ADMIN_SCOPES contains all scopes for ADMIN access' do @@ -30,7 +30,7 @@ describe Gitlab::Auth, :use_clean_rails_memory_store_caching do it 'optional_scopes contains all non-default scopes' do stub_container_registry_config(enabled: true) - expect(subject.optional_scopes).to eq %i[read_user read_repository write_repository read_registry sudo openid profile email] + expect(subject.optional_scopes).to eq %i[read_user read_api read_repository write_repository read_registry sudo openid profile email] end end @@ -38,21 +38,21 @@ describe Gitlab::Auth, :use_clean_rails_memory_store_caching do it 'contains all non-default scopes' do stub_container_registry_config(enabled: true) - expect(subject.all_available_scopes).to eq %i[api read_user read_repository write_repository read_registry sudo] + expect(subject.all_available_scopes).to eq %i[api read_user read_api read_repository write_repository read_registry sudo] end it 'contains for non-admin user all non-default scopes without ADMIN access' do stub_container_registry_config(enabled: true) user = create(:user, admin: false) - expect(subject.available_scopes_for(user)).to eq %i[api read_user read_repository write_repository read_registry] + expect(subject.available_scopes_for(user)).to eq %i[api read_user read_api read_repository write_repository read_registry] end it 'contains for admin user all non-default scopes with ADMIN access' do stub_container_registry_config(enabled: true) user = create(:user, admin: true) - expect(subject.available_scopes_for(user)).to eq %i[api read_user read_repository write_repository read_registry sudo] + expect(subject.available_scopes_for(user)).to eq %i[api read_user read_api read_repository write_repository read_registry sudo] end context 'registry_scopes' do diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index aaaf6458ee7..515d72add92 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -477,6 +477,7 @@ project: - export_jobs - daily_report_results - jira_imports +- compliance_framework_setting award_emoji: - awardable - user diff --git a/spec/models/ci/group_spec.rb b/spec/models/ci/group_spec.rb index 5516a1a9c61..868382e3756 100644 --- a/spec/models/ci/group_spec.rb +++ b/spec/models/ci/group_spec.rb @@ -3,12 +3,14 @@ require 'spec_helper' describe Ci::Group do + let_it_be(:project) { create(:project) } + + let!(:jobs) { build_list(:ci_build, 1, :success, project: project) } + subject do - described_class.new('test', name: 'rspec', jobs: jobs) + described_class.new(project, 'test', name: 'rspec', jobs: jobs) end - let!(:jobs) { build_list(:ci_build, 1, :success) } - it { is_expected.to include_module(StaticModel) } it { is_expected.to respond_to(:stage) } diff --git a/spec/models/concerns/ci/maskable_spec.rb b/spec/models/concerns/ci/maskable_spec.rb index 22ffb294819..01861b39165 100644 --- a/spec/models/concerns/ci/maskable_spec.rb +++ b/spec/models/concerns/ci/maskable_spec.rb @@ -61,8 +61,12 @@ describe Ci::Maskable do expect(subject.match?(string)).to eq(false) end + it 'does not match strings using unsupported characters' do + expect(subject.match?('HelloWorld%#^')).to eq(false) + end + it 'matches valid strings' do - expect(subject.match?('helloworld')).to eq(true) + expect(subject.match?('Hello+World_123/@:-.')).to eq(true) end end diff --git a/spec/requests/api/api_spec.rb b/spec/requests/api/api_spec.rb index baebbbce631..201c0d1796c 100644 --- a/spec/requests/api/api_spec.rb +++ b/spec/requests/api/api_spec.rb @@ -3,15 +3,60 @@ require 'spec_helper' describe API::API do - let(:user) { create(:user, last_activity_on: Date.yesterday) } + include GroupAPIHelpers describe 'Record user last activity in after hook' do # It does not matter which endpoint is used because last_activity_on should # be updated on every request. `/groups` is used as an example # to represent any API endpoint + let(:user) { create(:user, last_activity_on: Date.yesterday) } - it 'updates the users last_activity_on date' do + it 'updates the users last_activity_on to the current date' do expect { get api('/groups', user) }.to change { user.reload.last_activity_on }.to(Date.today) end end + + describe 'User with only read_api scope personal access token' do + # It does not matter which endpoint is used because this should behave + # in the same way for every request. `/groups` is used as an example + # to represent any API endpoint + + context 'when personal access token has only read_api scope' do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:token) { create(:personal_access_token, user: user, scopes: [:read_api]) } + + before_all do + group.add_owner(user) + end + + it 'does authorize user for get request' do + get api('/groups', personal_access_token: token) + + expect(response).to have_gitlab_http_status(:ok) + end + + it 'does not authorize user for post request' do + params = attributes_for_group_api + + post api("/groups", personal_access_token: token), params: params + + expect(response).to have_gitlab_http_status(:forbidden) + end + + it 'does not authorize user for put request' do + group_param = { name: 'Test' } + + put api("/groups/#{group.id}", personal_access_token: token), params: group_param + + expect(response).to have_gitlab_http_status(:forbidden) + end + + it 'does not authorize user for delete request' do + delete api("/groups/#{group.id}", personal_access_token: token) + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + end end diff --git a/spec/requests/openid_connect_spec.rb b/spec/requests/openid_connect_spec.rb index d7c08484dc4..bd270679acd 100644 --- a/spec/requests/openid_connect_spec.rb +++ b/spec/requests/openid_connect_spec.rb @@ -180,7 +180,7 @@ describe 'OpenID Connect requests' do expect(response).to have_gitlab_http_status(:ok) expect(json_response['issuer']).to eq('http://localhost') expect(json_response['jwks_uri']).to eq('http://www.example.com/oauth/discovery/keys') - expect(json_response['scopes_supported']).to eq(%w[api read_user read_repository write_repository sudo openid profile email]) + expect(json_response['scopes_supported']).to eq(%w[api read_user read_api read_repository write_repository sudo openid profile email]) end end diff --git a/spec/serializers/analytics_summary_serializer_spec.rb b/spec/serializers/analytics_summary_serializer_spec.rb index 06f2c0ca68b..7950f89bcc7 100644 --- a/spec/serializers/analytics_summary_serializer_spec.rb +++ b/spec/serializers/analytics_summary_serializer_spec.rb @@ -28,4 +28,18 @@ describe AnalyticsSummarySerializer do it 'contains important elements of AnalyticsStage' do expect(subject).to include(:title, :value) end + + it 'does not include unit' do + expect(subject).not_to include(:unit) + end + + context 'when representing with unit' do + let(:resource) { { title: 'frequency', value: 1.12, unit: 'per day' } } + + subject { described_class.new.represent(resource, with_unit: true) } + + it 'contains unit' do + expect(subject).to include(:unit) + end + end end diff --git a/spec/services/external_pull_requests/create_pipeline_service_spec.rb b/spec/services/ci/external_pull_requests/create_pipeline_service_spec.rb index d1893960960..5048f2b71b3 100644 --- a/spec/services/external_pull_requests/create_pipeline_service_spec.rb +++ b/spec/services/ci/external_pull_requests/create_pipeline_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ExternalPullRequests::CreatePipelineService do +describe Ci::ExternalPullRequests::CreatePipelineService do describe '#execute' do let_it_be(:project) { create(:project, :auto_devops, :repository) } let_it_be(:user) { create(:user) } diff --git a/spec/workers/update_external_pull_requests_worker_spec.rb b/spec/workers/update_external_pull_requests_worker_spec.rb index 8930a36ceb8..afac0357b2d 100644 --- a/spec/workers/update_external_pull_requests_worker_spec.rb +++ b/spec/workers/update_external_pull_requests_worker_spec.rb @@ -28,10 +28,10 @@ describe UpdateExternalPullRequestsWorker do context 'when ref is a branch' do let(:ref) { 'refs/heads/feature-1' } - let(:create_pipeline_service) { instance_double(ExternalPullRequests::CreatePipelineService) } + let(:create_pipeline_service) { instance_double(Ci::ExternalPullRequests::CreatePipelineService) } it 'runs CreatePipelineService for each pull request matching the source branch and repository' do - expect(ExternalPullRequests::CreatePipelineService) + expect(Ci::ExternalPullRequests::CreatePipelineService) .to receive(:new) .and_return(create_pipeline_service) .twice @@ -45,7 +45,7 @@ describe UpdateExternalPullRequestsWorker do let(:ref) { 'refs/tags/v1.2.3' } it 'does nothing' do - expect(ExternalPullRequests::CreatePipelineService).not_to receive(:new) + expect(Ci::ExternalPullRequests::CreatePipelineService).not_to receive(:new) subject end |