links_spec.rb 1.5 KB

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