test/unit/contact_test.rb in xero_gateway-2.3.0 vs test/unit/contact_test.rb in xero_gateway-2.4.0

- old
+ new

@@ -30,9 +30,71 @@ # Check the contact details assert_equal contact, result_contact end + # this allows you to remove addresses from Xero + test "explicity passing an empty array for addresses should include an empty element" do + contact = create_test_contact + contact.addresses = nil + + parsed = REXML::XPath.first(REXML::Document.new(contact.to_xml), "/Contact") + assert !parsed.children.map(&:name).include?("Addresses") + + contact.addresses = [] + parsed = REXML::XPath.first(REXML::Document.new(contact.to_xml), "/Contact") + assert parsed.children.map(&:name).include?("Addresses") + end + + test "should be able to set addresses as part of initialize" do + contact = XeroGateway::Contact.new(contact_id: "abcdef-3abe", name: "Test", addresses: []) + + parsed = REXML::XPath.first(REXML::Document.new(contact.to_xml), "/Contact") + assert parsed.children.map(&:name).include?("Addresses") + end + + test "parsing from XML" do + test_xml = <<-TESTING.strip_heredoc.chomp + <Contact> + <ContactID>f1d403d1-7d30-46c2-a2be-fc2bb29bd295</ContactID> + <ContactStatus>ACTIVE</ContactStatus> + <Name>24 Locks</Name> + <Addresses> + <Address> + <AddressType>POBOX</AddressType> + </Address> + <Address> + <AddressType>STREET</AddressType> + </Address> + </Addresses> + <Phones> + <Phone> + <PhoneType>DDI</PhoneType> + </Phone> + <Phone> + <PhoneType>DEFAULT</PhoneType> + </Phone> + <Phone> + <PhoneType>FAX</PhoneType> + </Phone> + <Phone> + <PhoneType>MOBILE</PhoneType> + </Phone> + </Phones> + <UpdatedDateUTC>2016-08-31T04:55:39.217</UpdatedDateUTC> + <IsSupplier>false</IsSupplier> + <IsCustomer>false</IsCustomer> + <HasAttachments>false</HasAttachments> + </Contact> + TESTING + + contact_element = REXML::XPath.first(REXML::Document.new(test_xml.gsub(/\s/, "")), "/Contact") + contact = XeroGateway::Contact.from_xml(contact_element) + + assert_equal Time.new(2016, 8, 31, 04, 55, 39), contact.updated_at.utc + + end + # Test Contact#add_address helper creates a valid XeroGateway::Contact object with the passed in values # and appends it to the Contact#addresses attribute. def test_add_address_helper contact = create_test_contact assert_equal(1, contact.addresses.size)