osm 1.0.6 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +30 -0
- data/README.md +17 -4
- data/lib/osm.rb +4 -1
- data/lib/osm/budget.rb +136 -0
- data/lib/osm/event.rb +12 -5
- data/lib/osm/giftaid.rb +292 -0
- data/lib/osm/invoice.rb +425 -0
- data/lib/osm/member.rb +24 -8
- data/lib/osm/model.rb +4 -2
- data/lib/osm/register.rb +9 -11
- data/lib/osm/section.rb +36 -19
- data/lib/osm/sms.rb +6 -5
- data/lib/osm/term.rb +2 -2
- data/spec/osm/budget_spec.rb +205 -0
- data/spec/osm/event_spec.rb +12 -0
- data/spec/osm/giftaid_spec.rb +224 -0
- data/spec/osm/invoice_spec.rb +699 -0
- data/spec/osm/member_spec.rb +21 -1
- data/spec/osm/section_spec.rb +16 -1
- data/spec/osm/sms_spec.rb +90 -3
- data/spec/osm/term_spec.rb +1 -1
- data/version.rb +1 -1
- metadata +8 -2
data/spec/osm/event_spec.rb
CHANGED
@@ -23,6 +23,7 @@ describe "Event" do
|
|
23
23
|
:reminders => false,
|
24
24
|
:attendance_limit => 3,
|
25
25
|
:attendance_limit_includes_leaders => true,
|
26
|
+
:attendance_reminder => 14,
|
26
27
|
:allow_booking => false,
|
27
28
|
}
|
28
29
|
event = Osm::Event.new(data)
|
@@ -44,6 +45,7 @@ describe "Event" do
|
|
44
45
|
event.reminders.should == false
|
45
46
|
event.attendance_limit.should == 3
|
46
47
|
event.attendance_limit_includes_leaders.should == true
|
48
|
+
event.attendance_reminder.should == 14
|
47
49
|
event.allow_booking.should be_false
|
48
50
|
event.valid?.should be_true
|
49
51
|
end
|
@@ -138,6 +140,7 @@ describe "Event" do
|
|
138
140
|
'allowchanges' => '1',
|
139
141
|
'disablereminders' => '1',
|
140
142
|
'attendancelimit' => '3',
|
143
|
+
'attendancereminder' => '7',
|
141
144
|
'limitincludesleaders' => '1',
|
142
145
|
'allowbooking' => '1',
|
143
146
|
}]
|
@@ -165,6 +168,7 @@ describe "Event" do
|
|
165
168
|
'pnnotepad' => '',
|
166
169
|
'structure' => [],
|
167
170
|
'attendancelimit' => '3',
|
171
|
+
'attendancereminder' => '7',
|
168
172
|
'limitincludesleaders' => '1',
|
169
173
|
'allowbooking' => '1',
|
170
174
|
}
|
@@ -196,6 +200,7 @@ describe "Event" do
|
|
196
200
|
event.reminders.should == false
|
197
201
|
event.attendance_limit.should == 3
|
198
202
|
event.attendance_limit_includes_leaders.should == true
|
203
|
+
event.attendance_reminder.should == 7
|
199
204
|
event.allow_booking.should == true
|
200
205
|
event.columns[0].id.should == 'f_1'
|
201
206
|
event.columns[0].name.should == 'Name'
|
@@ -398,6 +403,7 @@ describe "Event" do
|
|
398
403
|
'attendancelimit' => 3,
|
399
404
|
'limitincludesleaders' => 'true',
|
400
405
|
'allowbooking' => 'true',
|
406
|
+
'attendancereminder' => 1,
|
401
407
|
}
|
402
408
|
|
403
409
|
Osm::Event.stub(:get_for_section) { [] }
|
@@ -419,6 +425,7 @@ describe "Event" do
|
|
419
425
|
:reminders => true,
|
420
426
|
:attendance_limit => 3,
|
421
427
|
:attendance_limit_includes_leaders => true,
|
428
|
+
:attendance_reminder => 1,
|
422
429
|
:allow_booking => true,
|
423
430
|
})
|
424
431
|
event.should_not be_nil
|
@@ -444,6 +451,7 @@ describe "Event" do
|
|
444
451
|
'allowChanges' => 'true',
|
445
452
|
'disablereminders' => 'false',
|
446
453
|
'attendancelimit' => 3,
|
454
|
+
'attendancereminder' => 0,
|
447
455
|
'limitincludesleaders' => 'true',
|
448
456
|
'allowbooking' => 'true',
|
449
457
|
}
|
@@ -520,6 +528,7 @@ describe "Event" do
|
|
520
528
|
'allowChanges' => 'true',
|
521
529
|
'disablereminders' => 'false',
|
522
530
|
'attendancelimit' => 3,
|
531
|
+
'attendancereminder' => 2,
|
523
532
|
'limitincludesleaders' => 'true',
|
524
533
|
'allowbooking' => 'true',
|
525
534
|
}
|
@@ -544,6 +553,7 @@ describe "Event" do
|
|
544
553
|
:public_notepad => '',
|
545
554
|
:attendance_limit => 3,
|
546
555
|
:attendance_limit_includes_leaders => true,
|
556
|
+
:attendance_reminder => 2,
|
547
557
|
:allow_booking => true,
|
548
558
|
)
|
549
559
|
event.notepad = 'notepad'
|
@@ -571,6 +581,7 @@ describe "Event" do
|
|
571
581
|
'allowChanges' => 'true',
|
572
582
|
'disablereminders' => 'false',
|
573
583
|
'attendancelimit' => 3,
|
584
|
+
'attendancereminder' => 1,
|
574
585
|
'limitincludesleaders' => 'true',
|
575
586
|
'allowbooking' => 'true',
|
576
587
|
}
|
@@ -593,6 +604,7 @@ describe "Event" do
|
|
593
604
|
:public_notepad => '',
|
594
605
|
:attendance_limit => 3,
|
595
606
|
:attendance_limit_includes_leaders => true,
|
607
|
+
:attendance_reminder => 1,
|
596
608
|
:allow_booking => true,
|
597
609
|
)
|
598
610
|
event.cost = 'TBC'
|
@@ -0,0 +1,224 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
|
6
|
+
describe "Gift Aid" do
|
7
|
+
|
8
|
+
it "Create Donation" do
|
9
|
+
d = Osm::GiftAid::Donation.new(
|
10
|
+
:donation_date => Date.new(2000, 1, 2),
|
11
|
+
)
|
12
|
+
|
13
|
+
d.donation_date.should == Date.new(2000, 1, 2)
|
14
|
+
d.valid?.should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "Sorts Donation by date" do
|
18
|
+
d1 = Osm::GiftAid::Donation.new(:donation_date => Date.new(2000, 1, 2))
|
19
|
+
d2 = Osm::GiftAid::Donation.new(:donation_date => Date.new(2001, 1, 2))
|
20
|
+
|
21
|
+
data = [d2, d1]
|
22
|
+
data.sort.should == [d1, d2]
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
it "Create Data" do
|
27
|
+
d = Osm::GiftAid::Data.new(
|
28
|
+
:member_id => 1,
|
29
|
+
:first_name => 'A',
|
30
|
+
:last_name => 'B',
|
31
|
+
:tax_payer_name => 'C',
|
32
|
+
:tax_payer_address => 'D',
|
33
|
+
:tax_payer_postcode => 'E',
|
34
|
+
:section_id => 2,
|
35
|
+
:grouping_id => 3,
|
36
|
+
:total => '2.34',
|
37
|
+
:donations => {
|
38
|
+
Date.new(2012, 1, 2) => '1.23',
|
39
|
+
}
|
40
|
+
)
|
41
|
+
|
42
|
+
d.member_id.should == 1
|
43
|
+
d.section_id.should == 2
|
44
|
+
d.grouping_id.should == 3
|
45
|
+
d.first_name.should == 'A'
|
46
|
+
d.last_name.should == 'B'
|
47
|
+
d.tax_payer_name.should == 'C'
|
48
|
+
d.tax_payer_address.should == 'D'
|
49
|
+
d.tax_payer_postcode.should == 'E'
|
50
|
+
d.total.should == '2.34'
|
51
|
+
d.donations.should == {
|
52
|
+
Date.new(2012, 1, 2) => '1.23',
|
53
|
+
}
|
54
|
+
d.valid?.should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "Sorts Data by section_id, grouping_id, last_name then first_name" do
|
58
|
+
d1 = Osm::GiftAid::Data.new(:section_id => 1, :grouping_id => 1, :last_name => 'a', :first_name => 'a')
|
59
|
+
d2 = Osm::GiftAid::Data.new(:section_id => 2, :grouping_id => 1, :last_name => 'a', :first_name => 'a')
|
60
|
+
d3 = Osm::GiftAid::Data.new(:section_id => 2, :grouping_id => 2, :last_name => 'a', :first_name => 'a')
|
61
|
+
d4 = Osm::GiftAid::Data.new(:section_id => 2, :grouping_id => 2, :last_name => 'b', :first_name => 'a')
|
62
|
+
d5 = Osm::GiftAid::Data.new(:section_id => 2, :grouping_id => 2, :last_name => 'b', :first_name => 'b')
|
63
|
+
|
64
|
+
data = [d4, d3, d5, d2, d1]
|
65
|
+
data.sort.should == [d1, d2, d3, d4, d5]
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
describe "Using the API" do
|
70
|
+
|
71
|
+
it "Fetch the donations for a section" do
|
72
|
+
data = [
|
73
|
+
{"rows" => [
|
74
|
+
{"name" => "First name","field" => "firstname","width" => "100px","formatter" => "boldFormatter"},
|
75
|
+
{"name" => "Last name","field" => "lastname","width" => "100px","formatter" => "boldFormatter"},
|
76
|
+
{"name" => "Tax payer's name","field" => "parentname","width" => "150px","editable" => true,"formatter" => "boldFormatter"},
|
77
|
+
{"name" => "Total","field" => "total","width" => "60px","formatter" => "boldFormatter"}
|
78
|
+
],"noscroll" => true},
|
79
|
+
{"rows" => [
|
80
|
+
{"name" => "2000-01-02", "field" => "2000-01-02", "width" => "110px", "editable" => true, "formatter" => "boldFormatter"}
|
81
|
+
]}
|
82
|
+
]
|
83
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/giftaid.php?action=getStructure§ionid=1&termid=2", :body => data.to_json)
|
84
|
+
|
85
|
+
donations = Osm::GiftAid.get_donations(@api, 1, 2)
|
86
|
+
donations.should == [Osm::GiftAid::Donation.new(:donation_date => Date.new(2000, 1, 2))]
|
87
|
+
end
|
88
|
+
|
89
|
+
it "Fetch the data for a section" do
|
90
|
+
data = {
|
91
|
+
"identifier" => "scoutid",
|
92
|
+
"label" => "name",
|
93
|
+
"items" => [
|
94
|
+
{"2000-01-02" => "1.23", "total" => 2.34, "scoutid" => "2", "firstname" => "First", "lastname" => "Last", "patrolid" => "3", "parentname" => "Tax"},
|
95
|
+
{"2000-01-02" => 1.23,"firstname" => "TOTAL","lastname" => "","scoutid" => -1,"patrolid" => -1,"parentname" => "","total" => 1.23}
|
96
|
+
]
|
97
|
+
}
|
98
|
+
|
99
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/giftaid.php?action=getGrid§ionid=1&termid=2", :body => data.to_json)
|
100
|
+
|
101
|
+
data = Osm::GiftAid.get_data(@api, 1, 2)
|
102
|
+
data.is_a?(Array).should be_true
|
103
|
+
data.size.should == 1
|
104
|
+
data = data[0]
|
105
|
+
data.donations.should == {
|
106
|
+
Date.new(2000, 1, 2) => '1.23',
|
107
|
+
}
|
108
|
+
data.first_name.should == 'First'
|
109
|
+
data.last_name.should == 'Last'
|
110
|
+
data.tax_payer_name.should == 'Tax'
|
111
|
+
data.grouping_id.should == 3
|
112
|
+
data.member_id.should == 2
|
113
|
+
data.total.should == '2.34'
|
114
|
+
data.section_id.should == 1
|
115
|
+
data.valid?.should be_true
|
116
|
+
end
|
117
|
+
|
118
|
+
it "Update donation" do
|
119
|
+
url = 'https://www.onlinescoutmanager.co.uk/giftaid.php?action=update§ionid=1&termid=2'
|
120
|
+
post_data = {
|
121
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
122
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
123
|
+
'userid' => 'user_id',
|
124
|
+
'secret' => 'secret',
|
125
|
+
'scouts' => '["3", "4"]',
|
126
|
+
'donatedate'=> '2000-01-02',
|
127
|
+
'amount' => '1.23',
|
128
|
+
'notes' => 'Note',
|
129
|
+
'sectionid' => 1,
|
130
|
+
}
|
131
|
+
|
132
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'[]'}) }
|
133
|
+
Osm::GiftAid.update_donation({
|
134
|
+
:api => @api,
|
135
|
+
:section => 1,
|
136
|
+
:term => 2,
|
137
|
+
:donation_date => Date.new(2000, 1, 2),
|
138
|
+
:attendance => :yes,
|
139
|
+
:members => [3, 4],
|
140
|
+
:amount => '1.23',
|
141
|
+
:note => 'Note',
|
142
|
+
}).should be_true
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "Update data" do
|
146
|
+
|
147
|
+
before :each do
|
148
|
+
@data = Osm::GiftAid::Data.new(
|
149
|
+
:member_id => 1,
|
150
|
+
:first_name => 'A',
|
151
|
+
:last_name => 'B',
|
152
|
+
:tax_payer_name => 'C',
|
153
|
+
:tax_payer_address => 'D',
|
154
|
+
:tax_payer_postcode => 'E',
|
155
|
+
:section_id => 2,
|
156
|
+
:grouping_id => 3,
|
157
|
+
:total => '2.34',
|
158
|
+
:donations => {
|
159
|
+
Date.new(2012, 1, 2) => '1.23',
|
160
|
+
Date.new(2012, 1, 3) => '2.34',
|
161
|
+
}
|
162
|
+
)
|
163
|
+
Osm::Term.stub(:get_current_term_for_section) { Osm::Term.new(:id => 4) }
|
164
|
+
end
|
165
|
+
|
166
|
+
it "Tax payer" do
|
167
|
+
post_data = {
|
168
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
169
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
170
|
+
'userid' => 'user_id',
|
171
|
+
'secret' => 'secret',
|
172
|
+
'scoutid' => 1,
|
173
|
+
'termid' => 4,
|
174
|
+
'sectionid' => 2,
|
175
|
+
'row' => 0,
|
176
|
+
}
|
177
|
+
body_data = {
|
178
|
+
"items" => [
|
179
|
+
{"parentname" => "n", "address" => "a", "postcode" => "pc", "scoutid" => "1"},
|
180
|
+
{"firstname" => "TOTAL","lastname" => "","scoutid" => -1,"patrolid" => -1,"parentname" => "","total" => 0}
|
181
|
+
]
|
182
|
+
}
|
183
|
+
url = "https://www.onlinescoutmanager.co.uk/giftaid.php?action=updateScout"
|
184
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data.merge({'column' => 'parentname', 'value' => 'n'})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body_data.to_json}) }
|
185
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data.merge({'column' => 'address', 'value' => 'a'})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body_data.to_json}) }
|
186
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data.merge({'column' => 'postcode', 'value' => 'pc'})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body_data.to_json}) }
|
187
|
+
|
188
|
+
@data.tax_payer_name = 'n'
|
189
|
+
@data.tax_payer_address = 'a'
|
190
|
+
@data.tax_payer_postcode = 'pc'
|
191
|
+
@data.update(@api).should be_true
|
192
|
+
end
|
193
|
+
|
194
|
+
it "A donation" do
|
195
|
+
post_data = {
|
196
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
197
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
198
|
+
'userid' => 'user_id',
|
199
|
+
'secret' => 'secret',
|
200
|
+
'scoutid' => 1,
|
201
|
+
'termid' => 4,
|
202
|
+
'column' => '2012-01-03',
|
203
|
+
'value' => '3.45',
|
204
|
+
'sectionid' => 2,
|
205
|
+
'row' => 0,
|
206
|
+
}
|
207
|
+
body_data = {
|
208
|
+
"items" => [
|
209
|
+
{"2012-01-03" => "3.45","scoutid" => "1"},
|
210
|
+
{"firstname" => "TOTAL","lastname" => "","scoutid" => -1,"patrolid" => -1,"parentname" => "","total" => 0}
|
211
|
+
]
|
212
|
+
}
|
213
|
+
url = "https://www.onlinescoutmanager.co.uk/giftaid.php?action=updateScout"
|
214
|
+
HTTParty.should_receive(:post).with(url, {:body => post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>body_data.to_json}) }
|
215
|
+
|
216
|
+
@data.donations[Date.new(2012, 1, 3)] = '3.45'
|
217
|
+
@data.update(@api).should be_true
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
@@ -0,0 +1,699 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
|
5
|
+
describe "Invoice" do
|
6
|
+
|
7
|
+
it "Create Invoice" do
|
8
|
+
i = Osm::Invoice.new(
|
9
|
+
:id => 1,
|
10
|
+
:section_id => 2,
|
11
|
+
:name => 'Name',
|
12
|
+
:extra_details => 'Extra Details',
|
13
|
+
:date => Date.new(2001, 2, 3),
|
14
|
+
:archived => true,
|
15
|
+
:finalised => true,
|
16
|
+
)
|
17
|
+
|
18
|
+
i.id.should == 1
|
19
|
+
i.section_id.should == 2
|
20
|
+
i.name.should == 'Name'
|
21
|
+
i.extra_details.should == 'Extra Details'
|
22
|
+
i.date.should == Date.new(2001, 2, 3)
|
23
|
+
i.archived.should == true
|
24
|
+
i.finalised.should == true
|
25
|
+
i.valid?.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "Sorts Invoice by Section ID, Name then Date" do
|
29
|
+
i1 = Osm::Invoice.new(:section_id => 1, :name => 'a', :date => Date.new(2000, 1, 2))
|
30
|
+
i2 = Osm::Invoice.new(:section_id => 2, :name => 'a', :date => Date.new(2000, 1, 2))
|
31
|
+
i3 = Osm::Invoice.new(:section_id => 2, :name => 'b', :date => Date.new(2000, 1, 2))
|
32
|
+
i4 = Osm::Invoice.new(:section_id => 2, :name => 'b', :date => Date.new(2000, 1, 3))
|
33
|
+
|
34
|
+
data = [i2, i4, i1, i3]
|
35
|
+
data.sort.should == [i1, i2, i3, i4]
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Invoice Item" do
|
39
|
+
it "Create" do
|
40
|
+
ii = Osm::Invoice::Item.new(
|
41
|
+
:id => 1,
|
42
|
+
:invoice => Osm::Invoice.new,
|
43
|
+
:record_id => 3,
|
44
|
+
:date => Date.new(2002, 3, 4),
|
45
|
+
:amount => '5.00',
|
46
|
+
:type => :expense,
|
47
|
+
:payto => 'Name',
|
48
|
+
:description => 'Comments',
|
49
|
+
:budget_name => 'Budget',
|
50
|
+
)
|
51
|
+
|
52
|
+
ii.id.should == 1
|
53
|
+
ii.invoice.should == Osm::Invoice.new
|
54
|
+
ii.record_id.should == 3
|
55
|
+
ii.date.should == Date.new(2002, 3, 4)
|
56
|
+
ii.amount.should == '5.00'
|
57
|
+
ii.type.should == :expense
|
58
|
+
ii.payto.should == 'Name'
|
59
|
+
ii.description.should == 'Comments'
|
60
|
+
ii.budget_name.should == 'Budget'
|
61
|
+
ii.valid?.should be_true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "Sorts by Invoice then Date" do
|
65
|
+
i1 = Osm::Invoice.new(:section_id => 1, :name => 'a', :date => Date.new(2000, 1, 2))
|
66
|
+
i2 = Osm::Invoice.new(:section_id => 2, :name => 'a', :date => Date.new(2000, 1, 2))
|
67
|
+
ii1 = Osm::Invoice::Item.new(:invoice => i1, :date => Date.new(2000, 1, 1))
|
68
|
+
ii2 = Osm::Invoice::Item.new(:invoice => i2, :date => Date.new(2000, 1, 1))
|
69
|
+
ii3 = Osm::Invoice::Item.new(:invoice => i2, :date => Date.new(2000, 1, 2))
|
70
|
+
|
71
|
+
data = [ii2, ii3, ii1]
|
72
|
+
data.sort.should == [ii1, ii2, ii3]
|
73
|
+
end
|
74
|
+
|
75
|
+
it "Calculates value for easy summing" do
|
76
|
+
Osm::Invoice::Item.new(:type => :income, :amount => '1.00').value.should == 1.00
|
77
|
+
Osm::Invoice::Item.new(:type => :expense, :amount => '2.00').value.should == -2.00
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
describe "Using the API" do
|
84
|
+
|
85
|
+
describe "Invoice" do
|
86
|
+
|
87
|
+
describe "Get for section" do
|
88
|
+
before :all do
|
89
|
+
@invoices_body = {
|
90
|
+
"identifier" => "invoiceid",
|
91
|
+
"label" => "name",
|
92
|
+
"items" => [
|
93
|
+
{"invoiceid" => "1", "name" => "Invoice 1"},
|
94
|
+
{"invoiceid" => "2", "name" => "Invoice 2"},
|
95
|
+
]
|
96
|
+
}
|
97
|
+
|
98
|
+
@invoice1_body = {
|
99
|
+
"invoice" => {
|
100
|
+
"invoiceid" => "1",
|
101
|
+
"sectionid" => "3",
|
102
|
+
"name" => "Invoice 1",
|
103
|
+
"extra" => "Some more details",
|
104
|
+
"entrydate" => "2010-01-01",
|
105
|
+
"archived" => "0",
|
106
|
+
"finalised" => "0"
|
107
|
+
},
|
108
|
+
"people" => [
|
109
|
+
"Person 1",
|
110
|
+
"Person 2",
|
111
|
+
""
|
112
|
+
],
|
113
|
+
"categories" => [
|
114
|
+
"Default",
|
115
|
+
"A Budget"
|
116
|
+
]
|
117
|
+
}
|
118
|
+
@invoice2_body = {
|
119
|
+
"invoice" => {
|
120
|
+
"invoiceid" => "2",
|
121
|
+
"sectionid" => "3",
|
122
|
+
"name" => "Invoice 2",
|
123
|
+
"extra" => "",
|
124
|
+
"entrydate" => "2010-02-02",
|
125
|
+
"archived" => "1",
|
126
|
+
"finalised" => "1"
|
127
|
+
},
|
128
|
+
"people" => [
|
129
|
+
"Person 1",
|
130
|
+
"Person 2",
|
131
|
+
""
|
132
|
+
],
|
133
|
+
"categories" => [
|
134
|
+
"Default",
|
135
|
+
"A Budget"
|
136
|
+
]
|
137
|
+
}
|
138
|
+
end
|
139
|
+
|
140
|
+
it "From API" do
|
141
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoices§ionid=3&showArchived=true'
|
142
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
143
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
144
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
145
|
+
'userid' => 'user_id',
|
146
|
+
'secret' => 'secret',
|
147
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoices_body.to_json}) }
|
148
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoice§ionid=3&invoiceid=1'
|
149
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
150
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
151
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
152
|
+
'userid' => 'user_id',
|
153
|
+
'secret' => 'secret',
|
154
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoice1_body.to_json}) }
|
155
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoice§ionid=3&invoiceid=2'
|
156
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
157
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
158
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
159
|
+
'userid' => 'user_id',
|
160
|
+
'secret' => 'secret',
|
161
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoice2_body.to_json}) }
|
162
|
+
|
163
|
+
invoices = Osm::Invoice.get_for_section(@api, 3)
|
164
|
+
invoices.size.should == 1
|
165
|
+
invoice = invoices[0]
|
166
|
+
invoice.id.should == 1
|
167
|
+
invoice.section_id.should == 3
|
168
|
+
invoice.name.should == 'Invoice 1'
|
169
|
+
invoice.extra_details.should == 'Some more details'
|
170
|
+
invoice.date.should == Date.new(2010, 1, 1)
|
171
|
+
invoice.archived.should == false
|
172
|
+
invoice.finalised.should == false
|
173
|
+
invoice.valid?.should be_true
|
174
|
+
end
|
175
|
+
|
176
|
+
it "Honours archived option" do
|
177
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoices§ionid=3&showArchived=true'
|
178
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
179
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
180
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
181
|
+
'userid' => 'user_id',
|
182
|
+
'secret' => 'secret',
|
183
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoices_body.to_json}) }
|
184
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoice§ionid=3&invoiceid=1'
|
185
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
186
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
187
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
188
|
+
'userid' => 'user_id',
|
189
|
+
'secret' => 'secret',
|
190
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoice1_body.to_json}) }
|
191
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoice§ionid=3&invoiceid=2'
|
192
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
193
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
194
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
195
|
+
'userid' => 'user_id',
|
196
|
+
'secret' => 'secret',
|
197
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoice2_body.to_json}) }
|
198
|
+
|
199
|
+
invoices = Osm::Invoice.get_for_section(@api, 3, {:include_archived => true})
|
200
|
+
invoices.size.should == 2
|
201
|
+
end
|
202
|
+
|
203
|
+
it "From Cache" do
|
204
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoices§ionid=3&showArchived=true'
|
205
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
206
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
207
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
208
|
+
'userid' => 'user_id',
|
209
|
+
'secret' => 'secret',
|
210
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoices_body.to_json}) }
|
211
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoice§ionid=3&invoiceid=1'
|
212
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
213
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
214
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
215
|
+
'userid' => 'user_id',
|
216
|
+
'secret' => 'secret',
|
217
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoice1_body.to_json}) }
|
218
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoice§ionid=3&invoiceid=2'
|
219
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
220
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
221
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
222
|
+
'userid' => 'user_id',
|
223
|
+
'secret' => 'secret',
|
224
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => @invoice2_body.to_json}) }
|
225
|
+
|
226
|
+
invoices = Osm::Invoice.get_for_section(@api, 3)
|
227
|
+
HTTParty.should_not_receive(:post)
|
228
|
+
Osm::Invoice.get_for_section(@api, 3).should == invoices
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
it "Get" do
|
234
|
+
invoices_body = {
|
235
|
+
"identifier" => "invoiceid",
|
236
|
+
"label" => "name",
|
237
|
+
"items" => [
|
238
|
+
{"invoiceid" => "1", "name" => "Invoice 1"},
|
239
|
+
]
|
240
|
+
}
|
241
|
+
|
242
|
+
invoice1_body = {
|
243
|
+
"invoice" => {
|
244
|
+
"invoiceid" => "1",
|
245
|
+
"sectionid" => "3",
|
246
|
+
"name" => "Invoice 1",
|
247
|
+
"extra" => "Some more details",
|
248
|
+
"entrydate" => "2010-01-01",
|
249
|
+
"archived" => "0",
|
250
|
+
"finalised" => "0"
|
251
|
+
},
|
252
|
+
"people" => [
|
253
|
+
"Person 1",
|
254
|
+
"Person 2",
|
255
|
+
""
|
256
|
+
],
|
257
|
+
"categories" => [
|
258
|
+
"Default",
|
259
|
+
"A Budget"
|
260
|
+
]
|
261
|
+
}
|
262
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoice§ionid=3&invoiceid=1'
|
263
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
264
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
265
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
266
|
+
'userid' => 'user_id',
|
267
|
+
'secret' => 'secret',
|
268
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => invoice1_body.to_json}) }
|
269
|
+
|
270
|
+
invoice = Osm::Invoice.get(@api, 3, 1)
|
271
|
+
invoice.should_not be_nil
|
272
|
+
invoice.id.should == 1
|
273
|
+
end
|
274
|
+
|
275
|
+
it "Create (success)" do
|
276
|
+
invoice = Osm::Invoice.new(
|
277
|
+
:section_id => 1,
|
278
|
+
:name => 'Invoice name',
|
279
|
+
:extra_details => '',
|
280
|
+
:date => Date.new(2002, 3, 4),
|
281
|
+
)
|
282
|
+
|
283
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=addInvoice§ionid=1'
|
284
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
285
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
286
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
287
|
+
'userid' => 'user_id',
|
288
|
+
'secret' => 'secret',
|
289
|
+
'name' => 'Invoice name',
|
290
|
+
'extra' => '',
|
291
|
+
'date' => '2002-03-04',
|
292
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"id":2}'}) }
|
293
|
+
|
294
|
+
invoice.create(@api).should be_true
|
295
|
+
invoice.id.should == 2
|
296
|
+
end
|
297
|
+
|
298
|
+
it "Create (failure)" do
|
299
|
+
invoice = Osm::Invoice.new(
|
300
|
+
:section_id => 1,
|
301
|
+
:name => 'Invoice name',
|
302
|
+
:extra_details => '',
|
303
|
+
:date => Date.new(2002, 3, 4),
|
304
|
+
)
|
305
|
+
|
306
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=addInvoice§ionid=1'
|
307
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
308
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
309
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
310
|
+
'userid' => 'user_id',
|
311
|
+
'secret' => 'secret',
|
312
|
+
'name' => 'Invoice name',
|
313
|
+
'extra' => '',
|
314
|
+
'date' => '2002-03-04',
|
315
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"message":"Something went wrong"}'}) }
|
316
|
+
|
317
|
+
invoice.create(@api).should be_false
|
318
|
+
invoice.id.should be_nil
|
319
|
+
end
|
320
|
+
|
321
|
+
it "Update (success)" do
|
322
|
+
invoice = Osm::Invoice.new(
|
323
|
+
:id => 1,
|
324
|
+
:section_id => 2,
|
325
|
+
:name => 'Invoice name',
|
326
|
+
:extra_details => '',
|
327
|
+
:date => Date.new(2002, 3, 4),
|
328
|
+
)
|
329
|
+
|
330
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=addInvoice§ionid=2'
|
331
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
332
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
333
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
334
|
+
'userid' => 'user_id',
|
335
|
+
'secret' => 'secret',
|
336
|
+
'invoiceid' => 1,
|
337
|
+
'name' => 'Invoice name',
|
338
|
+
'extra' => '',
|
339
|
+
'date' => '2002-03-04',
|
340
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
|
341
|
+
|
342
|
+
invoice.update(@api).should be_true
|
343
|
+
end
|
344
|
+
|
345
|
+
it "Update (failure)" do
|
346
|
+
invoice = Osm::Invoice.new(
|
347
|
+
:id => 1,
|
348
|
+
:section_id => 2,
|
349
|
+
:name => 'Invoice name',
|
350
|
+
:extra_details => '',
|
351
|
+
:date => Date.new(2002, 3, 4),
|
352
|
+
)
|
353
|
+
|
354
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=addInvoice§ionid=2'
|
355
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
356
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
357
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
358
|
+
'userid' => 'user_id',
|
359
|
+
'secret' => 'secret',
|
360
|
+
'invoiceid' => 1,
|
361
|
+
'name' => 'Invoice name',
|
362
|
+
'extra' => '',
|
363
|
+
'date' => '2002-03-04',
|
364
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
|
365
|
+
|
366
|
+
invoice.update(@api).should be_false
|
367
|
+
end
|
368
|
+
|
369
|
+
it "Delete (success)" do
|
370
|
+
invoice = Osm::Invoice.new(:id => 1, :section_id => 2)
|
371
|
+
|
372
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=deleteInvoice§ionid=2'
|
373
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
374
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
375
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
376
|
+
'userid' => 'user_id',
|
377
|
+
'secret' => 'secret',
|
378
|
+
'invoiceid' => 1,
|
379
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
|
380
|
+
|
381
|
+
invoice.delete(@api).should be_true
|
382
|
+
end
|
383
|
+
|
384
|
+
it "Delete (failure)" do
|
385
|
+
invoice = Osm::Invoice.new(:id => 1, :section_id => 2)
|
386
|
+
|
387
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=deleteInvoice§ionid=2'
|
388
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
389
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
390
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
391
|
+
'userid' => 'user_id',
|
392
|
+
'secret' => 'secret',
|
393
|
+
'invoiceid' => 1,
|
394
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
|
395
|
+
|
396
|
+
invoice.delete(@api).should be_false
|
397
|
+
end
|
398
|
+
|
399
|
+
it "Finalise invoice (success)" do
|
400
|
+
invoice = Osm::Invoice.new(:id => 1, :section_id => 2)
|
401
|
+
|
402
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=finaliseInvoice§ionid=2&invoiceid=1'
|
403
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
404
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
405
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
406
|
+
'userid' => 'user_id',
|
407
|
+
'secret' => 'secret',
|
408
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
|
409
|
+
|
410
|
+
invoice.finalise(@api).should be_true
|
411
|
+
invoice.finalised.should be_true
|
412
|
+
end
|
413
|
+
|
414
|
+
it "Finalise invoice (failure)" do
|
415
|
+
invoice = Osm::Invoice.new(:id => 1, :section_id => 2)
|
416
|
+
|
417
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=finaliseInvoice§ionid=2&invoiceid=1'
|
418
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
419
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
420
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
421
|
+
'userid' => 'user_id',
|
422
|
+
'secret' => 'secret',
|
423
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
|
424
|
+
|
425
|
+
invoice.finalise(@api).should be_false
|
426
|
+
invoice.finalised.should be_false
|
427
|
+
end
|
428
|
+
|
429
|
+
it "Finalise invoice (already finalised)" do
|
430
|
+
invoice = Osm::Invoice.new(:id => 1, :section_id => 2, :finalised => true)
|
431
|
+
|
432
|
+
HTTParty.should_not_receive(:post)
|
433
|
+
|
434
|
+
invoice.finalise(@api).should be_false
|
435
|
+
invoice.finalised.should be_true
|
436
|
+
end
|
437
|
+
|
438
|
+
it "Archive invoice (success)" do
|
439
|
+
invoice = Osm::Invoice.new(:id => 1, :section_id => 2)
|
440
|
+
|
441
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=deleteInvoice§ionid=2'
|
442
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
443
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
444
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
445
|
+
'userid' => 'user_id',
|
446
|
+
'secret' => 'secret',
|
447
|
+
'invoiceid' => 1,
|
448
|
+
'archived' => 1,
|
449
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
|
450
|
+
|
451
|
+
invoice.archive(@api).should be_true
|
452
|
+
invoice.archived.should be_true
|
453
|
+
end
|
454
|
+
|
455
|
+
it "Archive invoice (failure)" do
|
456
|
+
invoice = Osm::Invoice.new(:id => 1, :section_id => 2)
|
457
|
+
|
458
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=deleteInvoice§ionid=2'
|
459
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
460
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
461
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
462
|
+
'userid' => 'user_id',
|
463
|
+
'secret' => 'secret',
|
464
|
+
'invoiceid' => 1,
|
465
|
+
'archived' => 1,
|
466
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
|
467
|
+
|
468
|
+
invoice.archive(@api).should be_false
|
469
|
+
invoice.archived.should be_false
|
470
|
+
end
|
471
|
+
|
472
|
+
it "Archive invoice (already archived)" do
|
473
|
+
invoice = Osm::Invoice.new(:id => 1, :section_id => 2, :archived => true)
|
474
|
+
|
475
|
+
HTTParty.should_not_receive(:post)
|
476
|
+
|
477
|
+
invoice.archive(@api).should be_false
|
478
|
+
invoice.archived.should be_true
|
479
|
+
end
|
480
|
+
|
481
|
+
end
|
482
|
+
|
483
|
+
|
484
|
+
describe "Item" do
|
485
|
+
|
486
|
+
it "Get for invoice" do
|
487
|
+
data = {"identifier" => "id","items" => [
|
488
|
+
{"id" => "1","invoiceid" => "2","recordid" => "3","sectionid" => "4","entrydate" => "2012-01-02","amount" => "1.23","type" => "Expense","payto_userid" => "John Smith","comments" => "Comment","categoryid" => "Default","firstname" => "John Smith"}
|
489
|
+
]}
|
490
|
+
FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/finances.php?action=getInvoiceRecords&invoiceid=2§ionid=4&dateFormat=generic", :body => data.to_json)
|
491
|
+
|
492
|
+
invoice = Osm::Invoice.new(:id => 2, :section_id => 4)
|
493
|
+
items = invoice.get_items(@api)
|
494
|
+
items.size.should == 1
|
495
|
+
item = items[0]
|
496
|
+
item.id.should == 1
|
497
|
+
item.invoice.should == invoice
|
498
|
+
item.record_id.should == 3
|
499
|
+
item.date.should == Date.new(2012, 1, 2)
|
500
|
+
item.amount.should == '1.23'
|
501
|
+
item.type.should == :expense
|
502
|
+
item.payto.should == 'John Smith'
|
503
|
+
item.budget_name.should == 'Default'
|
504
|
+
item.description.should == 'Comment'
|
505
|
+
item.valid?.should be_true
|
506
|
+
end
|
507
|
+
|
508
|
+
it "Create (success)" do
|
509
|
+
invoice = Osm::Invoice.new(:id => 3, :section_id => 2)
|
510
|
+
item = Osm::Invoice::Item.new(
|
511
|
+
:invoice => invoice,
|
512
|
+
:amount => '1.23',
|
513
|
+
:type => :expense,
|
514
|
+
:budget_name => 'A budget',
|
515
|
+
:date => Date.new(2003, 5, 6),
|
516
|
+
:description => 'A description',
|
517
|
+
:payto => 'Person to Pay',
|
518
|
+
)
|
519
|
+
|
520
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=addRecord&invoiceid=3§ionid=2'
|
521
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
522
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
523
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
524
|
+
'userid' => 'user_id',
|
525
|
+
'secret' => 'secret',
|
526
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
|
527
|
+
|
528
|
+
data1 = [
|
529
|
+
Osm::Invoice::Item.new(:id => 1, :invoice => invoice, :record_id => 3, :date => Date.new(2012, 1, 2), :amount => '1.23', :type => :expense, :payto => 'John Smith', :description => 'Comment', :budget_name => 'Default'),
|
530
|
+
]
|
531
|
+
data2 = [
|
532
|
+
Osm::Invoice::Item.new(:id => 1, :invoice => invoice, :record_id => 3, :date => Date.new(2012, 1, 2), :amount => '1.23', :type => :expense, :payto => 'John Smith', :description => 'Comment', :budget_name => 'Default'),
|
533
|
+
Osm::Invoice::Item.new(:id => 2, :invoice => invoice, :record_id => 4, :date => Date.new(2012, 1, 2), :amount => '1.23', :type => :expense, :payto => 'John Smith', :description => '', :budget_name => 'Default'),
|
534
|
+
]
|
535
|
+
invoice.should_receive(:get_items).with(@api, {:no_cache=>true}).and_return(data1, data2)
|
536
|
+
|
537
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=updateRecord§ionid=2&dateFormat=generic'
|
538
|
+
[
|
539
|
+
# osm_name, new_value
|
540
|
+
['amount', '1.23'],
|
541
|
+
['comments', 'A description'],
|
542
|
+
['type', 'Expense'],
|
543
|
+
['payto_userid', 'Person to Pay'],
|
544
|
+
['categoryid', 'A budget'],
|
545
|
+
['entrydate', '2003-05-06'],
|
546
|
+
].each do |osm_name, new_value|
|
547
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
548
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
549
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
550
|
+
'userid' => 'user_id',
|
551
|
+
'secret' => 'secret',
|
552
|
+
'section_id' => 2,
|
553
|
+
'invoiceid' => 3,
|
554
|
+
'recordid' => 4,
|
555
|
+
'row' => 0,
|
556
|
+
'column' => osm_name,
|
557
|
+
'value' => new_value,
|
558
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => {osm_name => new_value}.to_json}) }
|
559
|
+
end
|
560
|
+
|
561
|
+
item.create(@api).should be_true
|
562
|
+
item.id.should == 2
|
563
|
+
item.record_id.should == 4
|
564
|
+
end
|
565
|
+
|
566
|
+
it "Create (failure to create)" do
|
567
|
+
invoice = Osm::Invoice.new(:id => 3, :section_id => 2)
|
568
|
+
item = Osm::Invoice::Item.new(
|
569
|
+
:invoice => invoice,
|
570
|
+
:amount => '1.23',
|
571
|
+
:type => :expense,
|
572
|
+
:budget_name => 'A budget',
|
573
|
+
:date => Date.new(2003, 5, 6),
|
574
|
+
:description => 'A description',
|
575
|
+
:payto => 'Person to Pay',
|
576
|
+
)
|
577
|
+
|
578
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=addRecord&invoiceid=3§ionid=2'
|
579
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
580
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
581
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
582
|
+
'userid' => 'user_id',
|
583
|
+
'secret' => 'secret',
|
584
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
|
585
|
+
|
586
|
+
data = [
|
587
|
+
Osm::Invoice::Item.new(:id => 1, :invoice => invoice, :record_id => 3, :date => Date.new(2012, 1, 2), :amount => '1.23', :type => :expense, :payto => 'John Smith', :description => 'Comment', :budget_name => 'Default'),
|
588
|
+
]
|
589
|
+
invoice.should_receive(:get_items).with(@api, {:no_cache=>true}).and_return(data)
|
590
|
+
|
591
|
+
item.create(@api).should be_false
|
592
|
+
end
|
593
|
+
|
594
|
+
it "Update (success)" do
|
595
|
+
item = Osm::Invoice::Item.new(
|
596
|
+
:id => 1,
|
597
|
+
:invoice => Osm::Invoice.new(:id => 3, :section_id => 2),
|
598
|
+
:record_id => 4,
|
599
|
+
)
|
600
|
+
item.amount = '1.23'
|
601
|
+
item.type = :income
|
602
|
+
item.budget_name = 'A different budget'
|
603
|
+
item.date = Date.new(2003, 5, 6)
|
604
|
+
item.description = 'A new description'
|
605
|
+
item.payto = 'Another person to Pay'
|
606
|
+
|
607
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=updateRecord§ionid=2&dateFormat=generic'
|
608
|
+
[
|
609
|
+
# osm_name, new_value
|
610
|
+
['amount', '1.23'],
|
611
|
+
['comments', 'A new description'],
|
612
|
+
['type', 'Income'],
|
613
|
+
['payto_userid', 'Another person to Pay'],
|
614
|
+
['categoryid', 'A different budget'],
|
615
|
+
['entrydate', '2003-05-06'],
|
616
|
+
].each do |osm_name, new_value|
|
617
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
618
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
619
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
620
|
+
'userid' => 'user_id',
|
621
|
+
'secret' => 'secret',
|
622
|
+
'section_id' => 2,
|
623
|
+
'invoiceid' => 3,
|
624
|
+
'recordid' => 4,
|
625
|
+
'row' => 0,
|
626
|
+
'column' => osm_name,
|
627
|
+
'value' => new_value,
|
628
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => {osm_name => new_value}.to_json}) }
|
629
|
+
end
|
630
|
+
|
631
|
+
item.update(@api).should be_true
|
632
|
+
end
|
633
|
+
|
634
|
+
it "Update (failure)" do
|
635
|
+
item = Osm::Invoice::Item.new(
|
636
|
+
:id => 1,
|
637
|
+
:invoice => Osm::Invoice.new(:id => 3, :section_id => 2),
|
638
|
+
:record_id => 4,
|
639
|
+
:amount => '1.23',
|
640
|
+
:type => :expense,
|
641
|
+
:budget_name => 'A budget',
|
642
|
+
:date => Date.new(2003, 4, 5),
|
643
|
+
:description => 'A description',
|
644
|
+
:payto => 'Person to Pay',
|
645
|
+
)
|
646
|
+
item.description = 'A new description'
|
647
|
+
|
648
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=updateRecord§ionid=2&dateFormat=generic'
|
649
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
650
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
651
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
652
|
+
'userid' => 'user_id',
|
653
|
+
'secret' => 'secret',
|
654
|
+
'section_id' => 2,
|
655
|
+
'invoiceid' => 3,
|
656
|
+
'recordid' => 4,
|
657
|
+
'row' => 0,
|
658
|
+
'column' => 'comments',
|
659
|
+
'value' => 'A new description',
|
660
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"comments":"A description"}'}) }
|
661
|
+
|
662
|
+
item.update(@api).should be_false
|
663
|
+
end
|
664
|
+
|
665
|
+
it "Delete (success)" do
|
666
|
+
item = Osm::Invoice::Item.new(:id => 1, :invoice => Osm::Invoice.new(:id => 3, :section_id => 2))
|
667
|
+
|
668
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=deleteEntry§ionid=2'
|
669
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
670
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
671
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
672
|
+
'userid' => 'user_id',
|
673
|
+
'secret' => 'secret',
|
674
|
+
'id' => 1,
|
675
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":true}'}) }
|
676
|
+
|
677
|
+
item.delete(@api).should be_true
|
678
|
+
end
|
679
|
+
|
680
|
+
it "Delete (failure)" do
|
681
|
+
item = Osm::Invoice::Item.new(:id => 1, :invoice => Osm::Invoice.new(:id => 2, :section_id => 4),)
|
682
|
+
|
683
|
+
url = 'https://www.onlinescoutmanager.co.uk/finances.php?action=deleteEntry§ionid=4'
|
684
|
+
HTTParty.should_receive(:post).with(url, :body => {
|
685
|
+
'apiid' => @CONFIGURATION[:api][:osm][:id],
|
686
|
+
'token' => @CONFIGURATION[:api][:osm][:token],
|
687
|
+
'userid' => 'user_id',
|
688
|
+
'secret' => 'secret',
|
689
|
+
'id' => 1,
|
690
|
+
}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body => '{"ok":false}'}) }
|
691
|
+
|
692
|
+
item.delete(@api).should be_false
|
693
|
+
end
|
694
|
+
|
695
|
+
end
|
696
|
+
|
697
|
+
end
|
698
|
+
|
699
|
+
end
|