#encoding: UTF-8 require "spec_helper" describe PlataformaSocial::Badge do describe "Platform Route" do it "return correct url" do PlataformaSocial::Badge.socialp_route.should == "http://badge.dev.plataformasocial.com.br" end end describe "CREATE a new badge" do before :each do @params = { :badge_reference => 1, :badge_obj => "{\"reference\":\"1432423423\",\"updated_at\":\"2012-07-13T19:53:20Z\",\"id\":1,\"share_text\":\"Parab\\u00e9ns, voc\\u00ea ganhou a Badge de Coloridos da Dito.\",\"events_count\":10,\"picture_url\":\"http://www.jorge.com.br/sergio\",\"description\":\"Essa badge \\u00e9 dada para todos os Coloridos da Dito.\",\"name\":\"Dito Colorida\",\"created_at\":\"2012-07-13T19:53:20Z\",\"app_id\":23}" } end it "when request is successful", :vcr do badge = PlataformaSocial::Badge.new badge.create(@params).match(/badge_reference=1/).should be_true end context "when request is failed" do [:badge_reference, :badge_obj].each do |param| it "dont using params: #{param}" do @params.delete param badge = PlataformaSocial::Badge.new badge.create(@params).should == "Faltando o parâmetro: #{param}" end end end end describe "GIVE points to user" do before :each, :vcr do params = { :badge_reference => 1, :badge_obj => "{\"reference\":\"1\",\"updated_at\":\"2012-07-13T19:53:20Z\",\"id\":1,\"share_text\":\"Parab\\u00e9ns, voc\\u00ea ganhou a Badge de Coloridos da Dito.\",\"events_count\":10,\"picture_url\":\"http://www.jorge.com.br/sergio\",\"description\":\"Essa badge \\u00e9 dada para todos os Coloridos da Dito.\",\"name\":\"Dito Colorida\",\"created_at\":\"2012-07-13T19:53:20Z\",\"app_id\":23}" } @badge = PlataformaSocial::Badge.new @badge.create(params) end it "when request is successful and badges is array", :vcr do @badge.give({:user_reference => 1, :badges => [1]}).should == [] end it "when request is successful and badges is hash", :vcr do @badge.give({:user_reference => 1, :badges => [{ 1 => 12 }]}).should == [{"reference"=>"1", "updated_at"=>"2012-07-13T19:53:20Z", "id"=>1, "share_text"=>"Parabéns, você ganhou a Badge de Coloridos da Dito.", "events_count"=>10, "picture_url"=>"http://www.jorge.com.br/sergio", "description"=>"Essa badge é dada para todos os Coloridos da Dito.", "name"=>"Dito Colorida", "created_at"=>"2012-07-13T19:53:20Z", "app_id"=>23, "url"=>"http://appprova.sandbox.plataformasocial.com.br/badge?badge_reference=1&app_id=23"}] end context "when request is failed" do [:user_reference, :badges].each do |param| params = { :user_reference => 1, :badges => [1] } it "dont using params: #{param}" do params.delete param @badge.give(params).should == "Faltando o parâmetro: #{param}" end end end end describe "return INDEX to user" do before :each do params = { :badge_reference => 5, :badge_obj => "{\"reference\":\"5\",\"updated_at\":\"2012-07-13T19:53:20Z\",\"id\":1,\"share_text\":\"Parab\\u00e9ns, voc\\u00ea ganhou a Badge de Coloridos da Dito.\",\"events_count\":10,\"picture_url\":\"http://www.jorge.com.br/sergio\",\"description\":\"Essa badge \\u00e9 dada para todos os Coloridos da Dito.\",\"name\":\"Dito Colorida\",\"created_at\":\"2012-07-13T19:53:20Z\",\"app_id\":23}" } params1 = { :badge_reference => 6, :badge_obj => "{\"reference\":\"6\",\"updated_at\":\"2012-07-13T19:53:20Z\",\"id\":1,\"share_text\":\"Parab\\u00e9ns, voc\\u00ea ganhou a Badge de Coloridos da Dito.\",\"events_count\":10,\"picture_url\":\"http://www.jorge.com.br/sergio\",\"description\":\"Essa badge \\u00e9 dada para todos os Coloridos da Dito.\",\"name\":\"Dito Colorida\",\"created_at\":\"2012-07-13T19:53:20Z\",\"app_id\":23}" } @badge = PlataformaSocial::Badge.new @badge.create(params) @badge.create(params1) end it "when request is successful, but user hasnt earned any badge", :vcr do @badge.give({:user_reference => 4, :badges => [5]}) @badge.index({ :user_reference => 4 }).should include({"reference"=>"5", "updated_at"=>"2012-07-13T19:53:20Z", "id"=>1, "share_text"=>"Parabéns, você ganhou a Badge de Coloridos da Dito.", "events_count"=>10, "picture_url"=>"http://www.jorge.com.br/sergio", "description"=>"Essa badge é dada para todos os Coloridos da Dito.", "name"=>"Dito Colorida", "created_at"=>"2012-07-13T19:53:20Z", "app_id"=>23, "earned"=>false, "url"=>"http://appprova.sandbox.plataformasocial.com.br/badge?badge_reference=5&app_id=23"}) end it "when request is successful and user has already earned some badge", :vcr do @badge.give({:user_reference => 5, :badges => [{ 6 => 12 }]}) @badge.index({ :user_reference => 5 }).should include({"reference"=>"6", "updated_at"=>"2012-07-13T19:53:20Z", "id"=>1, "share_text"=>"Parabéns, você ganhou a Badge de Coloridos da Dito.", "events_count"=>10, "picture_url"=>"http://www.jorge.com.br/sergio", "description"=>"Essa badge é dada para todos os Coloridos da Dito.", "name"=>"Dito Colorida", "created_at"=>"2012-07-13T19:53:20Z", "app_id"=>23, "earned"=>true, "url"=>"http://appprova.sandbox.plataformasocial.com.br/badge?badge_reference=6&app_id=23"}) end context "when request is failed" do it "dont using params: user_reference" do @badge.index.should == "Faltando o parâmetro: user_reference" end end end end