osm 1.2.14 → 1.2.15.dev

Sign up to get free protection for your applications and to get access to all the features.
data/lib/osm/member.rb CHANGED
@@ -438,7 +438,7 @@ module Osm
438
438
 
439
439
  # Get the My.SCOUT link for this member
440
440
  # @param [Osm::Api] api The api to use to make the request
441
- # @param [Symbol] link_to The page in My.SCOUT to link to (:payments, :events, :programme, :badges, :notice or :details)
441
+ # @param [Symbol] link_to The page in My.SCOUT to link to (:payments, :events, :programme, :badges, :notice, :details, :census or :giftaid)
442
442
  # @param [#to_i] item_id Allows you to link to a specfic item (only for :events)
443
443
  # @return [String] the URL for this member's My.SCOUT
444
444
  # @raise [Osm::ObjectIsInvalid] If the Member is invalid
@@ -448,7 +448,7 @@ module Osm
448
448
  raise Osm::ObjectIsInvalid, 'member is invalid' unless valid?
449
449
  require_ability_to(api, :read, :member, section_id)
450
450
  raise Osm::Error, 'the member does not already exist in OSM' if id.nil?
451
- raise Osm::ArgumentIsInvalid, 'link_to is invalid' unless [:payments, :events, :programme, :badges, :notice, :details].include?(link_to)
451
+ raise Osm::ArgumentIsInvalid, 'link_to is invalid' unless [:payments, :events, :programme, :badges, :notice, :details, :census, :giftaid].include?(link_to)
452
452
 
453
453
  link = "#{api.base_url}/parents/#{link_to}.php?sc=#{self.id}&se=#{section_id}&c=#{myscout_link_key(api)}"
454
454
  link += "&e=#{item_id.to_i}" if item_id && link_to.eql?(:events)
data/lib/osm/model.rb CHANGED
@@ -99,7 +99,7 @@ module Osm
99
99
  end
100
100
  def self.cache_write(api, key, data, options={})
101
101
  return false if @@cache.nil?
102
- options.merge!(:expires_in => @@cache_ttl)
102
+ options.reverse_merge!(expires_in: @@cache_ttl)
103
103
  @@cache.write(cache_key(api, key), data, options)
104
104
  end
105
105
  def self.cache_exist?(api, key)
@@ -93,18 +93,24 @@ describe "Activity" do
93
93
  ],
94
94
  'badges' => [
95
95
  {
96
- 'activityid' => '1',
97
- 'section' => 'section',
98
- 'badgetype' => 'type',
99
- 'badge' => 'badge',
100
- 'columnname' => 'col_name',
101
- 'label' => 'This is a label',
96
+ 'badge' => 'activity_firesafety',
97
+ 'badgeLongName' => 'Fire Safety',
98
+ 'badge_id' => '181',
99
+ 'badge_version' => '0',
100
+ 'badgetype' => 'activity',
101
+ 'badgetypeLongName' => 'Activity',
102
+ 'column_id' => '93384',
103
+ 'columnname' => 'b_01',
104
+ 'columnnameLongName' => 'B: Fire drill',
105
+ 'data' => 'Yes',
106
+ 'section' => 'cubs',
107
+ 'sectionLongName' => 'Cubs',
102
108
  }
103
109
  ]
104
110
  }
105
111
  FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/programme.php?action=getActivity&id=1", :body => body.to_json, :content_type => 'application/json')
106
-
107
-
112
+
113
+
108
114
  activity = Osm::Activity.get(@api, 1)
109
115
 
110
116
  activity.id.should == 1
@@ -132,13 +138,14 @@ describe "Activity" do
132
138
  activity.files[0].activity_id.should == 1
133
139
  activity.files[0].file_name.should == 'File Name'
134
140
  activity.files[0].name.should == 'Name'
135
- activity.badges[0].activity_id.should == 1
136
- activity.badges[0].section_type.should == :section
137
- activity.badges[0].type.should == :type
138
- activity.badges[0].badge.should == 'badge'
139
- activity.badges[0].requirement.should == 'col_name'
140
- activity.badges[0].label.should == 'This is a label'
141
-
141
+ activity.badges[0].badge_type.should == :activity
142
+ activity.badges[0].badge_section.should == :cubs
143
+ activity.badges[0].badge_name.should == 'Fire Safety'
144
+ activity.badges[0].badge_id.should == 181
145
+ activity.badges[0].badge_version.should == 0
146
+ activity.badges[0].requirement_id.should == 93384
147
+ activity.badges[0].requirement_label.should == 'B: Fire drill'
148
+ activity.badges[0].data.should == 'Yes'
142
149
  activity.valid?.should be_true
143
150
  end
144
151
 
@@ -185,7 +192,7 @@ describe "Activity" do
185
192
  'location' => :indoors,
186
193
  'sections' => '["beavers","cubs"]',
187
194
  'tags' => '["tag1","tag2"]',
188
- 'links' => '[{"activityid":"2","section":"beavers","badgetype":"t","badge":"b","columnname":"r","label":"l"}]',
195
+ 'links' => '[{"badge_id":"181","badge_version":"0","column_id":"93384","badge":null,"badgeLongName":"Badge name","columnname":null,"columnnameLongName":"l","data":"","section":"beavers","sectionLongName":null,"sections":["beavers","cubs"],"badgetype":"activity","badgetypeLongName":null}]',
189
196
  'shared' => 0,
190
197
  'sectionid' => 1,
191
198
  'secretEdit' => true,
@@ -203,7 +210,16 @@ describe "Activity" do
203
210
  :location => :indoors,
204
211
  :sections => [:beavers, :cubs],
205
212
  :tags => ['tag1', 'tag2'],
206
- :badges => [Osm::Activity::Badge.new(:activity_id=>2, :section_type=>:beavers, :type=>:t, :badge=>'b', :requirement=>'r', :label=>'l')],
213
+ :badges => [Osm::Activity::Badge.new(
214
+ :badge_type => :activity,
215
+ :badge_section => :beavers,
216
+ :requirement_label => 'l',
217
+ :data => '',
218
+ :badge_name => 'Badge name',
219
+ :badge_id => 181,
220
+ :badge_version => 0,
221
+ :requirement_id => 93384,
222
+ )],
207
223
  :shared => 0,
208
224
  :section_id => 1,
209
225
  )
data/spec/osm/api_spec.rb CHANGED
@@ -14,7 +14,7 @@ describe "API" do
14
14
  expect{ Osm::Api.configure(@CONFIGURATION[:api].select{ |k,v| (k != :default_site)}) }.to raise_error(ArgumentError, ':default_site does not exist in options hash or is invalid, this should be set to either :osm or :ogm')
15
15
  expect{ Osm::Api.configure(@CONFIGURATION[:api].merge(:default_site => :invalid)) }.to raise_error(ArgumentError, ':default_site does not exist in options hash or is invalid, this should be set to either :osm or :ogm')
16
16
 
17
- expect{ Osm::Api.configure(@CONFIGURATION[:api].select{ |k,v| (k != :ogm) && (k != :osm)}) }.to raise_error(ArgumentError, ':osm and/or :ogm must be present')
17
+ expect{ Osm::Api.configure(@CONFIGURATION[:api].select{ |k,v| (k != :ogm) && (k != :osm)}) }.to raise_error(ArgumentError, ':osm does not exist in options hash')
18
18
  expect{ Osm::Api.configure(@CONFIGURATION[:api].merge(:osm => '')) }.to raise_error(ArgumentError, ':osm must be a Hash')
19
19
  expect{ Osm::Api.configure(@CONFIGURATION[:api].merge(:osm => @CONFIGURATION[:api][:osm].select{ |k,v| (k != :id)})) }.to raise_error(ArgumentError, ':osm must contain a key :id')
20
20
  expect{ Osm::Api.configure(@CONFIGURATION[:api].merge(:osm => @CONFIGURATION[:api][:osm].select{ |k,v| (k != :token)})) }.to raise_error(ArgumentError, ':osm must contain a key :token')
@@ -3,43 +3,64 @@ require 'spec_helper'
3
3
 
4
4
  describe "Badge" do
5
5
 
6
- it "Create" do
7
- badge = Osm::Badge.new(
8
- :name => 'name',
9
- :requirement_notes => 'notes',
10
- :osm_key => 'key',
11
- :osm_long_key => 'long_key',
12
- :sections_needed => 1,
13
- :total_needed => 2,
14
- :needed_from_section => {'a' => 1},
15
- :requirements => [],
16
- )
6
+ describe "Create" do
7
+
8
+ before :each do
9
+ @badge_options = {
10
+ :name => 'name',
11
+ :identifier => '12_3',
12
+ :id => 12,
13
+ :version => 3,
14
+ :group_name => '',
15
+ :latest => true,
16
+ :sharing => :draft,
17
+ :user_id => 4,
18
+ :levels => [1, 2, 3],
19
+ :requirement_notes => 'notes',
20
+ :requirements => [],
21
+ }
22
+ end
23
+
24
+ it "Attributes set" do
25
+ badge = Osm::Badge.new(@badge_options)
26
+ badge.name.should == 'name'
27
+ badge.identifier.should == '12_3'
28
+ badge.id.should == 12
29
+ badge.version.should == 3
30
+ badge.group_name.should == ''
31
+ badge.latest.should be_true
32
+ badge.sharing.should == :draft
33
+ badge.user_id.should == 4
34
+ badge.levels.should == [1, 2, 3]
35
+ badge.requirement_notes.should == 'notes'
36
+ badge.requirements.should == []
37
+ badge.valid?.should be_true
38
+ end
39
+
40
+ it "Valid with nil for levels" do
41
+ badge = Osm::Badge.new(@badge_options.merge(levels: nil))
42
+ badge.levels.should be_nil
43
+ badge.valid?.should be_true
44
+ end
17
45
 
