search_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'API Peers Search' do
  4. describe 'GET /api/v1/peers/search' do
  5. context 'when peers api is disabled' do
  6. before do
  7. Setting.peers_api_enabled = false
  8. end
  9. it 'returns http not found response' do
  10. get '/api/v1/peers/search'
  11. expect(response)
  12. .to have_http_status(404)
  13. end
  14. end
  15. context 'with no search param' do
  16. it 'returns http success and empty response' do
  17. get '/api/v1/peers/search'
  18. expect(response)
  19. .to have_http_status(200)
  20. expect(body_as_json)
  21. .to be_blank
  22. end
  23. end
  24. context 'with invalid search param' do
  25. it 'returns http success and empty response' do
  26. get '/api/v1/peers/search', params: { q: 'ftp://Invalid-Host!!.valüe' }
  27. expect(response)
  28. .to have_http_status(200)
  29. expect(body_as_json)
  30. .to be_blank
  31. end
  32. end
  33. context 'with search param' do
  34. let!(:account) { Fabricate(:account, domain: 'host.example') }
  35. before { Instance.refresh }
  36. it 'returns http success and json with known domains' do
  37. get '/api/v1/peers/search', params: { q: 'host.example' }
  38. expect(response)
  39. .to have_http_status(200)
  40. expect(body_as_json.size)
  41. .to eq(1)
  42. expect(body_as_json.first)
  43. .to eq(account.domain)
  44. end
  45. end
  46. end
  47. end