diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/serializers | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/serializers')
13 files changed, 268 insertions, 46 deletions
diff --git a/spec/serializers/deploy_keys/basic_deploy_key_entity_spec.rb b/spec/serializers/deploy_keys/basic_deploy_key_entity_spec.rb index c39eb14e339..7ea72351594 100644 --- a/spec/serializers/deploy_keys/basic_deploy_key_entity_spec.rb +++ b/spec/serializers/deploy_keys/basic_deploy_key_entity_spec.rb @@ -6,8 +6,8 @@ RSpec.describe DeployKeys::BasicDeployKeyEntity do include RequestAwareEntity let(:user) { create(:user) } - let(:project) { create(:project, :internal)} - let(:project_private) { create(:project, :private)} + let(:project) { create(:project, :internal) } + let(:project_private) { create(:project, :private) } let(:deploy_key) { create(:deploy_key) } let(:options) { { user: user } } diff --git a/spec/serializers/deploy_keys/deploy_key_entity_spec.rb b/spec/serializers/deploy_keys/deploy_key_entity_spec.rb index e989aa8656c..7719cafae11 100644 --- a/spec/serializers/deploy_keys/deploy_key_entity_spec.rb +++ b/spec/serializers/deploy_keys/deploy_key_entity_spec.rb @@ -6,8 +6,8 @@ RSpec.describe DeployKeys::DeployKeyEntity do include RequestAwareEntity let(:user) { create(:user) } - let(:project) { create(:project, :internal)} - let(:project_private) { create(:project, :private)} + let(:project) { create(:project, :internal) } + let(:project_private) { create(:project, :private) } let(:deploy_key) { create(:deploy_key) } let(:options) { { user: user } } diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index 05644dad151..01d1e47b5bb 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -101,6 +101,37 @@ RSpec.describe EnvironmentSerializer do expect(subject.third[:latest][:environment_type]).to be_nil end end + + context 'when folders and standalone environments share the same name' do + before do + create(:environment, project: project, name: 'staging/my-review-1') + create(:environment, project: project, name: 'staging/my-review-2') + create(:environment, project: project, name: 'production/my-review-3') + create(:environment, project: project, name: 'staging') + create(:environment, project: project, name: 'testing') + end + + it 'does not group standalone environments with folders that have the same name' do + expect(subject.count).to eq 4 + + expect(subject.first[:name]).to eq 'production' + expect(subject.first[:size]).to eq 1 + expect(subject.first[:latest][:name]).to eq 'production/my-review-3' + expect(subject.first[:latest][:environment_type]).to eq 'production' + expect(subject.second[:name]).to eq 'staging' + expect(subject.second[:size]).to eq 1 + expect(subject.second[:latest][:name]).to eq 'staging' + expect(subject.second[:latest][:environment_type]).to be_nil + expect(subject.third[:name]).to eq 'staging' + expect(subject.third[:size]).to eq 2 + expect(subject.third[:latest][:name]).to eq 'staging/my-review-2' + expect(subject.third[:latest][:environment_type]).to eq 'staging' + expect(subject.fourth[:name]).to eq 'testing' + expect(subject.fourth[:size]).to eq 1 + expect(subject.fourth[:latest][:name]).to eq 'testing' + expect(subject.fourth[:latest][:environment_type]).to be_nil + end + end end context 'when used with pagination' do diff --git a/spec/serializers/group_access_token_entity_spec.rb b/spec/serializers/group_access_token_entity_spec.rb new file mode 100644 index 00000000000..39b587c7df7 --- /dev/null +++ b/spec/serializers/group_access_token_entity_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GroupAccessTokenEntity do + let_it_be(:group) { create(:group) } + let_it_be(:bot) { create(:user, :project_bot) } + let_it_be(:token) { create(:personal_access_token, user: bot) } + + subject(:json) { described_class.new(token, group: group).as_json } + + context 'when bot is a member of the group' do + before do + group.add_developer(bot) + end + + it 'has the correct attributes' do + expected_revoke_path = Gitlab::Routing.url_helpers + .revoke_group_settings_access_token_path( + { id: token, + group_id: group.path }) + + expect(json).to( + include( + id: token.id, + name: token.name, + scopes: token.scopes, + user_id: token.user_id, + revoke_path: expected_revoke_path, + access_level: ::Gitlab::Access::DEVELOPER + )) + + expect(json).not_to include(:token) + end + end + + context 'when bot is unrelated to the group' do + it 'has the correct attributes' do + expected_revoke_path = Gitlab::Routing.url_helpers + .revoke_group_settings_access_token_path( + { id: token, + group_id: group.path }) + + expect(json).to( + include( + id: token.id, + name: token.name, + scopes: token.scopes, + user_id: token.user_id, + revoke_path: expected_revoke_path, + access_level: nil + )) + + expect(json).not_to include(:token) + end + end +end diff --git a/spec/serializers/group_access_token_serializer_spec.rb b/spec/serializers/group_access_token_serializer_spec.rb new file mode 100644 index 00000000000..3b12c3115c9 --- /dev/null +++ b/spec/serializers/group_access_token_serializer_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GroupAccessTokenSerializer do + let_it_be(:group) { create(:group) } + let_it_be(:bot) { create(:user, :project_bot) } + + subject(:serializer) { described_class.new } + + before do + group.add_developer(bot) + end + + describe '#represent' do + it 'can render a single token' do + token = create(:personal_access_token, user: bot) + + expect(serializer.represent(token, group: group)).to be_kind_of(Hash) + end + + it 'can render a collection of tokens' do + tokens = create_list(:personal_access_token, 2, user: bot) + + expect(serializer.represent(tokens, group: group)).to be_kind_of(Array) + end + end +end diff --git a/spec/serializers/integrations/project_entity_spec.rb b/spec/serializers/integrations/project_entity_spec.rb index 1564f7fad63..ac633d1d5c6 100644 --- a/spec/serializers/integrations/project_entity_spec.rb +++ b/spec/serializers/integrations/project_entity_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Integrations::ProjectEntity do it 'contains needed attributes' do expect(subject).to include( + id: project.id, avatar_url: include('uploads'), name: project.name, full_path: project_path(project), diff --git a/spec/serializers/issue_entity_spec.rb b/spec/serializers/issue_entity_spec.rb index 6b9c703c627..9335ca61b7d 100644 --- a/spec/serializers/issue_entity_spec.rb +++ b/spec/serializers/issue_entity_spec.rb @@ -39,6 +39,13 @@ RSpec.describe IssueEntity do expect(subject).to include(:time_estimate, :total_time_spent, :human_time_estimate, :human_total_time_spent) end + describe 'current_user' do + it 'has the exprected permissions' do + expect(subject[:current_user]).to include(:can_create_note, :can_update, :can_set_issue_metadata, + :can_award_emoji) + end + end + context 'when issue got moved' do let(:public_project) { create(:project, :public) } let(:member) { create(:user) } diff --git a/spec/serializers/merge_request_poll_widget_entity_spec.rb b/spec/serializers/merge_request_poll_widget_entity_spec.rb index 409585e52f1..90a82d16e38 100644 --- a/spec/serializers/merge_request_poll_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb @@ -184,38 +184,8 @@ RSpec.describe MergeRequestPollWidgetEntity do end describe '#mergeable_discussions_state?' do - context 'when change_response_code_merge_status is true' do - before do - stub_feature_flags(change_response_code_merge_status: true) - end - - it 'returns mergeable discussions state' do - expect(subject[:mergeable_discussions_state]).to eq(true) - end - end - - context 'when change_response_code_merge_status is false' do - context 'when merge request is in a mergeable state' do - before do - stub_feature_flags(change_response_code_merge_status: false) - allow(resource).to receive(:mergeable_discussions_state?).and_return(true) - end - - it 'returns mergeable discussions state' do - expect(subject[:mergeable_discussions_state]).to eq(true) - end - end - - context 'when merge request is not in a mergeable state' do - before do - stub_feature_flags(change_response_code_merge_status: false) - allow(resource).to receive(:mergeable_state?).and_return(false) - end - - it 'returns mergeable discussions state' do - expect(subject[:mergeable_discussions_state]).to eq(false) - end - end + it 'returns mergeable discussions state' do + expect(subject[:mergeable_discussions_state]).to eq(true) end end end diff --git a/spec/serializers/merge_request_user_entity_spec.rb b/spec/serializers/merge_request_user_entity_spec.rb index 7877356ff0f..5c7120ab6a4 100644 --- a/spec/serializers/merge_request_user_entity_spec.rb +++ b/spec/serializers/merge_request_user_entity_spec.rb @@ -18,8 +18,7 @@ RSpec.describe MergeRequestUserEntity do it 'exposes needed attributes' do is_expected.to include( :id, :name, :username, :state, :avatar_url, :web_url, - :can_merge, :can_update_merge_request, :reviewed, :approved, - :attention_requested + :can_merge, :can_update_merge_request, :reviewed, :approved ) end @@ -57,14 +56,6 @@ RSpec.describe MergeRequestUserEntity do end end - context 'attention_requested' do - before do - merge_request.find_assignee(user).update!(state: :attention_requested) - end - - it { is_expected.to include(attention_requested: true ) } - end - describe 'performance' do let_it_be(:user_a) { create(:user) } let_it_be(:user_b) { create(:user) } diff --git a/spec/serializers/personal_access_token_entity_spec.rb b/spec/serializers/personal_access_token_entity_spec.rb new file mode 100644 index 00000000000..8a77a4e0036 --- /dev/null +++ b/spec/serializers/personal_access_token_entity_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe PersonalAccessTokenEntity do + let_it_be(:user) { create(:user) } + let_it_be(:token) { create(:personal_access_token, user: user) } + + subject(:json) { described_class.new(token).as_json } + + it 'has the correct attributes' do + expected_revoke_path = Gitlab::Routing.url_helpers + .revoke_profile_personal_access_token_path( + { id: token }) + + expect(json).to( + include( + id: token.id, + name: token.name, + scopes: token.scopes, + user_id: token.user_id, + revoke_path: expected_revoke_path + )) + + expect(json).not_to include(:token) + end +end diff --git a/spec/serializers/personal_access_token_serializer_spec.rb b/spec/serializers/personal_access_token_serializer_spec.rb new file mode 100644 index 00000000000..e4adc6abccb --- /dev/null +++ b/spec/serializers/personal_access_token_serializer_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe PersonalAccessTokenSerializer do + subject(:serializer) { described_class.new } + + describe '#represent' do + it 'can render a single token' do + token = create(:personal_access_token) + + expect(serializer.represent(token)).to be_kind_of(Hash) + end + + it 'can render a collection of tokens' do + tokens = create_list(:personal_access_token, 2) + + expect(serializer.represent(tokens)).to be_kind_of(Array) + end + end +end diff --git a/spec/serializers/project_access_token_entity_spec.rb b/spec/serializers/project_access_token_entity_spec.rb new file mode 100644 index 00000000000..616aa45e9d5 --- /dev/null +++ b/spec/serializers/project_access_token_entity_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ProjectAccessTokenEntity do + let_it_be(:project) { create(:project) } + let_it_be(:bot) { create(:user, :project_bot) } + let_it_be(:token) { create(:personal_access_token, user: bot) } + + subject(:json) { described_class.new(token, project: project).as_json } + + context 'when bot is a member of the project' do + before do + project.add_developer(bot) + end + + it 'has the correct attributes' do + expected_revoke_path = Gitlab::Routing.url_helpers + .revoke_namespace_project_settings_access_token_path( + { id: token, + namespace_id: project.namespace.path, + project_id: project.path }) + + expect(json).to( + include( + id: token.id, + name: token.name, + scopes: token.scopes, + user_id: token.user_id, + revoke_path: expected_revoke_path, + access_level: ::Gitlab::Access::DEVELOPER + )) + + expect(json).not_to include(:token) + end + end + + context 'when bot is unrelated to the project' do + let_it_be(:project) { create(:project) } + + it 'has the correct attributes' do + expected_revoke_path = Gitlab::Routing.url_helpers + .revoke_namespace_project_settings_access_token_path( + { id: token, + namespace_id: project.namespace.path, + project_id: project.path }) + + expect(json).to( + include( + id: token.id, + name: token.name, + scopes: token.scopes, + user_id: token.user_id, + revoke_path: expected_revoke_path, + access_level: nil + )) + + expect(json).not_to include(:token) + end + end +end diff --git a/spec/serializers/project_access_token_serializer_spec.rb b/spec/serializers/project_access_token_serializer_spec.rb new file mode 100644 index 00000000000..1c0898d7841 --- /dev/null +++ b/spec/serializers/project_access_token_serializer_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ProjectAccessTokenSerializer do + let_it_be(:project) { create(:project) } + let_it_be(:bot) { create(:user, :project_bot) } + + subject(:serializer) { described_class.new } + + before do + project.add_developer(bot) + end + + describe '#represent' do + it 'can render a single token' do + token = create(:personal_access_token, user: bot) + + expect(serializer.represent(token, project: project)).to be_kind_of(Hash) + end + + it 'can render a collection of tokens' do + tokens = create_list(:personal_access_token, 2, user: bot) + + expect(serializer.represent(tokens, project: project)).to be_kind_of(Array) + end + end +end |