require_relative '../test_config' require 'helix_versioning_engine' describe 'HelixVersioningEngine depots' do include Rack::Test::Methods def app HELIX_WEB_SERVICES_APP end randstr = (0...8).map { (65 + rand(26)).chr }.join depot_id = "test_#{randstr}" new_depot = { 'Depot' => depot_id, 'Description' => "Test Depot #{randstr}", 'Type' => 'local', 'Map' => "#{depot_id}/..." } context 'POST /helix_versioning_engine/v78/depots' do it 'can create a new depot' do authorize 'super', ticket_for_super post('/helix_versioning_engine/v78/depots', new_depot) expect(last_response.status).to eq(200) end end context 'GET /helix_versioning_engine/v78/depots' do it 'returns the new depot in an array of depots' do authorize 'super', ticket_for_super get('/helix_versioning_engine/v78/depots') expect(last_response.status).to eq(200) depots = JSON.parse(last_response.body) expect(depots.map{|x| x['name']}).to include(depot_id) end end context 'GET /helix_versioning_engine/v78/depots/[depot]' do it 'can fetch the new depot' do authorize 'super', ticket_for_super get("/helix_versioning_engine/v78/depots/#{depot_id}") expect(last_response.status).to eq(200) depot = JSON.parse(last_response.body) expect(depot['Depot']).to eq(new_depot['Depot']) expect(depot['Description']).to include(new_depot['Description']) expect(depot['Type']).to eq(new_depot['Type']) expect(depot['Map']).to eq(new_depot['Map']) end end context 'PATCH /helix_versioning_engine/v78/depots/[depot]' do it 'can update the description' do authorize 'super', ticket_for_super patch("/helix_versioning_engine/v78/depots/#{depot_id}", { 'Description' => "Update #{randstr}"}) expect(last_response.status).to eq(200) get("/helix_versioning_engine/v78/depots/#{depot_id}") expect(last_response.status).to eq(200) depot = JSON.parse(last_response.body) expect(depot['Description']).to include("Update #{randstr}") end end context 'DELETE /helix_versioning_engine/v78/depots/[depot]' do it 'can delete the depot' do authorize 'super', ticket_for_super delete("/helix_versioning_engine/v78/depots/#{depot_id}") expect(last_response.status).to eq(200) get('/helix_versioning_engine/v78/depots') depots = JSON.parse(last_response.body) expect(depots.map{|x| x['name']}).to_not include(depot_id) end end end