email_addresses_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::EmailAddresses, type: :graphql do
  4. context 'when fetching EmailAddresses' do
  5. let(:agent) { create(:agent) }
  6. let(:query) do
  7. <<~QUERY
  8. query emailAddresses($onlyActive: Boolean = false) {
  9. emailAddresses(onlyActive: $onlyActive) {
  10. name
  11. email
  12. active
  13. }
  14. }
  15. QUERY
  16. end
  17. let(:variables) { { onlyActive: false } }
  18. let(:email_address) { create(:email_address) }
  19. before do
  20. email_address.update_columns(active: false)
  21. gql.execute(query, variables: variables)
  22. end
  23. context 'with authenticated session', authenticated_as: :agent do
  24. it 'has data' do
  25. expect(gql.result.data).to eq([{ 'name' => email_address.name, 'email' => email_address.email, 'active' => false }])
  26. end
  27. context 'when fetching only active addresses' do
  28. let(:variables) do
  29. { onlyActive: true }
  30. end
  31. it 'does not include inactive addresses' do
  32. expect(gql.result.data).to eq([])
  33. end
  34. end
  35. end
  36. it_behaves_like 'graphql responds with error if unauthenticated'
  37. end
  38. end