18
- badge.name.should == 'name'
19
- badge.requirement_notes.should == 'notes'
20
- badge.osm_key.should == 'key'
21
- badge.osm_long_key.should == 'long_key'
22
- badge.sections_needed.should == 1
23
- badge.total_needed.should == 2
24
- badge.needed_from_section.should == {'a' => 1}
25
- badge.requirements.should == []
26
- badge.valid?.should be_true
27
46
  end
28
47
 
29
48
  it "Create Requirement" do
30
49
  requirement = Osm::Badge::Requirement.new(
31
50
  :name => 'name',
32
51
  :description => 'description',
33
- :field => 'field',
52
+ :module_letter => 'a',
53
+ :field => 1,
34
54
  :editable => true,
35
- :badge => Osm::Badge.new(:osm_key => 'key'),
55
+ :badge => Osm::Badge.new(:identifier => 'key'),
36
56
  )
37
57
 
38
58
  requirement.name.should == 'name'
39
59
  requirement.description.should == 'description'
40
- requirement.field.should == 'field'
60
+ requirement.module_letter.should == 'a'
61
+ requirement.field.should == 1
41
62
  requirement.editable.should be_true
42
- requirement.badge.osm_key.should == 'key'
63
+ requirement.badge.identifier.should == 'key'
43
64
  requirement.valid?.should be_true
44
65
  end
45
66
 
@@ -48,33 +69,34 @@ describe "Badge" do
48
69
  :member_id => 1,
49
70
  :first_name => 'First',
50
71
  :last_name => 'Last',
51
- :completed => 4,
72
+ :due => 4,
52
73
  :awarded => 3,
53
74
  :awarded_date => Date.new(2000, 1, 2),
54
75
  :requirements => {},
55
76
  :section_id => 2,
56
- :badge => Osm::Badge.new(:osm_key => 'key'),
77
+ :badge => Osm::Badge.new(:identifier => 'key'),
57
78
  )
58
79
 
59
80
  data.member_id.should == 1
60
81
  data.first_name.should == 'First'
61
82
  data.last_name.should == 'Last'
62
- data.completed.should == 4
83
+ data.due.should == 4
63
84
  data.awarded.should == 3
64
85
  data.awarded_date.should == Date.new(2000, 1, 2)
65
86
  data.requirements.should == {}
66
87
  data.section_id.should == 2
67
- data.badge.osm_key.should == 'key'
88
+ data.badge.identifier.should == 'key'
68
89
  data.valid?.should be_true
69
90
  end
70
91
 
71
92
 
72
- it "Compare badges by name then osm_key" do
73
- b1 = Osm::Badge.new(:name => 'A', :osm_key => 'a')
74
- b2 = Osm::Badge.new(:name => 'B', :osm_key => 'a')
75
- b3 = Osm::Badge.new(:name => 'B', :osm_key => 'b')
76
- badges = [b3, b1, b2]
77
- badges.sort.should == [b1, b2, b3]
93
+ it "Compare badges by name then id then version (descending)" do
94
+ b1 = Osm::Badge.new(:name => 'A', :id => 1, :version => 1)
95
+ b2 = Osm::Badge.new(:name => 'B', :id => 1, :version => 1)
96
+ b3 = Osm::Badge.new(:name => 'B', :id => 2, :version => 2)
97
+ b4 = Osm::Badge.new(:name => 'B', :id => 2, :version => 1)
98
+ badges = [b3, b1, b4, b2]
99
+ badges.sort.should == [b1, b2, b3, b4]
78
100
  end
79
101
 
80
102
  it "Compare badge requirements by badge then field" do
@@ -112,52 +134,57 @@ describe "Badge" do
112
134
  data.total_gained.should == 4
113
135
  end
114
136
 
115
- it "Get total requirements met in each section for a member" do
137
+ it "Get total requirements met in each module for a member" do
116
138
  badge = Osm::Badge.new(
117
139
  :needed_from_section => {'a' => 1, 'b' => 2},
118
140
  :requirements => [
119
- Osm::Badge::Requirement.new(:field => 'a_1'),
120
- Osm::Badge::Requirement.new(:field => 'a_2'),
121
- Osm::Badge::Requirement.new(:field => 'b_1'),
122
- Osm::Badge::Requirement.new(:field => 'b_2'),
123
- Osm::Badge::Requirement.new(:field => 'y_1'),
124
- Osm::Badge::Requirement.new(:field => 'y_2'),
125
- ]
141
+ Osm::Badge::Requirement.new(:module_letter=> 'a', :field => '1'),
142
+ Osm::Badge::Requirement.new(:module_letter=> 'a', :field => '2'),
143
+ Osm::Badge::Requirement.new(:module_letter=> 'b', :field => '3'),
144
+ Osm::Badge::Requirement.new(:module_letter=> 'b', :field => '4'),
145
+ Osm::Badge::Requirement.new(:module_letter=> 'c', :field => '5'),
146
+ Osm::Badge::Requirement.new(:module_letter=> 'c', :field => '6'),
147
+ ],
148
+ :completion_criteria => {
149
+ :modules => [
150
+ { module_letter: 'a', module_id: 100 },
151
+ { module_letter: 'b', module_id: 200 },
152
+ { module_letter: 'c', module_id: 300 }
153
+ ]}
126
154
  )
127
155
  data = Osm::Badge::Data.new(
128
156
  :badge => badge,
129
- :requirements => {
130
- 'a_1' => 'x',
131
- 'a_2' => '',
132
- 'b_1' => 'yes',
133
- 'b_2' => '2000-01-02',
134
- 'y_1' => 1,
135
- }
157
+ :requirements => { 1=>'x', 2=>'', 3=>'yes', 4=>'2000-01-02', 5=>1 }
136
158
  )
137
- data.gained_in_sections.should == {'a' => 0, 'b' => 2, 'y' => 1}
159
+ data.gained_in_modules.should == {'a'=>0, 'b'=>2, 'c'=>1, 100=>0, 200=>2, 300=>1}
138
160
  end
139
161
 
140
- it "Get number of sections met for a member" do
162
+ it "Get modules met for a member" do
141
163
  badge = Osm::Badge.new(
142
- :needed_from_section => {'a' => 1, 'b' => 2, 'c' => 1},
143
164
  :requirements => [
144
- Osm::Badge::Requirement.new(:field => 'a_1'),
145
- Osm::Badge::Requirement.new(:field => 'a_2'),
146
- Osm::Badge::Requirement.new(:field => 'b_1'),
147
- Osm::Badge::Requirement.new(:field => 'b_2'),
148
- Osm::Badge::Requirement.new(:field => 'c_1'),
149
- ]
165
+ Osm::Badge::Requirement.new(:module_letter=> 'a', :field => '1'),
166
+ Osm::Badge::Requirement.new(:module_letter=> 'a', :field => '2'),
167
+ Osm::Badge::Requirement.new(:module_letter=> 'b', :field => '3'),
168
+ Osm::Badge::Requirement.new(:module_letter=> 'b', :field => '4'),
169
+ Osm::Badge::Requirement.new(:module_letter=> 'c', :field => '5'),
170
+ ],
171
+ :completion_criteria => {
172
+ :modules => [
173
+ { module_letter: 'a', module_id: 1000, min_required: 1 },
174
+ { module_letter: 'b', module_id: 2000, min_required: 2 },
175
+ { module_letter: 'c', module_id: 3000, min_required: 1 }
176
+ ]}
150
177
  )
151
178
  data = Osm::Badge::Data.new(
152
179
  :badge => badge,
153
- :requirements => {'a_1' => 'x', 'a_2' => '', 'b_1' => 'yes', 'b_2' => '2000-01-02', 'c_1' => 'yes'}
180
+ :requirements => {1=>'x', 2=>'', 3=>'yes', 4=>'2000-01-02', 5=>'yes'}
154
181
  )
155
- data.sections_gained.should == 2
182
+ data.modules_gained.should == ['b', 'c']
156
183
  end
157
184
 
158
185
  describe "Works out if the badge has been earnt" do
159
186
  it "Staged" do
160
- badge = Osm::StagedBadge.new(:osm_key => 'not_hikes_or_nights')
187
+ badge = Osm::StagedBadge.new(levels: [0, 1, 2, 3])
161
188
  data = Osm::Badge::Data.new(:awarded => 2, :badge => badge)
162
189
 
163
190
  data.stub(:earnt) { 1 }
@@ -171,95 +198,140 @@ describe "Badge" do
171
198
  end
172
199
 
173
200
  it "Non staged" do
174
- badge = Osm::ActivityBadge.new()
175
- data = Osm::Badge::Data.new(:completed => 1, :awarded => 1, :badge => badge)
201
+ completion_criteria = {
202
+ :min_modules_required => 0,
203
+ :min_requirements_completed => 0,
204
+ :modules => [
205
+ {module_id: 1, module_letter: 'a', min_required: 2},
206
+ {module_id: 2, module_letter: 'b', min_required: 1},
207
+ {module_id: 3, module_letter: 'c', min_required: 1},
208
+ ],
209
+ :badges_required => [],
210
+ :fields_required => [],
211
+ }
212
+ badge = Osm::ActivityBadge.new(completion_criteria: completion_criteria)
213
+ badge.requirements = [
214
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'a', field: 10),
215
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'a', field: 11),
216
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'b', field: 20),
217
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'b', field: 21),
218
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'c', field: 30),
219
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'c', field: 31),
220
+ ]
221
+
222
+
223
+ data = Osm::Badge::Data.new(:due => 1, :awarded => 1, :badge => badge)
176
224
  data.earnt?.should be_false
