func TestRelationshipsRelationship(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/\d+\/relationship\?access_token=\w+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 203}}`) data, _ := api.Relationships.Relationship(12345) assert.Equal(t, data.Meta.Code, 203) assert.TypeOf(t, "*jsons.Relationship", data) assert.TypeOf(t, "jsons.RelationshipData", data.Data) }
func TestRelationshipsFollows(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/\d+\/follows\?access_token=\w+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 200}}`) data, _ := api.Relationships.Follows(123) assert.Equal(t, data.Meta.Code, 200) assert.TypeOf(t, "*jsons.Users", data) assert.TypeOf(t, "[]jsons.UserData", data.Data) }
func TestRelationshipsSelfRequestedBy(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/self\/requested-by\?access_token=\w+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 202}}`) data, _ := api.Relationships.SelfRequestedBy() assert.Equal(t, data.Meta.Code, 202) assert.TypeOf(t, "*jsons.Users", data) assert.TypeOf(t, "[]jsons.UserData", data.Data) }
func TestRealTimeSubscriptions(t *testing.T) { api, mock := tNewRealTime(t, "my-clientid", "a-secret") reg := regmc(`v1\/subscriptions\?client_id=[a-z-]+&client_secret=[a-z-]+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 202}}`) data, _ := api.Subscriptions() assert.Equal(t, data.Meta.Code, 202) assert.TypeOf(t, "*jsons.Subscriptions", data) assert.TypeOf(t, "[]jsons.SubscriptionData", data.Data) }
func TestMediaMedia(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/media\/\d+\?access_token=\w+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 200}}`) data, _ := api.Media.Media(1234) assert.Equal(t, 200, data.Meta.Code) assert.TypeOf(t, "*jsons.Media", data) assert.TypeOf(t, "jsons.MediaData", data.Data) }
func TestUsersUser(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/\d+\?access_token=`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 201}}`) data, _ := api.Users.User(1234) assert.Equal(t, data.Meta.Code, 201) assert.TypeOf(t, "*jsons.User", data) assert.TypeOf(t, "jsons.UserData", data.Data) }
func TestTagsName(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/tags\/\w+\?access_token=\w+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 200}}`) data, _ := api.Tags.Name("Foo") assert.Equal(t, data.Meta.Code, 200) assert.TypeOf(t, "*jsons.Tag", data) assert.TypeOf(t, "jsons.TagData", data.Data) }
func TestLocationsLocation(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/locations\/\d+\?access_token=\w+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 200}}`) data, _ := api.Locations.Location(12345) assert.Equal(t, data.Meta.Code, 200) assert.TypeOf(t, "*jsons.Location", data) assert.TypeOf(t, "jsons.LocationData", data.Data) }
func TestLikesPost(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/media\/\d+\/likes\?access_token=\w+$`) mock.Expect("POST", reg).Respond(200, `{"meta": {"code": 201}}`) data, _ := api.Likes.Post(12345) assert.Equal(t, data.Meta.Code, 201) assert.TypeOf(t, "*jsons.Like", data) assert.TypeOf(t, "jsons.LikeData", data.Data) }
func TestCommentsComments(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/media\/\d+\/comments\?access_token=\w+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 200}}`) data, _ := api.Comments.Comments(12345) assert.Equal(t, data.Meta.Code, 200) assert.TypeOf(t, "*jsons.Comments", data) assert.TypeOf(t, "[]jsons.CommentData", data.Data) }
func TestCommentsDelete(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/media\/\d+\/comments\/\d+\?access_token=\w+$`) mock.Expect("DELETE", reg).Respond(200, `{"meta": {"code": 202}}`) data, _ := api.Comments.Delete(12345, 67890) assert.Equal(t, data.Meta.Code, 202) assert.TypeOf(t, "*jsons.Comment", data) assert.TypeOf(t, "jsons.CommentData", data.Data) }
func TestLocationsSearch(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/locations\/search\?access_token=\w+&distance=\d+&lat=(\d+\.\d+)&lng=(\d+\.\d+)$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 202}}`) data, _ := api.Locations.Search(40.7127, 74.0059, map[string]string{ "distance": "5000", }) assert.Equal(t, data.Meta.Code, 202) assert.TypeOf(t, "*jsons.Locations", data) assert.TypeOf(t, "[]jsons.LocationData", data.Data) }
func TestLocationsMediaRecent(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/locations\/\d+\/media\/recent\?access_token=\w+&min_id=\d+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 201}}`) data, _ := api.Locations.MediaRecent(12345, map[string]string{ "min_id": "67890", }) assert.Equal(t, data.Meta.Code, 201) assert.TypeOf(t, "*jsons.Locations", data) assert.TypeOf(t, "[]jsons.LocationData", data.Data) }
func TestUsersSelfMediaLiked(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/self\/media\/liked\?access_token=\w+&count=\d+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 204}}`) data, _ := api.Users.SelfMediaLiked(map[string]string{ "count": "50", }) assert.Equal(t, data.Meta.Code, 204) assert.TypeOf(t, "*jsons.Medias", data) assert.TypeOf(t, "[]jsons.MediaData", data.Data) }
func TestTagsMediaRecent(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/tags\/\w+\/media\/recent\?access_token=\w+&count=\d+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 201}}`) data, _ := api.Tags.MediaRecent("Foo", map[string]string{ "count": "50", }) assert.Equal(t, data.Meta.Code, 201) assert.TypeOf(t, "*jsons.Medias", data) assert.TypeOf(t, "[]jsons.MediaData", data.Data) }
func TestUsersSearch(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/search\?access_token=\w+&count=\d+&q=foo\+bar$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 205}}`) data, _ := api.Users.Search("foo bar", map[string]string{ "count": "50", }) assert.Equal(t, data.Meta.Code, 205) assert.TypeOf(t, "*jsons.Users", data) assert.TypeOf(t, "[]jsons.UserData", data.Data) }
func TestCommentsPost(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/media\/\d+\/comments\?access_token=\w+$`) _, mres := mock.Expect("POST", reg).Respond(200, `{"meta": {"code": 201}}`) data, _ := api.Comments.Post(12345, "Hello World") assert.Equal(t, data.Meta.Code, 201) assert.TypeOf(t, "*jsons.Comment", data) assert.TypeOf(t, "jsons.CommentData", data.Data) mres.Body().Equals("text=Hello World") }
func TestRelationshipsPost(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/\d+\/relationship\?access_token=\w+$`) _, mres := mock.Expect("POST", reg).Respond(200, `{"meta": {"code": 204}}`) data, _ := api.Relationships.Post(12345, "follow") assert.Equal(t, data.Meta.Code, 204) assert.TypeOf(t, "*jsons.Relationship", data) assert.TypeOf(t, "jsons.RelationshipData", data.Data) mres.Body().Equals("action=follow") }
func TestUsersMediaRecentCID(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/\d+\/media\/recent\?client_id=clientid&count=\d+&min_id=\d+$`) mock.Expect("GET", reg).Respond(200, `{"meta": {"code": 203}}`) data, _ := api.Users.MediaRecentCID(1234, "clientid", map[string]string{ "count": "50", "min_id": "12345678", }) assert.Equal(t, data.Meta.Code, 203) assert.TypeOf(t, "*jsons.Medias", data) assert.TypeOf(t, "[]jsons.MediaData", data.Data) }
func TestRateLimitError(t *testing.T) { api, mock := tNewInstagram(t) reg := regmc(`v1\/users\/self\/feed\?access_token=\w+$`) mock.Expect("GET", reg).Respond(429, `{"meta": {"code": 429}}`) data, err := api.Users.SelfFeed() assert.Equal(t, data.Meta.Code, 429) assert.Equal(t, err.Error(), "The maximum number of requests per hour has been exceeded.") assert.TypeOf(t, "instagram.RateLimitError", err) }
func TestRealTimeSubscribe(t *testing.T) { api, mock := tNewRealTime(t, "my-clientid", "a-secret") reg := regmc(`v1\/subscriptions$`) _, mres := mock.Expect("POST", reg).Respond(200, `{"meta": {"code": 200}}`) data, _ := api.Subscribe("tag", "token", "http://example.com/rt/user", map[string]string{ "object_id": "notifier", }) assert.Equal(t, data.Meta.Code, 200) assert.TypeOf(t, "*jsons.Subscriptions", data) assert.TypeOf(t, "[]jsons.SubscriptionData", data.Data) v := url.Values{} v.Add("client_id", "my-clientid") v.Add("client_secret", "a-secret") v.Add("object", "tag") v.Add("aspect", "media") v.Add("verify_token", "token") v.Add("callback_url", "http://example.com/rt/user") v.Add("object_id", "notifier") mres.Body().Equals(v.Encode()) }