trebbianno-ruby-api 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/trebbianno/order.rb +3 -3
- data/lib/trebbianno/version.rb +1 -1
- data/spec/fixtures/test_build_order_request.xml +3 -3
- data/spec/lib/order_spec.rb +9 -1
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 598745b39be227014634557a6dd1046fb40c29d6
|
4
|
+
data.tar.gz: 982f64e02ee77688308c2518735713f000cf9cd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ac4788d00fca11de249a58be76df651da71e2c3612d501bc0820c36089fa3c16d190e1ceed765fd9d08baf2b99a369fb6da42f61f59e55536d7193100122b0a
|
7
|
+
data.tar.gz: 963d81cfb0fff3ae92566e04a328e0011553f8f796fb3c47cba76ec0efa65e3f318685adc0f2c7130781d22157d32651dc0acb02b3973c1356e679a1d2308054
|
data/lib/trebbianno/order.rb
CHANGED
@@ -67,12 +67,12 @@ module Trebbianno
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def discount_percent(order)
|
70
|
-
order[:item_discount].to_f.abs /
|
70
|
+
order[:item_discount].to_f.abs / line_item_total(order)
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
73
|
+
def line_item_total(order)
|
74
74
|
order[:line_items].inject(0) do |sum, hash|
|
75
|
-
sum + hash[:price]
|
75
|
+
sum + (hash[:price] * hash[:quantity].to_i)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
data/lib/trebbianno/version.rb
CHANGED
@@ -20,14 +20,14 @@
|
|
20
20
|
<orderline>
|
21
21
|
<ordernumber>R123123123</ordernumber>
|
22
22
|
<sku>123332211</sku>
|
23
|
-
<qty>
|
24
|
-
<unitprice>
|
23
|
+
<qty>2</qty>
|
24
|
+
<unitprice>90.0</unitprice>
|
25
25
|
</orderline>
|
26
26
|
<orderline>
|
27
27
|
<ordernumber>R123123123</ordernumber>
|
28
28
|
<sku>123332212</sku>
|
29
29
|
<qty>1</qty>
|
30
|
-
<unitprice>
|
30
|
+
<unitprice>180.0</unitprice>
|
31
31
|
</orderline>
|
32
32
|
</order>
|
33
33
|
</orders>
|
data/spec/lib/order_spec.rb
CHANGED
@@ -39,7 +39,7 @@ describe Trebbianno::Order do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
describe 'private#line_item_discount' do
|
42
|
-
let(:discount) {[
|
42
|
+
let(:discount) {[10, 20]}
|
43
43
|
it 'should calculate discount price for line item' do
|
44
44
|
order_hash[:line_items].each_with_index do |item, index|
|
45
45
|
discount_amount = order_client.send(:line_item_discount, item[:price], order_hash)
|
@@ -48,4 +48,12 @@ describe Trebbianno::Order do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
describe 'private#line_item_total' do
|
52
|
+
let(:total) {400}
|
53
|
+
it 'should calculate total price for line items' do
|
54
|
+
total_amount = order_client.send(:line_item_total, order_hash)
|
55
|
+
expect(total_amount).to eq total
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trebbianno-ruby-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Grubbs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: builder
|