예제 #1
0
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)
}
예제 #2
0
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)
}
예제 #3
0
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)
}
예제 #4
0
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)
}
예제 #5
0
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)
}
예제 #6
0
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)
}
예제 #7
0
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)
}
예제 #8
0
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)
}
예제 #9
0
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)
}
예제 #10
0
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)
}
예제 #11
0
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)
}
예제 #12
0
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)
}
예제 #13
0
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)
}
예제 #14
0
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)
}
예제 #15
0
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)
}
예제 #16
0
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)
}
예제 #17
0
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")
}
예제 #18
0
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")
}
예제 #19
0
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)
}
예제 #20
0
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)
}
예제 #21
0
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())
}