2024-01-19 02:57:10 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 15:12:25 +10:00
|
|
|
RSpec.describe 'API Peers Search' do
|
2024-01-19 02:57:10 +11:00
|
|
|
describe 'GET /api/v1/peers/search' do
|
|
|
|
context 'when peers api is disabled' do
|
|
|
|
before do
|
|
|
|
Setting.peers_api_enabled = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http not found response' do
|
|
|
|
get '/api/v1/peers/search'
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no search param' do
|
|
|
|
it 'returns http success and empty response' do
|
|
|
|
get '/api/v1/peers/search'
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
2024-09-20 23:13:04 +10:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2024-09-06 19:58:46 +10:00
|
|
|
expect(response.parsed_body)
|
2024-01-19 02:57:10 +11:00
|
|
|
.to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with invalid search param' do
|
|
|
|
it 'returns http success and empty response' do
|
|
|
|
get '/api/v1/peers/search', params: { q: 'ftp://Invalid-Host!!.valüe' }
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
2024-09-20 23:13:04 +10:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2024-09-06 19:58:46 +10:00
|
|
|
expect(response.parsed_body)
|
2024-01-19 02:57:10 +11:00
|
|
|
.to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with search param' do
|
|
|
|
let!(:account) { Fabricate(:account, domain: 'host.example') }
|
|
|
|
|
|
|
|
before { Instance.refresh }
|
|
|
|
|
|
|
|
it 'returns http success and json with known domains' do
|
|
|
|
get '/api/v1/peers/search', params: { q: 'host.example' }
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
2024-09-20 23:13:04 +10:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2024-09-25 23:54:22 +10:00
|
|
|
expect(response.parsed_body)
|
|
|
|
.to contain_exactly(
|
|
|
|
eq(account.domain)
|
|
|
|
)
|
2024-01-19 02:57:10 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|