177
225
 
178
- badge = Osm::ActivityBadge.new()
179
- data = Osm::Badge::Data.new(:completed => 1, :awarded => 0, :badge => badge)
226
+ data = Osm::Badge::Data.new(:due => 1, :awarded => 0, :badge => badge)
180
227
  data.earnt?.should be_true
181
228
 
182
229
 
183
- badge = Osm::ActivityBadge.new(:total_needed => 0, :sections_needed => 2, :needed_from_section => {'a' => 2, 'b' => 1})
184
- data = Osm::Badge::Data.new(:requirements => {'a_01'=>'y', 'a_02'=>'y', 'b_01' => 'y'}, :completed => 0, :awarded => 0, :badge => badge)
230
+ # Number of modules required
231
+ this_badge = badge.clone
232
+ this_badge.completion_criteria = completion_criteria.merge({
233
+ :min_modules_required => 2
234
+ })
235
+
236
+ data = Osm::Badge::Data.new(:requirements => {10=>'y', 11=>'y', 20=>'y'}, :due => 0, :awarded => 0, :badge => this_badge)
185
237
  data.earnt?.should be_true
186
238
 
187
- badge = Osm::ActivityBadge.new(:total_needed => 0, :sections_needed => 2, :needed_from_section => {'a' => 2, 'b' => 1})
188
- data = Osm::Badge::Data.new(:requirements => {'a_01'=>'y', 'a_02'=>'y', 'b_01' => 'x'}, :completed => 0, :awarded => 0, :badge => badge)
239
+ data = Osm::Badge::Data.new(:requirements => {10=>'y', 11=>'y', 20=>'x'}, :due => 0, :awarded => 0, :badge => this_badge)
189
240
  data.earnt?.should be_false
190
241
 
191
- badge = Osm::ActivityBadge.new(:total_needed => 3, :sections_needed => 0, :needed_from_section => {'a' => 2, 'b' => 1})
192
- data = Osm::Badge::Data.new(:requirements => {'a_01'=>'y', 'a_02'=>'y', 'b_01' => 'y'}, :completed => 0, :awarded => 0, :badge => badge)
193
- data.earnt?.should be_true
194
242
 
195
- badge = Osm::ActivityBadge.new(:total_needed => 3, :sections_needed => 0, :needed_from_section => {'a' => 2, 'b' => 1})
196
- data = Osm::Badge::Data.new(:requirements => {'a_01'=>'y', 'a_02'=>'x', 'b_01' => 'y'}, :completed => 0, :awarded => 0, :badge => badge)
197
- data.earnt?.should be_false
243
+ # Number of requirements needed
244
+ this_badge = badge.clone
245
+ this_badge.completion_criteria = completion_criteria.merge({
246
+ :min_requirements_completed => 2
247
+ })
198
248
 
199
- badge = Osm::ActivityBadge.new(:total_needed => 3, :sections_needed => 2, :needed_from_section => {'a' => 2, 'b' => 1})
200
- data = Osm::Badge::Data.new(:requirements => {'a_01'=>'y', 'a_02'=>'y', 'b_01' => 'y'}, :completed => 0, :awarded => 0, :badge => badge)
249
+ data = Osm::Badge::Data.new(:requirements => {10=>'y', 11=>'y', 20=>'y'}, :due => 0, :awarded => 0, :badge => this_badge)
201
250
  data.earnt?.should be_true
202
251
 
203
- badge = Osm::ActivityBadge.new(:total_needed => 1, :sections_needed => 1, :needed_from_section => {'a' => 2, 'b' => 1})
204
- data = Osm::Badge::Data.new(:requirements => {'a_01'=>'y', 'a_02'=>'y', 'b_01' => 'y'}, :completed => 0, :awarded => 0, :badge => badge)
252
+ data = Osm::Badge::Data.new(:requirements => {10=>'y', 11=>'x', 20=>'y'}, :due => 0, :awarded => 0, :badge => this_badge)
205
253
  data.earnt?.should be_true
206
254
 
207
- badge = Osm::ActivityBadge.new(:total_needed => 0, :sections_needed => -1, :needed_from_section => {'a' => 2, 'b' => 1})
208
- data = Osm::Badge::Data.new(:requirements => {'a_01'=>'y', 'a_02'=>'y', 'b_01' => 'y'}, :completed => 0, :awarded => 0, :badge => badge)
209
- data.earnt?.should be_true
255
+ data = Osm::Badge::Data.new(:requirements => {10=>'y', 11=>'x', 20=>'x'}, :due => 0, :awarded => 0, :badge => this_badge)
256
+ data.earnt?.should be_false
257
+
258
+
259
+ # Module combinations
260
+ this_badge = badge.clone
261
+ this_badge.completion_criteria = completion_criteria.merge({
262
+ :requires => [['a'], ['b', 'c']]
263
+ })
264
+ data = Osm::Badge::Data.new(:requirements => {10=>'x', 11=>'x', 20=>'x', 30=>'x'}, :due => 0, :awarded => 0, :badge => this_badge)
265
+ data.earnt?.should be_false
210
266
 
211
- badge = Osm::ActivityBadge.new(:total_needed => 0, :sections_needed => -1, :needed_from_section => {'a' => 2, 'b' => 1})
212
- data = Osm::Badge::Data.new(:requirements => {'a_01'=>'y', 'a_02'=>'x', 'b_01' => 'y'}, :completed => 0, :awarded => 0, :badge => badge)
267
+ data = Osm::Badge::Data.new(:requirements => {10=>'y', 11=>'y', 20=>'x', 30=>'x'}, :due => 0, :awarded => 0, :badge => this_badge)
213
268
  data.earnt?.should be_false
269
+
270
+ data = Osm::Badge::Data.new(:requirements => {10=>'y', 11=>'y', 20=>'y', 30=>'x'}, :due => 0, :awarded => 0, :badge => this_badge)
271
+ data.earnt?.should be_true
272
+
273
+ data = Osm::Badge::Data.new(:requirements => {10=>'y', 11=>'y', 20=>'x', 30=>'y'}, :due => 0, :awarded => 0, :badge => this_badge)
274
+ data.earnt?.should be_true
214
275
  end
215
276
  end
216
277
 
217
278
  describe "Works out what level of a badge has been earnt" do
218
- it "Staged" do
219
- badge = Osm::StagedBadge.new(:osm_key => 'not_hikes_or_nights', :needed_from_section => {'a'=>1,'b'=>1,'c'=>1,'d'=>2,'e'=>2})
220
279
 
221
- data = Osm::Badge::Data.new(:requirements=>{'a_01'=>'','b_01'=>'','c_01'=>'','d_01'=>'','d_02'=>'','e_01'=>'','e_02'=>''}, :badge=>badge)
280
+ it "Staged (activity)" do
281
+ badge = Osm::StagedBadge.new(
282
+ :levels => [0, 1, 2, 3],
283
+ :completion_criteria => {
284
+ :min_modules_required => 0,
285
+ :min_requirements_completed => 0,
286
+ :modules => [
287
+ {module_id: 1, module_letter: 'a', min_required: 1},
288
+ {module_id: 2, module_letter: 'b', min_required: 1},
289
+ {module_id: 3, module_letter: 'c', min_required: 1},
290
+ ],
291
+ :show_letters => true,
292
+ }
293
+ )
294
+ badge.requirements = [
295
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'a', field: 10),
296
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'a', field: 11),
297
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'b', field: 20),
298
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'b', field: 21),
299
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'c', field: 30),
300
+ Osm::Badge::Requirement.new(badge: badge, module_letter: 'c', field: 31),
301
+ ]
302
+
303
+ requirements = {10=>'',11=>'',20=>'',21=>'',30=>'',31=>''}
304
+ data = Osm::Badge::Data.new(requirements: requirements, badge: badge)
222
305
  data.earnt.should == 0
223
306
 
224
- data = Osm::Badge::Data.new(:requirements=>{'a_01'=>'y','b_01'=>'','c_01'=>'','d_01'=>'','d_02'=>'','e_01'=>'','e_02'=>''}, :badge=>badge)
307
+ requirements = {10=>'y',11=>'',20=>'',21=>'',30=>'',31=>''}
308
+ data = Osm::Badge::Data.new(requirements: requirements, badge: badge)
225
309
  data.earnt.should == 1
226
310
 
227
- data = Osm::Badge::Data.new(:requirements=>{'a_01'=>'y','b_01'=>'y','c_01'=>'','d_01'=>'y','d_02'=>'','e_01'=>'','e_02'=>''}, :badge=>badge)
311
+ requirements = {10=>'y',11=>'',20=>'',21=>'y',30=>'',31=>''}
312
+ data = Osm::Badge::Data.new(requirements: requirements, badge: badge)
228
313
  data.earnt.should == 2
229
314
 
230
- data = Osm::Badge::Data.new(:requirements=>{'a_01'=>'y','b_01'=>'y','c_01'=>'','d_01'=>'y','d_02'=>'y','e_01'=>'','e_02'=>''}, :badge=>badge)
231
- data.earnt.should == 4
232
- end
233
-
234
- it "Nights away" do
235
- badge = Osm::StagedBadge.new(:osm_key => 'nightsaway')
315
+ requirements = {10=>'',11=>'',20=>'',21=>'y',30=>'',31=>''}
316
+ data = Osm::Badge::Data.new(requirements: requirements, badge: badge)
317
+ data.earnt.should == 2
236
318
 
