feed_tokens_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'KnowledgeBase::FeedTokens', authenticated_as: :user, type: :request do
  4. let(:endpoint) { '/api/v1/knowledge_bases/feed_tokens' }
  5. let(:user) { create(:admin) }
  6. let(:token) { create(:token, action: 'KnowledgeBaseFeed', user: user) }
  7. describe '#show' do
  8. it 'returns token when it exists' do
  9. token
  10. get endpoint
  11. expect(json_response['token']).to eq(token.token)
  12. end
  13. it 'created and returns token' do
  14. get endpoint
  15. expect(json_response['token']).to be_present
  16. end
  17. it 'creates a persistent token' do
  18. get endpoint
  19. expect(Token.find_by(action: 'KnowledgeBaseFeed')).to be_persistent
  20. end
  21. end
  22. describe '#update' do
  23. it 'changes token when it exists' do
  24. token
  25. expect { patch(endpoint) }.to change { token.reload.token }
  26. end
  27. it 'created and returns token' do
  28. patch endpoint
  29. expect(json_response['token']).to be_present
  30. end
  31. it 'creates a persistent token' do
  32. get endpoint
  33. expect(Token.find_by(action: 'KnowledgeBaseFeed')).to be_persistent
  34. end
  35. end
  36. end