Skip to content

Commit

Permalink
test: check clientprefix are there and correct creation order
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed May 14, 2020
1 parent e35d95d commit a59d225
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
13 changes: 9 additions & 4 deletions spec/models/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
let!(:prefixes) { create_list(:prefix, 3) }
let!(:prefix) { prefixes.first }

let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix) }
### Order is important in creating prefixes relations
let!(:provider_prefix) { create(:provider_prefix, provider: provider, prefix: prefix) }
let!(:provider_prefix_more) { create(:provider_prefix, provider: provider, prefix: prefixes.last) }
let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix, provider_prefix_id: provider_prefix.uid) }

let(:new_provider) { create(:provider, symbol: "QUECHUA", member_type: "direct_member") }
let(:options) { { target_id: new_provider.symbol } }
let(:bad_options) { { target_id: "SALS" } }
Expand All @@ -44,6 +46,8 @@

expect(new_provider.prefix_ids).to include(prefix.uid)
expect(provider.prefix_ids).not_to include(prefix.uid)

expect(client.prefix_ids).to include(prefix.uid)
end

it "it doesn't transfer" do
Expand Down Expand Up @@ -101,9 +105,10 @@
describe "Client prefixes transfer" do
let!(:prefixes) { create_list(:prefix, 3) }
let!(:prefix) { prefixes.first }
let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix) }
let!(:provider_prefix) { create(:provider_prefix, provider: provider, prefix: prefix) }
### Order is important in creating prefixes relations
let!(:provider_prefix) { create(:provider_prefix, provider: provider, prefix: prefix) }
let!(:provider_prefix_more) { create(:provider_prefix, provider: provider, prefix: prefixes.last) }
let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix , provider_prefix_id: provider_prefix.uid) }
let(:new_provider) { create(:provider, symbol: "QUECHUA") }

it "works" do
Expand All @@ -114,10 +119,10 @@

expect(new_provider.prefix_ids).to include(prefix.uid)
expect(provider.prefix_ids).not_to include(prefix.uid)
expect(client.prefix_ids).to include(prefix.uid)
end
end


describe "methods" do
it "should not update the symbol" do
client.update_attributes :symbol => client.symbol+'foo.bar'
Expand Down
10 changes: 5 additions & 5 deletions spec/requests/clients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,10 @@
let(:new_provider) { create(:provider, symbol: "QUECHUA", password_input: "12345") }
let!(:prefixes) { create_list(:prefix, 3) }
let!(:prefix) { prefixes.first }
let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix) }
let!(:provider_prefix) { create(:provider_prefix, provider: provider, prefix: prefix) }
let!(:provider_prefix_more) { create(:provider_prefix, provider: provider, prefix: prefixes.last) }
let!(:provider_prefix) { create(:provider_prefix, provider: provider, prefix: prefix) }
let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix, provider_prefix_id: provider_prefix.uid) }
let(:doi) { create_list(:doi, 10, client: client) }


let(:params) do
{
"data" => {
Expand All @@ -254,8 +252,10 @@
expect(json.dig("data", "relationships", "prefixes", "data").first.dig("id")).to eq(prefixes.last.uid)

get "/providers/#{new_provider.symbol}"

expect(json.dig("data", "relationships", "prefixes", "data").first.dig("id")).to eq(prefix.uid)

get "/prefixes/#{prefix.uid}"
expect(json.dig("data", "relationships", "clients", "data").first.dig("id")).to eq(client.symbol.downcase)
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/requests/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@

let(:new_provider) { create(:provider, symbol: "QUECHUA", password_input: "12345") }
let!(:prefix) { create(:prefix) }
let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix) }
let!(:provider_prefix) { create(:provider_prefix, provider: provider, prefix: prefix) }
let!(:client_prefix) { create(:client_prefix, client: client, prefix: prefix, provider_prefix_id: provider_prefix.uid) }
let(:doi) { create_list(:doi, 10, client: client) }

let(:params) do
Expand Down Expand Up @@ -318,6 +318,9 @@
get "/providers/#{new_provider.symbol}"

expect(json.dig("data", "relationships", "prefixes", "data").first.dig("id")).to eq(prefix.uid)

get "/prefixes/#{prefix.uid}"
expect(json.dig("data", "relationships", "clients", "data").first.dig("id")).to eq(client.symbol.downcase)
end
end

Expand Down

0 comments on commit a59d225

Please sign in to comment.