237
- Osm::Badge::Data.new(:requirements => {'y_01'=>9}, :badge => badge).earnt.should == 5
238
- Osm::Badge::Data.new(:requirements => {'y_01'=>10}, :badge => badge).earnt.should == 10
239
- Osm::Badge::Data.new(:requirements => {'y_01'=>11}, :badge => badge).earnt.should == 10
240
- Osm::Badge::Data.new(:requirements => {'y_01'=>999}, :badge => badge).earnt.should == 200
319
+ requirements = {10=>'y',11=>'',20=>'y',21=>'',30=>'y',31=>''}
320
+ data = Osm::Badge::Data.new(requirements: requirements, badge: badge)
321
+ data.earnt.should == 3
241
322
  end
242
323
 
243
- it "Hikes away" do
244
- badge = Osm::StagedBadge.new(:osm_key => 'hikes')
245
-
246
- Osm::Badge::Data.new(:requirements => {'y_01'=>3}, :badge => badge).earnt.should == 2
247
- Osm::Badge::Data.new(:requirements => {'y_01'=>5}, :badge => badge).earnt.should == 5
248
- Osm::Badge::Data.new(:requirements => {'y_01'=>6}, :badge => badge).earnt.should == 5
249
- Osm::Badge::Data.new(:requirements => {'y_01'=>49}, :badge => badge).earnt.should == 35
250
- Osm::Badge::Data.new(:requirements => {'y_01'=>50}, :badge => badge).earnt.should == 50
251
- Osm::Badge::Data.new(:requirements => {'y_01'=>999}, :badge => badge).earnt.should == 50
252
- end
253
-
254
- it "Time on the water" do
255
- badge = Osm::StagedBadge.new(:osm_key => 'timeonthewater')
256
-
257
- Osm::Badge::Data.new(:requirements => {'y_01'=>3}, :badge => badge).earnt.should == 2
258
- Osm::Badge::Data.new(:requirements => {'y_01'=>5}, :badge => badge).earnt.should == 5
259
- Osm::Badge::Data.new(:requirements => {'y_01'=>6}, :badge => badge).earnt.should == 5
260
- Osm::Badge::Data.new(:requirements => {'y_01'=>49}, :badge => badge).earnt.should == 35
261
- Osm::Badge::Data.new(:requirements => {'y_01'=>50}, :badge => badge).earnt.should == 50
262
- Osm::Badge::Data.new(:requirements => {'y_01'=>999}, :badge => badge).earnt.should == 50
324
+ it "Staged (count)" do
325
+ badge = Osm::StagedBadge.new(
326
+ :levels => [0,1,2,3,4,5,10,15,20],
327
+ :completion_criteria => {:show_letters => false, :levels_column_id => 3000},
328
+ :requirements => []
329
+ )
330
+
331
+ Osm::Badge::Data.new(:requirements => {3000 => 9}, :badge => badge).earnt.should == 5
332
+ Osm::Badge::Data.new(:requirements => {3000 => 10}, :badge => badge).earnt.should == 10
333
+ Osm::Badge::Data.new(:requirements => {3000 => 11}, :badge => badge).earnt.should == 10
334
+ Osm::Badge::Data.new(:requirements => {3000 => 999}, :badge => badge).earnt.should == 20
263
335
  end
264
336
 
265
337
  it "Non staged" do
@@ -274,102 +346,94 @@ describe "Badge" do
274
346
  end
275
347
 
276
348
  it "Works out if the badge has been started" do
277
- Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {'a_01' => 'Yes', 'a_02' => ''}).started?.should be_true
278
- Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {'a_01' => 'Yes', 'a_02' => ''}, :completed => 1).started?.should be_false
279
- Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {'a_01' => 'xNo', 'a_02' => ''}).started?.should be_false
280
- Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {'a_01' => '', 'a_02' => ''}).started?.should be_false
349
+ Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {1 => 'Yes', 2 => ''}).started?.should be_true
350
+ Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {1 => 'Yes', 2 => ''}, :due => 1).started?.should be_false
351
+ Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {1 => 'xNo', 2 => ''}).started?.should be_false
352
+ Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {1 => '', 2 => ''}).started?.should be_false
281
353
 
282
- # Staged Badge
354
+ # Staged Activity Badge
283
355
  Osm::Badge::Data.new(
284
- :badge => Osm::StagedBadge.new,
285
- :requirements => {'a_01' => 'Yes', 'b_01' => 'Yes', 'b_02' => ''},
286
- :completed => 1,
287
- ).started?.should be_true
288
- Osm::Badge::Data.new(
289
- :badge => Osm::StagedBadge.new(:osm_key => 'nightsaway'),
290
- :requirements => {'a_01' => 5, 'y_01' => '5', 'custom_26695' => ''},
291
- :completed => 5,
292
- ).started?.should be_false
293
- Osm::Badge::Data.new(
294
- :badge => Osm::StagedBadge.new(:osm_key => 'hikes'),
295
- :requirements => {'a_01' => 3, 'y_01' => '3', 'custom_26695' => ''},
296
- :completed => 1,
356
+ :badge => Osm::StagedBadge.new(
357
+ :levels => [0,1,2],
358
+ :completion_criteria => {:show_letters => true},
359
+ :requirements => [
360
+ Osm::Badge::Requirement.new(:module_letter => 'a', :field => 1000),
361
+ Osm::Badge::Requirement.new(:module_letter => 'b', :field => 2000),
362
+ Osm::Badge::Requirement.new(:module_letter => 'b', :field => 2001),
363
+ ]
364
+ ),
365
+ :requirements => {1000 => 'Yes', 2000 => 'Yes', 2001 => ''},
366
+ :due => 1,
297
367
  ).started?.should be_true
298
368
 
299
- # Scout's adventure challenge
369
+ # Staged Count Badge
300
370
  Osm::Badge::Data.new(
301
- :badge => Osm::ChallengeBadge.new(:osm_key => 'adventure'),
302
- :requirements => {'y_01' => 5, 'custom_26695' => 'Text'},
303
- :completed => 0,
304
- ).started?.should be_true
371
+ :badge => Osm::StagedBadge.new(:levels => [0,1,2,3,4,5,10,15,20], :completion_criteria => {:show_letters => false, :levels_column_id => 1000}),
372
+ :requirements => {1000 => 5, 2000 => '5', 3000 => ''},
373
+ :due => 5,
374
+ :awarded => 4,
375
+ ).started?.should be_false # Finished lvl 5 & not started lvl 10
305
376
  Osm::Badge::Data.new(
306
- :badge => Osm::ChallengeBadge.new(:osm_key => 'adventure'),
307
- :requirements => {'y_01' => '', 'custom_26695' => ''},
308
- :completed => 0,
309
- ).started?.should be_false
310
-
311
- # Scout's community challenge
312
- Osm::Badge::Data.new(
313
- :badge => Osm::ChallengeBadge.new(:osm_key => 'community'),
314
- :requirements => {'y_01' => 5, 'a_01' => '', 'custom_26695' => 'Text'},
315
- :completed => 0,
316
- ).started?.should be_true
317
- Osm::Badge::Data.new(
318
- :badge => Osm::ChallengeBadge.new(:osm_key => 'community'),
319
- :requirements => {'y_01' => '', 'a_01' => '4', 'custom_26695' => 'Text'},
320
- :completed => 0,
321
- ).started?.should be_true
322
- Osm::Badge::Data.new(
323
- :badge => Osm::ChallengeBadge.new(:osm_key => 'community'),
324
- :requirements => {'y_01' => '', 'a_01' => '', 'custom_26695' => ''},
325
- :completed => 0,
326
- ).started?.should be_false
327
-
328
- # Beaver's adventure activity
329
- Osm::Badge::Data.new(
330
- :badge => Osm::ActivityBadge.new(:osm_key => 'adventure'),
331
- :requirements => {'y_01' => 5, 'custom_26695' => 'Text'},
332
- :completed => 0,
333
- ).started?.should be_true
334
- Osm::Badge::Data.new(
335
- :badge => Osm::ActivityBadge.new(:osm_key => 'adventure'),
336
- :requirements => {'y_01' => '', 'custom_26695' => ''},
337
- :completed => 0,
338
- ).started?.should be_false
377
+ :badge => Osm::StagedBadge.new(:levels => [0,1,2,3,4,5,10,15,20], :completion_criteria => {:show_letters => false, :levels_column_id => 1000}),
378
+ :requirements => {1000 => 6, 2000 => '6', 3000 => ''},
379
+ :due => 5,
380
+ :awarded => 3,
381
+ ).started?.should be_true # Finished lvl 5 & started lvl 10
339
382
  end
340
383
 
341
384
  it "Works out what stage of the badge has been started" do
342
- Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {'a_01' => 'Yes', 'a_02' => ''}).started.should == 1
343
- Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {'a_01' => 'Yes', 'a_02' => ''}, :completed => 1).started.should == 0
344
- Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {'a_01' => 'xNo', 'a_02' => ''}).started.should == 0
345
- Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {'a_01' => '', 'a_02' => ''}).started.should == 0
385
+ # Non-Staged badges (0 or 1)
386
+ Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {10 => 'Yes', 11 => ''}).started.should == 1
387
+ Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {10 => 'Yes', 11 => ''}, :due => 1).started.should == 0
388
+ Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {10 => 'xNo', 11 => ''}).started.should == 0
389
+ Osm::Badge::Data.new(:badge => Osm::CoreBadge.new, :requirements => {10 => '', 11 => ''}).started.should == 0
390
+
391
+
392
+ # Staged Activity
393
+ staged_activity = Osm::StagedBadge.new(
394
+ :levels => [0,1,2],
395
+ :completion_criteria => {:show_letters => true},
396
+ :requirements => [
397
+ Osm::Badge::Requirement.new(:module_letter => 'a', :field => 100),
398
+ Osm::Badge::Requirement.new(:module_letter => 'b', :field => 200),
399
+ Osm::Badge::Requirement.new(:module_letter => 'b', :field => 201),
400
+ ]
401
+ )
346
402
 
