-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test permissions for consortium. #432
- Loading branch information
Martin Fenner
committed
Feb 27, 2020
1 parent
e1b75d4
commit fc5c2a1
Showing
3 changed files
with
67 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
require 'rails_helper' | ||
|
||
describe "Providers", type: :request, elasticsearch: true do | ||
let!(:provider) { create(:provider) } | ||
let(:token) { User.generate_token } | ||
let(:consortium) { create(:provider, role_name: "ROLE_CONSORTIUM") } | ||
let(:provider) { create(:provider, consortium: consortium, role_name: "ROLE_CONSORTIUM_ORGANIZATION") } | ||
let(:token) { User.generate_token(role_id: "consortium_admin", provider_id: consortium.symbol.downcase) } | ||
let(:admin_token) { User.generate_token } | ||
let(:params) do | ||
{ "data" => { "type" => "providers", | ||
"attributes" => { | ||
|
@@ -14,21 +16,22 @@ | |
"country" => "GB" } } } | ||
end | ||
let(:headers) { {'HTTP_ACCEPT'=>'application/vnd.api+json', 'HTTP_AUTHORIZATION' => 'Bearer ' + token } } | ||
let(:admin_headers) { {'HTTP_ACCEPT'=>'application/vnd.api+json', 'HTTP_AUTHORIZATION' => 'Bearer ' + admin_token } } | ||
|
||
describe 'GET /providers' do | ||
let!(:providers) { create_list(:provider, 3) } | ||
let!(:providers) { create_list(:provider, 3) } | ||
|
||
before do | ||
Provider.import | ||
sleep 2 | ||
sleep 1 | ||
end | ||
|
||
it "returns providers" do | ||
get "/providers", nil, headers | ||
|
||
expect(last_response.status).to eq(200) | ||
expect(json['data'].size).to eq(4) | ||
expect(json.dig('meta', 'total')).to eq(4) | ||
expect(json['data'].size).to eq(3) | ||
expect(json.dig('meta', 'total')).to eq(3) | ||
end | ||
end | ||
|
||
|
@@ -57,32 +60,22 @@ | |
end | ||
|
||
context 'get provider type ROLE_CONTRACTUAL_PROVIDER and check it works ' do | ||
let(:provider) { create(:provider, role_name: "ROLE_CONTRACTUAL_PROVIDER", name: "Contractor", symbol: "CONTRCTR") } | ||
let(:provider) { create(:provider, role_name: "ROLE_CONTRACTUAL_PROVIDER", name: "Contractor", symbol: "CONTRCTR") } | ||
|
||
it 'get provider' do | ||
get "/providers/#{provider.symbol.downcase}", nil, headers | ||
|
||
expect(last_response.status).to eq(200) | ||
expect(json).not_to be_empty | ||
expect(json.dig('data', 'id')).to eq(provider.symbol.downcase) | ||
end | ||
|
||
it 'returns status code 200' do | ||
get "/providers/#{provider.symbol.downcase}", nil, headers | ||
|
||
expect(last_response.status).to eq(200) | ||
end | ||
end | ||
|
||
context 'when the record does not exist' do | ||
it 'returns status code 404' do | ||
get "/providers/xxx", nil, headers | ||
|
||
expect(last_response.status).to eq(404) | ||
end | ||
|
||
it 'returns a not found message' do | ||
get "/providers/xxx", nil, headers | ||
|
||
expect(last_response.status).to eq(404) | ||
expect(json["errors"].first).to eq("status"=>"404", "title"=>"The resource you are looking for doesn't exist.") | ||
end | ||
end | ||
|
@@ -119,19 +112,29 @@ | |
end | ||
end | ||
|
||
describe 'POST /providers' do | ||
context 'request is valid' do | ||
describe "POST /providers" do | ||
context "request is valid" do | ||
let(:params) do | ||
{ "data" => { "type" => "providers", | ||
"attributes" => { | ||
"symbol" => "BL", | ||
"name" => "British Library", | ||
"displayName" => "British Library", | ||
"memberType" => "consortium_organization", | ||
"website" => "https://www.bl.uk", | ||
"salesforceId" => "abc012345678901234", | ||
"region" => "EMEA", | ||
"systemEmail" => "[email protected]", | ||
"country" => "GB" } } } | ||
"country" => "GB" | ||
}, | ||
"relationships": { | ||
"consortium": { | ||
"data": { | ||
"type": "providers", | ||
"id": consortium.symbol.downcase, | ||
} | ||
} | ||
} } } | ||
end | ||
|
||
it 'creates a provider' do | ||
|
@@ -140,12 +143,12 @@ | |
expect(last_response.status).to eq(200) | ||
expect(json.dig('data', 'attributes', 'name')).to eq("British Library") | ||
expect(json.dig('data', 'attributes', 'systemEmail')).to eq("[email protected]") | ||
expect(json.dig('data', 'attributes', 'salesforceId')).to eq("abc012345678901234") | ||
expect(json.dig('data', 'relationships', 'consortium', 'data', 'id')).to eq(consortium.symbol.downcase) | ||
end | ||
end | ||
|
||
context 'request ability check' do | ||
let!(:providers) { create_list(:provider, 2) } | ||
context "request ability check" do | ||
let!(:providers) { create_list(:provider, 2) } | ||
let(:last_provider_token) { User.generate_token(provider_id: providers.last.symbol, role_id:"provider_admin") } | ||
let(:headers_last) { {'HTTP_ACCEPT'=>'application/vnd.api+json', 'HTTP_AUTHORIZATION' => 'Bearer ' + last_provider_token } } | ||
|
||
|
@@ -154,7 +157,7 @@ | |
sleep 1 | ||
end | ||
|
||
it 'has no permission' do | ||
it "has no permission" do | ||
get "/providers/#{providers.first.symbol}", nil, headers_last | ||
|
||
expect(json["data"].dig('attributes', 'symbol')).to eq(providers.first.symbol) | ||
|
@@ -163,7 +166,7 @@ | |
end | ||
end | ||
|
||
context 'create provider member_role contractual_member' do | ||
context "create provider member_role contractual_member" do | ||
let(:params) do | ||
{ "data" => { "type" => "providers", | ||
"attributes" => { | ||
|
@@ -177,8 +180,8 @@ | |
"country" => "GB" } } } | ||
end | ||
|
||
it 'creates a provider' do | ||
post '/providers', params, headers | ||
it "creates a provider" do | ||
post "/providers", params, admin_headers | ||
|
||
expect(last_response.status).to eq(200) | ||
expect(json.dig('data', 'attributes', 'systemEmail')).to eq("[email protected]") | ||
|
@@ -187,8 +190,7 @@ | |
end | ||
end | ||
|
||
context 'create provider member_role consortium_organization' do | ||
let(:consortium) { create(:provider, member_type: "consortium") } | ||
context "create provider member_role consortium_organization" do | ||
let(:params) do | ||
{ "data" => { "type" => "providers", | ||
"attributes" => { | ||
|
@@ -241,8 +243,7 @@ | |
end | ||
end | ||
|
||
context 'create provider not member_role consortium_organization' do | ||
let(:consortium) { create(:provider, member_type: "consortium") } | ||
context "create provider not member_role consortium_organization" do | ||
let(:params) do | ||
{ "data" => { "type" => "providers", | ||
"attributes" => { | ||
|
@@ -276,7 +277,6 @@ | |
end | ||
|
||
context 'create provider not member_role consortium' do | ||
let(:consortium) { create(:provider, member_type: "provider") } | ||
let(:params) do | ||
{ "data" => { "type" => "providers", | ||
"attributes" => { | ||
|
@@ -287,19 +287,20 @@ | |
"systemEmail" => "[email protected]", | ||
"website" => "https://www.bl.uk", | ||
"memberType" => "consortium_organization", | ||
"country" => "GB" }, | ||
"relationships": { | ||
"consortium": { | ||
"data":{ | ||
"type": "providers", | ||
"id": consortium.symbol.downcase | ||
} | ||
"country" => "GB" | ||
}, | ||
"relationships": { | ||
"consortium": { | ||
"data":{ | ||
"type": "providers", | ||
"id": provider.symbol.downcase | ||
} | ||
}} } | ||
} | ||
}} } | ||
end | ||
|
||
it 'creates a provider' do | ||
post '/providers', params, headers | ||
post '/providers', params, admin_headers | ||
|
||
expect(last_response.status).to eq(422) | ||
expect(json["errors"].first).to eq("source"=>"consortium_id", "title"=>"The consortium must be of member_type consortium") | ||
|
@@ -347,7 +348,7 @@ | |
end | ||
|
||
it 'creates a provider' do | ||
post '/providers', params, headers | ||
post '/providers', params, admin_headers | ||
|
||
expect(last_response.status).to eq(200) | ||
expect(json.dig('data', 'attributes', 'systemEmail')).to eq("[email protected]") | ||
|
@@ -414,7 +415,7 @@ | |
end | ||
|
||
it 'creates a provider' do | ||
post '/providers', params, headers | ||
post '/providers', params, admin_headers | ||
|
||
expect(last_response.status).to eq(200) | ||
expect(json.dig('data', 'attributes', 'technicalContact',"email")).to eq("[email protected]") | ||
|
@@ -468,17 +469,11 @@ | |
end | ||
|
||
it 'creates a provider' do | ||
post '/providers', params, headers | ||
|
||
expect(json.dig('data', 'attributes', 'systemEmail')).to eq("[email protected]") | ||
end | ||
|
||
it 'returns status code 200' do | ||
post '/providers', params, headers | ||
post '/providers', params, admin_headers | ||
|
||
expect(last_response.status).to eq(200) | ||
expect(json.dig('data', 'attributes', 'systemEmail')).to eq("[email protected]") | ||
end | ||
|
||
end | ||
|
||
context 'request for admin provider' do | ||
|
@@ -494,7 +489,7 @@ | |
end | ||
|
||
it 'creates a provider' do | ||
post '/providers', params, headers | ||
post '/providers', params, admin_headers | ||
|
||
expect(last_response.status).to eq(200) | ||
expect(json.dig('data', 'attributes', 'systemEmail')).to eq("[email protected]") | ||
|
@@ -537,7 +532,7 @@ | |
end | ||
|
||
it 'creates a provider' do | ||
post '/providers', params, headers | ||
post '/providers', params, admin_headers | ||
|
||
expect(last_response.status).to eq(200) | ||
expect(json.dig('data', 'attributes', 'symbol')).to match(/\A[A-Z]{4}\Z/) | ||
|
@@ -556,7 +551,7 @@ | |
end | ||
|
||
it 'returns a validation failure message' do | ||
post '/providers', params, headers | ||
post '/providers', params, admin_headers | ||
|
||
expect(last_response.status).to eq(422) | ||
expect(json["errors"].first).to eq("source"=>"system_email", "title"=>"Can't be blank") | ||
|
@@ -576,7 +571,7 @@ | |
end | ||
|
||
it 'returns status code 400' do | ||
post '/providers', params, headers | ||
post '/providers', params, admin_headers | ||
|
||
expect(last_response.status).to eq(400) | ||
end | ||
|
@@ -595,10 +590,20 @@ | |
"name" => "British Library", | ||
"globusUuid" => "9908a164-1e4f-4c17-ae1b-cc318839d6c8", | ||
"displayName" => "British Library", | ||
"memberType" => "consortium_organization", | ||
"website" => "https://www.bl.uk", | ||
"region" => "Americas", | ||
"systemEmail" => "[email protected]", | ||
"country" => "GB" } } } | ||
"country" => "GB" | ||
}, | ||
"relationships": { | ||
"consortium": { | ||
"data":{ | ||
"type": "providers", | ||
"id": consortium.symbol.downcase | ||
} | ||
} | ||
}} } | ||
end | ||
|
||
it 'updates the record' do | ||
|
@@ -607,6 +612,7 @@ | |
expect(last_response.status).to eq(200) | ||
expect(json.dig('data', 'attributes', 'displayName')).to eq("British Library") | ||
expect(json.dig('data', 'attributes', 'globusUuid')).to eq("9908a164-1e4f-4c17-ae1b-cc318839d6c8") | ||
expect(json.dig('data', 'relationships', 'consortium', 'data', 'id')).to eq(consortium.symbol.downcase) | ||
end | ||
end | ||
|
||
|