history_spec.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::Ticket::History, timezone: 'Europe/Berlin', type: :graphql do
  4. context 'when fetching history of a ticket' do
  5. let(:group) { create(:group) }
  6. let(:owner) { create(:user) }
  7. let(:ticket) { create(:ticket, group:, owner:, created_by: owner) }
  8. let(:variables) { { ticketId: gql.id(ticket) } }
  9. let(:query) do
  10. <<~QUERY
  11. query ticketHistory($ticketId: ID, $ticketInternalId: Int, $ticketNumber: String) {
  12. ticketHistory(
  13. ticket: {
  14. ticketId: $ticketId
  15. ticketInternalId: $ticketInternalId
  16. ticketNumber: $ticketNumber
  17. }
  18. ) {
  19. createdAt
  20. records {
  21. issuer {
  22. ... on User {
  23. fullname
  24. }
  25. ... on Trigger {
  26. id
  27. internalId
  28. name
  29. }
  30. ... on Job {
  31. id
  32. internalId
  33. name
  34. }
  35. ... on PostmasterFilter {
  36. id
  37. internalId
  38. name
  39. }
  40. ... on ObjectClass {
  41. klass
  42. info
  43. }
  44. }
  45. events {
  46. createdAt
  47. action
  48. object {
  49. ... on Ticket {
  50. title
  51. }
  52. ... on TicketArticle {
  53. body
  54. }
  55. ... on ObjectClass {
  56. klass
  57. info
  58. }
  59. }
  60. attribute
  61. changes
  62. }
  63. }
  64. }
  65. }
  66. QUERY
  67. end
  68. before do
  69. Time.use_zone('UTC') do
  70. freeze_time
  71. travel_to(2.days.ago) do
  72. ticket
  73. ticket.update!(title: 'New title', updated_by: create(:agent))
  74. end
  75. travel_to(1.day.ago) do
  76. ticket.update!(title: 'Another title', updated_by: create(:agent))
  77. end
  78. end
  79. gql.execute(query, variables:)
  80. end
  81. it_behaves_like 'graphql responds with error if unauthenticated'
  82. context 'with authenticated session', authenticated_as: :authenticated do
  83. context 'when user has no access to ticket' do
  84. let(:authenticated) { create(:agent) }
  85. it 'raises an error' do
  86. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  87. end
  88. end
  89. context 'when user has access to ticket' do
  90. let(:authenticated) { create(:agent, groups: [group]) }
  91. it 'returns grouped history records' do
  92. expect(gql.result.data).to be_present
  93. end
  94. end
  95. end
  96. end
  97. end