public_links_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::PublicLinks, type: :graphql do
  4. context 'when fetching public links' do
  5. let(:query) do
  6. <<~QUERY
  7. query publicLinks($screen: EnumPublicLinksScreen!) {
  8. publicLinks(screen: $screen) {
  9. id
  10. link
  11. title
  12. description
  13. newTab
  14. }
  15. }
  16. QUERY
  17. end
  18. let!(:link_list) do
  19. first_link = create(:public_link, prio: 1)
  20. second_link = create(:public_link, prio: 2)
  21. third_link = create(:public_link, prio: 3)
  22. {
  23. first: first_link,
  24. second: second_link,
  25. third: third_link,
  26. }
  27. end
  28. let(:expected_result) do
  29. [
  30. {
  31. 'id' => gql.id(link_list[:first]),
  32. 'link' => link_list[:first]['link'],
  33. 'title' => link_list[:first]['title'],
  34. 'description' => link_list[:first]['description'],
  35. 'newTab' => link_list[:first]['new_tab'],
  36. },
  37. {
  38. 'id' => gql.id(link_list[:second]),
  39. 'link' => link_list[:second]['link'],
  40. 'title' => link_list[:second]['title'],
  41. 'description' => link_list[:second]['description'],
  42. 'newTab' => link_list[:second]['new_tab'],
  43. },
  44. {
  45. 'id' => gql.id(link_list[:third]),
  46. 'link' => link_list[:third]['link'],
  47. 'title' => link_list[:third]['title'],
  48. 'description' => link_list[:third]['description'],
  49. 'newTab' => link_list[:third]['new_tab'],
  50. },
  51. ]
  52. end
  53. before do
  54. gql.execute(query, variables: { screen: 'login' })
  55. end
  56. shared_examples 'returns public links' do
  57. it 'returns data' do
  58. expect(gql.result.data).to eq(expected_result)
  59. end
  60. end
  61. context 'when authorized', authenticated_as: :agent do
  62. let(:agent) { create(:agent) }
  63. include_examples 'returns public links'
  64. end
  65. context 'when unauthorized' do
  66. include_examples 'returns public links'
  67. end
  68. end
  69. end