recent_by_customer_spec.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::Tickets::RecentByCustomer, type: :graphql do
  4. let(:query) do
  5. <<~QUERY
  6. query ticketsRecentByCustomer($customerId: ID!, $exceptTicketInternalId: Int) {
  7. ticketsRecentByCustomer(customerId: $customerId, exceptTicketInternalId: $exceptTicketInternalId) {
  8. id
  9. }
  10. }
  11. QUERY
  12. end
  13. let(:variables) { { customerId: gql.id(customer), exceptTicketInternalId: ticket.id } }
  14. let(:group) { create(:group) }
  15. let(:customer) { create(:customer) }
  16. let(:ticket) { create(:ticket, group:, customer:) }
  17. let!(:customer_ticket) { create(:ticket, group:, customer:) }
  18. let(:user) { create(:agent, groups: [group]) }
  19. before do
  20. gql.execute(query, variables: variables)
  21. end
  22. context 'with an agent', authenticated_as: :user do
  23. it 'returns data' do
  24. expect(gql.result.data).to eq(
  25. [{ 'id' => gql.id(customer_ticket) }]
  26. )
  27. end
  28. end
  29. context 'with a customer', authenticated_as: :user do
  30. let(:user) { create(:customer) }
  31. it 'raises an error' do
  32. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  33. end
  34. end
  35. it_behaves_like 'graphql responds with error if unauthenticated'
  36. end