123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
- require 'rails_helper'
- RSpec.describe Gql::Queries::Ticket::Signature, type: :graphql do
- let(:signature) { create(:signature, body: "\#{user.fullname} via \#{config.product_name}") }
- let(:group) { create(:group, signature_id: signature.id) }
- let(:query) do
- <<~QUERY
- query ticketSignature($groupId: ID!, $ticketId: ID) {
- ticketSignature(groupId: $groupId) {
- id
- renderedBody(ticketId: $ticketId)
- }
- }
- QUERY
- end
- let(:variables) { { groupId: gql.id(group) } }
- before do
- gql.execute(query, variables: variables)
- end
- context 'with an agent', authenticated_as: :user do
- context 'with permission' do
- let(:user) { create(:agent, groups: [group]) }
- context 'without ticket context' do
- it 'returns data' do
- expect(gql.result.data).to eq({
- 'id' => gql.id(signature),
- 'renderedBody' => "#{user.fullname} via #{Setting.get('product_name')}",
- })
- end
- end
- context 'with ticket context' do
- let(:signature) { create(:signature, body: "\#{user.fullname} via \#{config.product_name} (\#{ticket.number})") }
- let(:ticket) { create(:ticket, group: group) }
- let(:variables) { { groupId: gql.id(group), ticketId: gql.id(ticket) } }
- it 'returns data' do
- expect(gql.result.data).to eq({
- 'id' => gql.id(signature),
- 'renderedBody' => "#{user.fullname} via #{Setting.get('product_name')} (#{ticket.number})",
- })
- end
- end
- context 'without assigned signature to the group' do
- let(:group) { create(:group) }
- it 'returns no data' do
- expect(gql.result.data).to be_nil
- end
- end
- context 'with inactive signature' do
- let(:signature) { create(:signature, active: false) }
- it 'returns no data' do
- expect(gql.result.data).to be_nil
- end
- end
- context 'with empty body signature' do
- let(:signature) { create(:signature, body: '') }
- it 'returns no data' do
- expect(gql.result.data).to be_nil
- end
- end
- end
- context 'without permission' do
- let(:user) { create(:agent) }
- it 'raises an error' do
- expect(gql.result.error_type).to eq(Exceptions::Forbidden)
- end
- end
- end
- context 'with a customer', authenticated_as: :user do
- let(:user) { create(:customer) }
- it 'raises an error' do
- expect(gql.result.error_type).to eq(Exceptions::Forbidden)
- end
- end
- it_behaves_like 'graphql responds with error if unauthenticated'
- end
|