From 74e4e8ccb2e93b1f2d5ccb133271b8c7d40d27c2 Mon Sep 17 00:00:00 2001 From: Gareth Robinson Date: Mon, 6 Sep 2021 15:36:30 +1000 Subject: [PATCH 1/2] Fix contacts array when creating or updating client --- lib/xpm_ruby/schema/client/add.rb | 18 ++++++++---------- lib/xpm_ruby/schema/client/update.rb | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/xpm_ruby/schema/client/add.rb b/lib/xpm_ruby/schema/client/add.rb index 129335f..f2c9f07 100644 --- a/lib/xpm_ruby/schema/client/add.rb +++ b/lib/xpm_ruby/schema/client/add.rb @@ -25,16 +25,14 @@ module Client AccountManagerID?: Types::String, Contacts?: Types::Array.of( Types::Hash.schema( - Contact: Types::Hash.schema( - Name: Types::String, - IsPrimary?: Types::String, - Salutation?: Types::String, - Addressee?: Types::String, - Phone?: Types::Coercible::String, - Mobile?: Types::Coercible::String, - Email?: Types::String, - Position?: Types::String - ).with_key_transform(&:to_sym) + Name: Types::String, + IsPrimary?: Types::String, + Salutation?: Types::String, + Addressee?: Types::String, + Phone?: Types::Coercible::String, + Mobile?: Types::Coercible::String, + Email?: Types::String, + Position?: Types::String ).with_key_transform(&:to_sym) ), BillingClientID?: Types::Coercible::String, diff --git a/lib/xpm_ruby/schema/client/update.rb b/lib/xpm_ruby/schema/client/update.rb index a02ef6c..a5e0047 100644 --- a/lib/xpm_ruby/schema/client/update.rb +++ b/lib/xpm_ruby/schema/client/update.rb @@ -26,16 +26,14 @@ module Client AccountManagerID?: Types::String, Contacts?: Types::Array.of( Types::Hash.schema( - Contact: Types::Hash.schema( - Name: Types::String, - IsPrimary?: Types::String, - Salutation?: Types::String, - Addressee?: Types::String, - Phone?: Types::Coercible::String, - Mobile?: Types::Coercible::String, - Email?: Types::String, - Position?: Types::String - ).with_key_transform(&:to_sym) + Name: Types::String, + IsPrimary?: Types::String, + Salutation?: Types::String, + Addressee?: Types::String, + Phone?: Types::Coercible::String, + Mobile?: Types::Coercible::String, + Email?: Types::String, + Position?: Types::String ).with_key_transform(&:to_sym) ), BillingClientID?: Types::Coercible::String, From 150752518217ec9daaadb4ca3434aedd3ba55d82 Mon Sep 17 00:00:00 2001 From: Gareth Robinson Date: Mon, 6 Sep 2021 15:42:37 +1000 Subject: [PATCH 2/2] Fix specs --- spec/xpm_ruby/schema/client/add_spec.rb | 4 ++-- spec/xpm_ruby/schema/client/update_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/xpm_ruby/schema/client/add_spec.rb b/spec/xpm_ruby/schema/client/add_spec.rb index f6406e0..e275486 100644 --- a/spec/xpm_ruby/schema/client/add_spec.rb +++ b/spec/xpm_ruby/schema/client/add_spec.rb @@ -6,7 +6,7 @@ module Schema context "with a valid Add schema" do context "with contacts" do it "should not raise an error" do - hash = { "Name" => "Joe Bloggs Consulting", "Contacts" => [{ "Contact" => { "Name" => "Joe Bloggs" } }] } + hash = { "Name" => "Joe Bloggs Consulting", "Contacts" => [{ "Name" => "Joe Bloggs" }] } expect { Client::Add[hash] }.not_to raise_error end end @@ -32,7 +32,7 @@ module Schema end it "should raise an error on contacts" do - hash = { "Name" => "Joe Bloggs Consulting", "Contacts" => [{ "Contact" => { "Email" => "Joe Bloggs" } }] } + hash = { "Name" => "Joe Bloggs Consulting", "Contacts" => [{ "Email" => "Joe Bloggs" }] } expect { Client::Add[hash] }.to raise_error(Dry::Types::SchemaError, /Name is missing in Hash input/) end end diff --git a/spec/xpm_ruby/schema/client/update_spec.rb b/spec/xpm_ruby/schema/client/update_spec.rb index a3ca8a7..ef32e95 100644 --- a/spec/xpm_ruby/schema/client/update_spec.rb +++ b/spec/xpm_ruby/schema/client/update_spec.rb @@ -6,7 +6,7 @@ module Schema context "with a valid Update schema" do context "with contacts" do it "should not raise an error" do - hash = { "ID" => 25655881, "Name" => "Joe Bloggs Consulting", "Contacts" => [{ "Contact" => { "Name" => "Joe Bloggs" } }] } + hash = { "ID" => 25655881, "Name" => "Joe Bloggs Consulting", "Contacts" => [{ "Name" => "Joe Bloggs" }] } expect { Client::Update[hash] }.not_to raise_error end end @@ -32,7 +32,7 @@ module Schema end it "should raise an error on contacts" do - hash = { "ID" => 25655881, "Name" => "Joe Bloggs Consulting", "Contacts" => [{ "Contact" => { "Email" => "Joe Bloggs" } }] } + hash = { "ID" => 25655881, "Name" => "Joe Bloggs Consulting", "Contacts" => [{ "Email" => "Joe Bloggs" }] } expect { Client::Update[hash] }.to raise_error(Dry::Types::SchemaError, /Name is missing in Hash input/) end end