Skip to content

Commit

Permalink
Expanding tests for custom field list
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed Jul 15, 2021
1 parent 9836ca7 commit 04105ca
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
42 changes: 40 additions & 2 deletions spec/netsuite/records/custom_field_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,53 @@
describe NetSuite::Records::CustomFieldList do
let(:list) { NetSuite::Records::CustomFieldList.new }

before(:all) { savon.mock! }
after(:all) { savon.unmock! }

it 'has a custom_fields attribute' do
expect(list.custom_fields).to be_kind_of(Array)
end

it 'accepts a collection of CustomField records' do
field = NetSuite::Records::CustomField.new({:value=>{:internal_id=>"5", :type_id=>"103"},
:script_id=>"custitem_item_category", :"@xsi:type"=>"platformCore:SelectCustomFieldRef"})
field = NetSuite::Records::CustomField.new({
:value=>{:internal_id=>"5", :type_id=>"103"},
:script_id=>"custitem_item_category",
:"@xsi:type"=>"platformCore:SelectCustomFieldRef"
})

list = described_class.new(custom_field: [field])

expect(list.custom_fields).to eq([field])
end

it 'properly decodes various custom field types' do
savon.
expects(:get).
with(message: {"platformMsgs:baseRef"=>{"@xsi:type"=>"platformCore:RecordRef", "@internalId"=>123, "@type"=>"creditMemo"}}).
returns(File.read('spec/support/fixtures/custom_fields/multi_select.xml'))

credit_memo_with_custom_fields = NetSuite::Records::CreditMemo.get(123)

expect(credit_memo_with_custom_fields.custom_field_list.custbody_standard_select.value.internal_id).to eq("2")
expect(credit_memo_with_custom_fields.custom_field_list.custbody_standard_select.value.attributes[:name]).to eq("Manual")

expect(credit_memo_with_custom_fields.custom_field_list.custbody_date_field.value).to be_a(DateTime)
expect(credit_memo_with_custom_fields.custom_field_list.custbody_date_field.value.to_s).to eq("2021-07-13T22:00:00-07:00")

expect(credit_memo_with_custom_fields.custom_field_list.custbody_string_field.value).to eq("a very nice string")
expect(credit_memo_with_custom_fields.custom_field_list.custbody_boolean_field.value).to eq(false)

# even if there's a single value, it should return an array
expect(credit_memo_with_custom_fields.custom_field_list.custbody_multi_select_field.value).to be_a(Array)
expect(credit_memo_with_custom_fields.custom_field_list.custbody_multi_select_field.value.size).to eq(1)
expect(credit_memo_with_custom_fields.custom_field_list.custbody_multi_select_field.value.first.attributes[:name]).to eq("selection value")

expect(credit_memo_with_custom_fields.custom_field_list.custbody_multi_select_with_multiple.value).to be_a(Array)
expect(credit_memo_with_custom_fields.custom_field_list.custbody_multi_select_with_multiple.value.size).to eq(2)
expect(credit_memo_with_custom_fields.custom_field_list.custbody_multi_select_with_multiple.value.first.attributes[:name]).to eq("selection value 1")
expect(credit_memo_with_custom_fields.custom_field_list.custbody_multi_select_with_multiple.value.last.attributes[:name]).to eq("selection value 2")
end

context 'initializing with custom field attributes without a type' do
it 'does not mutate the attributes' do
field = {:value=>{:internal_id=>"5", :type_id=>"103"},
Expand All @@ -28,7 +64,9 @@
it 'does not mutate the attributes' do
field = {:value=>{:internal_id=>"5", :type_id=>"103"},
:script_id=>"custitem_item_category", :"@xsi:type"=>"platformCore:SelectCustomFieldRef"}

described_class.new(custom_field: [field])

expect(field).to eq({:value=>{:internal_id=>"5", :type_id=>"103"},
:script_id=>"custitem_item_category", :"@xsi:type"=>"platformCore:SelectCustomFieldRef"})
end
Expand Down
47 changes: 47 additions & 0 deletions spec/support/fixtures/custom_fields/multi_select.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2017_2.platform.webservices.netsuite.com">
<platformMsgs:nsId>WEBSERVICES_4384362_0714202114843454571284681300_c8529d78de5</platformMsgs:nsId>
</platformMsgs:documentInfo>
</soapenv:Header>
<soapenv:Body>
<getResponse xmlns="urn:messages_2017_2.platform.webservices.netsuite.com">
<readResponse>
<platformCore:status xmlns:platformCore="urn:core_2017_2.platform.webservices.netsuite.com" isSuccess="true"/>
<record xmlns:tranCust="urn:customers_2017_2.transactions.webservices.netsuite.com" internalId="9948394" xsi:type="tranCust:CreditMemo">
<tranCust:createdDate>2021-07-14T12:45:42.000-07:00</tranCust:createdDate>
<tranCust:lastModifiedDate>2021-07-14T14:56:35.000-07:00</tranCust:lastModifiedDate>
<tranCust:customFieldList xmlns:platformCore="urn:core_2017_2.platform.webservices.netsuite.com">
<platformCore:customField internalId="520" scriptId="custbody_standard_select" xsi:type="platformCore:SelectCustomFieldRef">
<platformCore:value internalId="2" typeId="142">
<platformCore:name>Manual</platformCore:name>
</platformCore:value>
</platformCore:customField>
<platformCore:customField internalId="26" scriptId="custbody_date_field" xsi:type="platformCore:DateCustomFieldRef">
<platformCore:value>2021-07-13T22:00:00.000-07:00</platformCore:value>
</platformCore:customField>
<platformCore:customField internalId="1371" scriptId="custbody_string_field" xsi:type="platformCore:StringCustomFieldRef">
<platformCore:value>a very nice string</platformCore:value>
</platformCore:customField>
<platformCore:customField internalId="1593" scriptId="custbody_boolean_field" xsi:type="platformCore:BooleanCustomFieldRef">
<platformCore:value>false</platformCore:value>
</platformCore:customField>
<platformCore:customField internalId="1552" scriptId="custbody_multi_select_field" xsi:type="platformCore:MultiSelectCustomFieldRef">
<platformCore:value internalId="7623" typeId="164">
<platformCore:name>selection value</platformCore:name>
</platformCore:value>
</platformCore:customField>
<platformCore:customField internalId="1553" scriptId="custbody_multi_select_with_multiple" xsi:type="platformCore:MultiSelectCustomFieldRef">
<platformCore:value internalId="7613" typeId="164">
<platformCore:name>selection value 1</platformCore:name>
</platformCore:value>
<platformCore:value internalId="7614" typeId="165">
<platformCore:name>selection value 2</platformCore:name>
</platformCore:value>
</platformCore:customField>
</tranCust:customFieldList>
</record>
</readResponse>
</getResponse>
</soapenv:Body>
</soapenv:Envelope>

0 comments on commit 04105ca

Please sign in to comment.