BigW Consortium Gitlab

deploy_key_entity_spec.rb 1.21 KB
Newer Older
1 2 3
require 'spec_helper'

describe DeployKeyEntity do
4 5
  include RequestAwareEntity
  
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
  let(:user) { create(:user) }
  let(:project) { create(:empty_project, :internal)}
  let(:project_private) { create(:empty_project, :private)}
  let(:deploy_key) { create(:deploy_key) }
  let!(:deploy_key_internal) { create(:deploy_keys_project, project: project, deploy_key: deploy_key) }
  let!(:deploy_key_private)  { create(:deploy_keys_project, project: project_private, deploy_key: deploy_key) }

  let(:entity) { described_class.new(deploy_key, user: user) }

  it 'returns deploy keys with projects a user can read' do
    expected_result = {
      id: deploy_key.id,
      user_id: deploy_key.user_id,
      title: deploy_key.title,
      fingerprint: deploy_key.fingerprint,
      can_push: deploy_key.can_push,
22 23
      destroyed_when_orphaned: true,
      almost_orphaned: false,
24 25 26
      created_at: deploy_key.created_at,
      updated_at: deploy_key.updated_at,
      projects: [
27 28 29 30 31 32
        {
          id: project.id,
          name: project.name,
          full_path: namespace_project_path(project.namespace, project),
          full_name: project.full_name
        }
33 34 35 36 37 38
      ]
    }

    expect(entity.as_json).to eq(expected_result)
  end
end