require_relative '../test_config' require 'helix_versioning_engine' describe 'HelixVersioningEngine labels' do include Rack::Test::Methods randstr = (0...8).map { (65 + rand(26)).chr }.join label_id = "test_#{randstr}" new_label = { 'Label' => label_id, 'Description' => "test label #{label_id}", 'View' => ['//depot/...'] } def app HELIX_WEB_SERVICES_APP end context 'POST /p4/v78/labels' do it 'can create a test label' do skip 'Not available for cloud (no stream support)' if Cloud::Settings.cloud_enabled? authorize 'jdoe', ticket_for_jdoe post('/p4/v78/labels', new_label) expect(last_response.status).to eq(200) end end context 'GET /p4/v78/labels' do it 'can find the new label in an array of labels' do skip 'Not available for cloud (no stream support)' if Cloud::Settings.cloud_enabled? authorize 'jdoe', ticket_for_jdoe get('/p4/v78/labels') expect(last_response.status).to eq(200) results = JSON.parse(last_response.body) label_ids = results.map { |x| x['label'] } expect(label_ids).to include(label_id) end end context 'PATCH /p4/v78/labels/[label]' do it 'can update the users list' do authorize 'jdoe', ticket_for_jdoe patch("/p4/v78/labels/#{label_id}", 'Description' => "Update label #{label_id}") expect(last_response.status).to eq(200) end end context 'GET /p4/v78/labels/[label]' do it 'can load the new label with a View' do authorize 'jdoe', ticket_for_jdoe get("/p4/v78/labels/#{label_id}") expect(last_response.status).to eq(200) obj = JSON.parse(last_response.body) expect(obj['Label']).to eq(label_id) expect(obj['Description']).to include("Update label #{label_id}") end end context 'DELETE /p4/v78/labels/[label]' do it 'can delete the label' do authorize 'jdoe', ticket_for_jdoe delete("/p4/v78/labels/#{label_id}") expect(last_response.status).to eq(200) get('/p4/v78/labels') expect(last_response.status).to eq(200) results = JSON.parse(last_response.body) label_ids = results.map { |x| x['label'] } expect(label_ids).to_not include(label_id) end end end