appearance_spec.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::Appearance, type: :graphql do
  4. let(:user) { create(:agent) }
  5. let(:mutation) do
  6. <<~GQL
  7. mutation userCurrentAppearance($theme: EnumAppearanceTheme!) {
  8. userCurrentAppearance(theme: $theme) {
  9. success
  10. errors {
  11. message
  12. field
  13. }
  14. }
  15. }
  16. GQL
  17. end
  18. let(:variables) { { theme: 'light' } }
  19. def execute_graphql_query
  20. gql.execute(mutation, variables: variables)
  21. end
  22. context 'when user is not authenticated' do
  23. it 'returns an error' do
  24. expect(execute_graphql_query.error_message).to eq('Authentication required')
  25. end
  26. end
  27. context 'when user is authenticated', authenticated_as: :user do
  28. context 'without valid theme' do
  29. let(:variables) { { theme: 'invalid' } }
  30. it 'returns an error' do
  31. expect(execute_graphql_query.error_message).to eq('Variable $theme of type EnumAppearanceTheme! was provided invalid value')
  32. end
  33. end
  34. context 'with valid theme' do
  35. it 'updates user profile appearance settings' do
  36. expect { execute_graphql_query }.to change { user.reload.preferences['theme'] }.from(nil).to('light')
  37. end
  38. end
  39. end
  40. end