locales_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::Locales, type: :graphql do
  4. context 'when fetching locales' do
  5. let(:agent) { create(:agent) }
  6. let(:query) do
  7. <<~QUERY
  8. query locales($onlyActive: Boolean = false) {
  9. locales(onlyActive: $onlyActive) {
  10. locale
  11. alias
  12. name
  13. dir
  14. active
  15. }
  16. }
  17. QUERY
  18. end
  19. let(:active) { true }
  20. let(:variables) { { onlyActive: false } }
  21. let(:target_locale) do
  22. {
  23. 'locale' => 'de-de',
  24. 'alias' => 'de',
  25. 'name' => 'Deutsch',
  26. 'dir' => 'ltr',
  27. 'active' => active,
  28. }
  29. end
  30. before do
  31. gql.execute(query, variables: variables)
  32. end
  33. context 'with authenticated session', authenticated_as: :agent do
  34. it 'has data' do
  35. expect(gql.result.data).to include(target_locale)
  36. end
  37. context 'when fetching only active locales' do
  38. let(:active) { false }
  39. let(:variables) do
  40. Locale.find_by(locale: 'de-de').update!(active: false)
  41. { onlyActive: true }
  42. end
  43. it 'does not include inactive locales' do
  44. expect(gql.result.data.select { |e| e['locale'] == 'de-de' }).to eq([])
  45. end
  46. end
  47. end
  48. context 'without authenticated session', authenticated_as: false do
  49. it 'has data' do
  50. expect(gql.result.data).to include(target_locale)
  51. end
  52. end
  53. end
  54. end