fourmer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestCampaign < Test::Unit::TestCase
4
+ def setup
5
+ @consumer = Foursquare::Merchant::Consumer.new('TOKEN')
6
+ hash = {'venues' => {'count' => 1, 'items' => [{'id' => 'abcdefghjik'}]}}
7
+ @campaign = Foursquare::Merchant::Campaign.new(hash, @consumer)
8
+ end
9
+
10
+ def test_initialize
11
+ assert_equal(Foursquare::Merchant::Campaign, @campaign.class)
12
+ assert_kind_of(Foursquare::Merchant::Model, @campaign)
13
+ assert_equal(['abcdefghjik'], @campaign.venue_ids)
14
+ end
15
+
16
+ def test_timeseries
17
+ Foursquare::Merchant::TimeSeries.stubs(:new).returns([])
18
+ @campaign.stubs(:get).returns({'timeseries' => []})
19
+ assert_equal([], @campaign.timeseries)
20
+ end
21
+
22
+ def test_start
23
+ @campaign.stubs(:post).returns(true)
24
+ assert @campaign.start
25
+ end
26
+
27
+ def test_end
28
+ @campaign.stubs(:post).returns(true)
29
+ assert @campaign.end
30
+ end
31
+
32
+ def test_delete
33
+ @campaign.stubs(:post).returns(true)
34
+ assert @campaign.delete
35
+ end
36
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestCampaign < Test::Unit::TestCase
4
+ def setup
5
+ @consumer = Foursquare::Merchant::Consumer.new('TOKEN')
6
+ end
7
+
8
+ def test_initialize
9
+ campaigns_proxy = Foursquare::Merchant::Campaigns.new(@consumer)
10
+ assert_instance_of(Foursquare::Merchant::Campaigns, campaigns_proxy)
11
+ end
12
+
13
+ def test_find
14
+ response = stub(:parsed_response => {
15
+ 'meta' => {'code' => 200},
16
+ 'response' => {'campaign' => {'id' => 'abcdef'}}
17
+ }
18
+ )
19
+ Foursquare::Merchant::Campaigns.stubs(:get).returns(response)
20
+ assert_equal('abcdef', @consumer.campaigns.find('abcdef').id)
21
+ end
22
+
23
+ def test_add
24
+ response = stub(:parsed_response => {
25
+ 'meta' => {'code' => 200},
26
+ 'response' => {'campaign' => {'id' => 'abcdef'}}
27
+ }
28
+ )
29
+ Foursquare::Merchant::Campaigns.stubs(:post).returns(response)
30
+ assert_equal('abcdef', @consumer.campaigns.add('abcdef').id)
31
+ end
32
+
33
+ def test_list
34
+ items = [{'id' => 'abcdef'}, {'id' => 'abcdef'}]
35
+ response = stub(:parsed_response => {
36
+ 'meta' => {'code' => 200},
37
+ 'response' => {'campaigns' => {'count' => 2, 'items' => items}}
38
+ }
39
+ )
40
+ Foursquare::Merchant::Campaigns.stubs(:get).returns(response)
41
+ campaigns = [Foursquare::Merchant::Campaign.new(items[0], @consumer),
42
+ Foursquare::Merchant::Campaign.new(items[0], @consumer)]
43
+
44
+ assert_equal(campaigns, @consumer.campaigns.list)
45
+ end
46
+ end
@@ -0,0 +1,107 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestConsumer < Test::Unit::TestCase
4
+ def setup
5
+ @consumer_token = Foursquare::Merchant::Consumer.new('ACCESS_TOKEN')
6
+ @consumer_id = Foursquare::Merchant::Consumer.new('CLIENT_ID', 'CLIENT_SECRET')
7
+ end
8
+
9
+ def test_initialize_no_args
10
+ assert_raise ArgumentError do
11
+ Foursquare::Merchant::Consumer.new
12
+ end
13
+ end
14
+
15
+ def test_initialize_one_arg
16
+ assert_nothing_raised ArgumentError do
17
+ Foursquare::Merchant::Consumer.new('ACCESS_TOKEN')
18
+ end
19
+ assert_equal('ACCESS_TOKEN', @consumer_token.oauth_token)
20
+ end
21
+
22
+ def test_initialize_two_args
23
+ assert_nothing_raised ArgumentError do
24
+ Foursquare::Merchant::Consumer.new('CLIENT_ID', 'CLIENT_SECRET')
25
+ end
26
+ assert_equal('CLIENT_ID', @consumer_id.client_id)
27
+ assert_equal('CLIENT_SECRET', @consumer_id.client_secret)
28
+ end
29
+
30
+ def test_authorize_url_no_args
31
+ assert_raise(ArgumentError) { @consumer_id.authorize_url }
32
+ end
33
+
34
+ def test_authorize_url_invalid_callback_url
35
+ callback_url = "path/to/some/url"
36
+ assert_raise(ArgumentError) { @consumer_id.authorize_url(callback_url) }
37
+ end
38
+
39
+ def test_authorize_url
40
+ callback_url = "http://path/to/some/url"
41
+ assert_nothing_raised(RuntimeError) { @consumer_id.authorize_url(callback_url) }
42
+ query = {
43
+ :client_id => 'CLIENT_ID',
44
+ :response_type => 'code',
45
+ :redirect_uri => callback_url
46
+ }.map { |k,v| "#{k}=#{v}"}.join('&')
47
+ response = "https://foursquare.com/oauth2/authenticate?#{query}"
48
+ assert_equal(response, @consumer_id.authorize_url(callback_url))
49
+ end
50
+
51
+ def test_access_token
52
+ response = stub(:code => 200, :parsed_response => {'access_token' => 'ABCDEF'})
53
+ Foursquare::Merchant::Consumer.stubs(:get).returns(response)
54
+ assert_equal('ABCDEF', @consumer_id.access_token('SOME CODE', 'http://some.url.com'))
55
+ end
56
+
57
+ def test_access_token_fail
58
+ response = stub(:code => 400, :parsed_response => {'error' => 'Some error'})
59
+ Foursquare::Merchant::Consumer.stubs(:get).returns(response)
60
+ assert_raise(Foursquare::Merchant::Errors::OAuthError) do
61
+ @consumer_id.access_token('SOME CODE', 'http://some.url.com')
62
+ end
63
+ end
64
+
65
+ def test_access_token_with_consumer_only_initialized_with_oauth_token
66
+ assert_raise(RuntimeError) { @consumer_token.access_token('code', 'http://call.com') }
67
+ end
68
+
69
+ def test_access_token_with_consumer_initialized_with_invalid_params
70
+ consumer = Foursquare::Merchant::Consumer.new('ID', nil)
71
+ assert_raise(RuntimeError) { consumer.access_token('code', 'http://call.com') }
72
+
73
+ consumer = Foursquare::Merchant::Consumer.new(nil, 'SECRET')
74
+ assert_raise(RuntimeError) { consumer.access_token('code', 'http://call.com') }
75
+ end
76
+
77
+ def test_access_token_with_invalid_arguments
78
+ assert_raise(RuntimeError) { @consumer_id.access_token(nil, 'http://call.com') }
79
+ assert_raise(RuntimeError) { @consumer_id.access_token('code', 'call.com') }
80
+ assert_raise(RuntimeError) { @consumer_id.access_token('code', nil) }
81
+ end
82
+
83
+ def test_valid_oauth_url
84
+ assert_equal('https://foursquare.com/oauth2', Foursquare::Merchant::Consumer::OAUTH)
85
+ end
86
+
87
+ def test_campaigns
88
+ @consumer_token.expects(:campaigns).returns(Foursquare::Merchant::Campaigns.new(@consumer_token))
89
+ @consumer_token.campaigns
90
+ end
91
+
92
+ def test_venues
93
+ @consumer_token.expects(:venues).returns(Foursquare::Merchant::Venues.new(@consumer_token))
94
+ @consumer_token.venues
95
+ end
96
+
97
+ def test_venue_groups
98
+ @consumer_token.expects(:venue_groups).returns(Foursquare::Merchant::VenueGroups.new(@consumer_token))
99
+ @consumer_token.venue_groups
100
+ end
101
+
102
+ def test_specials
103
+ @consumer_token.expects(:specials).returns(Foursquare::Merchant::Specials.new(@consumer_token))
104
+ @consumer_token.specials
105
+ end
106
+
107
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestErrors < Test::Unit::TestCase
4
+ def test_api_error
5
+ assert_kind_of(StandardError, Foursquare::Merchant::Errors::APIError.new)
6
+ end
7
+
8
+ def test_oauth_error
9
+ assert_kind_of(Foursquare::Merchant::Errors::APIError, Foursquare::Merchant::Errors::OAuthError.new)
10
+ end
11
+
12
+ def test_new_error
13
+ error = Foursquare::Merchant::Errors.new('TestError', 'This is a test error')
14
+ assert_equal('Foursquare::Merchant::Errors::TestError', error.class.name)
15
+ assert_equal('This is a test error', error.message)
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestFourmer < Test::Unit::TestCase
4
+ def test_nothing
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestModel < Test::Unit::TestCase
4
+ def setup
5
+ @model = Foursquare::Merchant::Model.new({}, [])
6
+ end
7
+
8
+ def test_inheritance
9
+ assert_kind_of(Hashie::Trash, @model)
10
+ end
11
+
12
+ def test_get
13
+ assert_respond_to(@model, :get)
14
+ end
15
+
16
+ def test_post
17
+ assert_respond_to(@model, :post)
18
+ end
19
+
20
+ def test_listify_array
21
+ assert_equal('abc,def', @model.send(:listify, ['abc', 'def']))
22
+ end
23
+
24
+ def test_listify_string
25
+ assert_equal('abc,def', @model.send(:listify, 'abc,def'))
26
+ end
27
+
28
+ def test_listify_other
29
+ assert_raise(ArgumentError) { @model.send(:listify, nil) }
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestSpecial < Test::Unit::TestCase
4
+ def setup
5
+ @consumer = Foursquare::Merchant::Consumer.new('TOKEN')
6
+ hash = {'id' => 'abcdefghjik'}
7
+ @special = Foursquare::Merchant::Special.new(hash, @consumer)
8
+ end
9
+
10
+ def test_initialize
11
+ assert_equal(Foursquare::Merchant::Special, @special.class)
12
+ assert_kind_of(Foursquare::Merchant::Model, @special)
13
+ assert_equal('abcdefghjik', @special.id)
14
+ end
15
+
16
+ def test_retire
17
+ @special.stubs(:post).returns(true)
18
+ assert @special.retire
19
+ end
20
+
21
+ def test_configuration
22
+ response = {'special' => {'id' => 'config', 'count1' => 5}}
23
+ @special.stubs(:get).returns(response)
24
+ configuration = @special.configuration
25
+ assert_equal(Foursquare::Merchant::Special, configuration.class)
26
+ assert_equal(5, configuration.count1)
27
+ end
28
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestSpecials < Test::Unit::TestCase
4
+ def setup
5
+ @consumer = Foursquare::Merchant::Consumer.new('TOKEN')
6
+ end
7
+
8
+ def test_initialize
9
+ specials_proxy = Foursquare::Merchant::Specials.new(@consumer)
10
+ assert_instance_of(Foursquare::Merchant::Specials, specials_proxy)
11
+ end
12
+
13
+ def test_find
14
+ response = stub(:parsed_response => {
15
+ 'meta' => {'code' => 200},
16
+ 'response' => {'special' => {'id' => 'abcdef'}}
17
+ }
18
+ )
19
+ Foursquare::Merchant::Specials.stubs(:get).returns(response)
20
+ assert_equal('abcdef', @consumer.specials.find('abcdef').id)
21
+ end
22
+
23
+ def test_add
24
+ response = stub(:parsed_response => {
25
+ 'meta' => {'code' => 200},
26
+ 'response' => {'special' => {'id' => 'abcdef'}}
27
+ }
28
+ )
29
+ Foursquare::Merchant::Specials.stubs(:post).returns(response)
30
+ assert_equal('abcdef', @consumer.specials.add('abcdef').id)
31
+ end
32
+
33
+ def test_list
34
+ items = [{'id' => 'abcdef'}, {'id' => 'fedcba'}]
35
+ response = stub(:parsed_response => {
36
+ 'meta' => {'code' => 200},
37
+ 'response' => {'specials' => {'count' => 2, 'items' => items}}
38
+ }
39
+ )
40
+ Foursquare::Merchant::Specials.stubs(:get).returns(response)
41
+ specials = [Foursquare::Merchant::Special.new(items[0], @consumer),
42
+ Foursquare::Merchant::Special.new(items[1], @consumer)]
43
+
44
+ assert_equal(specials, @consumer.specials.list)
45
+ end
46
+
47
+ def test_search_no_lat_lng
48
+ items = [{'id' => 'abcdef'}, {'id' => 'fedcba'}]
49
+ response = stub(:parsed_response => {
50
+ 'meta' => {'code' => 200},
51
+ 'response' => {'specials' => {'count' => 2, 'items' => items}}
52
+ }
53
+ )
54
+ Foursquare::Merchant::Specials.stubs(:get).returns(response)
55
+ assert_raise(RuntimeError) { @consumer.specials.search({}) }
56
+ end
57
+
58
+ def test_search_with_lat_lng
59
+ items = [{'id' => 'abcdef'}, {'id' => 'fedcba'}]
60
+ response = stub(:parsed_response => {
61
+ 'meta' => {'code' => 200},
62
+ 'response' => {'specials' => {'count' => 2, 'items' => items}}
63
+ }
64
+ )
65
+ Foursquare::Merchant::Specials.stubs(:get).returns(response)
66
+ specials = [Foursquare::Merchant::Special.new(items[0], @consumer),
67
+ Foursquare::Merchant::Special.new(items[1], @consumer)]
68
+
69
+ assert_equal(specials, @consumer.specials.search({:ll => '20.2,-110.1'}))
70
+ end
71
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestTimeSeries < Test::Unit::TestCase
4
+ def test_initialize_with_venue_id
5
+ timeseries = Foursquare::Merchant::TimeSeries.new({:venueId => 'abc'})
6
+ assert_kind_of(Hashie::Trash, timeseries)
7
+ assert_equal('abc', timeseries.venue_id)
8
+ end
9
+
10
+ def test_initialize_no_venue_id
11
+ assert_raise(ArgumentError) { timeseries = Foursquare::Merchant::TimeSeries.new({}) }
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestVenue < Test::Unit::TestCase
4
+ def setup
5
+ @consumer = Foursquare::Merchant::Consumer.new('TOKEN')
6
+ hash = {'id' => 'abcdefghjik'}
7
+ @venue = Foursquare::Merchant::Venue.new(hash, @consumer)
8
+ end
9
+
10
+ def test_initialize
11
+ assert_equal(Foursquare::Merchant::Venue, @venue.class)
12
+ assert_kind_of(Foursquare::Merchant::Model, @venue)
13
+ assert_equal('abcdefghjik', @venue.id)
14
+ end
15
+
16
+ def test_fetch
17
+ response = {'venue' => {'id' => 'new_venue'}}
18
+ @venue.stubs(:get).returns(response)
19
+ assert_kind_of(Foursquare::Merchant::Venue, @venue.fetch)
20
+ assert_equal('new_venue', @venue.fetch.id)
21
+ assert_not_equal(@venue, @venue.fetch)
22
+ end
23
+
24
+ def test_stats
25
+ @venue.stubs(:get).returns({'stats' => {'sharing' => {"twitter"=>233, "facebook"=>203}}})
26
+ stats = Foursquare::Merchant::VenueStats.new({'sharing' => {"twitter"=>233, "facebook"=>203}})
27
+ assert_equal(stats, @venue.stats)
28
+ end
29
+
30
+ def test_edit
31
+ response = {'venue' => {'id' => 'new_id'}}
32
+ @venue.stubs(:post).returns(response)
33
+ @venue.stubs(:get).returns(response)
34
+
35
+ assert_equal('abcdefghjik', @venue.id)
36
+ @venue.edit({'id' => 'new_id'})
37
+ assert_equal('new_id', @venue.id)
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestVenueGroup < Test::Unit::TestCase
4
+ def setup
5
+ @consumer = Foursquare::Merchant::Consumer.new('TOKEN')
6
+ hash = {'id' => 'abcdefghjik'}
7
+ @venue_group = Foursquare::Merchant::VenueGroup.new(hash, @consumer)
8
+ end
9
+
10
+ def test_initialize_no_venue_ids
11
+ assert_equal(Foursquare::Merchant::VenueGroup, @venue_group.class)
12
+ assert_kind_of(Foursquare::Merchant::Model, @venue_group)
13
+ assert_equal('abcdefghjik', @venue_group.id)
14
+ end
15
+
16
+ def test_initialize_with_venue_ids
17
+ hash = {'id' => 'abcdefghjik', 'venues' => {'items' => [{'id' => 'a'}]}}
18
+ venue_group = Foursquare::Merchant::VenueGroup.new(hash, @consumer)
19
+ venue = Foursquare::Merchant::Venue.new(hash['venues']['items'][0], @consumer)
20
+ assert_equal([venue], venue_group.venues)
21
+ end
22
+
23
+ def test_delete
24
+ @venue_group.stubs(:post).returns(true)
25
+ assert @venue_group.delete
26
+ end
27
+
28
+ def test_add_venue
29
+ @venue_group.stubs(:post).returns(true)
30
+ assert @venue_group.add_venue(['abc', 'def'])
31
+ end
32
+
33
+ def test_remove_venue
34
+ @venue_group.stubs(:post).returns(true)
35
+ assert @venue_group.remove_venue(['abc', 'def'])
36
+ end
37
+
38
+ end