rconomic 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- 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::Invoice do
|
4
4
|
let(:session) { make_session }
|
@@ -9,9 +9,9 @@ describe Economic::Invoice do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe '#remainder' do
|
12
|
-
it
|
13
|
-
mock_request(
|
14
|
-
expect(subject.remainder).to eq(
|
12
|
+
it "should get the remainder" do
|
13
|
+
mock_request("Invoice_GetRemainder", {"invoiceHandle" => {"Number" => 512}}, :success)
|
14
|
+
expect(subject.remainder).to eq(512.32)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -33,13 +33,13 @@ describe Economic::Invoice do
|
|
33
33
|
|
34
34
|
describe "#pdf" do
|
35
35
|
it "gets PDF data from API" do
|
36
|
-
mock_request(
|
36
|
+
mock_request("Invoice_GetPdf", {"invoiceHandle" => {"Number" => 512}}, :success)
|
37
37
|
subject.pdf
|
38
38
|
end
|
39
39
|
|
40
40
|
it "decodes the base64Binary encoded data" do
|
41
|
-
stub_request(
|
42
|
-
expect(subject.pdf).to eq(
|
41
|
+
stub_request("Invoice_GetPdf", nil, :success)
|
42
|
+
expect(subject.pdf).to eq("This is not really PDF data")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -84,4 +84,46 @@ describe Economic::Invoice do
|
|
84
84
|
expect(subject.debtor_handle).to eq(handle)
|
85
85
|
end
|
86
86
|
end
|
87
|
+
|
88
|
+
describe "#days_past_due" do
|
89
|
+
it "after date has passed" do
|
90
|
+
subject.due_date = (Date.today - 3).to_datetime
|
91
|
+
expect(subject.days_past_due).to eq(3)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "before date has passed" do
|
95
|
+
subject.due_date = (Date.today + 3).to_datetime
|
96
|
+
expect(subject.days_past_due).to eq(0)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#past_due?" do
|
101
|
+
it "when due date has passed and the invoiced hasn't been paid" do
|
102
|
+
subject.due_date = (Date.today - 3).to_datetime
|
103
|
+
subject.instance_variable_set "@remainder", 1
|
104
|
+
|
105
|
+
expect(subject.past_due?).to eq(true)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "when due date has passed and the invoice has been paid" do
|
109
|
+
subject.due_date = (Date.today - 3).to_datetime
|
110
|
+
subject.instance_variable_set "@remainder", 0
|
111
|
+
|
112
|
+
expect(subject.past_due?).to eq(false)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "before due date has passed and the invoiced hasn't been paid" do
|
116
|
+
subject.due_date = (Date.today + 3).to_datetime
|
117
|
+
subject.instance_variable_set "@remainder", 1
|
118
|
+
|
119
|
+
expect(subject.past_due?).to eq(false)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "before due date has passed and the invoice has been paid" do
|
123
|
+
subject.due_date = (Date.today + 3).to_datetime
|
124
|
+
subject.instance_variable_set "@remainder", 0
|
125
|
+
|
126
|
+
expect(subject.past_due?).to eq(false)
|
127
|
+
end
|
128
|
+
end
|
87
129
|
end
|
data/spec/economic/order_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::Order do
|
4
4
|
let(:session) { make_session }
|
@@ -26,13 +26,13 @@ describe Economic::Order do
|
|
26
26
|
|
27
27
|
describe "#pdf" do
|
28
28
|
it "gets PDF data from API" do
|
29
|
-
mock_request(
|
29
|
+
mock_request("Order_GetPdf", {"orderHandle" => {"Number" => 512}}, :success)
|
30
30
|
subject.pdf
|
31
31
|
end
|
32
32
|
|
33
33
|
it "decodes the base64Binary encoded data" do
|
34
|
-
stub_request(
|
35
|
-
expect(subject.pdf).to eq(
|
34
|
+
stub_request("Order_GetPdf", nil, :success)
|
35
|
+
expect(subject.pdf).to eq("This is not really PDF data")
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "./spec/spec_helper"
|
2
|
+
|
3
|
+
describe Economic::Product do
|
4
|
+
let(:session) { make_session }
|
5
|
+
subject { Economic::Product.new(:session => session) }
|
6
|
+
|
7
|
+
it "inherits from Economic::Entity" do
|
8
|
+
expect(Economic::Product.ancestors).to include(Economic::Entity)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "class methods" do
|
12
|
+
subject { Economic::Product }
|
13
|
+
|
14
|
+
describe ".proxy" do
|
15
|
+
it "should return ProductProxy" do
|
16
|
+
expect(subject.proxy).to eq(Economic::ProductProxy)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".key" do
|
21
|
+
it "should == :product" do
|
22
|
+
expect(Economic::Product.key).to eq(:product)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".proxy" do
|
28
|
+
it "should return a CreditorProxy" do
|
29
|
+
expect(subject.proxy).to be_instance_of(Economic::ProductProxy)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return a proxy owned by session" do
|
33
|
+
expect(subject.proxy.session).to eq(session)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#save" do
|
38
|
+
it "should save it" do
|
39
|
+
stub_request("Product_CreateFromData", nil, :success)
|
40
|
+
subject.save
|
41
|
+
end
|
42
|
+
|
43
|
+
it "builds and sends data to API" do
|
44
|
+
mock_request(
|
45
|
+
:product_create_from_data, {
|
46
|
+
"data" => {
|
47
|
+
"Handle" => {},
|
48
|
+
"Number" => nil,
|
49
|
+
"ProductGroupHandle" => {"Number" => 1},
|
50
|
+
"Name" => nil,
|
51
|
+
"SalesPrice" => nil,
|
52
|
+
"CostPrice" => nil,
|
53
|
+
"RecommendedPrice" => nil,
|
54
|
+
"UnitHandle" => {"Number" => 2},
|
55
|
+
"IsAccessible" => nil,
|
56
|
+
"Volume" => nil,
|
57
|
+
"DepartmentHandle" => {"Number" => 1},
|
58
|
+
"DistributionKeyHandle" => {"Number" => 314}
|
59
|
+
}
|
60
|
+
},
|
61
|
+
:success
|
62
|
+
)
|
63
|
+
|
64
|
+
subject.product_group_handle = Economic::Entity::Handle.new(:number => 1)
|
65
|
+
subject.unit_handle = Economic::Entity::Handle.new(:number => 2)
|
66
|
+
subject.department_handle = Economic::Entity::Handle.new(:number => 1)
|
67
|
+
subject.distribution_key_handle = Economic::Entity::Handle.new(:number => 314)
|
68
|
+
|
69
|
+
subject.save
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "./spec/spec_helper"
|
2
|
+
|
3
|
+
describe Economic::AccountProxy do
|
4
|
+
let(:session) { make_session }
|
5
|
+
subject { Economic::AccountProxy.new(session) }
|
6
|
+
|
7
|
+
describe ".new" do
|
8
|
+
it "stores session" do
|
9
|
+
expect(subject.session).to equal(session)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".build" do
|
14
|
+
it "instantiates a new Account" do
|
15
|
+
expect(subject.build).to be_instance_of(Economic::Account)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "assigns the session to the Account" do
|
19
|
+
expect(subject.build.session).to equal(session)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not build a partial Account" do
|
23
|
+
expect(subject.build).to_not be_partial
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".find" do
|
28
|
+
it "gets account data from API" do
|
29
|
+
mock_request(
|
30
|
+
"Account_GetData",
|
31
|
+
{"entityHandle" => {"Id" => 42}},
|
32
|
+
:success
|
33
|
+
)
|
34
|
+
subject.find(42)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns Account object" do
|
38
|
+
stub_request("Account_GetData", nil, :success)
|
39
|
+
expect(subject.find(42)).to be_instance_of(Economic::Account)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".all" do
|
44
|
+
it "returns an empty array when there are no accounts" do
|
45
|
+
stub_request("Account_GetAll", nil, :none)
|
46
|
+
expect(subject.all.size).to eq(0)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "finds and adds a single account" do
|
50
|
+
stub_request("Account_GetAll", nil, :single)
|
51
|
+
mock_request(
|
52
|
+
"Account_GetData",
|
53
|
+
{"entityHandle" => {"Number" => "1"}},
|
54
|
+
:success
|
55
|
+
)
|
56
|
+
|
57
|
+
accounts = subject.all
|
58
|
+
expect(accounts).to be_instance_of(Economic::AccountProxy)
|
59
|
+
|
60
|
+
expect(accounts.size).to eq(1)
|
61
|
+
expect(accounts.first).to be_instance_of(Economic::Account)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "adds multiple accounts" do
|
65
|
+
stub_request("Account_GetAll", nil, :multiple)
|
66
|
+
stub_request("Account_GetDataArray", nil, :multiple)
|
67
|
+
|
68
|
+
accounts = subject.all
|
69
|
+
expect(accounts.size).to eq(2)
|
70
|
+
expect(accounts.first).to be_instance_of(Economic::Account)
|
71
|
+
expect(accounts.last).to be_instance_of(Economic::Account)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "./spec/spec_helper"
|
2
|
+
|
3
|
+
describe Economic::Proxies::Actions::DebtorContact::All do
|
4
|
+
let(:session) { make_session }
|
5
|
+
let(:proxy) { Economic::DebtorContactProxy.new(session) }
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Economic::Proxies::Actions::DebtorContact::All.new(proxy)
|
9
|
+
}
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
allow(session).to receive(:number) { 123 }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#call" do
|
16
|
+
it "returns debtor contacts" do
|
17
|
+
stub_request("Debtor_GetDebtorContacts", nil, :multiple)
|
18
|
+
expect(subject.call.first).to be_instance_of(Economic::DebtorContact)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns empty array when nothing is found" do
|
22
|
+
stub_request("Debtor_GetDebtorContacts", nil, :none)
|
23
|
+
expect(subject.call).to be_empty
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::Proxies::Actions::FindByName do
|
4
4
|
let(:session) { make_session }
|
@@ -10,23 +10,23 @@ describe Economic::Proxies::Actions::FindByName do
|
|
10
10
|
|
11
11
|
describe "#call" do
|
12
12
|
it "gets contact data from the API" do
|
13
|
-
mock_request(
|
13
|
+
mock_request("CreditorContact_FindByName", {"name" => "Bob"}, :multiple)
|
14
14
|
subject.call
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns creditor contacts" do
|
18
|
-
stub_request(
|
18
|
+
stub_request("CreditorContact_FindByName", nil, :multiple)
|
19
19
|
expect(subject.call.first).to be_instance_of(Economic::CreditorContact)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "returns empty when nothing is found" do
|
23
|
-
stub_request(
|
23
|
+
stub_request("CreditorContact_FindByName", nil, :none)
|
24
24
|
expect(subject.call).to be_empty
|
25
25
|
end
|
26
26
|
|
27
27
|
context "when calling proxy is owned by session" do
|
28
28
|
it "returns all creditor contacts" do
|
29
|
-
stub_request(
|
29
|
+
stub_request("CreditorContact_FindByName", nil, :multiple)
|
30
30
|
expect(subject.call.size).to eq(2)
|
31
31
|
end
|
32
32
|
end
|
@@ -35,7 +35,7 @@ describe Economic::Proxies::Actions::FindByName do
|
|
35
35
|
it "returns only contacts for creditor" do
|
36
36
|
# Note the order of these stubs actually matters. They need to match
|
37
37
|
# the order they are called in in the implementation
|
38
|
-
stub_request(
|
38
|
+
stub_request("CreditorContact_FindByName", nil, :multiple)
|
39
39
|
stub_request("CreditorContact_GetData", nil, :success)
|
40
40
|
stub_request("Creditor_GetData", nil, :success)
|
41
41
|
stub_request("CreditorContact_GetData", nil, :success)
|
@@ -47,5 +47,4 @@ describe Economic::Proxies::Actions::FindByName do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
51
50
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::CashBookEntryProxy do
|
4
|
-
|
5
4
|
let(:session) { make_session }
|
6
5
|
let(:cash_book) { Economic::CashBook.new(:session => session) }
|
7
6
|
subject { Economic::CashBookEntryProxy.new(cash_book) }
|
@@ -28,63 +27,62 @@ describe Economic::CashBookEntryProxy do
|
|
28
27
|
end
|
29
28
|
|
30
29
|
describe "#create_finance_voucher" do
|
31
|
-
it
|
32
|
-
stub_request(
|
33
|
-
stub_request(
|
34
|
-
cash_book_entry = subject.create_finance_voucher(:account_handle => {
|
30
|
+
it "should create a finance voucher and return the created cash book entry" do
|
31
|
+
stub_request("CashBookEntry_CreateFinanceVoucher", nil, :success)
|
32
|
+
stub_request("CashBookEntry_GetData", {"entityHandle" => {"Id1" => 15, "Id2" => 16}}, :success)
|
33
|
+
cash_book_entry = subject.create_finance_voucher(:account_handle => {:number => 2}, :contra_account_handle => {:number => 3})
|
35
34
|
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
38
|
describe "#create_debtor_payment" do
|
40
|
-
it
|
41
|
-
stub_request(
|
42
|
-
stub_request(
|
43
|
-
cash_book_entry = subject.create_debtor_payment(:debtor_handle => {
|
39
|
+
it "should create a debtor payment and then return the created cash book entry" do
|
40
|
+
stub_request("CashBookEntry_CreateDebtorPayment", nil, :success)
|
41
|
+
stub_request("CashBookEntry_GetData", {"entityHandle" => {"Id1" => 13, "Id2" => 14}}, :success)
|
42
|
+
cash_book_entry = subject.create_debtor_payment(:debtor_handle => {:number => 2}, :contra_account_handle => {:number => 3})
|
44
43
|
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
47
|
describe "#create_creditor_invoice" do
|
49
|
-
it
|
50
|
-
stub_request(
|
51
|
-
stub_request(
|
52
|
-
cash_book_entry = subject.create_creditor_invoice(:creditor_handle => {
|
48
|
+
it "should create a creditor invoice and then return the created cash book entry" do
|
49
|
+
stub_request("CashBookEntry_CreateCreditorInvoice", nil, :success)
|
50
|
+
stub_request("CashBookEntry_GetData", {"entityHandle" => {"Id1" => 13, "Id2" => 14}}, :success)
|
51
|
+
cash_book_entry = subject.create_creditor_invoice(:creditor_handle => {:number => 2}, :contra_account_handle => {:number => 3})
|
53
52
|
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
54
53
|
end
|
55
54
|
|
56
|
-
it
|
57
|
-
stub_request(
|
58
|
-
stub_request(
|
55
|
+
it "should not send handles that were not given" do
|
56
|
+
stub_request("CashBookEntry_CreateCreditorInvoice", {"cashBookHandle" => {"Number" => 42}}, :success)
|
57
|
+
stub_request("CashBookEntry_GetData", {"entityHandle" => {"Id1" => 13, "Id2" => 14}}, :success)
|
59
58
|
cash_book.number = 42
|
60
|
-
cash_book_entry = subject.create_creditor_invoice(
|
59
|
+
cash_book_entry = subject.create_creditor_invoice(:number => 13)
|
61
60
|
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
64
|
describe "#create_creditor_payment" do
|
66
|
-
it
|
67
|
-
stub_request(
|
68
|
-
stub_request(
|
69
|
-
cash_book_entry = subject.create_creditor_payment(:creditor_handle => {
|
65
|
+
it "should create a creditor payment and then return the created cash book entry" do
|
66
|
+
stub_request("CashBookEntry_CreateCreditorPayment", nil, :success)
|
67
|
+
stub_request("CashBookEntry_GetData", {"entityHandle" => {"Id1" => 13, "Id2" => 14}}, :success)
|
68
|
+
cash_book_entry = subject.create_creditor_payment(:creditor_handle => {:number => 2}, :contra_account_handle => {:number => 3})
|
70
69
|
expect(cash_book_entry).to be_instance_of(Economic::CashBookEntry)
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
74
73
|
describe "#set_due_date" do
|
75
|
-
it
|
76
|
-
mock_request(
|
74
|
+
it "should set due date" do
|
75
|
+
mock_request("CashBookEntry_SetDueDate", {"cashBookEntryHandle" => {"Id1" => subject.owner.id, "Id2" => 234}, :value => Date.new(2012, 12, 21)}, :success)
|
77
76
|
subject.set_due_date(234, Date.new(2012, 12, 21))
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
80
|
describe "#all" do
|
82
|
-
it
|
83
|
-
stub_request(
|
84
|
-
expect(subject).to receive(:find).with(
|
85
|
-
expect(subject).to receive(:find).with(
|
81
|
+
it "should get the cash book entries" do
|
82
|
+
stub_request("CashBook_GetEntries", nil, :success)
|
83
|
+
expect(subject).to receive(:find).with(:id1 => "1", :id2 => "2")
|
84
|
+
expect(subject).to receive(:find).with(:id1 => "11", :id2 => "12")
|
86
85
|
subject.all
|
87
86
|
end
|
88
87
|
end
|
89
|
-
|
90
88
|
end
|
@@ -1,20 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::CashBookProxy do
|
4
|
-
|
5
4
|
let(:session) { make_session }
|
6
5
|
subject { Economic::CashBookProxy.new(session) }
|
7
6
|
|
8
7
|
describe ".new" do
|
9
|
-
|
10
8
|
it "stores session" do
|
11
9
|
expect(subject.session).to equal(session)
|
12
10
|
end
|
13
|
-
|
14
11
|
end
|
15
12
|
|
16
13
|
describe ".build" do
|
17
|
-
|
18
14
|
it "instantiates a new CashBook" do
|
19
15
|
expect(subject.build).to be_instance_of(Economic::CashBook)
|
20
16
|
end
|
@@ -22,14 +18,12 @@ describe Economic::CashBookProxy do
|
|
22
18
|
it "assigns the session to the CashBook" do
|
23
19
|
expect(subject.build.session).to equal(session)
|
24
20
|
end
|
25
|
-
|
26
21
|
end
|
27
22
|
|
28
23
|
describe ".all" do
|
29
|
-
|
30
24
|
it "returns multiple cashbooks" do
|
31
|
-
stub_request(
|
32
|
-
stub_request(
|
25
|
+
stub_request("CashBook_GetAll", nil, :multiple)
|
26
|
+
stub_request("CashBook_GetDataArray", nil, :multiple)
|
33
27
|
|
34
28
|
all = subject.all
|
35
29
|
expect(all.size).to eq(2)
|
@@ -38,11 +32,11 @@ describe Economic::CashBookProxy do
|
|
38
32
|
|
39
33
|
it "properly fills out handles of cash books" do
|
40
34
|
# Issue #12
|
41
|
-
stub_request(
|
42
|
-
stub_request(
|
43
|
-
stub_request(
|
44
|
-
stub_request(
|
45
|
-
stub_request(
|
35
|
+
stub_request("CashBook_GetAll", nil, :multiple)
|
36
|
+
stub_request("CashBook_GetDataArray", nil, :multiple)
|
37
|
+
stub_request("CashBook_GetData", nil, :success)
|
38
|
+
stub_request("CashBook_GetAll", nil, :multiple)
|
39
|
+
stub_request("CashBook_GetDataArray", nil, :multiple)
|
46
40
|
|
47
41
|
cash_book = subject.find(subject.all.first.handle)
|
48
42
|
expect(subject.all.first.handle).to eq(cash_book.handle)
|
@@ -50,21 +44,19 @@ describe Economic::CashBookProxy do
|
|
50
44
|
end
|
51
45
|
|
52
46
|
describe ".get_name" do
|
53
|
-
|
54
|
-
|
55
|
-
mock_request('CashBook_GetName', {"cashBookHandle" => { "Number" => "52" }}, :success)
|
47
|
+
it "returns a cash book with a name" do
|
48
|
+
mock_request("CashBook_GetName", {"cashBookHandle" => {"Number" => "52"}}, :success)
|
56
49
|
result = subject.get_name("52")
|
57
50
|
expect(result).to be_instance_of(Economic::CashBook)
|
58
51
|
expect(result.number).to eq("52")
|
59
52
|
expect(result.name).to be_a(String)
|
60
53
|
end
|
61
|
-
|
62
54
|
end
|
63
55
|
|
64
56
|
describe "#last" do
|
65
57
|
it "returns the last cash book" do
|
66
|
-
stub_request(
|
67
|
-
stub_request(
|
58
|
+
stub_request("CashBook_GetAll", nil, :multiple)
|
59
|
+
stub_request("CashBook_GetDataArray", nil, :multiple)
|
68
60
|
|
69
61
|
expect(subject.all.last.name).to eq("Another cash book")
|
70
62
|
end
|
@@ -72,8 +64,8 @@ describe Economic::CashBookProxy do
|
|
72
64
|
|
73
65
|
describe "#[]" do
|
74
66
|
it "returns the specific cash book" do
|
75
|
-
stub_request(
|
76
|
-
stub_request(
|
67
|
+
stub_request("CashBook_GetAll", nil, :multiple)
|
68
|
+
stub_request("CashBook_GetDataArray", nil, :multiple)
|
77
69
|
|
78
70
|
expect(subject.all[1].name).to eq("Another cash book")
|
79
71
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "./spec/spec_helper"
|
2
|
+
|
3
|
+
describe Economic::CompanyProxy do
|
4
|
+
let(:session) { make_session }
|
5
|
+
subject { Economic::CompanyProxy.new(session) }
|
6
|
+
|
7
|
+
describe ".get" do
|
8
|
+
let!(:company) { Economic::Company.new.tap { |e| e.session = session } }
|
9
|
+
|
10
|
+
it "Calls CompanyGet endpoint" do
|
11
|
+
mock_request("Company_Get", nil, :success)
|
12
|
+
stub_request("Company_GetData", {"entityHandle" => {"Number" => "string"}}, :success)
|
13
|
+
company.get
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Calls CopmanyGetData endpoint with valid data" do
|
17
|
+
stub_request("Company_Get", nil, :success)
|
18
|
+
mock_request("Company_GetData", {"entityHandle" => {"Number" => "string"}}, :success)
|
19
|
+
company.get
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Returns a valid company" do
|
23
|
+
stub_request("Company_Get", nil, :success)
|
24
|
+
stub_request("Company_GetData", {"entityHandle" => {"Number" => "string"}}, :success)
|
25
|
+
expectation = {:handle => {:number => "string"},
|
26
|
+
:number => "string",
|
27
|
+
:base_currency_handle => {:code => "string"},
|
28
|
+
:name => "string",
|
29
|
+
:address1 => "string",
|
30
|
+
:address2 => "string",
|
31
|
+
:postal_code => "string",
|
32
|
+
:city => "string",
|
33
|
+
:county => "string",
|
34
|
+
:country => "string",
|
35
|
+
:telephone_number => "string",
|
36
|
+
:fax_number => "string",
|
37
|
+
:mobile_number => "string",
|
38
|
+
:contact => "string",
|
39
|
+
:web_site => "string",
|
40
|
+
:email => "string",
|
41
|
+
:ci_number => "string",
|
42
|
+
:vat_number => "string",
|
43
|
+
:sign_up_date => "dateTime"}
|
44
|
+
expect(company.get).to eq expectation
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::CreditorContactProxy do
|
4
4
|
let(:session) { make_session }
|
@@ -40,13 +40,19 @@ describe Economic::CreditorContactProxy do
|
|
40
40
|
|
41
41
|
describe ".find" do
|
42
42
|
it "gets contact data from API" do
|
43
|
-
mock_request(
|
43
|
+
mock_request(
|
44
|
+
"CreditorContact_GetData",
|
45
|
+
{"entityHandle" => {"Id" => 42}},
|
46
|
+
:success
|
47
|
+
)
|
44
48
|
subject.find(42)
|
45
49
|
end
|
46
50
|
|
47
51
|
it "returns CreditorContact object" do
|
48
|
-
stub_request(
|
49
|
-
expect(
|
52
|
+
stub_request("CreditorContact_GetData", nil, :success)
|
53
|
+
expect(
|
54
|
+
subject.find(42)
|
55
|
+
).to be_instance_of(Economic::CreditorContact)
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
@@ -54,7 +60,7 @@ describe Economic::CreditorContactProxy do
|
|
54
60
|
it "uses the FindByName command" do
|
55
61
|
expect(Economic::Proxies::Actions::FindByName).to receive(:new).
|
56
62
|
with(subject, "Bob").
|
57
|
-
and_return(
|
63
|
+
and_return(-> { "Result" })
|
58
64
|
expect(subject.find_by_name("Bob")).to eq("Result")
|
59
65
|
end
|
60
66
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/spec_helper"
|
2
2
|
|
3
3
|
describe Economic::CreditorEntryProxy do
|
4
4
|
let(:session) { make_session }
|
@@ -11,32 +11,32 @@ describe Economic::CreditorEntryProxy do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#find_by_invoice_number" do
|
14
|
-
it
|
15
|
-
mock_request("CreditorEntry_FindByInvoiceNumber", {
|
16
|
-
expect(subject.find_by_invoice_number(
|
14
|
+
it "should be able to find multiple creditor entries" do
|
15
|
+
mock_request("CreditorEntry_FindByInvoiceNumber", {"invoiceNumber" => "123"}, :many)
|
16
|
+
expect(subject.find_by_invoice_number("123")).to eq([1, 2])
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "should handle a single serial number in the response" do
|
20
20
|
stub_request("CreditorEntry_FindByInvoiceNumber", nil, :single)
|
21
|
-
expect(subject.find_by_invoice_number(
|
21
|
+
expect(subject.find_by_invoice_number("123")).to eq([1])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "#find" do
|
26
|
-
it
|
27
|
-
mock_request("CreditorEntry_GetData", {
|
28
|
-
expect(subject.find(
|
26
|
+
it "should get a creditor entry by serial number" do
|
27
|
+
mock_request("CreditorEntry_GetData", {"entityHandle" => {"SerialNumber" => "123"}}, :success)
|
28
|
+
expect(subject.find("123")).to be_instance_of(Economic::CreditorEntry)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#match" do
|
33
|
-
it
|
33
|
+
it "should match two creditor entries by serial numbers" do
|
34
34
|
stub_request(
|
35
35
|
"CreditorEntry_MatchEntries",
|
36
36
|
{:entries => {
|
37
37
|
"CreditorEntryHandle" => [
|
38
|
-
{"SerialNumber"=>1},
|
39
|
-
{"SerialNumber"=>2}
|
38
|
+
{"SerialNumber" => 1},
|
39
|
+
{"SerialNumber" => 2}
|
40
40
|
]
|
41
41
|
}},
|
42
42
|
:success
|