spec/osm/badges_spec.rb in osm-1.2.14 vs spec/osm/badges_spec.rb in osm-1.2.15.dev
- old
+ new
@@ -6,105 +6,146 @@
describe "Using the OSM API" do
it "Get due badges" do
data = {
+ 'includeStock' => true,
+ 'count' => 2,
+ 'badgesToBuy' => 0,
+ 'description' => {
+ '93_0' => {
+ 'badge_identifier' => '93_0',
+ 'msg' => 'You do not have enough badges!',
+ 'name' => 'Participation',
+ 'picture' => '',
+ 'typeLabel' => 'Staged',
+ 'type_id' => 3
+ },
+ '145_0' => {
+ 'badge_identifier' => '145_0',
+ 'name' => 'Badge Name',
+ 'picture' => '',
+ 'typeLabel' => 'Activity',
+ 'type_id' => 2
+ },
+ },
'pending' => {
- 'badge_name' => [
+ '93_0' => [
{
- 'scoutid' => '1',
+ 'badge_id' => '93',
+ 'badge_identifier' => '93_0',
+ 'badge_version' => '0',
+ 'completed' => '2',
+ 'current_stock' => '20',
+ 'extra' => 'Lvl 2',
'firstname' => 'John',
+ 'label' => 'Staged',
'lastname' => 'Doe',
- 'level' => '',
- 'extra' => '',
- }
- ],
- 'staged_staged_participation' => [{
- 'scoutid' => '2',
+ 'name' => 'Participation',
+ 'patrolid' => '1502',
+ 'pic' => true,
+ 'picture' => '',
+ 'scout_id' => '1',
+ 'sid' => '1',
+ 'type_id' => '3',
+ },
+ {
+ 'badge_id' => '93',
+ 'badge_identifier' => '93_0',
+ 'badge_version' => '0',
+ 'completed' => '2',
+ 'current_stock' => '20',
+ 'extra' => 'Lvl 2',
'firstname' => 'Jane',
+ 'label' => 'Staged',
'lastname' => 'Doe',
- 'level' => '2',
- 'extra' => 'Lvl 2'
- }, {
- 'scoutid' => '1',
- 'firstname' => 'John',
- 'lastname' => 'Doe',
- 'level' => '2',
- 'extra' => 'Lvl 2'
- }
- ]
- },
- 'description' => {
- 'badge_name' => {
+ 'name' => 'Participation',
+ 'patrolid' => '1502',
+ 'pic' => true,
+ 'picture' => '',
+ 'scout_id' => '2',
+ 'sid' => '2',
+ 'type_id' => '3',
+ },
+ ],
+ '145_0' => [{
+ 'badge_id' => '145',
+ 'badge_identifier' => '145_0',
+ 'badge_version' => '0',
+ 'completed' => '1',
+ 'current_stock' => '10',
+ 'firstname' => 'John',
+ 'label' => 'Activity',
+ 'lastname' => 'Doe',
'name' => 'Badge Name',
- 'section' => 'cubs',
- 'type' => 'activity',
- 'badge' => 'badge_name'
- },
- 'staged_staged_participation' => {
- 'name' => 'Participation',
- 'section' => 'staged',
- 'type' => 'staged',
- 'badge' => 'participation'
- }
- }
+ 'patrolid' => '1502',
+ 'pic' => true,
+ 'picture' => '',
+ 'scout_id' => '1',
+ 'sid' => '1',
+ 'type_id' => '2',
+ }],
+ },
}
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=outstandingBadges§ion=cubs§ionid=1&termid=2", :body => data.to_json, :content_type => 'application/json')
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/ext/badges/due/?action=get§ion=cubs§ionid=1&termid=2", :body => data.to_json, :content_type => 'application/json')
db = Osm::Badges.get_due_badges(@api, Osm::Section.new(:id => 1, :type => :cubs), 2)
db.empty?.should be_false
- db.badge_names.should == {'badge_name_1'=>'Badge Name', 'staged_staged_participation_2'=>'Participation (Level 2)'}
- db.by_member.should == {1=>['badge_name_1', 'staged_staged_participation_2'], 2=>['staged_staged_participation_2']}
+ db.badge_names.should == {'145_0_1'=>'Activity - Badge Name', '93_0_2'=>'Staged - Participation (Lvl 2)'}
+ db.by_member.should == {1=>['93_0_2', '145_0_1'], 2=>['93_0_2']}
db.member_names.should == {1 => 'John Doe', 2 => 'Jane Doe'}
- db.totals.should == {'staged_staged_participation_2'=>2, 'badge_name_1'=>1}
+ db.badge_stock.should == {'93_0_2'=>20, '145_0_1'=>10}
+ db.totals.should == {'93_0_2'=>2, '145_0_1'=>1}
db.valid?.should be_true
end
it "handles an empty array representing no due badges" do
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=outstandingBadges§ion=cubs§ionid=1&termid=2", :body => '[]', :content_type => 'application/json')
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/ext/badges/due/?action=get§ion=cubs§ionid=1&termid=2", :body => '[]', :content_type => 'application/json')
db = Osm::Badges.get_due_badges(@api, Osm::Section.new(:id => 1, :type => :cubs), 2)
db.should_not be_nil
end
it "Fetch badge stock levels" do
badges_body = {
- 'stock' => {
- 'sectionid' => '1',
- 'badge_1' => '1',
- 'badge_2' => '2'
- }
+ 'identifier' => 'badge_id_level',
+ 'items' => [
+ { 'shortname' => 'badge_1', 'stock' => 1, 'desired' => 0, 'due' => 0 },
+ { 'shortname' => 'badge_2', 'stock' => 2, 'desired' => 0, 'due' => 0 },
+ ]
}
- FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/challenges.php?action=getInitialBadges&type=core§ionid=1§ion=beavers&termid=2", :body => badges_body.to_json, :content_type => 'application/json')
+ FakeWeb.register_uri(:post, "https://www.onlinescoutmanager.co.uk/ext/badges/stock/?action=getBadgeStock§ion=beavers§ion_id=1&term_id=2", :body => badges_body.to_json, :content_type => 'application/json')
Osm::Term.stub(:get_current_term_for_section) { Osm::Term.new(:id => 2) }
section = Osm::Section.new(:id => 1, :type => :beavers)
Osm::Badges.get_stock(@api, section).should == {'badge_1' => 1, 'badge_2' => 2}
end
describe "Update badge stock levels" do
it "Succeds" do
- url = "https://www.onlinescoutmanager.co.uk/challenges.php?action=updateStock"
+ url = "https://www.onlinescoutmanager.co.uk/ext/badges.php?action=updateStock"
HTTParty.should_receive(:post).with(url, {:body => {
'apiid' => @CONFIGURATION[:api][:osm][:id],
'token' => @CONFIGURATION[:api][:osm][:token],
'userid' => 'user_id',
'secret' => 'secret',
'stock' => 10,
- 'table' => 'badge',
- 'sectionid' => 1,
+ 'sectionid' => 2,
'section' => :beavers,
- }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"sectionid":"1","badge":"10"}'}) }
+ 'type' => 'current',
+ 'level' => 1,
+ 'badge_id' => 3
+ }}) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"ok":true}'}) }
- section = Osm::Section.new(:id => 1, :type => :beavers)
- Osm::Badges.update_stock(@api, section, 'badge', 10).should be_true
+ section = Osm::Section.new(:id => 2, :type => :beavers)
+ Osm::Badges.update_stock(@api, section, 3, 10).should be_true
end
it "Fails" do
- HTTParty.stub(:post) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"sectionid":"1","badge":"1"}'}) }
+ HTTParty.stub(:post) { OsmTest::DummyHttpResult.new(:response=>{:code=>'200', :body=>'{"ok":false}'}) }
section = Osm::Section.new(:id => 1, :type => :beavers)
- Osm::Badges.update_stock(@api, section, 'badge', 10).should be_false
+ Osm::Badges.update_stock(@api, section, 3, 10).should be_false
end
end
end