attachments_controller_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe AttachmentsController, type: :request do
  4. include_context 'basic Knowledge Base'
  5. let(:object) { create(:knowledge_base_answer, :draft, :with_attachment, category: category) }
  6. let(:attachment_id) { object.attachments.first.id }
  7. describe '#show' do
  8. it 'returns 404 when does not exist' do
  9. get '/api/v1/attachments/123'
  10. expect(response).to have_http_status(:not_found)
  11. end
  12. it 'returns 404 when no access', authenticated_as: -> { create(:agent) } do
  13. get "/api/v1/attachments/#{attachment_id}"
  14. expect(response).to have_http_status(:not_found)
  15. end
  16. it 'returns ok on success', authenticated_as: -> { create(:admin) } do
  17. get "/api/v1/attachments/#{attachment_id}"
  18. expect(response).to have_http_status(:ok)
  19. end
  20. end
  21. describe '#destroy' do
  22. it 'returns 404 when does not exist' do
  23. delete '/api/v1/attachments/123'
  24. expect(response).to have_http_status(:not_found)
  25. end
  26. it 'returns 404 when no access', authenticated_as: -> { create(:agent) } do
  27. delete "/api/v1/attachments/#{attachment_id}"
  28. expect(response).to have_http_status(:not_found)
  29. end
  30. it 'returns ok on success', authenticated_as: -> { create(:admin) } do
  31. delete "/api/v1/attachments/#{attachment_id}"
  32. expect(response).to have_http_status(:ok)
  33. end
  34. end
  35. end