Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
576d0f4
commit 64f9fb0
Showing
6 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
require 'spec_helper' | ||
|
||
describe NetSuite::Actions::UpdateList do | ||
before { savon.mock! } | ||
after { savon.unmock! } | ||
|
||
context 'Items' do | ||
context 'one item' do | ||
let(:item) do | ||
[ | ||
NetSuite::Records::InventoryItem.new(internal_id: '624113', item_id: 'Target', upccode: 'Target') | ||
] | ||
end | ||
|
||
before do | ||
savon.expects(:update_list).with(:message => | ||
{ | ||
'record' => [{ | ||
'listAcct:itemId' => 'Target', | ||
'@xsi:type' => 'listAcct:InventoryItem', | ||
'@internalId' => '624113' | ||
}] | ||
}).returns(File.read('spec/support/fixtures/update_list/update_list_one_item.xml')) | ||
end | ||
|
||
it 'makes a valid request to the NetSuite API' do | ||
NetSuite::Actions::UpdateList.call(item) | ||
end | ||
|
||
it 'returns a valid Response object' do | ||
response = NetSuite::Actions::UpdateList.call(item) | ||
expect(response).to be_kind_of(NetSuite::Response) | ||
expect(response).to be_success | ||
end | ||
end | ||
|
||
context 'two items' do | ||
let(:items) do | ||
[ | ||
NetSuite::Records::InventoryItem.new(internal_id: '624172', item_id: 'Shutter Fly', upccode: 'Shutter Fly, Inc.'), | ||
NetSuite::Records::InventoryItem.new(internal_id: '624113', item_id: 'Target', upccode: 'Target') | ||
] | ||
end | ||
|
||
before do | ||
savon.expects(:update_list).with(:message => | ||
{ | ||
'record' => [{ | ||
'listAcct:itemId' => 'Shutter Fly', | ||
'@xsi:type' => 'listAcct:InventoryItem', | ||
'@internalId' => '624172' | ||
}, | ||
{ | ||
'listAcct:itemId' => 'Target', | ||
'@xsi:type' => 'listAcct:InventoryItem', | ||
'@internalId' => '624113' | ||
} | ||
] | ||
}).returns(File.read('spec/support/fixtures/update_list/update_list_items.xml')) | ||
end | ||
|
||
it 'makes a valid request to the NetSuite API' do | ||
NetSuite::Actions::UpdateList.call(items) | ||
end | ||
|
||
it 'returns a valid Response object' do | ||
response = NetSuite::Actions::UpdateList.call(items) | ||
expect(response).to be_kind_of(NetSuite::Response) | ||
expect(response).to be_success | ||
end | ||
end | ||
end | ||
|
||
context 'with errors' do | ||
let(:items) do | ||
[ | ||
NetSuite::Records::InventoryItem.new(internal_id: '624172-bad', item_id: 'Shutter Fly', upccode: 'Shutter Fly, Inc.'), | ||
NetSuite::Records::InventoryItem.new(internal_id: '624113-bad', item_id: 'Target', upccode: 'Target') | ||
] | ||
end | ||
|
||
before do | ||
savon.expects(:update_list).with(:message => | ||
{ | ||
'record' => [{ | ||
'listAcct:itemId' => 'Shutter Fly', | ||
'@xsi:type' => 'listAcct:InventoryItem', | ||
'@internalId' => '624172-bad' | ||
}, | ||
{ | ||
'listAcct:itemId' => 'Target', | ||
'@xsi:type' => 'listAcct:InventoryItem', | ||
'@internalId' => '624113-bad' | ||
} | ||
] | ||
}).returns(File.read('spec/support/fixtures/update_list/update_list_with_errors.xml')) | ||
end | ||
|
||
it 'constructs error objects' do | ||
response = NetSuite::Actions::UpdateList.call(items) | ||
expect(response.errors.keys).to match_array(['624172', '624113']) | ||
expect(response.errors['624172'].first.code).to eq('USER_ERROR') | ||
expect(response.errors['624172'].first.message).to eq('Please enter value(s) for: ItemId') | ||
expect(response.errors['624172'].first.type).to eq('ERROR') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<soapenv:Header> | ||
<platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2015_1.platform.webservices.netsuite.com"> | ||
<platformMsgs:nsId>WEBSERVICES_4094105_100420174020144521635732562_3cddd9b4c927</platformMsgs:nsId> | ||
</platformMsgs:documentInfo> | ||
</soapenv:Header> | ||
<soapenv:Body> | ||
<updateListResponse xmlns="urn:messages_2015_1.platform.webservices.netsuite.com"> | ||
<writeResponseList> | ||
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/> | ||
<writeResponse> | ||
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/> | ||
<baseRef xsi:type="platformCore:RecordRef" type="inventoryItem" externalId="testing1" internalId="624113" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/> | ||
</writeResponse> | ||
<writeResponse> | ||
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/> | ||
<baseRef xsi:type="platformCore:RecordRef" type="inventoryItem" externalId="testing1" internalId="624172" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/> | ||
</writeResponse> | ||
</writeResponseList> | ||
</updateListResponse> | ||
</soapenv:Body> | ||
</soapenv:Envelope> |
18 changes: 18 additions & 0 deletions
18
spec/support/fixtures/update_list/update_list_one_item.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<soapenv:Header> | ||
<platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2015_1.platform.webservices.netsuite.com"> | ||
<platformMsgs:nsId>WEBSERVICES_4094105_100420174020144521635732562_3cddd9b4c927</platformMsgs:nsId> | ||
</platformMsgs:documentInfo> | ||
</soapenv:Header> | ||
<soapenv:Body> | ||
<updateListResponse xmlns="urn:messages_2015_1.platform.webservices.netsuite.com"> | ||
<writeResponseList> | ||
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/> | ||
<writeResponse> | ||
<platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/> | ||
<baseRef xsi:type="platformCore:RecordRef" type="inventoryItem" externalId="testing" internalId="624113" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/> | ||
</writeResponse> | ||
</writeResponseList> | ||
</updateListResponse> | ||
</soapenv:Body> | ||
</soapenv:Envelope> |
32 changes: 32 additions & 0 deletions
32
spec/support/fixtures/update_list/update_list_with_errors.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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_2014_1.platform.webservices.netsuite.com"> | ||
<platformMsgs:nsId>WEBSERVICES_3868171_1117201410832887841076557109_965331437a3</platformMsgs:nsId> | ||
</platformMsgs:documentInfo> | ||
</soapenv:Header> | ||
<soapenv:Body> | ||
<updateListResponse xmlns="urn:messages_2014_1.platform.webservices.netsuite.com"> | ||
<writeResponseList> | ||
<writeResponse> | ||
<platformCore:status xmlns:platformCore="urn:core_2014_1.platform.webservices.netsuite.com" isSuccess="false"> | ||
<platformCore:statusDetail type="ERROR"> | ||
<platformCore:code>USER_ERROR</platformCore:code> | ||
<platformCore:message>Please enter value(s) for: ItemId</platformCore:message> | ||
</platformCore:statusDetail> | ||
</platformCore:status> | ||
<baseRef xmlns:platformCore="urn:core_2014_1.platform.webservices.netsuite.com" internalId="624172" type="InventoryItem" xsi:type="platformCore:RecordRef"/> | ||
</writeResponse> | ||
<writeResponse> | ||
<platformCore:status xmlns:platformCore="urn:core_2014_1.platform.webservices.netsuite.com" isSuccess="false"> | ||
<platformCore:statusDetail type="ERROR"> | ||
<platformCore:code>USER_ERROR</platformCore:code> | ||
<platformCore:message>Please enter value(s) for: ItemId</platformCore:message> | ||
</platformCore:statusDetail> | ||
</platformCore:status> | ||
<baseRef xmlns:platformCore="urn:core_2014_1.platform.webservices.netsuite.com" internalId="624113" type="InventoryItem" xsi:type="platformCore:RecordRef"/> | ||
</writeResponse> | ||
</writeResponseList> | ||
</updateListResponse> | ||
</soapenv:Body> | ||
</soapenv:Envelope> |