rconomic 0.5.2 → 0.6.0
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/.rubocop.yml +40 -0
- data/.ruby-version +1 -0
- data/.travis.yml +14 -3
- data/CHANGELOG.md +28 -0
- data/Gemfile +5 -4
- data/Guardfile +9 -4
- data/README.md +23 -4
- data/Rakefile +5 -5
- data/gemfiles/Gemfile.ruby-2.0 +14 -0
- data/lib/economic/account.rb +3 -3
- data/lib/economic/cash_book.rb +4 -7
- data/lib/economic/cash_book_entry.rb +4 -24
- data/lib/economic/company.rb +61 -0
- data/lib/economic/creditor.rb +4 -5
- data/lib/economic/creditor_contact.rb +5 -6
- data/lib/economic/creditor_entry.rb +1 -3
- data/lib/economic/current_invoice.rb +14 -21
- data/lib/economic/current_invoice_line.rb +4 -13
- data/lib/economic/debtor.rb +10 -11
- data/lib/economic/debtor_contact.rb +7 -8
- data/lib/economic/debtor_entry.rb +1 -3
- data/lib/economic/endpoint.rb +36 -6
- data/lib/economic/entity/handle.rb +54 -29
- data/lib/economic/entity/mapper.rb +1 -1
- data/lib/economic/entity.rb +26 -29
- data/lib/economic/entry.rb +1 -2
- data/lib/economic/invoice.rb +15 -8
- data/lib/economic/order.rb +2 -4
- data/lib/economic/product.rb +73 -0
- data/lib/economic/proxies/account_proxy.rb +2 -4
- data/lib/economic/proxies/actions/debtor_contact/all.rb +63 -0
- data/lib/economic/proxies/actions/find_by_ci_number.rb +1 -3
- data/lib/economic/proxies/actions/find_by_date_interval.rb +3 -6
- data/lib/economic/proxies/actions/find_by_handle_with_number.rb +1 -1
- data/lib/economic/proxies/actions/find_by_name.rb +1 -1
- data/lib/economic/proxies/actions/find_by_number.rb +2 -4
- data/lib/economic/proxies/actions/find_by_telephone_and_fax_number.rb +1 -3
- data/lib/economic/proxies/cash_book_entry_proxy.rb +19 -22
- data/lib/economic/proxies/cash_book_proxy.rb +5 -10
- data/lib/economic/proxies/company_proxy.rb +9 -0
- data/lib/economic/proxies/creditor_contact_proxy.rb +2 -2
- data/lib/economic/proxies/creditor_entry_proxy.rb +8 -14
- data/lib/economic/proxies/creditor_proxy.rb +8 -11
- data/lib/economic/proxies/current_invoice_line_proxy.rb +2 -2
- data/lib/economic/proxies/current_invoice_proxy.rb +3 -3
- data/lib/economic/proxies/debtor_contact_proxy.rb +6 -2
- data/lib/economic/proxies/debtor_entry_proxy.rb +6 -10
- data/lib/economic/proxies/debtor_proxy.rb +40 -55
- data/lib/economic/proxies/entity_proxy.rb +15 -15
- data/lib/economic/proxies/entry_proxy.rb +10 -16
- data/lib/economic/proxies/invoice_proxy.rb +3 -3
- data/lib/economic/proxies/order_proxy.rb +3 -3
- data/lib/economic/proxies/product_proxy.rb +11 -0
- data/lib/economic/session.rb +48 -21
- data/lib/economic/support/string.rb +5 -5
- data/lib/rconomic/version.rb +1 -1
- data/lib/rconomic.rb +39 -34
- data/lib/savon_ext/request.rb +17 -0
- data/rconomic.gemspec +8 -7
- data/spec/economic/account_spec.rb +3 -3
- data/spec/economic/cash_book_entry_spec.rb +26 -3
- data/spec/economic/cash_book_spec.rb +7 -7
- data/spec/economic/company_spec.rb +20 -0
- data/spec/economic/creditor_contact_spec.rb +4 -5
- data/spec/economic/creditor_entry_spec.rb +20 -0
- data/spec/economic/creditor_spec.rb +3 -3
- data/spec/economic/current_invoice_line_spec.rb +3 -3
- data/spec/economic/current_invoice_spec.rb +19 -19
- data/spec/economic/debtor_contact_spec.rb +4 -5
- data/spec/economic/debtor_entry_spec.rb +1 -1
- data/spec/economic/debtor_spec.rb +13 -13
- data/spec/economic/endpoint_spec.rb +27 -11
- data/spec/economic/entity/handle_spec.rb +10 -23
- data/spec/economic/entity/mapper_spec.rb +26 -30
- data/spec/economic/entity_spec.rb +36 -31
- data/spec/economic/entry_spec.rb +1 -1
- data/spec/economic/invoice_spec.rb +49 -7
- data/spec/economic/order_spec.rb +4 -4
- data/spec/economic/product_spec.rb +72 -0
- data/spec/economic/proxies/account_proxy_spec.rb +74 -0
- data/spec/economic/proxies/actions/debtor_contact/all_spec.rb +26 -0
- data/spec/economic/proxies/actions/find_by_name_spec.rb +6 -7
- data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +27 -29
- data/spec/economic/proxies/cash_book_proxy_spec.rb +14 -22
- data/spec/economic/proxies/company_proxy_spec.rb +47 -0
- data/spec/economic/proxies/creditor_contact_proxy_spec.rb +11 -5
- data/spec/economic/proxies/creditor_entry_proxy_spec.rb +12 -12
- data/spec/economic/proxies/creditor_proxy_spec.rb +15 -15
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +10 -4
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +37 -19
- data/spec/economic/proxies/debtor_contact_proxy_spec.rb +8 -4
- data/spec/economic/proxies/debtor_entry_proxy_spec.rb +21 -11
- data/spec/economic/proxies/debtor_proxy_spec.rb +81 -40
- data/spec/economic/proxies/entry_proxy_spec.rb +17 -14
- data/spec/economic/proxies/invoice_proxy_spec.rb +24 -10
- data/spec/economic/proxies/order_proxy_spec.rb +20 -10
- data/spec/economic/proxies/product_proxy_spec.rb +86 -0
- data/spec/economic/session_spec.rb +74 -35
- data/spec/fixtures/account_get_all/multiple.xml +15 -0
- data/spec/fixtures/account_get_all/none.xml +8 -0
- data/spec/fixtures/account_get_all/single.xml +12 -0
- data/spec/fixtures/account_get_data_array/multiple.xml +69 -0
- data/spec/fixtures/company_get/success.xml +10 -0
- data/spec/fixtures/company_get_data/success.xml +32 -0
- data/spec/fixtures/current_invoice_line_create_from_data/success.xml +6 -37
- data/spec/fixtures/debtor_create_from_data/success.xml +5 -52
- data/spec/fixtures/debtor_get_orders/none.xml +9 -0
- data/spec/fixtures/product_create_from_data/success.xml +37 -0
- data/spec/fixtures/product_find_by_number/found.xml +10 -0
- data/spec/fixtures/product_find_by_number/not_found.xml +6 -0
- data/spec/fixtures/product_get_all/multiple.xml +15 -0
- data/spec/fixtures/product_get_all/single.xml +12 -0
- data/spec/fixtures/product_get_data/success.xml +37 -0
- data/spec/fixtures/product_get_data_array/multiple.xml +69 -0
- data/spec/spec_helper.rb +6 -9
- data/spec/support/factories.rb +14 -14
- metadata +54 -9
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::CreditorProxy do
|
4
4
|
let(:session) { make_session }
|
@@ -12,30 +12,30 @@ describe Economic::CreditorProxy do
|
|
12
12
|
|
13
13
|
describe "find" do
|
14
14
|
it "gets creditor data from API" do
|
15
|
-
mock_request(
|
15
|
+
mock_request("Creditor_GetData", {"entityHandle" => {"Number" => 42}}, :success)
|
16
16
|
subject.find(42)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "returns Creditor object" do
|
20
|
-
stub_request(
|
20
|
+
stub_request("Creditor_GetData", nil, :success)
|
21
21
|
expect(subject.find(42)).to be_instance_of(Economic::Creditor)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "find_by_number" do
|
26
26
|
it "can find a creditor" do
|
27
|
-
mock_request(
|
28
|
-
result = subject.find_by_number(
|
27
|
+
mock_request("Creditor_FindByNumber", {"number" => "1"}, :found)
|
28
|
+
result = subject.find_by_number("1")
|
29
29
|
expect(result).to be_instance_of(Economic::Creditor)
|
30
|
-
expect(result.
|
31
|
-
expect(result.
|
32
|
-
expect(result.
|
33
|
-
expect(result.handle).to eq(Economic::Entity::Handle.new(
|
30
|
+
expect(result.partial).to be_truthy
|
31
|
+
expect(result.persisted).to be_truthy
|
32
|
+
expect(result.number).to eq("1")
|
33
|
+
expect(result.handle).to eq(Economic::Entity::Handle.new(:number => "1"))
|
34
34
|
end
|
35
35
|
|
36
36
|
it "returns nil when there is no creditor" do
|
37
|
-
mock_request(
|
38
|
-
result = subject.find_by_number(
|
37
|
+
mock_request("Creditor_FindByNumber", {"number" => "1"}, :not_found)
|
38
|
+
result = subject.find_by_number("1")
|
39
39
|
expect(result).to be_nil
|
40
40
|
end
|
41
41
|
end
|
@@ -60,16 +60,16 @@ describe Economic::CreditorProxy do
|
|
60
60
|
|
61
61
|
describe ".all" do
|
62
62
|
it "returns a single creditor" do
|
63
|
-
stub_request(
|
64
|
-
mock_request(
|
63
|
+
stub_request("Creditor_GetAll", nil, :single)
|
64
|
+
mock_request("Creditor_GetData", {"entityHandle" => {"Number" => "1"}}, :success)
|
65
65
|
all = subject.all
|
66
66
|
expect(all.size).to eq(1)
|
67
67
|
expect(all.first).to be_instance_of(Economic::Creditor)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "returns multiple creditors" do
|
71
|
-
mock_request(
|
72
|
-
stub_request(
|
71
|
+
mock_request("Creditor_GetAll", nil, :multiple)
|
72
|
+
stub_request("Creditor_GetDataArray", nil, :multiple)
|
73
73
|
all = subject.all
|
74
74
|
expect(all.size).to eq(2)
|
75
75
|
expect(all.first).to be_instance_of(Economic::Creditor)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::CurrentInvoiceLineProxy do
|
4
4
|
let(:session) { make_session }
|
@@ -58,12 +58,16 @@ describe Economic::CurrentInvoiceLineProxy do
|
|
58
58
|
|
59
59
|
describe ".find" do
|
60
60
|
it "gets invoice_line data from API" do
|
61
|
-
mock_request(
|
61
|
+
mock_request(
|
62
|
+
"CurrentInvoiceLine_GetData",
|
63
|
+
{"entityHandle" => {"Number" => 42}},
|
64
|
+
:success
|
65
|
+
)
|
62
66
|
subject.find(42)
|
63
67
|
end
|
64
68
|
|
65
69
|
it "returns CurrentInvoiceLine object" do
|
66
|
-
stub_request(
|
70
|
+
stub_request("CurrentInvoiceLine_GetData", nil, :success)
|
67
71
|
expect(subject.find(42)).to be_instance_of(Economic::CurrentInvoiceLine)
|
68
72
|
end
|
69
73
|
end
|
@@ -82,7 +86,9 @@ describe Economic::CurrentInvoiceLineProxy do
|
|
82
86
|
it "can be iterated over" do
|
83
87
|
line = Economic::CurrentInvoiceLine.new
|
84
88
|
subject << line
|
85
|
-
expect(subject.all? { |l|
|
89
|
+
expect(subject.all? { |l|
|
90
|
+
l.is_a?(Economic::CurrentInvoiceLine)
|
91
|
+
}).to be_truthy
|
86
92
|
end
|
87
93
|
end
|
88
94
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::CurrentInvoiceProxy do
|
4
|
-
|
5
4
|
let(:session) { make_session }
|
6
5
|
subject { Economic::CurrentInvoiceProxy.new(session) }
|
7
6
|
|
@@ -41,7 +40,9 @@ describe Economic::CurrentInvoiceProxy do
|
|
41
40
|
expect(invoice.debtor_city).to eq(debtor.city)
|
42
41
|
|
43
42
|
expect(invoice.debtor_handle).to eq(debtor.handle)
|
44
|
-
expect(invoice.term_of_payment_handle).to eq(
|
43
|
+
expect(invoice.term_of_payment_handle).to eq(
|
44
|
+
debtor.term_of_payment_handle
|
45
|
+
)
|
45
46
|
expect(invoice.layout_handle).to eq(debtor.layout_handle)
|
46
47
|
expect(invoice.currency_handle).to eq(debtor.currency_handle)
|
47
48
|
end
|
@@ -50,12 +51,16 @@ describe Economic::CurrentInvoiceProxy do
|
|
50
51
|
|
51
52
|
describe ".find" do
|
52
53
|
it "gets invoice data from API" do
|
53
|
-
mock_request(
|
54
|
+
mock_request(
|
55
|
+
"CurrentInvoice_GetData",
|
56
|
+
{"entityHandle" => {"Id" => 42}},
|
57
|
+
:success
|
58
|
+
)
|
54
59
|
subject.find(42)
|
55
60
|
end
|
56
61
|
|
57
62
|
it "returns CurrentInvoice object" do
|
58
|
-
stub_request(
|
63
|
+
stub_request("CurrentInvoice_GetData", nil, :success)
|
59
64
|
expect(subject.find(42)).to be_instance_of(Economic::CurrentInvoice)
|
60
65
|
end
|
61
66
|
end
|
@@ -65,39 +70,53 @@ describe Economic::CurrentInvoiceProxy do
|
|
65
70
|
let(:unto) { Time.now }
|
66
71
|
|
67
72
|
it "should be able to return a single current invoice" do
|
68
|
-
mock_request(
|
69
|
-
|
73
|
+
mock_request(
|
74
|
+
"CurrentInvoice_FindByDateInterval",
|
75
|
+
{"first" => from.iso8601, "last" => unto.iso8601},
|
76
|
+
:single
|
77
|
+
)
|
78
|
+
stub_request("CurrentInvoice_GetDataArray", nil, :single)
|
70
79
|
results = subject.find_by_date_interval(from, unto)
|
71
80
|
expect(results.size).to eq(1)
|
72
81
|
expect(results.first).to be_instance_of(Economic::CurrentInvoice)
|
73
82
|
end
|
74
83
|
|
75
84
|
it "should be able to return multiple invoices" do
|
76
|
-
mock_request(
|
77
|
-
|
85
|
+
mock_request(
|
86
|
+
"CurrentInvoice_FindByDateInterval",
|
87
|
+
{"first" => from.iso8601, "last" => unto.iso8601},
|
88
|
+
:many
|
89
|
+
)
|
90
|
+
stub_request("CurrentInvoice_GetDataArray", nil, :multiple)
|
78
91
|
results = subject.find_by_date_interval(from, unto)
|
79
92
|
expect(results.size).to eq(2)
|
80
93
|
expect(results.first).to be_instance_of(Economic::CurrentInvoice)
|
81
94
|
end
|
82
95
|
|
83
96
|
it "should be able to return nothing" do
|
84
|
-
mock_request(
|
97
|
+
mock_request(
|
98
|
+
"CurrentInvoice_FindByDateInterval",
|
99
|
+
{"first" => from.iso8601, "last" => unto.iso8601},
|
100
|
+
:none
|
101
|
+
)
|
85
102
|
results = subject.find_by_date_interval(from, unto)
|
86
103
|
expect(results.size).to eq(0)
|
87
104
|
end
|
88
|
-
|
89
105
|
end
|
90
|
-
|
91
|
-
describe ".all" do
|
92
106
|
|
107
|
+
describe ".all" do
|
93
108
|
it "returns an empty array when there are no current invoices" do
|
94
|
-
stub_request(
|
109
|
+
stub_request("CurrentInvoice_GetAll", nil, :none)
|
95
110
|
expect(subject.all.size).to eq(0)
|
96
111
|
end
|
97
112
|
|
98
113
|
it "finds and adds a single current invoice" do
|
99
|
-
stub_request(
|
100
|
-
mock_request(
|
114
|
+
stub_request("CurrentInvoice_GetAll", nil, :single)
|
115
|
+
mock_request(
|
116
|
+
"CurrentInvoice_GetData",
|
117
|
+
{"entityHandle" => {"Id" => 1}},
|
118
|
+
:success
|
119
|
+
)
|
101
120
|
|
102
121
|
current_invoices = subject.all
|
103
122
|
expect(current_invoices).to be_instance_of(Economic::CurrentInvoiceProxy)
|
@@ -107,14 +126,13 @@ describe Economic::CurrentInvoiceProxy do
|
|
107
126
|
end
|
108
127
|
|
109
128
|
it "adds multiple current invoices" do
|
110
|
-
stub_request(
|
111
|
-
stub_request(
|
129
|
+
stub_request("CurrentInvoice_GetAll", nil, :multiple)
|
130
|
+
stub_request("CurrentInvoice_GetDataArray", nil, :multiple)
|
112
131
|
|
113
132
|
current_invoices = subject.all
|
114
133
|
expect(current_invoices.size).to eq(2)
|
115
134
|
expect(current_invoices.first).to be_instance_of(Economic::CurrentInvoice)
|
116
135
|
expect(current_invoices.last).to be_instance_of(Economic::CurrentInvoice)
|
117
136
|
end
|
118
|
-
|
119
137
|
end
|
120
138
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::DebtorContactProxy do
|
4
4
|
let(:session) { make_session }
|
@@ -40,12 +40,16 @@ describe Economic::DebtorContactProxy do
|
|
40
40
|
|
41
41
|
describe ".find" do
|
42
42
|
it "gets contact data from API" do
|
43
|
-
mock_request(
|
43
|
+
mock_request(
|
44
|
+
"DebtorContact_GetData",
|
45
|
+
{"entityHandle" => {"Id" => 42}},
|
46
|
+
:success
|
47
|
+
)
|
44
48
|
subject.find(42)
|
45
49
|
end
|
46
50
|
|
47
51
|
it "returns DebtorContact object" do
|
48
|
-
stub_request(
|
52
|
+
stub_request("DebtorContact_GetData", nil, :success)
|
49
53
|
expect(subject.find(42)).to be_instance_of(Economic::DebtorContact)
|
50
54
|
end
|
51
55
|
end
|
@@ -54,7 +58,7 @@ describe Economic::DebtorContactProxy do
|
|
54
58
|
it "uses the FindByName command" do
|
55
59
|
expect(Economic::Proxies::Actions::FindByName).to receive(:new).
|
56
60
|
with(subject, "Bob").
|
57
|
-
and_return(
|
61
|
+
and_return(-> { "Result" })
|
58
62
|
expect(subject.find_by_name("Bob")).to eq("Result")
|
59
63
|
end
|
60
64
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::DebtorEntryProxy do
|
4
4
|
let(:session) { make_session }
|
@@ -11,24 +11,32 @@ describe Economic::DebtorEntryProxy do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#find_by_invoice_number" do
|
14
|
-
it
|
15
|
-
mock_request(
|
16
|
-
|
14
|
+
it "should be able to find multiple debtor entries" do
|
15
|
+
mock_request(
|
16
|
+
"DebtorEntry_FindByInvoiceNumber",
|
17
|
+
{"from" => "123", "to" => "456"},
|
18
|
+
:many
|
19
|
+
)
|
20
|
+
expect(subject.find_by_invoice_number("123", "456")).to eq([1, 2])
|
17
21
|
end
|
18
22
|
|
19
|
-
it
|
20
|
-
mock_request(
|
21
|
-
|
23
|
+
it "should be able to find debtor entries with one invoice id" do
|
24
|
+
mock_request(
|
25
|
+
"DebtorEntry_FindByInvoiceNumber",
|
26
|
+
{"from" => "123", "to" => "123"},
|
27
|
+
:many
|
28
|
+
)
|
29
|
+
expect(subject.find_by_invoice_number("123")).to eq([1, 2])
|
22
30
|
end
|
23
31
|
|
24
|
-
it
|
32
|
+
it "should handle a single serial number in the response" do
|
25
33
|
stub_request("DebtorEntry_FindByInvoiceNumber", nil, :single)
|
26
|
-
expect(subject.find_by_invoice_number(
|
34
|
+
expect(subject.find_by_invoice_number("123")).to eq([1])
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
30
38
|
describe "#match" do
|
31
|
-
it
|
39
|
+
it "should match two debtor entries by serial numbers" do
|
32
40
|
stub_request(
|
33
41
|
"DebtorEntry_MatchEntries",
|
34
42
|
{:entries => {
|
@@ -45,7 +53,9 @@ describe Economic::DebtorEntryProxy do
|
|
45
53
|
|
46
54
|
describe "#entity_class" do
|
47
55
|
it "should return Economic::DebtorEntry" do
|
48
|
-
expect(
|
56
|
+
expect(
|
57
|
+
Economic::DebtorEntryProxy.entity_class
|
58
|
+
).to eq(Economic::DebtorEntry)
|
49
59
|
end
|
50
60
|
end
|
51
61
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::DebtorProxy do
|
4
4
|
let(:session) { make_session }
|
@@ -12,32 +12,42 @@ describe Economic::DebtorProxy do
|
|
12
12
|
|
13
13
|
describe "find" do
|
14
14
|
it "gets debtor data from API" do
|
15
|
-
mock_request(
|
15
|
+
mock_request(
|
16
|
+
"Debtor_GetData",
|
17
|
+
{"entityHandle" => {"Number" => 42}},
|
18
|
+
:success
|
19
|
+
)
|
16
20
|
subject.find(42)
|
17
21
|
end
|
18
22
|
|
19
23
|
it "returns Debtor object" do
|
20
|
-
stub_request(
|
24
|
+
stub_request("Debtor_GetData", nil, :success)
|
21
25
|
expect(subject.find(42)).to be_instance_of(Economic::Debtor)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
describe "find_by_ci_number" do
|
26
30
|
it "uses FindByCINumber on API" do
|
27
|
-
mock_request(
|
28
|
-
|
31
|
+
mock_request(
|
32
|
+
"Debtor_FindByCINumber",
|
33
|
+
{"ciNumber" => "12345678"},
|
34
|
+
:many
|
35
|
+
)
|
36
|
+
subject.find_by_ci_number("12345678")
|
29
37
|
end
|
30
38
|
|
31
39
|
context "when many debtors exist" do
|
32
40
|
before :each do
|
33
|
-
stub_request(
|
41
|
+
stub_request("Debtor_FindByCINumber", nil, :many)
|
34
42
|
end
|
35
43
|
|
36
|
-
let(:results) { subject.find_by_ci_number(
|
44
|
+
let(:results) { subject.find_by_ci_number("12345678") }
|
37
45
|
|
38
46
|
it "returns a Debtor object for each result" do
|
39
47
|
expect(results.size).to eq(2)
|
40
|
-
results.all? { |result|
|
48
|
+
results.all? { |result|
|
49
|
+
expect(result).to be_instance_of(Economic::Debtor)
|
50
|
+
}
|
41
51
|
end
|
42
52
|
|
43
53
|
it "returns partial Debtor objects" do
|
@@ -52,43 +62,51 @@ describe Economic::DebtorProxy do
|
|
52
62
|
|
53
63
|
describe "find_by_number" do
|
54
64
|
it "can find a debtor" do
|
55
|
-
mock_request(
|
56
|
-
result = subject.find_by_number(
|
65
|
+
mock_request("Debtor_FindByNumber", {"number" => "1"}, :found)
|
66
|
+
result = subject.find_by_number("1")
|
57
67
|
expect(result).to be_instance_of(Economic::Debtor)
|
58
|
-
expect(result.
|
59
|
-
expect(result.
|
60
|
-
expect(result.
|
61
|
-
expect(result.handle).to eq(Economic::Entity::Handle.new(
|
68
|
+
expect(result.partial).to be_truthy
|
69
|
+
expect(result.persisted).to be_truthy
|
70
|
+
expect(result.number).to eq("1")
|
71
|
+
expect(result.handle).to eq(Economic::Entity::Handle.new(:number => "1"))
|
62
72
|
end
|
63
73
|
|
64
74
|
it "returns nil when there is no debtor" do
|
65
|
-
mock_request(
|
66
|
-
result = subject.find_by_number(
|
75
|
+
mock_request("Debtor_FindByNumber", {"number" => "1"}, :not_found)
|
76
|
+
result = subject.find_by_number("1")
|
67
77
|
expect(result).to be_nil
|
68
78
|
end
|
69
79
|
end
|
70
80
|
|
71
81
|
describe "find_by_telephone_and_fax_number" do
|
72
82
|
it "can find a debtor" do
|
73
|
-
mock_request(
|
74
|
-
|
83
|
+
mock_request(
|
84
|
+
"Debtor_FindByTelephoneAndFaxNumber",
|
85
|
+
{"telephoneAndFaxNumber" => "22334455"},
|
86
|
+
:found
|
87
|
+
)
|
88
|
+
result = subject.find_by_telephone_and_fax_number("22334455")
|
75
89
|
expect(result).to be_instance_of(Economic::Debtor)
|
76
90
|
expect(result.number).to eq(1)
|
77
|
-
expect(result.partial).to
|
78
|
-
expect(result.persisted).to
|
91
|
+
expect(result.partial).to be_truthy
|
92
|
+
expect(result.persisted).to be_truthy
|
79
93
|
end
|
80
94
|
|
81
95
|
it "returns nil when there is no debtor" do
|
82
|
-
mock_request(
|
83
|
-
|
96
|
+
mock_request(
|
97
|
+
"Debtor_FindByTelephoneAndFaxNumber",
|
98
|
+
{"telephoneAndFaxNumber" => "22334455"},
|
99
|
+
:not_found
|
100
|
+
)
|
101
|
+
result = subject.find_by_telephone_and_fax_number("22334455")
|
84
102
|
expect(result).to be_nil
|
85
103
|
end
|
86
104
|
end
|
87
105
|
|
88
106
|
describe "next_available_number" do
|
89
107
|
it "gets the next available debtor number from API" do
|
90
|
-
mock_request(
|
91
|
-
expect(subject.next_available_number).to eq(
|
108
|
+
mock_request("Debtor_GetNextAvailableNumber", nil, :success)
|
109
|
+
expect(subject.next_available_number).to eq("105")
|
92
110
|
end
|
93
111
|
end
|
94
112
|
|
@@ -110,20 +128,24 @@ describe Economic::DebtorProxy do
|
|
110
128
|
end
|
111
129
|
end
|
112
130
|
|
113
|
-
# Complete specs in current_invoice, no point in duplicating them here, just
|
114
|
-
# it handles debtors "Number" id.
|
131
|
+
# Complete specs in current_invoice, no point in duplicating them here, just
|
132
|
+
# ensuring that it handles debtors "Number" id.
|
115
133
|
describe ".all" do
|
116
134
|
it "returns a single debtor" do
|
117
|
-
mock_request(
|
118
|
-
mock_request(
|
135
|
+
mock_request("Debtor_GetAll", nil, :single)
|
136
|
+
mock_request(
|
137
|
+
"Debtor_GetData",
|
138
|
+
{"entityHandle" => {"Number" => "1"}},
|
139
|
+
:success
|
140
|
+
)
|
119
141
|
all = subject.all
|
120
142
|
expect(all.size).to eq(1)
|
121
143
|
expect(all.first).to be_instance_of(Economic::Debtor)
|
122
144
|
end
|
123
145
|
|
124
146
|
it "returns multiple debtors" do
|
125
|
-
mock_request(
|
126
|
-
mock_request(
|
147
|
+
mock_request("Debtor_GetAll", nil, :multiple)
|
148
|
+
mock_request("Debtor_GetDataArray", :any, :multiple)
|
127
149
|
all = subject.all
|
128
150
|
expect(all.size).to eq(2)
|
129
151
|
expect(all.first).to be_instance_of(Economic::Debtor)
|
@@ -131,14 +153,18 @@ describe Economic::DebtorProxy do
|
|
131
153
|
end
|
132
154
|
|
133
155
|
describe ".get_debtor_contacts" do
|
134
|
-
let(:handle) { Economic::Entity::Handle.new(
|
156
|
+
let(:handle) { Economic::Entity::Handle.new(:number => 1) }
|
135
157
|
it "gets debtor contact data from API" do
|
136
|
-
mock_request(
|
158
|
+
mock_request(
|
159
|
+
"Debtor_GetDebtorContacts",
|
160
|
+
{"debtorHandle" => {"Number" => 1}},
|
161
|
+
:multiple
|
162
|
+
)
|
137
163
|
subject.get_debtor_contacts(handle)
|
138
164
|
end
|
139
165
|
|
140
166
|
it "returns DebtorContact objects" do
|
141
|
-
stub_request(
|
167
|
+
stub_request("Debtor_GetDebtorContacts", nil, :multiple)
|
142
168
|
subject.get_debtor_contacts(handle).each do |d|
|
143
169
|
expect(d).to be_instance_of(Economic::DebtorContact)
|
144
170
|
end
|
@@ -146,14 +172,18 @@ describe Economic::DebtorProxy do
|
|
146
172
|
end
|
147
173
|
|
148
174
|
describe ".get_invoices" do
|
149
|
-
let(:handle) { Economic::Entity::Handle.new(
|
175
|
+
let(:handle) { Economic::Entity::Handle.new(:number => 1) }
|
150
176
|
it "gets invoice data from API" do
|
151
|
-
mock_request(
|
177
|
+
mock_request(
|
178
|
+
"Debtor_GetInvoices",
|
179
|
+
{"debtorHandle" => {"Number" => 1}},
|
180
|
+
:success
|
181
|
+
)
|
152
182
|
subject.get_invoices(handle)
|
153
183
|
end
|
154
184
|
|
155
185
|
it "returns Invoice object" do
|
156
|
-
stub_request(
|
186
|
+
stub_request("Debtor_GetInvoices", nil, :success)
|
157
187
|
subject.get_invoices(handle).each do |i|
|
158
188
|
expect(i).to be_instance_of(Economic::Invoice)
|
159
189
|
end
|
@@ -161,24 +191,35 @@ describe Economic::DebtorProxy do
|
|
161
191
|
end
|
162
192
|
|
163
193
|
describe ".get_order" do
|
164
|
-
let(:handle) { Economic::Entity::Handle.new(
|
194
|
+
let(:handle) { Economic::Entity::Handle.new(:number => 1) }
|
165
195
|
it "gets invoice data from API" do
|
166
|
-
mock_request(
|
196
|
+
mock_request(
|
197
|
+
"Debtor_GetOrders",
|
198
|
+
{"debtorHandle" => {"Number" => 1}},
|
199
|
+
:success
|
200
|
+
)
|
167
201
|
subject.get_orders(handle)
|
168
202
|
end
|
169
203
|
|
170
204
|
it "returns Order object" do
|
171
|
-
stub_request(
|
205
|
+
stub_request("Debtor_GetOrders", nil, :success)
|
172
206
|
subject.get_orders(handle).each do |i|
|
173
207
|
expect(i).to be_instance_of(Economic::Order)
|
174
208
|
end
|
175
209
|
end
|
176
210
|
|
177
211
|
it "sets the number" do
|
178
|
-
stub_request(
|
212
|
+
stub_request("Debtor_GetOrders", nil, :success)
|
179
213
|
subject.get_orders(handle).each do |i|
|
180
214
|
expect(i.number).to eq(1)
|
181
215
|
end
|
182
216
|
end
|
217
|
+
|
218
|
+
it "returns nil if no orders are found" do
|
219
|
+
stub_request("Debtor_GetOrders", nil, :none)
|
220
|
+
expect(
|
221
|
+
subject.get_orders(handle)
|
222
|
+
).to be_nil
|
223
|
+
end
|
183
224
|
end
|
184
225
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::EntryProxy do
|
4
4
|
let(:session) { make_session }
|
@@ -11,60 +11,64 @@ describe Economic::EntryProxy do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#find_by_date_interval" do
|
14
|
-
it
|
14
|
+
it "should be able to find multiple entries" do
|
15
15
|
from_date = Date.new
|
16
16
|
to_date = Date.new
|
17
17
|
mock_request(
|
18
18
|
"Entry_FindByDateInterval",
|
19
|
-
{
|
19
|
+
{"fromDate" => from_date, "toDate" => to_date},
|
20
20
|
:many
|
21
21
|
)
|
22
22
|
expect(subject.find_by_date_interval(from_date, to_date)).to eq([1, 2])
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it "should handle a single serial number in the response" do
|
26
26
|
stub_request("Entry_FindByDateInterval", nil, :single)
|
27
27
|
expect(subject.find_by_date_interval(Date.new, Date.new)).to eq([1])
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "should handle an empty response" do
|
31
31
|
stub_request("Entry_FindByDateInterval", nil, :none)
|
32
32
|
expect(subject.find_by_date_interval(Date.new, Date.new)).to eq([])
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe "#find_by_serial_number_interval" do
|
37
|
-
it
|
37
|
+
it "should be able to find multiple entries" do
|
38
38
|
mock_request(
|
39
39
|
"Entry_FindBySerialNumberInterval",
|
40
|
-
{
|
40
|
+
{"minNumber" => 123, "maxNumber" => 456},
|
41
41
|
:many
|
42
42
|
)
|
43
43
|
expect(subject.find_by_serial_number_interval(123, 456)).to eq([1, 2])
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it "should handle a single serial number in the response" do
|
47
47
|
stub_request("Entry_FindBySerialNumberInterval", nil, :single)
|
48
48
|
expect(subject.find_by_serial_number_interval(123, 456)).to eq([1])
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it "should handle an empty response" do
|
52
52
|
stub_request("Entry_FindBySerialNumberInterval", nil, :none)
|
53
53
|
expect(subject.find_by_serial_number_interval(123, 456)).to eq([])
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
describe "#get_last_used_serial_number" do
|
58
|
-
it
|
58
|
+
it "returns the number" do
|
59
59
|
mock_request("Entry_GetLastUsedSerialNumber", nil, :success)
|
60
60
|
expect(subject.get_last_used_serial_number).to eq(123)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
describe "#find" do
|
65
|
-
it
|
66
|
-
mock_request(
|
67
|
-
|
65
|
+
it "should get a entry by serial number" do
|
66
|
+
mock_request(
|
67
|
+
"Entry_GetData",
|
68
|
+
{"entityHandle" => {"SerialNumber" => "123"}},
|
69
|
+
:success
|
70
|
+
)
|
71
|
+
expect(subject.find("123")).to be_instance_of(Economic::Entry)
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
@@ -74,4 +78,3 @@ describe Economic::EntryProxy do
|
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end
|
77
|
-
|