[add] added public mode

This commit is contained in:
2021-03-07 16:39:38 -05:00
parent 8bbd3e02f3
commit c4cb76fe0b
4 changed files with 109 additions and 2 deletions

View File

@@ -587,4 +587,49 @@ RSpec.describe 'Clients', type: :request do
end
end
end
describe 'POST /public/:name' do
# FIXME: rather have this automated than adding ENV by hand
if ENV['RAILS_API_PUBLIC']
context 'when request to write public client' do
before { post "/public/#{public_client.name}" }
it 'returns status code 200' do
expect(json_response['name']).to eq public_client.name
expect(json_response['ipv4']).to eq '127.0.0.1'
expect(response).to have_http_status(200)
end
end
context 'when requesting to write public client with body' do
before { post "/public/#{public_client.name}", params: { ipv4: '99.55.66.2' } }
it 'returns status code 200' do
expect(json_response['name']).to eq public_client.name
expect(json_response['ipv4']).to eq '99.55.66.2'
expect(response).to have_http_status(200)
end
end
context 'when requesting to write non existing client' do
before { post "/public/#{non_existing_client}" }
it 'returns status code 201' do
expect(json_response['name']).to eq non_existing_client
expect(json_response['ipv4']).to eq '127.0.0.1'
expect(response).to have_http_status(201)
end
end
# TODO: 406 and 429, check client count on 200
else
context 'when request to write public client' do
before { post "/public/#{public_client.name}" }
it 'returns status code 403' do
expect(response.body).to be_empty
expect(response).to have_http_status(403)
end
end
# TODO: check client count/modification
end
end
end