347
- # Staged Badge
348
403
  Osm::Badge::Data.new(
349
- :badge => Osm::StagedBadge.new(:osm_key => 'test'),
350
- :requirements => {'a_01' => 'Yes', 'b_01' => 'Yes', 'b_02' => ''},
351
- :completed => 1,
404
+ :badge => staged_activity,
405
+ :requirements => {100 => 'Yes', 200 => 'Yes', 201 => ''},
406
+ :due => 1,
352
407
  ).started.should == 2
353
408
  Osm::Badge::Data.new(
354
- :badge => Osm::StagedBadge.new(:osm_key => 'test'),
355
- :requirements => {'a_01' => 'Yes', 'b_01' => 'Yes', 'b_02' => '', 'c_01' => 'Yes', 'c_02' => ''},
356
- :completed => 1,
409
+ :badge => staged_activity,
410
+ :requirements => {100 => 'Yes', 200 => 'Yes', 201 => ''},
411
+ :due => 1,
357
412
  ).started.should == 2
358
413
  Osm::Badge::Data.new(
359
- :badge => Osm::StagedBadge.new(:osm_key => 'test'),
360
- :requirements => {'a_01' => '', 'b_01' => '', 'c_01' => '', 'd_01' => '', 'e_01' => ''},
361
- :completed => 5,
414
+ :badge => staged_activity,
415
+ :requirements => {},
416
+ :due => 2,
362
417
  ).started.should == 0 # No more stages to do
418
+
419
+
420
+ # Staged count
421
+ staged_count = Osm::StagedBadge.new(
422
+ :levels => [0,1,2,3,4,5,10,15,20],
423
+ :completion_criteria => {:show_letters => false, :levels_column_id => 3000},
424
+ :requirements => []
425
+ )
426
+
363
427
  Osm::Badge::Data.new(
364
- :badge => Osm::StagedBadge.new(:osm_key => 'nightsaway'),
365
- :requirements => {'a_01' => 7, 'y_01' => '7', 'custom_26695' => ''},
366
- :completed => 5,
428
+ :badge => staged_count,
429
+ :requirements => {3000 => 7},
430
+ :due => 5,
367
431
  ).started.should == 10
368
432
  Osm::Badge::Data.new(
369
- :badge => Osm::StagedBadge.new(:osm_key => 'hikes'),
370
- :requirements => {'a_01' => 3, 'y_01' => '3', 'custom_26695' => ''},
371
- :completed => 1,
372
- ).started.should == 5
433
+ :badge => staged_count,
434
+ :requirements => {3000 => 3},
435
+ :due => 3,
436
+ ).started.should == 0
373
437
  end
374
438
 
375
439
  describe "Using the OSM API" do
@@ -377,12 +441,32 @@ describe "Badge" do
377
441
  describe "Get Badges" do
378
442
 
379
443
  before :each do
380
- @data = {
381
- "badgeOrder" => "badge",
382
- "structure" => {
383
- "badge" => [
444
+ @badge_data = {
445
+ 'badgeOrder' => '123_0',
446
+ 'details' => {
447
+ '123_0' => {
448
+ 'badge_id' => '123',
449
+ 'badge_id_version' => '123_0',
450
+ 'badge_identifier' => '123_0',
451
+ 'badge_order' => '4',
452
+ 'badge_version' => '0',
453
+ 'config' => '{"numModulesRequired":1}',
454
+ 'description' => 'b_req_notes',
455
+ 'group_name' => '',
456
+ 'lastupdated' => '2014-09-14 02:32:05',
457
+ 'latest' => '1',
458
+ 'name' => 'b_name',
459
+ 'picture' => 'path/to/image.gif',
460
+ 'portal_config' => '{"position":{"x":58,"y":282,"w":20,"h":20,"r":6}}',
461
+ 'sharing' => 'default-locked',
462
+ 'shortname' => '00',
463
+ 'userid' => '0',
464
+ }
465
+ },
466
+ 'structure' => {
467
+ '123_0' => [
384
468
  {
385
- "rows" => [
469
+ 'rows' => [
386
470
  {"name" => "First name","field" => "firstname","width" => "120px"},
387
471
  {"name" => "Last name","field" => "lastname","width" => "120px"},
388
472
  {"name" => "Done","field" => "completed","width" => "70px","formatter" => "doneFormatter"},
@@ -390,222 +474,125 @@ describe "Badge" do
390
474
  ],
391
475
  "numactivities" => "23",
392
476
  "noscroll" => true
393
- },{
394
- "rows" => [
395
- {"name" => "r_name","field" => "r_field","width" => "80px","formatter" => "cellFormatter","tooltip" => "r_description","editable" => "true"}
396
- ]
477
+ },{
478
+ 'rows' => [
479
+ {"name" => "r_name","field" => "2345","width" => "80px","formatter" => "cellFormatter","tooltip" => "r_description","editable" => "true","module"=>"a"}
480
+ ]
397
481
  }
398
482
  ],
399
- },
400
- "details" => {
401
- "badge" => {
402
- "shortname" => "badge",
403
- "name" => "b_name",
404
- "description" => "b_req_notes",
405
- "picture" => "badge.png",
406
- "config" => "{\"sectionsneeded\":\"1\",\"totalneeded\":\"2\",\"sections\":{\"a\":\"1\"}}",
407
- "order" => "1",
408
- "groupname" => nil,
409
- "status" => "3",
410
- "userid" => "0",
411
- "table" => "table"
412
- },
413
- },
414
- "stock" => {"sectionid" => "1","badge" => "3"}
483
+ }
415
484
  }
416
- @data = @data.to_json
417
- end
418
-
419
- it "Core" do
420
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=getInitialBadges&type=core&sectionid=1&section=beavers&termid=2", :body => @data, :content_type => 'application/json')
421
- Osm::Term.stub(:get_current_term_for_section){ Osm::Term.new(:id => 2) }
422
-
423
- badges = Osm::CoreBadge.get_badges_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers))
424
- badges.size.should == 1
425
- badge = badges[0]
426
- badge.name.should == 'b_name'
427
- badge.requirement_notes.should == 'b_req_notes'
428
- badge.osm_key.should == 'badge'
429
- badge.osm_long_key.should == 'table'
430
- badge.sections_needed.should == 1
431
- badge.total_needed.should == 2
432
- badge.needed_from_section.should == {'a' => 1}
433
- badge.requirements.size.should == 1
434
- requirement = badge.requirements[0]
435
- requirement.name.should == 'r_name'
436
- requirement.description.should == 'r_description'
437
- requirement.field.should == 'r_field'
438
- requirement.editable.should be_true
439
- requirement.badge.osm_key.should == 'badge'
440
- end
441
-
442
- it "Challenge" do
443
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=getInitialBadges&type=challenge&sectionid=1&section=beavers&termid=2", :body => @data, :content_type => 'application/json')
444
- Osm::Term.stub(:get_current_term_for_section){ Osm::Term.new(:id => 2) }
445
-
446
- badges = Osm::ChallengeBadge.get_badges_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers))
447
- badges.size.should == 1
448
- badge = badges[0]
449
- badge.name.should == 'b_name'
450
- badge.requirement_notes.should == 'b_req_notes'
451
- badge.osm_key.should == 'badge'
452
- badge.osm_long_key.should == 'table'
453
- badge.sections_needed.should == 1
454
- badge.total_needed.should == 2
455
- badge.needed_from_section.should == {'a' => 1}
456
- badge.requirements.size.should == 1
457
- requirement = badge.requirements[0]
458
- requirement.name.should == 'r_name'
459
- requirement.description.should == 'r_description'
460
- requirement.field.should == 'r_field'
461
- requirement.editable.should be_true
462
- requirement.badge.osm_key.should == 'badge'
463
- end
464
-
465
- it "Staged" do
466
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=getInitialBadges&type=staged&sectionid=1&section=beavers&termid=2", :body => @data, :content_type => 'application/json')
467
- Osm::Term.stub(:get_current_term_for_section){ Osm::Term.new(:id => 2) }
468
-
469
- badges = Osm::StagedBadge.get_badges_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers))
470
- badges.size.should == 1
471
- badge = badges[0]
472
- badge.name.should == 'b_name'
473
- badge.requirement_notes.should == 'b_req_notes'
474
- badge.osm_key.should == 'badge'
475
- badge.osm_long_key.should == 'table'
476
- badge.sections_needed.should == 1
477
- badge.total_needed.should == 2
478
- badge.needed_from_section.should == {'a' => 1}
479
- badge.requirements.size.should == 1
480
- requirement = badge.requirements[0]
481
- requirement.name.should == 'r_name'
482
- requirement.description.should == 'r_description'
483
- requirement.field.should == 'r_field'
484
- requirement.editable.should be_true
485
- requirement.badge.osm_key.should == 'badge'
486
- end
487
-
488
- it "Activity" do
489
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=getInitialBadges&type=activity&sectionid=1&section=beavers&termid=2", :body => @data, :content_type => 'application/json')
490
- Osm::Term.stub(:get_current_term_for_section){ Osm::Term.new(:id => 2) }
491
-
492
- badges = Osm::ActivityBadge.get_badges_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers))
493
- badges.size.should == 1
494
- badge = badges[0]
495
- badge.name.should == 'b_name'
496
- badge.requirement_notes.should == 'b_req_notes'
497
- badge.osm_key.should == 'badge'
498
- badge.osm_long_key.should == 'table'
499
- badge.sections_needed.should == 1
500
- badge.total_needed.should == 2
501
- badge.needed_from_section.should == {'a' => 1}
502
- badge.requirements.size.should == 1
503
- requirement = badge.requirements[0]
504
- requirement.name.should == 'r_name'
505
- requirement.description.should == 'r_description'
506
- requirement.field.should == 'r_field'
507
- requirement.editable.should be_true
508
- requirement.badge.osm_key.should == 'badge'
485
+ @badge_data = @badge_data.to_json
486
+
487
+ @module_data = {'items' => [
488
+ {
489
+ 'badge_id' => '123',
490
+ 'badge_version' => '0',
491
+ 'module_id' => '234',
492
+ 'module_letter' => 'a',
493
+ 'num_required' => '',
494
+ 'custom_columns' => '',
495
+ 'completed_into_column_id' => '',
496
+ 'numeric_into_column_id' => '',
497
+ 'add_column_id_to_numeric' => '',
498
+ },
499
+ ]}
500
+ @module_data = @module_data.to_json
509
501
  end
