Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
erniebrodeur committed Nov 16, 2018
1 parent e682400 commit 283e451
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 132 deletions.
2 changes: 1 addition & 1 deletion spec/cts/mpx/driver/connections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Cts
module Mpx
module Driver
describe Connections do
include_context "with basic parameters"
include_context "with parameters"
let(:uri) { account_id }
let(:connection) { Excon.new uri }

Expand Down
5 changes: 3 additions & 2 deletions spec/cts/mpx/driver/exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ module Cts
module Mpx
module Driver
describe Exceptions do
include_context "with parameters"

let(:false_block) { proc { false } }
let(:true_block) { proc { true } }
let(:reference) { 1234 }

describe "::raise_unless_account_id" do
context "when the argument is not an account_id" do
let(:reference) { 1234 }

it "is expected to raise a ArgumentError with is not a valid account_id " do
expect { described_class.raise_unless_account_id(reference) }.to raise_error ArgumentError, /#{reference} is not a valid account_id/
Expand Down Expand Up @@ -44,7 +46,6 @@ module Driver
describe "::raise_unless_reference?" do
it { expect(described_class).to respond_to(:raise_unless_reference?).with(1).argument }
context "when the argument is not a reference" do
let(:reference) { 1234 }

it "is expected to raise a ArgumentError with is not a valid reference " do
expect { described_class.raise_unless_reference?(reference) }.to raise_error ArgumentError, /#{reference} is not a valid reference/
Expand Down
2 changes: 2 additions & 0 deletions spec/cts/mpx/driver/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Cts
module Mpx
module Driver
describe Request do
include_context "with parameters"

it { is_expected.to be_a_kind_of Creatable }

describe "Instance method signatures" do
Expand Down
2 changes: 1 addition & 1 deletion spec/cts/mpx/driver/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Cts
module Mpx
module Driver
describe Response do
include_context "with request and response"
include_context "with request and response objects"

it { is_expected.to be_a_kind_of Creatable }

Expand Down
4 changes: 2 additions & 2 deletions spec/cts/mpx/entries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module Cts
module Mpx
describe Entries do
include_context "with media entries"
include_context "with field"
include_context "with entries objects"
include_context "with field objects"

let(:other_entries) { Entries.create(collection: [other_entry]) }
let(:other_entry) { Entry.new }
Expand Down
60 changes: 29 additions & 31 deletions spec/cts/mpx/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
module Cts
module Mpx
describe Entry do
include_context "with basic parameters"
include_context "with field"
include_context "with media entry"
include_context "with page"
include_context "with parameters"
include_context "with field objects"
include_context "with media objects"
include_context "with page objects"
include_context "with empty objects"

let(:data) { { id: media_id } }
let(:empty_entry) { described_class.new }

it { is_expected.to be_a_kind_of Creatable }

Expand All @@ -28,8 +28,8 @@ module Mpx
end

describe '::self.load_by_id' do
include_context "with user"
include_context "with request and response"
include_context "with user objects"
include_context "with request and response objects"

let(:entries) { [{ "id" => media_id, "guid" => "123" }] }

Expand All @@ -54,7 +54,7 @@ module Mpx
end

it "is expected to call entry.load" do
allow(empty_entry).to receive(:load).and_return media_entry
allow(entry).to receive(:load).and_return media_entry
described_class.load_by_id user: user, id: 'http://data.media.theplatform.com/media/data/Media/1'
expect(media_entry).to have_received(:load)
end
Expand All @@ -64,27 +64,27 @@ module Mpx

describe '#id' do
context "when the argument is not a reference" do
it { expect { empty_entry.id = 'no' }.to raise_error ArgumentError, /is not a valid reference/ }
it { expect { entry.id = 'no' }.to raise_error ArgumentError, /is not a valid reference/ }
end

it "is expected to set service" do
empty_entry.id = media_id
expect(empty_entry.service).to eq media_service
entry.id = media_id
expect(entry.service).to eq media_service
end

it "is expected to set endpoint" do
empty_entry.id = media_id
expect(empty_entry.endpoint).to eq 'Media'
entry.id = media_id
expect(entry.endpoint).to eq 'Media'
end
it "is expected to build an id field" do
empty_entry.id = media_id
expect(empty_entry.fields['id']).to eq media_id
entry.id = media_id
expect(entry.fields['id']).to eq media_id
end
end

