test/test_tracksale_campaign.rb in tracksale-0.0.4 vs test/test_tracksale_campaign.rb in tracksale-0.0.5

- old
+ new

@@ -4,29 +4,36 @@ class TestTracksaleCampaign < Minitest::Test def setup Tracksale.configure { |c| c.key = 'foobar'; c.force_dummy_client(false) } + body_for_campaign = '[{"name":"random - name",' \ + '"code":1234, "detractors":1,' \ + '"passives":2, "promoters":3 }]' + stub_request(:get, 'http://api.tracksale.co/v2/campaign') .with(headers: { 'authorization' => 'bearer foobar' }) - .to_return(body: '[{"name":"random - name",' \ - '"code":1234, "detractors":1,' \ - '"passives":2, "promoters":3 }]', - headers: { content_type: 'application/json' }, status: 200) + .to_return(body: body_for_campaign, + headers: { content_type: 'application/json' }, status: 200) + stub_request(:get, 'http://api.tracksale.co/v2/campaign/771') + .with(headers: { 'authorization' => 'bearer foobar' }) + .to_return(body: body_for_campaign, + headers: { content_type: 'application/json' }, status: 200) + stub_dispatch(121, 200, '{ "msg": "scheduled" }') stub_dispatch(123, 400, '{ "error": "Invalid Time"}') stub_dispatch(124, 500, '{ "foo": "bar"}') end def stub_dispatch(code, status, body) url = 'http://api.tracksale.co/v2/campaign/' + code.to_s + '/dispatch' stub_request(:post, url) .with(headers: { 'authorization' => 'bearer foobar', - 'content-type' => 'application/json' }, body: '"foo"') + 'content-type' => 'application/json' }, body: '"foo"') .to_return(body: body, - headers: { content_type: 'application/json' }, status: status) + headers: { content_type: 'application/json' }, status: status) end def test_dispatch_successful dispatch = Tracksale::Campaign.schedule_dispatch(121, 'foo') assert_equal dispatch['msg'], 'scheduled' @@ -73,9 +80,14 @@ assert_equal expected_score, campaign.score end def test_all_returns_campaigns assert Tracksale::Campaign.all.first.is_a? Tracksale::Campaign + end + + def test_find_by_code + assert Tracksale::Campaign.find_by_code(771).respond_to? :name + assert_equal 'random - name', Tracksale::Campaign.find_by_code(771).name end private def subject