require_relative '../test_config' require 'helix_versioning_engine' describe 'HelixVersioningEngine jobs' do include Rack::Test::Methods def app HELIX_WEB_SERVICES_APP end randstr = (0...8).map { (65 + rand(26)).chr }.join job_id = nil new_job = { 'Job' => 'new', 'User' => 'jdoe', 'Description' => "Test Job #{randstr}", 'Status' => 'open' } context 'POST /helix_versioning_engine/v78/jobs' do it 'can create a new job' do authorize 'super', ticket_for_super post('/helix_versioning_engine/v78/jobs', new_job) expect(last_response.status).to eq(200) end end context 'GET /helix_versioning_engine/v78/jobs' do it 'returns the new job in an array of jobs' do authorize 'super', ticket_for_super get('/helix_versioning_engine/v78/jobs') expect(last_response.status).to eq(200) jobs = JSON.parse(last_response.body) job = jobs.find{ |x| x['Description'].include?(new_job['Description'])} expect(job).to_not be nil job_id = job['Job'] end end context 'GET /helix_versioning_engine/v78/jobs/[job]' do it 'can fetch the new job' do authorize 'super', ticket_for_super get("/helix_versioning_engine/v78/jobs/#{job_id}") expect(last_response.status).to eq(200) job = JSON.parse(last_response.body) expect(job['Description']).to include(new_job['Description']) end end context 'PATCH /helix_versioning_engine/v78/jobs/[job]' do it 'can update the description' do authorize 'super', ticket_for_super patch("/helix_versioning_engine/v78/jobs/#{job_id}", { 'Description' => "Update #{randstr}"}) expect(last_response.status).to eq(200) get("/helix_versioning_engine/v78/jobs/#{job_id}") expect(last_response.status).to eq(200) job = JSON.parse(last_response.body) expect(job['Description']).to include("Update #{randstr}") end end context 'DELETE /helix_versioning_engine/v78/jobs/[job]' do it 'can delete the job' do authorize 'super', ticket_for_super delete("/helix_versioning_engine/v78/jobs/#{job_id}") expect(last_response.status).to eq(200) get('/helix_versioning_engine/v78/jobs') jobs = JSON.parse(last_response.body) expect(jobs.map{|x| x['name']}).to_not include(job_id) end end end