describe '#load' do
include_context "with user"
include_context "with request and response"
include_context "with user objects"
include_context "with request and response objects"

let(:fields) { 'id,guid' }
let(:params) { { user: user, fields: fields } }
Expand Down Expand Up @@ -131,10 +131,8 @@ module Mpx
end

describe '#save (when ID is not set)' do
include_context "with user"
include_context "with request and response"

let(:empty_entry) { Cts::Mpx::Entry.new }
include_context "with user objects"
include_context "with request and response objects"

before do
media_entry.fields['ownerId'] = account_id
Expand Down Expand Up @@ -163,33 +161,33 @@ module Mpx

context "when fields['ownerId'] is not set" do

before { empty_entry.fields['ownerId'] = nil }
before { entry.fields['ownerId'] = nil }

it { expect { empty_entry.save user: user }.to raise_error ArgumentError, "fields['ownerId'] must be set" }
it { expect { entry.save user: user }.to raise_error ArgumentError, "fields['ownerId'] must be set" }
end

context "when service is not set" do
before do
empty_entry.fields['ownerId'] = account_id
empty_entry.instance_variable_set :@service, nil
entry.fields['ownerId'] = account_id
entry.instance_variable_set :@service, nil
end

it { expect { empty_entry.save user: user }.to raise_error ArgumentError, /is a required keyword/ }
it { expect { entry.save user: user }.to raise_error ArgumentError, /is a required keyword/ }
end

context "when endpoint is not set" do
before do
empty_entry.fields['ownerId'] = account_id
empty_entry.instance_variable_set :@endpoint, nil
entry.fields['ownerId'] = account_id
entry.instance_variable_set :@endpoint, nil
end

it { expect { empty_entry.save user: user }.to raise_error ArgumentError, /is a required keyword/ }
it { expect { entry.save user: user }.to raise_error ArgumentError, /is a required keyword/ }
end
end

describe '#save (when ID is set)' do
include_context "with user"
include_context "with request and response"
include_context "with user objects"
include_context "with request and response objects"

before do
media_entry.fields['ownerId'] = account_id
Expand Down
14 changes: 4 additions & 10 deletions spec/cts/mpx/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
module Cts
module Mpx
describe Field do
let(:field_name) { 'guid' }
let(:field_value) { '12345' }
let(:custom_field_name) { 'custom$guid' }
let(:guid_field) { described_class.create name: field_name, value: field_value }
let(:custom_field) { described_class.create(name: custom_field_name, value: 'abcdef', xmlns: { "custom" => "http://1234a.com" }) }
include_context "with field objects"

it { is_expected.to be_a_kind_of Creatable }

Expand All @@ -23,14 +19,12 @@ module Mpx
it { is_expected.to respond_to(:type).with(0).argument }

describe '::to_h' do
let(:result) { guid_field }

it "is expected to have a key set to name" do
expect(result.to_h.keys.first).to eq field_name
expect(field.name).to eq field_name
end

it "is expected to have a value set to value" do
expect(result.to_h.values.first).to eq field_value
expect(field.value).to eq field_value
end
end

Expand All @@ -39,7 +33,7 @@ module Mpx
it { expect(custom_field.type).to eq :custom }
end

it { expect(guid_field.type).to eq :internal }
it { expect(field.type).to eq :internal }
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/cts/mpx/fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module Mpx
# entry: data
# }
# end
include_context "with field"
include_context "with basic objects"
include_context "with field objects"
include_context "with empty objects"

it { is_expected.to be_a_kind_of Enumerable }
it { is_expected.to be_a_kind_of Creatable }
Expand Down Expand Up @@ -137,7 +137,7 @@ module Mpx
end

describe '::parse' do
include_context "with media entry"
include_context "with media objects"

let(:data) { { id: media_id, service: media_service, endpoint: media_endpoint } }

Expand Down
17 changes: 6 additions & 11 deletions spec/cts/mpx/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ module Cts
module Mpx
describe Query do
include_context "with fields"
include_context "with media entry"
include_context "with request and response"
include_context "with user"

let(:new_entry) { described_class.new }
let(:query) { described_class.new }
include_context "with media objects"
include_context "with user objects"
include_context "with empty objects"
include_context "with request and response objects"

before do
allow(described_class).to receive(:new).and_return new_entry
allow(described_class).to receive(:new).and_return query
allow(Cts::Mpx::Services::Data).to receive(:get).and_return(populated_response)
end

