out_of_office_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::User::Current::OutOfOffice, type: :graphql do
  4. let(:user) { create(:agent) }
  5. let(:mutation) do
  6. <<~GQL
  7. mutation userCurrentOutOfOffice($input: OutOfOfficeInput!) {
  8. userCurrentOutOfOffice(input: $input) {
  9. success
  10. errors {
  11. message
  12. field
  13. }
  14. }
  15. }
  16. GQL
  17. end
  18. let(:variables) do
  19. {
  20. input: {
  21. enabled: true,
  22. text: 'Out of office message',
  23. startAt: '2011-02-03',
  24. endAt: '2011-03-03',
  25. replacementId: gql.id(create(:agent))
  26. }
  27. }
  28. end
  29. def execute_graphql_query
  30. gql.execute(mutation, variables: variables)
  31. end
  32. context 'when user is not authenticated' do
  33. it 'returns an error' do
  34. expect(execute_graphql_query.error_message).to eq('Authentication required')
  35. end
  36. end
  37. context 'when user is authenticated', authenticated_as: :user do
  38. context 'with invalid settings' do
  39. let(:variables) do
  40. {
  41. input: {
  42. enabled: true,
  43. text: 'Out of office message',
  44. startAt: '2011-02-03',
  45. endAt: '2011-03-03',
  46. replacementId: nil
  47. }
  48. }
  49. end
  50. it 'returns an error' do
  51. execute_graphql_query
  52. expect(gql.result.data).to include('errors' => include(
  53. include(
  54. 'field' => 'outOfOfficeReplacementId',
  55. 'message' => 'This field can\'t be blank'
  56. )
  57. ))
  58. end
  59. end
  60. context 'with valid setting' do
  61. it 'updates user profile out of office input' do
  62. expect { execute_graphql_query }
  63. .to change { user.reload.preferences['out_of_office_text'] }
  64. .from(nil)
  65. .to('Out of office message')
  66. end
  67. end
  68. end
  69. end