510
502
 
511
- it "For a different section type" do
512
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=getInitialBadges&type=activity&sectionid=1&section=cubs&termid=2", :body => @data, :content_type => 'application/json')
513
- Osm::Term.stub(:get_current_term_for_section){ Osm::Term.new(:id => 2) }
514
-
515
- badges = Osm::ActivityBadge.get_badges_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), :cubs)
516
- badges.size.should == 1
503
+ urls = {
504
+ Osm::CoreBadge => 'https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=getBadgeStructureByType&section=beavers&type_id=4&term_id=2&section_id=1',
505
+ Osm::ChallengeBadge => 'https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=getBadgeStructureByType&section=beavers&type_id=1&term_id=2&section_id=1',
506
+ Osm::StagedBadge => 'https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=getBadgeStructureByType&section=beavers&type_id=3&term_id=2&section_id=1',
507
+ Osm::ActivityBadge => 'https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=getBadgeStructureByType&section=beavers&type_id=2&term_id=2&section_id=1',
508
+ }
509
+ urls.each do |type, url|
510
+ it type.type.to_s.titleize do
511
+ FakeWeb.register_uri(:post, url, :body => @badge_data, :content_type => 'application/json')
512
+ FakeWeb.register_uri(:post, 'https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=_getModuleDetails', :body => @module_data, :content_type => 'application/json')
513
+ Osm::Term.stub(:get_current_term_for_section){ Osm::Term.new(:id => 2) }
514
+
515
+ badges = type.get_badges_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers))
516
+ badges.size.should == 1
517
+ badge = badges[0]
518
+ badge.name.should == 'b_name'
519
+ badge.requirement_notes.should == 'b_req_notes'
520
+ badge.identifier.should == '123_0'
521
+ badge.id.should == 123
522
+ badge.version.should == 0
523
+ badge.latest.should be_true
524
+ badge.user_id.should == 0
525
+ badge.sharing.should == :default_locked
526
+ badge.requirements.size.should == 1
527
+ badge.valid?.should be_true
528
+ requirement = badge.requirements[0]
529
+ requirement.name.should == 'r_name'
530
+ requirement.description.should == 'r_description'
531
+ requirement.field.should == 2345
532
+ requirement.module_letter.should == 'a'
533
+ requirement.editable.should be_true
534
+ requirement.badge.should == badge
535
+ requirement.valid?.should be_true
536
+ badge.completion_criteria.should == {
537
+ :min_modules_required => 1,
538
+ :fields_required => [],
539
+ :badges_required => [],
540
+ :min_requirements_completed => 0,
541
+ :requires => nil,
542
+ :add_columns_to_module => nil,
543
+ :levels_column => nil,
544
+ :show_letters => false,
545
+ :modules => [
546
+ {
547
+ :badge_id => 123,
548
+ :badge_version => 0,
549
+ :module_id => 234,
550
+ :module_letter => 'a',
551
+ :min_required => 0,
552
+ :custom_columns => 0,
553
+ :completed_into_column => nil,
554
+ :numeric_into_column => nil,
555
+ :add_column_id_to_numeric => nil,
556
+ }
557
+ ]
558
+ }
559
+ end
517
560
  end
518
561
 
519
562
  end
520
563
 
521
564
 
522
- describe "Get badge data for a section" do
523
-
524
- before :each do
525
- @data = {
526
- 'identifier' => 'scoutid',
527
- 'items' => [{
528
- 'scoutid' => 3,
529
- 'firstname' => 'fn',
530
- 'lastname' => 'ln',
531
- 'sid' => '',
532
- 'completed' => '2',
533
- 'awarded' => '1',
534
- 'awardeddate' => '2000-01-02',
535
- 'patrolid' => 4,
536
- 'a_1' => 'd',
537
- }]
538
- }
539
- @data = @data.to_json
540
- end
541
-
542
- it "Core badge" do
543
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?termid=2&type=core&section=beavers&c=badge&sectionid=1", :body => @data, :content_type => 'application/json')
544
- datas = Osm::CoreBadge.new(:osm_key => 'badge').get_data_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
545
- datas.size.should == 1
546
- data = datas[0]
547
- data.member_id.should == 3
548
- data.first_name.should == 'fn'
549
- data.last_name.should == 'ln'
550
- data.completed.should == 2
551
- data.awarded.should == 1
552
- data.awarded_date.should == Date.new(2000, 1, 2)
553
- data.requirements.should == {'a_1' => 'd'}
554
- data.section_id.should == 1
555
- data.badge.osm_key.should == 'badge'
556
- end
557
-
558
- it "Challenge badge" do
559
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?termid=2&type=challenge&section=beavers&c=badge&sectionid=1", :body => @data, :content_type => 'application/json')
560
- datas = Osm::ChallengeBadge.new(:osm_key => 'badge').get_data_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
561
- datas.size.should == 1
562
- data = datas[0]
563
- data.member_id.should == 3
564
- data.first_name.should == 'fn'
565
- data.last_name.should == 'ln'
566
- data.completed.should == 2
567
- data.awarded.should == 1
568
- data.awarded_date.should == Date.new(2000, 1, 2)
569
- data.requirements.should == {'a_1' => 'd'}
570
- data.section_id.should == 1
571
- data.badge.osm_key.should == 'badge'
572
- end
573
-
574
- it "Staged badge" do
575
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?termid=2&type=staged&section=beavers&c=badge&sectionid=1", :body => @data, :content_type => 'application/json')
576
- datas = Osm::StagedBadge.new(:osm_key => 'badge').get_data_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
577
- datas.size.should == 1
578
- data = datas[0]
579
- data.member_id.should == 3
580
- data.first_name.should == 'fn'
581
- data.last_name.should == 'ln'
582
- data.completed.should == 2
583
- data.awarded.should == 1
584
- data.awarded_date.should == Date.new(2000, 1, 2)
585
- data.requirements.should == {'a_1' => 'd'}
586
- data.section_id.should == 1
587
- data.badge.osm_key.should == 'badge'
588
- end
589
-
590
- it "Activity badge" do
591
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?termid=2&type=activity&section=beavers&c=badge&sectionid=1", :body => @data, :content_type => 'application/json')
592
- datas = Osm::ActivityBadge.new(:osm_key => 'badge').get_data_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
593
- datas.size.should == 1
594
- data = datas[0]
595
- data.member_id.should == 3
596
- data.first_name.should == 'fn'
597
- data.last_name.should == 'ln'
598
- data.completed.should == 2
599
- data.awarded.should == 1
600
- data.awarded_date.should == Date.new(2000, 1, 2)
601
- data.requirements.should == {'a_1' => 'd'}
602
- data.section_id.should == 1
603
- data.badge.osm_key.should == 'badge'
604
- end
605
-
565
+ it "Get badge data for a section" do
566
+ data = {
567
+ 'identifier' => 'scoutid',
568
+ 'items' => [{
569
+ 'scoutid' => '3',
570
+ 'firstname' => 'fn',
571
+ 'lastname' => 'ln',
572
+ 'completed' => '2',
573
+ 'awarded' => '1',
574
+ 'awardeddate' => '2000-01-02',
575
+ '2345' => 'd',
576
+ }]
577
+ }
578
+ data = data.to_json
579
+
580
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=getBadgeRecords&term_id=2&section=beavers&badge_id=123&section_id=1&badge_version=0", :body => data, :content_type => 'application/json')
581
+ datas = Osm::CoreBadge.new(:id => 123, :version => 0).get_data_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
582
+ datas.size.should == 1
583
+ data = datas[0]
584
+ data.member_id.should == 3
585
+ data.first_name.should == 'fn'
586
+ data.last_name.should == 'ln'
587
+ data.due.should == 2
588
+ data.awarded.should == 1
589
+ data.awarded_date.should == Date.new(2000, 1, 2)
590
+ data.requirements.should == {2345 => 'd'}
591
+ data.section_id.should == 1
592
+ data.badge.id.should == 123
606
593
  end
607
594
 
608
- describe "Update badge data for a section/member" do
595
+ describe "Update badge data in OSM" do
609
596
 
610
597
  before :each do
611
598
  @update_post_data = {
@@ -613,288 +600,221 @@ describe "Badge" do
613
600
  'token' => @CONFIGURATION[:api][:osm][:token],
614
601
  'userid' => 'user_id',
615
602
  'secret' => 'secret',
616
- 'action' => 'updatesingle',
617
- 'id' => 1,
618
- 'col' => 'a',
619
- 'value' => '2',
620
- 'chal' => 'badge',
621
- 'sectionid' => 2,
603
+ 'scoutid' => 1,
604
+ 'section_id' => 2,
605
+ 'badge_id' => 123,
606
+ 'badge_version' => 0,
607
+ 'field' => 2345,
608
+ 'value' => '2'
622
609
  }
