require_relative '../test_config' require 'helix_versioning_engine' describe 'HelixVersioningEngine groups' do include Rack::Test::Methods randstr = (0...8).map { (65 + rand(26)).chr }.join group_id = "test_#{randstr}" new_group = { 'Group' => group_id, 'Users' => ['jdoe'] } def app HELIX_WEB_SERVICES_APP end context 'POST /helix_versioning_engine/v78/groups' do it 'can create a test group' do authorize 'super', ticket_for_super post('/helix_versioning_engine/v78/groups', new_group) expect(last_response.status).to eq(200) end end context 'GET /helix_versioning_engine/v78/groups' do it 'can find the new group in an array of groups' do authorize 'super', ticket_for_super get('/helix_versioning_engine/v78/groups') expect(last_response.status).to eq(200) results = JSON.parse(last_response.body) group_ids = results.map { |x| x['group'] } expect(group_ids).to include(group_id) end end context 'PATCH /helix_versioning_engine/v78/groups/[group]' do it 'can update the users list' do authorize 'super', ticket_for_super patch("/helix_versioning_engine/v78/groups/#{group_id}", 'Users' => ['super']) expect(last_response.status).to eq(200) end end context 'GET /helix_versioning_engine/v78/groups/[group]' do it 'can load the new group with a View' do authorize 'super', ticket_for_super get("/helix_versioning_engine/v78/groups/#{group_id}") expect(last_response.status).to eq(200) obj = JSON.parse(last_response.body) expect(obj['Group']).to eq(group_id) expect(obj['Users']).to include('super') end end context 'DELETE /helix_versioning_engine/v78/groups/[group]' do it 'can delete the group' do authorize 'super', ticket_for_super delete("/helix_versioning_engine/v78/groups/#{group_id}") expect(last_response.status).to eq(200) get('/helix_versioning_engine/v78/groups') expect(last_response.status).to eq(200) results = JSON.parse(last_response.body) group_ids = results.map { |x| x['group'] } expect(group_ids).to_not include(group_id) end end end