diff --git a/spec/integration/api/restart_spec.rb b/spec/integration/api/restart_spec.rb index 5c4bb6c..674d2b5 100644 --- a/spec/integration/api/restart_spec.rb +++ b/spec/integration/api/restart_spec.rb @@ -18,13 +18,55 @@ describe Vmpooler::API::Restart do describe '/restart' do + before(:each) do + expect(app).to receive(:run!).once + app.execute([:api], config, redis, nil, nil) + end + + + describe 'GET /restart' do + context '(auth not configured)' do + let(:config) { { + config: {}, + auth: false + } } + + it 'returns a 404' do + get "/restart" + expect_json(ok = false, http = 404) + end + end + + + context '(auth configured)' do + let(:config) { + { + config: {}, + auth: { + 'provider' => 'dummy' + } + } + } + let(:username_str) { 'admin' } + let(:password_str) { 's3cr3t' } + + it 'returns a 401 if no token is provided' do + get "/restart" + expect_json(ok = false, http = 401) + end + + it 'restarts if token is provided' do + + authorize 'admin', 's3cr3t' + get "/restart" + expect_json(ok = true, http = 200) + + expect(JSON.parse(last_response.body).to eq JSON.parse(JSON.dump({ 'ok' => true, 'message' => 'Restarting ...' }))) + + end + end + + end - it 'returns OK' do - get "/restart" - - expect(last_response.status).to eq(200) - result = JSON.parse(last_response.body) - expect(result).to eq({'ok' => true}) - end end end \ No newline at end of file