623
- @update_body_data = {'sid' => '1', 'a' => '2', 'b' => '2'}
610
+ @update_body_data = {'scoutid' => '1', '2345' => '2', 'completed' => '0', 'awarded' => '0', 'firstname' => 'fn', 'lastname' => 'ln'}
624
611
 
625
- @awarded_post_data = {
626
- 'apiid' => @CONFIGURATION[:api][:osm][:id],
627
- 'token' => @CONFIGURATION[:api][:osm][:token],
628
- 'userid' => 'user_id',
629
- 'secret' => 'secret',
630
- 'dateAwarded' => '2000-01-02',
631
- 'sectionid' => 2,
632
- 'section' => :beavers,
633
- 'chal' => 'badge',
634
- 'stagedLevel' => 1,
635
- 'due' => :awarded,
636
- }
637
- @awarded_body_data = [{'sid'=>'1', 'awarded'=>'1', 'awardeddate'=>'2000-01-02'}]
638
- @awarded_url = "https://www.onlinescoutmanager.co.uk/challenges.php?action=award"
639
- end
640
-
641
- it "Core badge" do
642
- data = Osm::Badge::Data.new(
612
+ @data = Osm::Badge::Data.new(
643
613
  :member_id => 1,
644
614
  :first_name => 'fn',
645
615
  :last_name => 'ln',
646
616
  :section_id => 2,
647
- :requirements => {'a' => '1', 'b' => '2'},
617
+ :requirements => {2345 => '1', 6789 => '2'},
648
618
  :badge => Osm::CoreBadge.new(
649
- :osm_key => 'badge',
619
+ :id => 123,
620
+ :version => 0,
650
621
  :requirements => [
651
- Osm::Badge::Requirement.new(:field => 'a', :editable => true),
652
- Osm::Badge::Requirement.new(:field => 'b', :editable => true),
622
+ Osm::Badge::Requirement.new(:field => 2345, :editable => true),
623
+ Osm::Badge::Requirement.new(:field => 6789, :editable => true),
653
624
  ]),
654
- :completed => 0,
625
+ :due => 0,
655
626
  )
627
+ end
656
628
 
657
- update_url = "https://www.onlinescoutmanager.co.uk/challenges.php?type=core&section=beavers"
658
- HTTParty.should_receive(:post).with(update_url, {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
659
- HTTParty.should_receive(:post).with(@awarded_url, {:body => @awarded_post_data.merge({'type' => :core})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@awarded_body_data.to_json}) }
629
+ it "Success (requirmeent, due & awarded)" do
630
+ date = Date.new(2000, 1, 2)
631
+ HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=updateSingleRecord', {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
660
632
  Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
661
-
662
- data.requirements['a'] = '2'
663
- data.awarded = 1
664
- data.awarded_date = Date.new(2000, 1, 2)
665
- data.update(@api).should be_true
633
+ @data.should_receive(:mark_awarded).with(@api, date, 1) { true }
634
+ @data.should_receive(:mark_due).with(@api, 1) { true }
635
+
636
+ @data.requirements[2345] = '2'
637
+ @data.due = 1
638
+ @data.awarded = 1
639
+ @data.awarded_date = date
640
+ @data.update(@api).should be_true
666
641
  end
667
642
 
668
- it "Challenge badge" do
669
- data = Osm::Badge::Data.new(
670
- :member_id => 1,
671
- :first_name => 'fn',
672
- :last_name => 'ln',
673
- :section_id => 2,
674
- :requirements => {'a' => '1', 'b' => '2'},
675
- :badge => Osm::ChallengeBadge.new(
676
- :osm_key => 'badge',
677
- :requirements => [
678
- Osm::Badge::Requirement.new(:field => 'a', :editable => true),
679
- Osm::Badge::Requirement.new(:field => 'b', :editable => true),
680
- ]),
681
- :completed => 0,
682
- )
683
-
684
- update_url = "https://www.onlinescoutmanager.co.uk/challenges.php?type=challenge&section=beavers"
685
- HTTParty.should_receive(:post).with(update_url, {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
686
- HTTParty.should_receive(:post).with(@awarded_url, {:body => @awarded_post_data.merge({'type' => :challenge})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@awarded_body_data.to_json}) }
643
+ it "Success (just requirement)" do
644
+ date = Date.new(2000, 1, 2)
645
+ HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=updateSingleRecord', {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
687
646
  Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
647
+ @data.should_not_receive(:mark_awarded)
648
+ @data.should_not_receive(:mark_due)
688
649
 
689
- data.requirements['a'] = '2'
690
- data.awarded = 1
691
- data.awarded_date = Date.new(2000, 1, 2)
692
- data.update(@api).should be_true
650
+ @data.requirements[2345] = '2'
651
+ @data.update(@api).should be_true
693
652
  end
694
653
 
695
- it "Staged badge" do
696
- data = Osm::Badge::Data.new(
697
- :member_id => 1,
698
- :first_name => 'fn',
699
- :last_name => 'ln',
700
- :section_id => 2,
701
- :requirements => {'a' => '1', 'b' => '2'},
702
- :badge => Osm::StagedBadge.new(
703
- :osm_key => 'badge',
704
- :requirements => [
705
- Osm::Badge::Requirement.new(:field => 'a', :editable => true),
706
- Osm::Badge::Requirement.new(:field => 'b', :editable => true),
707
- ]),
708
- :completed => 0,
709
- )
710
-
711
- update_url = "https://www.onlinescoutmanager.co.uk/challenges.php?type=staged&section=beavers"
712
- HTTParty.should_receive(:post).with(update_url, {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
713
- HTTParty.should_receive(:post).with(@awarded_url, {:body => @awarded_post_data.merge({'type' => :staged})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@awarded_body_data.to_json}) }
654
+ it "Success (just due)" do
655
+ date = Date.new(2000, 1, 2)
656
+ HTTParty.should_not_receive(:post)
714
657
  Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
658
+ @data.should_not_receive(:mark_awarded)
659
+ @data.should_receive(:mark_due).with(@api, 1) { true }
715
660
 
716
- data.requirements['a'] = '2'
717
- data.awarded = 1
718
- data.awarded_date = Date.new(2000, 1, 2)
719
- data.update(@api).should be_true
661
+ @data.due = 1
662
+ @data.update(@api).should be_true
720
663
  end
721
664
 
722
- it "Activity badge" do
723
- data = Osm::Badge::Data.new(
724
- :member_id => 1,
725
- :first_name => 'fn',
726
- :last_name => 'ln',
727
- :section_id => 2,
728
- :requirements => {'a' => '1', 'b' => '2'},
729
- :badge => Osm::ActivityBadge.new(
730
- :osm_key => 'badge',
731
- :requirements => [
732
- Osm::Badge::Requirement.new(:field => 'a', :editable => true),
733
- Osm::Badge::Requirement.new(:field => 'b', :editable => true),
734
- ]),
735
- :completed => 0,
736
- )
737
-
738
- update_url = "https://www.onlinescoutmanager.co.uk/challenges.php?type=activity&section=beavers"
739
- HTTParty.should_receive(:post).with(update_url, {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
740
- HTTParty.should_receive(:post).with(@awarded_url, {:body => @awarded_post_data.merge({'type' => :activity})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@awarded_body_data.to_json}) }
665
+ it "Success (just awarded)" do
666
+ date = Date.new(2000, 1, 2)
667
+ HTTParty.should_not_receive(:post)
741
668
  Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
669
+ @data.should_receive(:mark_awarded).with(@api, date, 1) { true }
670
+ @data.should_not_receive(:mark_due).with(@api, 1) { true }
742
671
 
743
- data.requirements['a'] = '2'
744
- data.awarded = 1
745
- data.awarded_date = Date.new(2000, 1, 2)
746
- data.update(@api).should be_true
672
+ @data.awarded = 1
673
+ @data.awarded_date = date
674
+ @data.update(@api).should be_true
747
675
  end
748
676
 
749
- end
750
-
751
-
752
- describe "Mark badge awarded" do
753
-
754
- before :each do
755
- @awarded_post_data = {
756
- 'apiid' => @CONFIGURATION[:api][:osm][:id],
757
- 'token' => @CONFIGURATION[:api][:osm][:token],
758
- 'userid' => 'user_id',
759
- 'secret' => 'secret',
760
- 'dateAwarded' => '2000-01-02',
761
- 'sectionid' => 2,
762
- 'section' => :beavers,
763
- 'chal' => 'badge',
764
- 'stagedLevel' => 1,
765
- 'due' => :awarded,
766
- }
767
- @awarded_body_data = [{'sid'=>'1', 'awarded'=>'1', 'awardeddate'=>'2000-01-02'}]
768
- @awarded_url = "https://www.onlinescoutmanager.co.uk/challenges.php?action=award"
677
+ it "Failed (requirement)" do
678
+ date = Date.new(2000, 1, 2)
679
+ @update_body_data['2345'] = '1'
680
+ HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=updateSingleRecord', {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
681
+ Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
682
+ @data.should_receive(:mark_awarded).with(@api, date, 1) { true }
683
+ @data.should_receive(:mark_due).with(@api, 1) { true }
684
+
685
+ @data.requirements[2345] = '2'
686
+ @data.due = 1
687
+ @data.awarded = 1
688
+ @data.awarded_date = date
689
+ @data.update(@api).should be_false
769
690
  end
770
691
 
771
- it "Core badge" do
772
- data = Osm::Badge::Data.new(
773
- :member_id => 1,
774
- :section_id => 2,
775
- :badge => Osm::CoreBadge.new(
776
- :osm_key => 'badge',
777
- )
778
- )
779
-
780
- HTTParty.should_receive(:post).with(@awarded_url, {:body => @awarded_post_data.merge({'type' => :core})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@awarded_body_data.to_json}) }
692
+ it "Failed (due)" do
693
+ date = Date.new(2000, 1, 2)
694
+ HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=updateSingleRecord', {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
781
695
  Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
782
-
783
- data.mark_awarded(@api, Date.new(2000, 1, 2), 1).should be_true
696
+ @data.should_receive(:mark_awarded).with(@api, date, 1) { true }
697
+ @data.should_receive(:mark_due).with(@api, 1) { false }
698
+
699
+ @data.requirements[2345] = '2'
700
+ @data.due = 1
701
+ @data.awarded = 1
702
+ @data.awarded_date = date
703
+ @data.update(@api).should be_false
784
704
  end
785
705
 
786
- it "Challenge badge" do
787
- data = Osm::Badge::Data.new(
788
- :member_id => 1,
789
- :section_id => 2,
790
- :badge => Osm::ChallengeBadge.new(
791
- :osm_key => 'badge',
792
- )
793
- )
794
-
795
- HTTParty.should_receive(:post).with(@awarded_url, {:body => @awarded_post_data.merge({'type' => :challenge})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@awarded_body_data.to_json}) }
706
+ it "Failed (awarded)" do
707
+ date = Date.new(2000, 1, 2)
708
+ HTTParty.should_receive(:post).with('https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=updateSingleRecord', {:body => @update_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@update_body_data.to_json}) }
796
709
  Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
797
-
798
- data.mark_awarded(@api, Date.new(2000, 1, 2), 1).should be_true
710
+ @data.should_receive(:mark_awarded).with(@api, date, 1) { false }
711
+ @data.should_receive(:mark_due).with(@api, 1) { true }
712
+
713
+ @data.requirements[2345] = '2'
714
+ @data.due = 1
715
+ @data.awarded = 1
716
+ @data.awarded_date = date
717
+ @data.update(@api).should be_false
799
718
  end
800
719
 
801
- it "Staged badge" do
802
- data = Osm::Badge::Data.new(
803
- :member_id => 1,
804
- :section_id => 2,
805
- :badge => Osm::StagedBadge.new(
806
- :osm_key => 'badge',
807
- )
808
- )
720
+ end
809
721
 
810
- @awarded_body_data[0].merge!({'awarded' => '4'})
811
- HTTParty.should_receive(:post).with(@awarded_url, {:body => @awarded_post_data.merge({'type' => :staged, 'stagedLevel' => 4})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@awarded_body_data.to_json}) }
812
- Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
813
722
 
814
- data.mark_awarded(@api, Date.new(2000, 1, 2), 4).should be_true
815
- end
723
+ it "Mark badge awarded" do
816
724
 
817
- it "Activity badge" do
818
- data = Osm::Badge::Data.new(
819
- :member_id => 1,
820
- :section_id => 2,
821
- :badge => Osm::ActivityBadge.new(
822
- :osm_key => 'badge',
823
- )
725
+ awarded_post_data = {
726
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
727
+ 'token' => @CONFIGURATION[:api][:osm][:token],
728
+ 'userid' => 'user_id',
729
+ 'secret' => 'secret',
730
+ 'date' => '2000-01-02',
731
+ 'sectionid' => 2,
732
+ 'entries' => '[{"badge_id":"123","badge_version":"0","scout_id":"1","level":"1"}]',
733
+ }
734
+ awarded_body_data = {'scoutid'=>'1', 'completed'=>'1', 'awarded' => '1', 'awardeddate'=>'2000-01-02', 'firstname' => 'fn', 'lastname' => 'ln'}
735
+ awarded_url = "https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=awardBadge"
736
+
737
+ data = Osm::Badge::Data.new(
738
+ :member_id => 1,
739
+ :section_id => 2,
740
+ :badge => Osm::CoreBadge.new(
741
+ :id => 123,
742
+ :version => 0
824
743
  )
744
+ )
825
745
 
826
- HTTParty.should_receive(:post).with(@awarded_url, {:body => @awarded_post_data.merge({'type' => :activity})}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>@awarded_body_data.to_json}) }
827
- Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
828
-
829
- data.mark_awarded(@api, Date.new(2000, 1, 2), 1).should be_true
830
- end
746
+ HTTParty.should_receive(:post).with(awarded_url, {:body => awarded_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>awarded_body_data.to_json}) }
747
+ Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
831
748
 
