debian-mirror-gitlab/spec/serializers/deploy_key_entity_spec.rb

78 lines
2 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe DeployKeyEntity do
include RequestAwareEntity
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :internal)}
let(:project_private) { create(:project, :private)}
2017-08-17 22:00:37 +05:30
let(:deploy_key) { create(:deploy_key) }
let(:entity) { described_class.new(deploy_key, user: user) }
2019-12-21 20:55:43 +05:30
before do
project.deploy_keys << deploy_key
project_private.deploy_keys << deploy_key
end
2017-09-10 17:25:29 +05:30
describe 'returns deploy keys with projects a user can read' do
let(:expected_result) do
{
id: deploy_key.id,
user_id: deploy_key.user_id,
title: deploy_key.title,
fingerprint: deploy_key.fingerprint,
2020-03-13 15:44:24 +05:30
fingerprint_sha256: deploy_key.fingerprint_sha256,
2017-09-10 17:25:29 +05:30
destroyed_when_orphaned: true,
almost_orphaned: false,
created_at: deploy_key.created_at,
updated_at: deploy_key.updated_at,
can_edit: false,
2018-03-17 18:26:18 +05:30
deploy_keys_projects: [
2017-09-10 17:25:29 +05:30
{
2018-03-17 18:26:18 +05:30
can_push: false,
project:
{
id: project.id,
name: project.name,
full_path: project_path(project),
full_name: project.full_name
}
2017-09-10 17:25:29 +05:30
}
]
}
end
it { expect(entity.as_json).to eq(expected_result) }
end
2019-12-21 20:55:43 +05:30
context 'user is an admin' do
let(:user) { create(:user, :admin) }
it { expect(entity.as_json).to include(can_edit: true) }
end
context 'user is a project maintainer' do
2017-09-10 17:25:29 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-09-10 17:25:29 +05:30
end
2019-12-21 20:55:43 +05:30
context 'project deploy key' do
it { expect(entity.as_json).to include(can_edit: true) }
end
2017-09-10 17:25:29 +05:30
2019-12-21 20:55:43 +05:30
context 'public deploy key' do
let(:deploy_key_public) { create(:deploy_key, public: true) }
let(:entity_public) { described_class.new(deploy_key_public, { user: user, project: project }) }
2017-09-10 17:25:29 +05:30
2019-12-21 20:55:43 +05:30
before do
project.deploy_keys << deploy_key_public
end
it { expect(entity_public.as_json).to include(can_edit: true) }
end
2017-08-17 22:00:37 +05:30
end
end