public_links_spec.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'PublicLinks', type: :request do
  4. let(:admin) { create(:admin) }
  5. let(:agent) { create(:agent, password: 'dummy') }
  6. let(:link) { link_list[:first] }
  7. let(:link_list) do
  8. first_link = create(:public_link, prio: 1)
  9. second_link = create(:public_link, prio: 2)
  10. third_link = create(:public_link, prio: 3)
  11. {
  12. first: first_link,
  13. second: second_link,
  14. third: third_link,
  15. }
  16. end
  17. let(:create_params) do
  18. {
  19. link: 'https://zammad.org',
  20. title: 'Zammad <3',
  21. description: 'Zammad is a very cool application',
  22. screen: ['login'],
  23. prio: 1,
  24. }
  25. end
  26. let(:update_params) { create_params.merge(id: link.id, title: 'Zammad Community',) }
  27. let(:prio_params) do
  28. {
  29. prios: [
  30. [ link_list[:third].id, 1 ],
  31. [ link_list[:second].id, 2 ],
  32. [ link_list[:first].id, 3 ],
  33. ]
  34. }
  35. end
  36. describe 'request handling' do
  37. it 'does create a new public link', :aggregate_failures do
  38. authenticated_as(admin)
  39. post '/api/v1/public_links', params: create_params, as: :json
  40. expect(response).to have_http_status(:created)
  41. expect(json_response).to include('link' => 'https://zammad.org', 'title' => 'Zammad <3')
  42. end
  43. it 'supports setting prios', :aggregate_failures do
  44. authenticated_as(admin)
  45. post '/api/v1/public_links_prio', params: prio_params, as: :json
  46. expect(response).to have_http_status(:ok)
  47. expect(json_response).to include('success' => true)
  48. expect(link_list[:first].reload.prio).to eq(3)
  49. expect(link_list[:second].reload.prio).to eq(2)
  50. expect(link_list[:third].reload.prio).to eq(1)
  51. end
  52. it 'updates an existing link', :aggregate_failures do
  53. authenticated_as(admin)
  54. put "/api/v1/public_links/#{link.id}", params: update_params, as: :json
  55. expect(response).to have_http_status(:ok)
  56. expect(json_response).to include('title' => 'Zammad Community')
  57. end
  58. it 'deletes an existing link', :aggregate_failures do
  59. authenticated_as(admin)
  60. delete "/api/v1/public_links/#{link.id}", params: {}, as: :json
  61. expect(response).to have_http_status(:ok)
  62. expect(PublicLink).not_to exist(link.id)
  63. end
  64. end
  65. end