749
+ data.mark_awarded(@api, Date.new(2000, 1, 2), 1).should be_true
832
750
  end
833
751
 
752
+ it "Mark badge due" do
753
+
754
+ awarded_post_data = {
755
+ 'apiid' => @CONFIGURATION[:api][:osm][:id],
756
+ 'token' => @CONFIGURATION[:api][:osm][:token],
757
+ 'userid' => 'user_id',
758
+ 'secret' => 'secret',
759
+ 'section_id' => 2,
760
+ 'badge_id' => 123,
761
+ 'badge_version' => 0,
762
+ 'scoutid' => 1,
763
+ 'level' => 1
764
+ }
765
+ awarded_body_data = {'scoutid'=>'1', 'completed'=>'1', 'awarded' => '1', 'awardeddate'=>'2000-01-02', 'firstname' => 'fn', 'lastname' => 'ln'}
766
+ awarded_url = "https://www.onlinescoutmanager.co.uk/ext/badges/records/?action=overrideCompletion"
767
+
768
+ data = Osm::Badge::Data.new(
769
+ :member_id => 1,
770
+ :section_id => 2,
771
+ :badge => Osm::CoreBadge.new(
772
+ :id => 123,
773
+ :version => 0
774
+ )
775
+ )
834
776
 
835
- describe "Get summary data for a section" do
836
-
837
- before :each do
838
- @data = {
839
- 'items' => [
840
- {
841
- 'firstname' => 'First',
842
- 'lastname' => 'Last',
843
- 'badge_none' => '',
844
- 'badge_earnt' => '2000-01-02',
845
- }
846
- ]
847
- }
848
- @data = @data.to_json
849
- end
850
-
851
- it "Core badge" do
852
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=summary&section=beavers&sectionid=1&termid=2&type=core", :body => @data, :content_type => 'application/json')
853
- summary = Osm::CoreBadge.get_summary_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
854
- summary.size.should == 1
855
- summary[0].should == {
856
- :first_name => 'First',
857
- :last_name => 'Last',
858
- 'badge_none' => '',
859
- 'badge_earnt' => '2000-01-02',
860
- }
861
- end
862
-
863
- it "Challenge badge" do
864
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=summary&section=beavers&sectionid=1&termid=2&type=challenge", :body => @data, :content_type => 'application/json')
865
- summary = Osm::ChallengeBadge.get_summary_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
866
- summary.size.should == 1
867
- summary[0].should == {
868
- :first_name => 'First',
869
- :last_name => 'Last',
870
- 'badge_none' => '',
871
- 'badge_earnt' => '2000-01-02',
872
- }
873
- end
777
+ HTTParty.should_receive(:post).with(awarded_url, {:body => awarded_post_data}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>awarded_body_data.to_json}) }
778
+ Osm::Section.stub(:get) { Osm::Section.new(:id => 2, :type => :beavers) }
874
779
 
875
- it "Staged badge" do
876
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=summary&section=beavers&sectionid=1&termid=2&type=staged", :body => @data, :content_type => 'application/json')
877
- summary = Osm::StagedBadge.get_summary_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
878
- summary.size.should == 1
879
- summary[0].should == {
880
- :first_name => 'First',
881
- :last_name => 'Last',
882
- 'badge_none' => '',
883
- 'badge_earnt' => '2000-01-02',
884
- }
885
- end
780
+ data.mark_due(@api, 1).should be_true
781
+ end
886
782
 
887
- it "Activity badge" do
888
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=summary&section=beavers&sectionid=1&termid=2&type=activity", :body => @data, :content_type => 'application/json')
889
- summary = Osm::ActivityBadge.get_summary_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
890
- summary.size.should == 1
891
- summary[0].should == {
892
- :first_name => 'First',
893
- :last_name => 'Last',
894
- 'badge_none' => '',
895
- 'badge_earnt' => '2000-01-02',
896
- }
897
- end
783
+ it "Get summary data for a section" do
784
+
785
+ data = {
786
+ 'identifier' => 'scout_id',
787
+ 'items' => [
788
+ {
789
+ 'firstname' => 'First',
790
+ 'lastname' => 'Last',
791
+ 'scout_id' => 1,
792
+ '92_0' => nil,
793
+ '93_0' => '',
794
+ '94_0' => 'Started',
795
+ '95_0' => 'Due',
796
+ '96_0' => 'Awarded',
797
+ '97_0' => 'Awarded Lvl 2',
798
+ '98_0' => 'Due Lvl 3',
799
+ }
800
+ ]
801
+ }
802
+ data = data.to_json
803
+
804
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/ext/badges/records/summary/?action=get&mode=verbose&section=beavers&sectionid=1&termid=2", :body => data, :content_type => 'application/json')
805
+ summary = Osm::Badge.get_summary_for_section(@api, Osm::Section.new(:id => 1, :type => :beavers), 2)
806
+ summary.size.should == 1
807
+ summary[0].should == {
808
+ :first_name => 'First',
809
+ :last_name => 'Last',
810
+ :name => 'First Last',
811
+ :member_id => 1,
812
+ '94_0' => :started,
813
+ '95_0' => :due,
814
+ '96_0' => :awarded,
815
+ '97_0' => :awarded,
816
+ '98_0' => :due,
817
+ }
898
818
  end
899
819
 
900
820
  end