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 end pending_change = nil context 'GET /helix_sync/v1/changes/:project_id/pending' 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 get("/helix_sync/v1/changes/#{my_project_id}") 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 'POST /helix_sync/v1/changes/:project_id' do context 'HVE projects' do it 'can create a pending changelist for the project' do HWSSettings.settings_handle.HVE_PROJECTS_PATH = '//depot/main' authorize 'jdoe', ticket_for_jdoe post("/helix_sync/v1/changes/#{my_project_id}") expect(last_response.status).to eq(200) info = JSON.parse(last_response.body) expect(info['change']).to_not be_nil end end end context 'GET /helix_sync/v1/changes/:project_id/pending' do context 'HVE projects' do it 'can fetches the pending changelist for a project' do HWSSettings.settings_handle.HVE_PROJECTS_PATH = '//depot/main' authorize 'jdoe', ticket_for_jdoe get("/helix_sync/v1/changes/#{my_project_id}/pending") expect(last_response.status).to eq(200) info = JSON.parse(last_response.body) expect(info['change']).to_not be_nil pending_change = info['change'] end end end context 'POST /helix_sync/v1/changes/:project_id/pending' do context 'HVE projects' do it 'can submit the pending changelist for a project with shelved files' do HWSSettings.settings_handle.HVE_PROJECTS_PATH = '//depot/main' # Obtain a client pointing to a temporary directory client_info = { project: my_project_id, device: 'test_device', root: Dir.mktmpdir('test_helix_sync') } authorize 'jdoe', ticket_for_jdoe post('/helix_sync/v1/clients', client_info) expect(last_response.status).to eq(200) client_name = JSON.parse(last_response.body)['client'] # Update our pending changelist to use our project client p4_as_jdoe do |p4| p4.client = client_name change_spec = p4.fetch_change(pending_change) change_spec._client = client_name p4.save_change(change_spec) end # Add and shelve a new test file rand_str = (0...8).map { (65 + rand(26)).chr }.join path = File.absolute_path("#{client_info[:root]}/#{rand_str}") unless Dir.exist?(File.dirname(path)) FileUtils.mkdir_p(File.dirname(path)) end IO.write(path, "I'm a little teapot") p4_as_jdoe do |p4| p4.client = client_name results = p4.run_add('-c', pending_change, path) #puts "add: #{results}" results = p4.run_shelve('-c', pending_change) #puts "shelve: #{results}" results = p4.run_revert('-c', pending_change, path) #puts "revert: #{results}" end # Test our submit authorize 'jdoe', ticket_for_jdoe post("/helix_sync/v1/changes/#{my_project_id}/pending") expect(last_response.status).to eq(200) end end end end