rconomic 0.5.0 → 0.5.1
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 +6 -14
- data/.travis.yml +0 -1
- data/Gemfile +0 -1
- data/lib/economic/account.rb +3 -5
- data/lib/economic/cash_book.rb +1 -1
- data/lib/economic/cash_book_entry.rb +92 -94
- data/lib/economic/creditor.rb +1 -1
- data/lib/economic/creditor_contact.rb +15 -17
- data/lib/economic/creditor_entry.rb +0 -1
- data/lib/economic/current_invoice.rb +32 -35
- data/lib/economic/current_invoice_line.rb +14 -2
- data/lib/economic/debtor.rb +60 -37
- data/lib/economic/debtor_contact.rb +26 -20
- data/lib/economic/endpoint.rb +72 -0
- data/lib/economic/entity/handle.rb +35 -21
- data/lib/economic/entity/mapper.rb +41 -0
- data/lib/economic/entity.rb +58 -34
- data/lib/economic/invoice.rb +15 -2
- data/lib/economic/proxies/account_proxy.rb +2 -3
- data/lib/economic/proxies/actions/find_by_ci_number.rb +4 -2
- data/lib/economic/proxies/actions/find_by_date_interval.rb +0 -1
- data/lib/economic/proxies/actions/find_by_name.rb +5 -1
- data/lib/economic/proxies/cash_book_entry_proxy.rb +1 -1
- data/lib/economic/proxies/entity_proxy.rb +15 -8
- data/lib/economic/session.rb +27 -31
- data/lib/rconomic/version.rb +1 -1
- data/rconomic.gemspec +1 -5
- data/spec/economic/cash_book_entry_spec.rb +27 -5
- data/spec/economic/cash_book_spec.rb +6 -6
- data/spec/economic/creditor_contact_spec.rb +24 -15
- data/spec/economic/creditor_spec.rb +9 -9
- data/spec/economic/current_invoice_line_spec.rb +7 -7
- data/spec/economic/current_invoice_spec.rb +82 -33
- data/spec/economic/debtor_contact_spec.rb +25 -15
- data/spec/economic/debtor_entry_spec.rb +3 -3
- data/spec/economic/debtor_spec.rb +49 -15
- data/spec/economic/endpoint_spec.rb +71 -0
- data/spec/economic/entity/handle_spec.rb +42 -49
- data/spec/economic/entity/mapper_spec.rb +54 -0
- data/spec/economic/entity_spec.rb +78 -72
- data/spec/economic/entry_spec.rb +3 -3
- data/spec/economic/invoice_spec.rb +37 -18
- data/spec/economic/proxies/actions/find_by_name_spec.rb +15 -12
- data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +26 -24
- data/spec/economic/proxies/cash_book_proxy_spec.rb +23 -21
- data/spec/economic/proxies/creditor_contact_proxy_spec.rb +12 -16
- data/spec/economic/proxies/creditor_entry_proxy_spec.rb +18 -14
- data/spec/economic/proxies/creditor_proxy_spec.rb +23 -26
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +17 -20
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +38 -41
- data/spec/economic/proxies/debtor_contact_proxy_spec.rb +12 -15
- data/spec/economic/proxies/debtor_entry_proxy_spec.rb +18 -14
- data/spec/economic/proxies/debtor_proxy_spec.rb +31 -34
- data/spec/economic/proxies/entry_proxy_spec.rb +26 -22
- data/spec/economic/proxies/invoice_proxy_spec.rb +18 -21
- data/spec/economic/session_spec.rb +57 -44
- data/spec/fixtures/{spec_entity_create_from_data → account_create_from_data}/success.xml +5 -5
- data/spec/fixtures/{spec_entity_delete → account_delete}/success.xml +1 -1
- data/spec/fixtures/{spec_entity_get_data → account_get_data}/success.xml +5 -5
- data/spec/fixtures/{spec_entity_update_from_data → account_update_from_data}/success.xml +5 -5
- data/spec/fixtures/cash_book_entry_create_creditor_invoice/success.xml +2 -2
- data/spec/fixtures/cash_book_entry_create_creditor_payment/success.xml +2 -2
- data/spec/fixtures/creditor_contact_create_from_data/success.xml +10 -0
- data/spec/fixtures/debtor_contact_create_from_data/success.xml +10 -0
- data/spec/fixtures/debtor_create_from_data/success.xml +57 -0
- data/spec/spec_helper.rb +10 -104
- data/spec/support/api_requests.rb +20 -0
- data/spec/support/factories.rb +65 -0
- data/spec/support/fixtures.rb +9 -0
- metadata +27 -31
@@ -6,21 +6,21 @@ describe Economic::DebtorContactProxy do
|
|
6
6
|
|
7
7
|
describe ".new" do
|
8
8
|
it "stores session" do
|
9
|
-
subject.session.
|
9
|
+
expect(subject.session).to equal(session)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe ".build" do
|
14
14
|
it "instantiates a new DebtorContact" do
|
15
|
-
subject.build.
|
15
|
+
expect(subject.build).to be_instance_of(Economic::DebtorContact)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "assigns the session to the DebtorContact" do
|
19
|
-
subject.build.session.
|
19
|
+
expect(subject.build.session).to equal(session)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not build a partial DebtorContact" do
|
23
|
-
subject.build.
|
23
|
+
expect(subject.build).to_not be_partial
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when owner is a Debtor" do
|
@@ -28,37 +28,34 @@ describe Economic::DebtorContactProxy do
|
|
28
28
|
subject { debtor.contacts }
|
29
29
|
|
30
30
|
it "should use the Debtors session" do
|
31
|
-
subject.build.session.
|
31
|
+
expect(subject.build.session).to eq(debtor.session)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should initialize with values from Debtor" do
|
35
35
|
contact = subject.build
|
36
|
-
contact.debtor_handle.
|
36
|
+
expect(contact.debtor_handle).to eq(debtor.handle)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe ".find" do
|
42
|
-
before :each do
|
43
|
-
savon.stubs('DebtorContact_GetData').returns(:success)
|
44
|
-
end
|
45
|
-
|
46
42
|
it "gets contact data from API" do
|
47
|
-
|
43
|
+
mock_request('DebtorContact_GetData', {'entityHandle' => {'Id' => 42}}, :success)
|
48
44
|
subject.find(42)
|
49
45
|
end
|
50
46
|
|
51
47
|
it "returns DebtorContact object" do
|
52
|
-
|
48
|
+
stub_request('DebtorContact_GetData', nil, :success)
|
49
|
+
expect(subject.find(42)).to be_instance_of(Economic::DebtorContact)
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
53
|
describe "#find_by_name" do
|
57
54
|
it "uses the FindByName command" do
|
58
|
-
Economic::Proxies::Actions::FindByName.
|
55
|
+
expect(Economic::Proxies::Actions::FindByName).to receive(:new).
|
59
56
|
with(subject, "Bob").
|
60
|
-
|
61
|
-
subject.find_by_name("Bob").
|
57
|
+
and_return(lambda { "Result" })
|
58
|
+
expect(subject.find_by_name("Bob")).to eq("Result")
|
62
59
|
end
|
63
60
|
end
|
64
61
|
end
|
@@ -6,42 +6,46 @@ describe Economic::DebtorEntryProxy do
|
|
6
6
|
|
7
7
|
describe "new" do
|
8
8
|
it "stores session" do
|
9
|
-
subject.session.
|
9
|
+
expect(subject.session).to equal(session)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#find_by_invoice_number" do
|
14
14
|
it 'should be able to find multiple debtor entries' do
|
15
|
-
|
16
|
-
subject.find_by_invoice_number('123', '456').
|
15
|
+
mock_request("DebtorEntry_FindByInvoiceNumber", {'from' => '123', 'to' => '456'}, :many)
|
16
|
+
expect(subject.find_by_invoice_number('123', '456')).to eq([1, 2])
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should be able to find debtor entries with one invoice id' do
|
20
|
-
|
21
|
-
subject.find_by_invoice_number('123').
|
20
|
+
mock_request("DebtorEntry_FindByInvoiceNumber", {'from' => '123', 'to' => '123'}, :many)
|
21
|
+
expect(subject.find_by_invoice_number('123')).to eq([1, 2])
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should handle a single serial number in the response' do
|
25
|
-
|
26
|
-
subject.find_by_invoice_number('123').
|
25
|
+
stub_request("DebtorEntry_FindByInvoiceNumber", nil, :single)
|
26
|
+
expect(subject.find_by_invoice_number('123')).to eq([1])
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "#match" do
|
31
31
|
it 'should match two debtor entries by serial numbers' do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
stub_request(
|
33
|
+
"DebtorEntry_MatchEntries",
|
34
|
+
{:entries => {
|
35
|
+
"DebtorEntryHandle" => [
|
36
|
+
{"SerialNumber" => 1},
|
37
|
+
{"SerialNumber" => 2}
|
38
|
+
]
|
39
|
+
}},
|
40
|
+
:success
|
41
|
+
)
|
38
42
|
subject.match(1, 2)
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
42
46
|
describe "#entity_class" do
|
43
47
|
it "should return Economic::DebtorEntry" do
|
44
|
-
Economic::DebtorEntryProxy.entity_class.
|
48
|
+
expect(Economic::DebtorEntryProxy.entity_class).to eq(Economic::DebtorEntry)
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
@@ -6,75 +6,72 @@ describe Economic::DebtorProxy do
|
|
6
6
|
|
7
7
|
describe "new" do
|
8
8
|
it "stores session" do
|
9
|
-
subject.session.
|
9
|
+
expect(subject.session).to equal(session)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "find" do
|
14
|
-
before :each do
|
15
|
-
savon.stubs('Debtor_GetData').returns(:success)
|
16
|
-
end
|
17
|
-
|
18
14
|
it "gets debtor data from API" do
|
19
|
-
|
15
|
+
mock_request('Debtor_GetData', {'entityHandle' => {'Number' => 42}}, :success)
|
20
16
|
subject.find(42)
|
21
17
|
end
|
22
18
|
|
23
19
|
it "returns Debtor object" do
|
24
|
-
|
20
|
+
stub_request('Debtor_GetData', nil, :success)
|
21
|
+
expect(subject.find(42)).to be_instance_of(Economic::Debtor)
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
25
|
describe "find_by_ci_number" do
|
29
26
|
it "uses FindByCINumber on API" do
|
30
|
-
|
27
|
+
mock_request('Debtor_FindByCINumber', {'ciNumber' => '12345678'}, :many)
|
31
28
|
subject.find_by_ci_number('12345678')
|
32
29
|
end
|
33
30
|
|
34
31
|
context "when many debtors exist" do
|
35
32
|
before :each do
|
36
|
-
|
33
|
+
stub_request('Debtor_FindByCINumber', nil, :many)
|
37
34
|
end
|
38
35
|
|
39
36
|
let(:results) { subject.find_by_ci_number('12345678') }
|
40
37
|
|
41
38
|
it "returns a Debtor object for each result" do
|
42
|
-
results.size.
|
43
|
-
results.all? { |result| result.
|
39
|
+
expect(results.size).to eq(2)
|
40
|
+
results.all? { |result| expect(result).to be_instance_of(Economic::Debtor) }
|
44
41
|
end
|
45
42
|
|
46
43
|
it "returns partial Debtor objects" do
|
47
|
-
results.all? { |result| result.
|
44
|
+
results.all? { |result| expect(result).to be_partial }
|
48
45
|
end
|
49
46
|
|
50
47
|
it "returns persisted Debtor objects" do
|
51
|
-
results.all? { |result| result.
|
48
|
+
results.all? { |result| expect(result).to be_persisted }
|
52
49
|
end
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
53
|
describe "find_by_number" do
|
57
54
|
it "can find a debtor" do
|
58
|
-
|
55
|
+
mock_request('Debtor_FindByNumber', {'number' => '1'}, :found)
|
59
56
|
result = subject.find_by_number('1')
|
60
|
-
result.
|
61
|
-
result.number.
|
62
|
-
result.partial.
|
63
|
-
result.persisted.
|
64
|
-
result.handle.
|
57
|
+
expect(result).to be_instance_of(Economic::Debtor)
|
58
|
+
expect(result.number).to eq(1)
|
59
|
+
expect(result.partial).to be_true
|
60
|
+
expect(result.persisted).to be_true
|
61
|
+
expect(result.handle).to eq(Economic::Entity::Handle.new({:number => 1}))
|
65
62
|
end
|
66
63
|
|
67
64
|
it "returns nil when there is no debtor" do
|
68
|
-
|
65
|
+
mock_request('Debtor_FindByNumber', {'number' => '1'}, :not_found)
|
69
66
|
result = subject.find_by_number('1')
|
70
|
-
result.
|
67
|
+
expect(result).to be_nil
|
71
68
|
end
|
72
69
|
end
|
73
70
|
|
74
71
|
describe "next_available_number" do
|
75
72
|
it "gets the next available debtor number from API" do
|
76
|
-
|
77
|
-
subject.next_available_number.
|
73
|
+
mock_request('Debtor_GetNextAvailableNumber', nil, :success)
|
74
|
+
expect(subject.next_available_number).to eq('105')
|
78
75
|
end
|
79
76
|
end
|
80
77
|
|
@@ -82,17 +79,17 @@ describe Economic::DebtorProxy do
|
|
82
79
|
subject { session.debtors.build }
|
83
80
|
|
84
81
|
it "instantiates a new Debtor" do
|
85
|
-
subject.
|
82
|
+
expect(subject).to be_instance_of(Economic::Debtor)
|
86
83
|
end
|
87
84
|
|
88
85
|
it "assigns the session to the Debtor" do
|
89
|
-
subject.session.
|
86
|
+
expect(subject.session).to equal(session)
|
90
87
|
end
|
91
88
|
end
|
92
89
|
|
93
90
|
describe "#entity_class" do
|
94
91
|
it "should return Economic::Debtor" do
|
95
|
-
Economic::DebtorProxy.entity_class.
|
92
|
+
expect(Economic::DebtorProxy.entity_class).to eq(Economic::Debtor)
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
@@ -100,19 +97,19 @@ describe Economic::DebtorProxy do
|
|
100
97
|
# it handles debtors "Number" id.
|
101
98
|
describe ".all" do
|
102
99
|
it "returns a single debtor" do
|
103
|
-
|
104
|
-
|
100
|
+
mock_request('Debtor_GetAll', nil, :single)
|
101
|
+
mock_request('Debtor_GetData', {'entityHandle' => {'Number' => 1}}, :success)
|
105
102
|
all = subject.all
|
106
|
-
all.size.
|
107
|
-
all.first.
|
103
|
+
expect(all.size).to eq(1)
|
104
|
+
expect(all.first).to be_instance_of(Economic::Debtor)
|
108
105
|
end
|
109
106
|
|
110
107
|
it "returns multiple debtors" do
|
111
|
-
|
112
|
-
|
108
|
+
mock_request('Debtor_GetAll', nil, :multiple)
|
109
|
+
mock_request('Debtor_GetDataArray', :any, :multiple)
|
113
110
|
all = subject.all
|
114
|
-
all.size.
|
115
|
-
all.first.
|
111
|
+
expect(all.size).to eq(2)
|
112
|
+
expect(all.first).to be_instance_of(Economic::Debtor)
|
116
113
|
end
|
117
114
|
end
|
118
115
|
end
|
@@ -6,7 +6,7 @@ describe Economic::EntryProxy do
|
|
6
6
|
|
7
7
|
describe "new" do
|
8
8
|
it "stores session" do
|
9
|
-
subject.session.
|
9
|
+
expect(subject.session).to equal(session)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -14,59 +14,63 @@ describe Economic::EntryProxy do
|
|
14
14
|
it 'should be able to find multiple entries' do
|
15
15
|
from_date = Date.new
|
16
16
|
to_date = Date.new
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
mock_request(
|
18
|
+
"Entry_FindByDateInterval",
|
19
|
+
{'fromDate' => from_date, 'toDate' => to_date},
|
20
|
+
:many
|
21
|
+
)
|
22
|
+
expect(subject.find_by_date_interval(from_date, to_date)).to eq([1, 2])
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'should handle a single serial number in the response' do
|
24
|
-
|
25
|
-
subject.find_by_date_interval(Date.new, Date.new).
|
26
|
+
stub_request("Entry_FindByDateInterval", nil, :single)
|
27
|
+
expect(subject.find_by_date_interval(Date.new, Date.new)).to eq([1])
|
26
28
|
end
|
27
29
|
|
28
30
|
it 'should handle an empty response' do
|
29
|
-
|
30
|
-
subject.find_by_date_interval(Date.new, Date.new).
|
31
|
+
stub_request("Entry_FindByDateInterval", nil, :none)
|
32
|
+
expect(subject.find_by_date_interval(Date.new, Date.new)).to eq([])
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
36
|
describe "#find_by_serial_number_interval" do
|
35
37
|
it 'should be able to find multiple entries' do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
mock_request(
|
39
|
+
"Entry_FindBySerialNumberInterval",
|
40
|
+
{'minNumber' => 123, 'maxNumber' => 456},
|
41
|
+
:many
|
42
|
+
)
|
43
|
+
expect(subject.find_by_serial_number_interval(123, 456)).to eq([1, 2])
|
40
44
|
end
|
41
45
|
|
42
46
|
it 'should handle a single serial number in the response' do
|
43
|
-
|
44
|
-
subject.find_by_serial_number_interval(123, 456).
|
47
|
+
stub_request("Entry_FindBySerialNumberInterval", nil, :single)
|
48
|
+
expect(subject.find_by_serial_number_interval(123, 456)).to eq([1])
|
45
49
|
end
|
46
50
|
|
47
51
|
it 'should handle an empty response' do
|
48
|
-
|
49
|
-
subject.find_by_serial_number_interval(123, 456).
|
52
|
+
stub_request("Entry_FindBySerialNumberInterval", nil, :none)
|
53
|
+
expect(subject.find_by_serial_number_interval(123, 456)).to eq([])
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
53
57
|
describe "#get_last_used_serial_number" do
|
54
58
|
it 'returns the number' do
|
55
|
-
|
56
|
-
subject.get_last_used_serial_number.
|
59
|
+
mock_request("Entry_GetLastUsedSerialNumber", nil, :success)
|
60
|
+
expect(subject.get_last_used_serial_number).to eq(123)
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
60
64
|
describe "#find" do
|
61
65
|
it 'should get a entry by serial number' do
|
62
|
-
|
63
|
-
subject.find('123').
|
66
|
+
mock_request("Entry_GetData", {'entityHandle' => { 'SerialNumber' => '123' }}, :success)
|
67
|
+
expect(subject.find('123')).to be_instance_of(Economic::Entry)
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
67
71
|
describe "#entity_class" do
|
68
72
|
it "should return Economic::Entry" do
|
69
|
-
Economic::EntryProxy.entity_class.
|
73
|
+
expect(Economic::EntryProxy.entity_class).to eq(Economic::Entry)
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
@@ -7,63 +7,60 @@ describe Economic::InvoiceProxy do
|
|
7
7
|
|
8
8
|
describe ".new" do
|
9
9
|
it "stores session" do
|
10
|
-
subject.session.
|
10
|
+
expect(subject.session).to equal(session)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe ".build" do
|
15
15
|
it "instantiates a new Invoice" do
|
16
|
-
subject.build.
|
16
|
+
expect(subject.build).to be_instance_of(Economic::Invoice)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "assigns the session to the Invoice" do
|
20
|
-
subject.build.session.
|
20
|
+
expect(subject.build.session).to equal(session)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should not build a partial Invoice" do
|
24
|
-
subject.build.
|
24
|
+
expect(subject.build).to_not be_partial
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe ".find" do
|
29
|
-
before :each do
|
30
|
-
savon.stubs('Invoice_GetData').returns(:success)
|
31
|
-
end
|
32
|
-
|
33
29
|
it "gets invoice data from API" do
|
34
|
-
|
30
|
+
mock_request('Invoice_GetData', {'entityHandle' => {'Number' => 42}}, :success)
|
35
31
|
subject.find(42)
|
36
32
|
end
|
37
33
|
|
38
34
|
it "returns Invoice object" do
|
39
|
-
|
35
|
+
stub_request('Invoice_GetData', nil, :success)
|
36
|
+
expect(subject.find(42)).to be_instance_of(Economic::Invoice)
|
40
37
|
end
|
41
|
-
end
|
38
|
+
end
|
42
39
|
|
43
40
|
describe ".find_by_date_interval" do
|
44
41
|
let(:from) { Time.now - 60 }
|
45
42
|
let(:unto) { Time.now }
|
46
43
|
|
47
44
|
it "should be able to return a single current invoice" do
|
48
|
-
|
49
|
-
|
45
|
+
mock_request('Invoice_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :single)
|
46
|
+
mock_request('Invoice_GetDataArray', :any, :single)
|
50
47
|
results = subject.find_by_date_interval(from, unto)
|
51
|
-
results.size.
|
52
|
-
results.first.
|
48
|
+
expect(results.size).to eq(1)
|
49
|
+
expect(results.first).to be_instance_of(Economic::Invoice)
|
53
50
|
end
|
54
51
|
|
55
52
|
it "should be able to return multiple invoices" do
|
56
|
-
|
57
|
-
|
53
|
+
mock_request('Invoice_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :many)
|
54
|
+
mock_request('Invoice_GetDataArray', :any, :multiple)
|
58
55
|
results = subject.find_by_date_interval(from, unto)
|
59
|
-
results.size.
|
60
|
-
results.first.
|
56
|
+
expect(results.size).to eq(2)
|
57
|
+
expect(results.first).to be_instance_of(Economic::Invoice)
|
61
58
|
end
|
62
59
|
|
63
60
|
it "should be able to return nothing" do
|
64
|
-
|
61
|
+
mock_request('Invoice_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :none)
|
65
62
|
results = subject.find_by_date_interval(from, unto)
|
66
|
-
results.size.
|
63
|
+
expect(results.size).to eq(0)
|
67
64
|
end
|
68
65
|
|
69
66
|
end
|
@@ -1,124 +1,137 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Economic::Session do
|
4
|
-
let(:client) { subject.send(:client) }
|
5
|
-
|
6
4
|
subject { Economic::Session.new(123456, 'api', 'passw0rd') }
|
7
5
|
|
6
|
+
let(:endpoint) { subject.endpoint }
|
7
|
+
|
8
8
|
describe "new" do
|
9
9
|
it "should store authentication details" do
|
10
|
-
subject.agreement_number.
|
11
|
-
subject.user_name.
|
12
|
-
subject.password.
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "client" do
|
17
|
-
subject { Economic::Session.new(123456, 'api', 'passw0rd') }
|
18
|
-
|
19
|
-
it "returns a Savon::Client" do
|
20
|
-
client.should be_instance_of(::Savon::Client)
|
10
|
+
expect(subject.agreement_number).to eq(123456)
|
11
|
+
expect(subject.user_name).to eq('api')
|
12
|
+
expect(subject.password).to eq('passw0rd')
|
21
13
|
end
|
22
14
|
end
|
23
15
|
|
24
16
|
describe "connect" do
|
17
|
+
let(:authentication_details) { {:agreementNumber => 123456, :userName => 'api', :password => 'passw0rd'} }
|
18
|
+
|
25
19
|
it "connects to e-conomic with authentication details" do
|
26
|
-
|
20
|
+
mock_request(:connect, authentication_details, :success)
|
27
21
|
subject.connect
|
28
22
|
end
|
29
23
|
|
30
|
-
it "stores the
|
31
|
-
|
24
|
+
it "stores the authentication token for later requests" do
|
25
|
+
response = {
|
26
|
+
:headers => {'Set-Cookie' => 'cookie value from e-conomic'},
|
27
|
+
:body => fixture(:connect, :success)
|
28
|
+
}
|
29
|
+
stub_request('Connect', authentication_details, response)
|
30
|
+
|
32
31
|
subject.connect
|
33
|
-
|
34
|
-
subject.
|
35
|
-
|
32
|
+
|
33
|
+
expect(subject.authentication_token.collect { |cookie|
|
34
|
+
cookie.name_and_value.split("=").last
|
35
|
+
}).to eq(["cookie value from e-conomic"])
|
36
36
|
end
|
37
37
|
|
38
|
-
it "updates the
|
39
|
-
|
38
|
+
it "updates the authentication token for new sessions" do
|
39
|
+
stub_request("Connect", nil, {:headers => {"Set-Cookie" => "authentication token"}})
|
40
40
|
subject.connect
|
41
|
+
|
42
|
+
stub_request('Connect', nil, {:headers => {"Set-Cookie" => "another token"}})
|
41
43
|
other_session = Economic::Session.new(123456, 'api', 'passw0rd')
|
42
|
-
savon.expects('Connect').returns({:headers => {'Set-Cookie' => 'other-cookie'}})
|
43
44
|
other_session.connect
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
expect(subject.authentication_token.collect { |cookie|
|
47
|
+
cookie.name_and_value.split("=").last
|
48
|
+
}).to eq(["authentication token"])
|
49
|
+
expect(other_session.authentication_token.collect { |cookie|
|
50
|
+
cookie.name_and_value.split("=").last
|
51
|
+
}).to eq(["another token"])
|
48
52
|
end
|
49
53
|
|
50
|
-
it "
|
51
|
-
|
52
|
-
savon.stubs('Connect').returns({:headers => {'Set-Cookie' => 'cookie'}})
|
54
|
+
it "doesn't use existing authentication details when connecting" do
|
55
|
+
expect(endpoint).to receive(:call).with(:connect, instance_of(Hash))
|
53
56
|
subject.connect
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
60
|
+
describe ".endpoint" do
|
61
|
+
it "returns Economic::Endpoint" do
|
62
|
+
expect(subject.endpoint).to be_instance_of(Economic::Endpoint)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
57
66
|
describe ".session" do
|
58
67
|
it "returns self" do
|
59
|
-
subject.session.
|
68
|
+
expect(subject.session).to equal(subject)
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
63
72
|
describe "contacts" do
|
64
73
|
it "returns a DebtorContactProxy" do
|
65
|
-
subject.contacts.
|
74
|
+
expect(subject.contacts).to be_instance_of(Economic::DebtorContactProxy)
|
66
75
|
end
|
67
76
|
|
68
77
|
it "memoizes the proxy" do
|
69
|
-
subject.contacts.
|
78
|
+
expect(subject.contacts).to equal(subject.contacts)
|
70
79
|
end
|
71
80
|
end
|
72
81
|
|
73
82
|
describe "current_invoices" do
|
74
83
|
it "returns an CurrentInvoiceProxy" do
|
75
|
-
subject.current_invoices.
|
84
|
+
expect(subject.current_invoices).to be_instance_of(Economic::CurrentInvoiceProxy)
|
76
85
|
end
|
77
86
|
|
78
87
|
it "memoizes the proxy" do
|
79
|
-
subject.current_invoices.
|
88
|
+
expect(subject.current_invoices).to equal(subject.current_invoices)
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
83
92
|
describe "invoices" do
|
84
93
|
it "returns an InvoiceProxy" do
|
85
|
-
subject.invoices.
|
94
|
+
expect(subject.invoices).to be_instance_of(Economic::InvoiceProxy)
|
86
95
|
end
|
87
96
|
|
88
97
|
it "memoizes the proxy" do
|
89
|
-
subject.invoices.
|
98
|
+
expect(subject.invoices).to equal(subject.invoices)
|
90
99
|
end
|
91
100
|
end
|
92
101
|
|
93
102
|
describe "debtors" do
|
94
103
|
it "returns a DebtorProxy" do
|
95
|
-
subject.debtors.
|
104
|
+
expect(subject.debtors).to be_instance_of(Economic::DebtorProxy)
|
96
105
|
end
|
97
106
|
|
98
107
|
it "memoizes the proxy" do
|
99
|
-
subject.debtors.
|
108
|
+
expect(subject.debtors).to equal(subject.debtors)
|
100
109
|
end
|
101
110
|
end
|
102
111
|
|
103
112
|
describe "request" do
|
104
113
|
it "sends a request to API" do
|
105
|
-
|
106
|
-
|
114
|
+
expect(endpoint).to receive(:call).with(
|
115
|
+
:invoice_get_all,
|
116
|
+
{},
|
117
|
+
nil
|
118
|
+
).and_return({})
|
119
|
+
subject.request(:invoice_get_all, {})
|
107
120
|
end
|
108
121
|
|
109
122
|
it "sends data if given" do
|
110
|
-
|
123
|
+
mock_request(:current_invoice_get_all, {:bar => :baz}, :none)
|
111
124
|
subject.request(:current_invoice_get_all, {:bar => :baz})
|
112
125
|
end
|
113
126
|
|
114
127
|
it "returns a hash with data" do
|
115
|
-
|
116
|
-
subject.request(:current_invoice_get_all).
|
128
|
+
stub_request(:current_invoice_get_all, nil, :single)
|
129
|
+
expect(subject.request(:current_invoice_get_all)).to eq({:current_invoice_handle => {:id => "1"}})
|
117
130
|
end
|
118
131
|
|
119
132
|
it "returns an empty hash if no data returned" do
|
120
|
-
|
121
|
-
subject.request(:current_invoice_get_all).
|
133
|
+
stub_request(:current_invoice_get_all, nil, :none)
|
134
|
+
expect(subject.request(:current_invoice_get_all)).to be_empty
|
122
135
|
end
|
123
136
|
end
|
124
137
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
2
2
|
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
3
3
|
<soap:Body>
|
4
|
-
<
|
5
|
-
<
|
4
|
+
<Account_CreateFromDataResponse xmlns="http://e-conomic.com">
|
5
|
+
<Account_CreateFromDataResult>
|
6
6
|
<Number>42</Number>
|
7
|
-
</
|
8
|
-
</
|
7
|
+
</Account_CreateFromDataResult>
|
8
|
+
</Account_CreateFromDataResponse>
|
9
9
|
</soap:Body>
|
10
|
-
</soap:Envelope>
|
10
|
+
</soap:Envelope>
|