require_relative '../test_config' require 'helix_versioning_engine' describe 'HelixVersioningEngine branches' do include Rack::Test::Methods randstr = (0...8).map { (65 + rand(26)).chr }.join branch_id = "test_#{randstr}" new_branch = { 'Branch' => branch_id, 'View' => ["//depot/main/#{branch_id}/... //depot/dev/#{branch_id}/..."] } def app HELIX_WEB_SERVICES_APP end context 'POST /helix_versioning_engine/v78/branches' do it 'can create a test branch' do authorize 'jdoe', ticket_for_jdoe post('/helix_versioning_engine/v78/branches', new_branch) expect(last_response.status).to eq(200) end end context 'GET /helix_versioning_engine/v78/branches' do it 'can find the new branch in an array of branches' do authorize 'jdoe', ticket_for_jdoe get('/helix_versioning_engine/v78/branches') expect(last_response.status).to eq(200) results = JSON.parse(last_response.body) branch_ids = results.map { |x| x['branch'] } expect(branch_ids).to include(branch_id) end end context 'PATCH /helix_versioning_engine/v78/branches/[branch]' do it 'can update the branch description' do authorize 'jdoe', ticket_for_jdoe patch("/helix_versioning_engine/v78/branches/#{branch_id}", 'Description' => "Test #{randstr}") expect(last_response.status).to eq(200) end end context 'GET /helix_versioning_engine/v78/branches/[branch]' do it 'can load the new branch with a View' do authorize 'jdoe', ticket_for_jdoe get("/helix_versioning_engine/v78/branches/#{branch_id}") expect(last_response.status).to eq(200) obj = JSON.parse(last_response.body) expect(obj['Branch']).to eq(branch_id) expect(obj['View']).to eq(new_branch['View']) # Our description field gets newlines appended to it expect(obj['Description']).to include("Test #{randstr}") end end context 'DELETE /helix_versioning_engine/v78/branches/[branch]' do it 'can delete the branch' do authorize 'jdoe', ticket_for_jdoe delete("/helix_versioning_engine/v78/branches/#{branch_id}") expect(last_response.status).to eq(200) get('/helix_versioning_engine/v78/branches') expect(last_response.status).to eq(200) results = JSON.parse(last_response.body) branch_ids = results.map { |x| x['branch'] } expect(branch_ids).to_not include(branch_id) end end end