# Copyright (c) 2015 Perforce Software, Inc. All rights reserved. require_relative '../test_config' require 'helix_versioning_engine' RSpec.describe 'HelixVersioningEngine protections' do include Rack::Test::Methods def app HELIX_WEB_SERVICES_APP end context 'GET /p4/v78/protections' do it 'should return an array with at least two protections' do authorize 'super', ticket_for_super get('/p4/v78/protections') expect(last_response.status).to eq(200) obj = JSON.parse(last_response.body) expect(obj['Protections'].length).to be >= 2 end end context 'PUT /p4/v78/protections' do entry = 'super user jdoe * //...' it 'should add a protections entry for the user jdoe' do authorize 'super', ticket_for_super get('/p4/v78/protections') expect(last_response.status).to eq(200) obj = JSON.parse(last_response.body) obj['Protections'] << entry put('/p4/v78/protections', obj) expect(last_response.status).to eq(200) get('/p4/v78/protections') expect(last_response.status).to eq(200) updated = JSON.parse(last_response.body) expect(updated['Protections']).to include(entry) end it 'should remove the protections entry for user jdoe' do authorize 'super', ticket_for_super get('/p4/v78/protections') expect(last_response.status).to eq(200) obj = JSON.parse(last_response.body) obj['Protections'].delete(entry) put('/p4/v78/protections', obj) expect(last_response.status).to eq(200) get('/p4/v78/protections') expect(last_response.status).to eq(200) updated = JSON.parse(last_response.body) expect(updated['Protections']).to_not include(entry) end end end