links_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. require 'rails_helper'
  2. RSpec.describe 'Link', type: :request do
  3. describe 'GET /api/v1/links' do
  4. context 'when requesting links of Ticket', authenticated_as: -> { agent } do
  5. subject!(:ticket) { create(:ticket) }
  6. let(:agent) { create(:agent, groups: [ticket.group]) }
  7. let(:params) do
  8. {
  9. link_object: ticket.class.name,
  10. link_object_value: ticket.id,
  11. }
  12. end
  13. let(:linked) { create(:ticket, group: ticket.group) }
  14. before do
  15. create(:link, from: ticket, to: linked)
  16. get '/api/v1/links', params: params, as: :json
  17. end
  18. it 'is present in response' do
  19. expect(response).to have_http_status(:ok)
  20. expect(json_response['links']).to eq([
  21. {
  22. 'link_type' => 'normal',
  23. 'link_object' => 'Ticket',
  24. 'link_object_value' => linked.id
  25. }
  26. ])
  27. end
  28. context 'without permission to linked Ticket Group' do
  29. let(:linked) { create(:ticket) }
  30. it 'is not present in response' do
  31. expect(response).to have_http_status(:ok)
  32. expect(json_response['links']).to be_blank
  33. end
  34. end
  35. end
  36. end
  37. end