require_relative '../test_config' require 'helix_versioning_engine' describe 'HelixVersioningEngine servers' do include Rack::Test::Methods randstr = (0...8).map { (65 + rand(26)).chr }.join server_id = "test_#{randstr}" new_server = { 'ServerID' => server_id, 'Description' => "test server #{server_id}", 'Type' => 'server', 'Services' => 'standard' } def app HELIX_WEB_SERVICES_APP end context 'POST /helix_versioning_engine/v78/servers' do it 'can create a test server' do authorize 'super', ticket_for_super post('/helix_versioning_engine/v78/servers', new_server) expect(last_response.status).to eq(200) end end context 'GET /helix_versioning_engine/v78/servers' do it 'can find the new server in an array of servers' do authorize 'super', ticket_for_super get('/helix_versioning_engine/v78/servers') expect(last_response.status).to eq(200) results = JSON.parse(last_response.body) server_ids = results.map { |x| x['ServerID'] } expect(server_ids).to include(server_id) end end context 'PATCH /helix_versioning_engine/v78/servers/[server]' do it 'can update the users list' do authorize 'super', ticket_for_super patch("/helix_versioning_engine/v78/servers/#{server_id}", 'Description' => "Update server #{server_id}") expect(last_response.status).to eq(200) end end context 'GET /helix_versioning_engine/v78/servers/[server]' do it 'can load the new server with a View' do authorize 'super', ticket_for_super get("/helix_versioning_engine/v78/servers/#{server_id}") expect(last_response.status).to eq(200) obj = JSON.parse(last_response.body) expect(obj['ServerID']).to eq(server_id) expect(obj['Description']).to include("Update server #{server_id}") end end context 'DELETE /helix_versioning_engine/v78/servers/[server]' do it 'can delete the server' do authorize 'super', ticket_for_super delete("/helix_versioning_engine/v78/servers/#{server_id}") expect(last_response.status).to eq(200) get('/helix_versioning_engine/v78/servers') expect(last_response.status).to eq(200) results = JSON.parse(last_response.body) server_ids = results.map { |x| x['ServerID'] } expect(server_ids).to_not include(server_id) end end end