diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /spec/serializers/ci/trigger_entity_spec.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'spec/serializers/ci/trigger_entity_spec.rb')
-rw-r--r-- | spec/serializers/ci/trigger_entity_spec.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/serializers/ci/trigger_entity_spec.rb b/spec/serializers/ci/trigger_entity_spec.rb new file mode 100644 index 00000000000..b2f3337d166 --- /dev/null +++ b/spec/serializers/ci/trigger_entity_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::TriggerEntity do + let(:project) { create(:project) } + let(:trigger) { create(:ci_trigger, project: project, token: '237f3604900a4cd71ed06ef13e57b96d') } + let(:user) { create(:user) } + let(:entity) { described_class.new(trigger, current_user: user, project: project) } + + describe '#as_json' do + let(:as_json) { entity.as_json } + let(:project_trigger_path) { "/#{project.full_path}/-/triggers/#{trigger.id}" } + + it 'contains required fields' do + expect(as_json).to include( + :description, :owner, :last_used, :token, :has_token_exposed, :can_access_project + ) + end + + it 'contains user fields' do + expect(as_json[:owner].to_json).to match_schema('entities/user') + end + + context 'when current user can manage triggers' do + before do + project.add_maintainer(user) + end + + it 'returns short_token as token' do + expect(as_json[:token]).to eq(trigger.short_token) + end + + it 'contains project_trigger_path' do + expect(as_json[:project_trigger_path]).to eq(project_trigger_path) + end + + it 'does not contain edit_project_trigger_path' do + expect(as_json).not_to include(:edit_project_trigger_path) + end + + it 'returns has_token_exposed' do + expect(as_json[:has_token_exposed]).to eq(false) + end + end + + context 'when current user is the owner of the trigger' do + before do + project.add_maintainer(user) + trigger.update!(owner: user) + end + + it 'returns token as token' do + expect(as_json[:token]).to eq(trigger.token) + end + + it 'contains project_trigger_path' do + expect(as_json[:project_trigger_path]).to eq(project_trigger_path) + end + + it 'contains edit_project_trigger_path' do + expect(as_json[:edit_project_trigger_path]).to eq("#{project_trigger_path}/edit") + end + + it 'returns has_token_exposed' do + expect(as_json[:has_token_exposed]).to eq(true) + end + end + end +end |