BigW Consortium Gitlab

keys_spec.rb 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
require 'spec_helper'

describe API::API, api: true  do
  include ApiHelpers

  let(:user)  { create(:user) }
  let(:admin) { create(:admin) }
  let(:key)   { create(:key, user: user) }
  let(:email)   { create(:email, user: user) }

  describe 'GET /keys/:uid' do
    before { admin }

    context 'when unauthenticated' do
15
      it 'returns authentication error' do
16
        get api("/keys/#{key.id}")
17
        expect(response).to have_http_status(401)
18 19 20 21
      end
    end

    context 'when authenticated' do
22
      it 'returns 404 for non-existing key' do
23
        get api('/keys/999999', admin)
24
        expect(response).to have_http_status(404)
25 26 27
        expect(json_response['message']).to eq('404 Not found')
      end

28
      it 'returns single ssh key with user information' do
29 30 31
        user.keys << key
        user.save
        get api("/keys/#{key.id}", admin)
32
        expect(response).to have_http_status(200)
33 34 35 36 37 38 39
        expect(json_response['title']).to eq(key.title)
        expect(json_response['user']['id']).to eq(user.id)
        expect(json_response['user']['username']).to eq(user.username)
      end
    end
  end
end