Expand All @@ -33,11 +31,8 @@ module Mpx
it { is_expected.to have_attributes(sort: nil) }
end

describe "Class methods" do
describe "Responds to" do
it { expect(described_class).to respond_to(:create) }
end

describe "Instance methods" do
it { is_expected.to respond_to(:entries).with(0).arguments }
it { is_expected.to respond_to(:to_h).with(0).arguments.and_keywords(:include_entries) }
it { is_expected.to respond_to(:run).with(0).arguments.and_keywords(:user) }
Expand Down
40 changes: 17 additions & 23 deletions spec/cts/mpx/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
module Cts
module Mpx
describe Registry do
let(:user) { user }
let(:account_id) { account_id }
let(:root_account) { 'urn:theplatform:auth:root' }
let(:root_domain) { Driver.load_json_file('config/root_registry_sea1.json')['resolveDomainResponse'] }
include_context "with user objects"
include_context "with parameters"

let(:result_hash) do
{ 'resolveDomainResponse' => root_domain }
end
let(:root_domain) { Driver.load_json_file('config/root_registry_sea1.json')['resolveDomainResponse'] }
let(:result_hash) { { 'resolveDomainResponse' => root_domain } }

# before { described_class.initialize }
describe "Attributes" do
it { is_expected.to have_attributes(domains: an_instance_of(Hash)) }
end
Expand All @@ -26,7 +22,7 @@ module Mpx
describe "::fetch_and_store_domain" do
before do
allow(described_class).to receive(:fetch_domain).and_return(root_domain)
Registry.instance_variable_set(:@domains, root_account => root_domain)
Registry.instance_variable_set(:@domains, root_account_id => root_domain)
end

it "is expected to call fetch_domain" do
Expand All @@ -41,8 +37,8 @@ module Mpx
end

it "is expected to store the domain in domains" do
described_class.fetch_and_store_domain user, root_account
expect(described_class.domains).to eq root_account => result_hash["resolveDomainResponse"]
described_class.fetch_and_store_domain user, root_account_id
expect(described_class.domains).to eq root_account_id => result_hash["resolveDomainResponse"]
end

it "is expected to return the domain" do
Expand All @@ -51,6 +47,9 @@ module Mpx
end

describe "::fetch_domain" do
include_context "with response objects"
include_context "with user objects"

let(:post_params) do
{
user: user,
Expand All @@ -70,15 +69,10 @@ module Mpx
}'
end

let(:response) do
r = Driver::Response.new
r.instance_variable_set :@data, Oj.load(post_response_string)
r.instance_variable_set :@status, 200
r
before do
response.instance_variable_set :@data, Oj.load(post_response_string)
allow(Services::Web).to receive(:post).and_return response
end
let(:user) { user }

before { allow(Services::Web).to receive(:post).and_return response }

it { expect { described_class.fetch_domain user, account_id }.to raise_error_without_user_token(user) }

Expand All @@ -101,7 +95,7 @@ module Mpx

context "when no account_id is supplied" do
it "is expected to return the root account_id (urn:theplatform:auth:root)" do
expect(described_class.fetch_domain(user, root_account)).to eq described_class.domains[root_account]
expect(described_class.fetch_domain(user, root_account_id)).to eq described_class.domains[root_account_id]
end
end
end
Expand All @@ -110,7 +104,7 @@ module Mpx
let(:file) { 'config/root_registry.sea1.json' }

# this effectively re-initializes things without calling initialize or store_domain.
after { Registry.instance_variable_set(:@domains, root_account => root_domain) }
after { Registry.instance_variable_set(:@domains, root_account_id => root_domain) }

before do
allow(Driver).to receive(:load_json_file).with(/#{file}/).and_return(result_hash)
Expand All @@ -121,10 +115,10 @@ module Mpx
expect(Driver).to have_received(:load_json_file)
end

it "is expected to call store_domain with root_account and the hash" do
it "is expected to call store_domain with root_account_id and the hash" do
allow(described_class).to receive(:store_domain).and_return(result_hash)
described_class.initialize
expect(described_class).to have_received(:store_domain).with(root_domain, root_account)
expect(described_class).to have_received(:store_domain).with(root_domain, root_account_id)
end
end

Expand Down
Loading

0 comments on commit 283e451

Please sign in to comment.