locale_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::Locale, type: :graphql do
  4. context 'when updating language of the logged-in user', authenticated_as: :agent do
  5. let(:agent) { create(:agent, preferences: { 'locale' => 'de-de' }) }
  6. let(:query) do
  7. <<~QUERY
  8. mutation userCurrentLocale($locale: String!) {
  9. userCurrentLocale(locale: $locale) {
  10. success
  11. errors {
  12. message
  13. field
  14. }
  15. }
  16. }
  17. QUERY
  18. end
  19. let(:locale) { 'en-us' }
  20. let(:variables) { { locale: locale } }
  21. before do
  22. gql.execute(query, variables: variables)
  23. end
  24. context 'with valid locale' do
  25. it 'returns success' do
  26. expect(gql.result.data[:success]).to be true
  27. end
  28. it 'updates the locale' do
  29. expect(agent.reload.preferences['locale']).to eq('en-us')
  30. end
  31. end
  32. context 'with invalid locale' do
  33. let(:locale) { 'nonexisting-locale' }
  34. it 'fails with error message' do
  35. expect(gql.result.error_message).to eq('Locale could not be found.')
  36. end
  37. it 'fails with error type' do
  38. expect(gql.result.error_type).to eq(ActiveRecord::RecordNotFound)
  39. end
  40. end
  41. it_behaves_like 'graphql responds with error if unauthenticated'
  42. end
  43. end