require_relative '../test_config' require 'hws_settings' require 'helix_sync' require 'base64' require 'hws_strings' describe 'HelixSync changes' do include Rack::Test::Methods def app HELIX_WEB_SERVICES_APP end my_project_id = HWSStrings.component_encode('My Project') after(:each) do HWSSettings.settings_handle.HVE_PROJECTS_PATH = nil HWSSettings.system_handle.HELIX_SYNC_LOCK_RETRIES = 30 end context 'GET /helix-sync/v1/:project_id/last-change' do context 'HVE projects' do it 'can fetch the latest change for the project' do HWSSettings.settings_handle.HVE_PROJECTS_PATH = '//depot/main' authorize 'jdoe', ticket_for_jdoe post("/helix-sync/v1/#{my_project_id}/clients/shelf") expect(last_response.status).to eq(200) get("/helix-sync/v1/#{my_project_id}/last-change") expect(last_response.status).to eq(200) info = JSON.parse(last_response.body) expect(info['change'].to_i).to be > 1 end end end context 'GET /helix-sync/v1/:project_id/pending' do context 'default value' do it 'returns the default value if no change found' do authorize 'jdoe', ticket_for_jdoe get('/helix-sync/v1/totally_does_not_exist/pending?default=0') expect(last_response.status).to eq(200) info = JSON.parse(last_response.body) expect(info['change']).to eq('0') end end end context 'POST /helix-sync/v1/:project_id/submit' do context 'locked client' do it 'times out and fails if the client is already locked' do # Let's limit the number of retries HWSSettings.system_handle.HELIX_SYNC_LOCK_RETRIES = 1 lock_client = "_hve_jdoe_#{my_project_id}_shelf_lock" p4 = p4_as_jdoe client_spec = p4.fetch_client(lock_client) p4.client = client_spec._client p4.save_client(client_spec, '-x') authorize 'jdoe', ticket_for_jdoe post("/helix-sync/v1/#{my_project_id}/submit") # # I'm a little surprised this is required here p4.run_client('-d', lock_client) p4.disconnect expect(last_response.status).to eq(400) end end end end