Skip to content

Commit a366534

Browse files
committed
Tests for mutating records inside AddList
1 parent 68400c0 commit a366534

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

spec/netsuite/actions/add_list_spec.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
expect(response).to be_kind_of(NetSuite::Response)
3434
expect(response).to be_success
3535
end
36+
37+
it 'returns array of records when called as Record static method' do
38+
records = NetSuite::Records::Customer.add_list(customers)
39+
records.each do |record|
40+
expect(record).to be_instance_of(NetSuite::Records::Customer)
41+
expect(record.internal_id).not_to be nil
42+
end
43+
end
44+
45+
it 'mutates records with internal_id when called as Record static method' do
46+
NetSuite::Records::Customer.add_list(customers)
47+
expect(customers[0].internal_id).to eq "974"
48+
end
3649
end
3750

3851
context 'two customers' do
@@ -71,6 +84,62 @@
7184
expect(response).to be_kind_of(NetSuite::Response)
7285
expect(response).to be_success
7386
end
87+
88+
it 'returns array of records when called as Record static method' do
89+
records = NetSuite::Records::Customer.add_list(customers)
90+
records.each do |record|
91+
expect(record).to be_instance_of(NetSuite::Records::Customer)
92+
expect(record.internal_id).not_to be nil
93+
end
94+
end
95+
96+
it 'mutates records with internal_id when called as Record static method' do
97+
NetSuite::Records::Customer.add_list(customers)
98+
expect(customers[0].internal_id).to eq "970"
99+
expect(customers[1].internal_id).to eq "974"
100+
end
101+
end
102+
103+
context 'one customer without external id' do
104+
let(:customers) do
105+
[
106+
NetSuite::Records::Customer.new(entity_id: 'Target', company_name: 'Target')
107+
]
108+
end
109+
110+
before do
111+
savon.expects(:add_list).with(:message =>
112+
{
113+
'record' => [{
114+
'listRel:entityId' => 'Target',
115+
'listRel:companyName' => 'Target',
116+
'@xsi:type' => 'listRel:Customer'
117+
}]
118+
}).returns(File.read('spec/support/fixtures/add_list/add_list_one_customer_without_external_id.xml'))
119+
end
120+
121+
it 'makes a valid request to the NetSuite API' do
122+
NetSuite::Actions::AddList.call(customers)
123+
end
124+
125+
it 'returns a valid Response object' do
126+
response = NetSuite::Actions::AddList.call(customers)
127+
expect(response).to be_kind_of(NetSuite::Response)
128+
expect(response).to be_success
129+
end
130+
131+
it 'returns array of records when called as Record static method' do
132+
records = NetSuite::Records::Customer.add_list(customers)
133+
records.each do |record|
134+
expect(record).to be_instance_of(NetSuite::Records::Customer)
135+
expect(record.internal_id).to be nil
136+
end
137+
end
138+
139+
it 'does not mutate records if external_id was not used' do
140+
NetSuite::Records::Customer.add_list(customers)
141+
expect(customers.first.internal_id).to be nil
142+
end
74143
end
75144
end
76145

0 commit comments

Comments
 (0)