require_relative '../test_config' require 'fileutils' require 'base64' require 'helix_versioning_engine' describe 'HelixVersioningEngine changes' do include Rack::Test::Methods def app HELIX_WEB_SERVICES_APP end context 'GET /helix_versioning_engine/v78/changes' do it 'should list change 1' do authorize 'jdoe', ticket_for_jdoe get('/helix_versioning_engine/v78/changes') expect(last_response.status).to eq(200) changes = JSON.parse(last_response.body) expect(changes.map { |c| c['change'] }).to include('1') end it 'can limit the test results to 1 with the max parameter' do authorize 'jdoe', ticket_for_jdoe get('/helix_versioning_engine/v78/changes?max=1') expect(last_response.status).to eq(200) changes = JSON.parse(last_response.body) expect(changes.length).to eq(1) end it 'can limit the change results by user' do authorize 'jdoe', ticket_for_jdoe get('/helix_versioning_engine/v78/changes?user=super') expect(last_response.status).to eq(200) changes = JSON.parse(last_response.body) expect(changes.map { |c| c['user'] }).to satisfy { |x| x.all? { |y| y == 'super'} } end it 'can limit the change results by status' do authorize 'jdoe', ticket_for_jdoe get('/helix_versioning_engine/v78/changes?status=submitted') expect(last_response.status).to eq(200) changes = JSON.parse(last_response.body) expect(changes.map { |c| c['status'] }).to satisfy { |x| x.all? { |y| y == 'submitted'} } end it 'can limit the change results by a files query' do authorize 'jdoe', ticket_for_jdoe get('/helix_versioning_engine/v78/changes?files=//depot/dev/Experimental/README') expect(last_response.status).to eq(200) changes = JSON.parse(last_response.body) expect(changes.map { |c| c['change'] }).to include('1') end end context 'POST /helix_versioning_engine/v78/changes' do # This test is really only valid after an immediate reset of p4d. it 'can branch files' do rand_str = (0...8).map { (65 + rand(26)).chr }.join request_body = { 'Files' => [ { 'DepotFile' => "//depot/test-#{rand_str}/Experimental/...", 'FromDepotFile' => '//depot/dev/Experimental/...', 'Action' => 'branch' } ] } authorize 'jdoe', ticket_for_jdoe post('/helix_versioning_engine/v78/changes', request_body) expect(last_response.status).to eq(200) get("/helix_versioning_engine/v78/files/depot/test-#{rand_str}/Experimental") expect(last_response.status).to eq(200) files = JSON.parse(last_response.body) expect(files.map {|f| f['depotFile']}).to include("//depot/test-#{rand_str}/Experimental/README") end it 'can add files' do rand_str = (0...8).map { (65 + rand(26)).chr }.join request_body = { 'Description' => 'Upload two experimental files', 'Files' => [ { 'DepotFile' => "//depot/dev/Experimental/teapot1-#{rand_str}.txt", 'Action' => 'upload', 'Content' => Base64.encode64("I'm a little teapot") }, { 'DepotFile' => "//depot/dev/Experimental/teapot2-#{rand_str}.txt", 'Action' => 'upload', 'Content' => Base64.encode64('Short and stout!') } ] } authorize 'jdoe', ticket_for_jdoe post('/helix_versioning_engine/v78/changes', request_body) expect(last_response.status).to eq(200) get('/helix_versioning_engine/v78/files/depot/dev/Experimental') expect(last_response.status).to eq(200) files = JSON.parse(last_response.body) expect(files.map {|f| f['depotFile']}).to include("//depot/dev/Experimental/teapot1-#{rand_str}.txt") expect(files.map {|f| f['depotFile']}).to include("//depot/dev/Experimental/teapot2-#{rand_str}.txt") end end context 'GET /helix_versioning_engine/v78/changes/[change]' do it 'can describe file lists in submitted changes' do authorize 'jdoe', ticket_for_jdoe get('/helix_versioning_engine/v78/changes/1') expect(last_response.status).to eq(200) change = JSON.parse(last_response.body).first expect(change['depotFile']).to include('//depot/dev/Experimental/README') expect(change['depotFile']).to include('//depot/main/My Project/README') end end context 'POST /helix_versioning_engine/v78/changes/[change]' do it 'can submit a changelist with shelved changes on a normal client' do rand_str = (0...8).map { (65 + rand(26)).chr }.join relative_path = "depot/shelved_stuff/#{rand_str}" temp_client_as_jdoe do |p4, p4_root| path = File.absolute_path("#{p4_root}/#{relative_path}") unless Dir.exist?(File.dirname(path)) FileUtils.mkdir_p(File.dirname(path)) end IO.write(path, "I'm a little teapot") change_spec = p4.fetch_change change_spec._description = "Testing shelving for #{rand_str}" results = p4.save_change(change_spec) change_num = /^Change (\d+) created.$/.match(results.first)[1] #puts "change_num: #{change_num}" results = p4.run_add('-c', change_num, path) #puts "add: #{results}" results = p4.run_shelve('-c', change_num) #puts "shelve: #{results}" results = p4.run_revert('-c', change_num, path) #puts "revert: #{results}" authorize 'jdoe', ticket_for_jdoe post("/helix_versioning_engine/v78/changes/#{change_num}") end expect(last_response.status).to eq(200) get("/helix_versioning_engine/v78/files/#{relative_path}") expect(last_response.status).to eq(200) file = JSON.parse(last_response.body) expect(file['depotFile']).to eq("//#{relative_path}") end it 'can submit a changelist with shelved changes on a normal client' do rand_str = (0...8).map { (65 + rand(26)).chr }.join relative_path = "shelved_stuff/#{rand_str}" stream = nil temp_stream_client_as_jdoe do |p4, p4_root, s| stream = s path = File.absolute_path("#{p4_root}/#{relative_path}") unless Dir.exist?(File.dirname(path)) FileUtils.mkdir_p(File.dirname(path)) end IO.write(path, "I'm a little teapot") change_spec = p4.fetch_change change_spec._description = "Testing shelving for #{rand_str}" results = p4.save_change(change_spec) change_num = /^Change (\d+) created.$/.match(results.first)[1] #puts "change_num: #{change_num}" results = p4.run_add('-c', change_num, path) #puts "add: #{results}" results = p4.run_shelve('-c', change_num) #puts "shelve: #{results}" results = p4.run_revert('-c', change_num, path) #puts "revert: #{results}" authorize 'jdoe', ticket_for_jdoe post("/helix_versioning_engine/v78/changes/#{change_num}") end expect(last_response.status).to eq(200) get("/helix_versioning_engine/v78/files/#{stream}/#{relative_path}") expect(last_response.status).to eq(200) file = JSON.parse(last_response.body) expect(file['depotFile']).to eq("#{stream}/#{relative_path}") end end end