templates_spec.rb 1.5 KB

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