Merge pull request #8 from 178inaba/follow

Add ID to Relationship, add follow unfollow test
pull/10/head
mattn 2017-04-15 00:40:13 +09:00 committed by GitHub
commit 5d72d54344
2 changed files with 80 additions and 5 deletions

View File

@ -68,6 +68,7 @@ func (c *Client) GetAccountFollowing(id int64) ([]*Account, error) {
// Relationship hold information for relation-ship to the account. // Relationship hold information for relation-ship to the account.
type Relationship struct { type Relationship struct {
ID int64 `json:"id"`
Following bool `json:"following"` Following bool `json:"following"`
FollowedBy bool `json:"followed_by"` FollowedBy bool `json:"followed_by"`
Blocking bool `json:"blocking"` Blocking bool `json:"blocking"`

74
accounts_test.go 100644
View File

@ -0,0 +1,74 @@
package mastodon
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestAccountFollow(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/accounts/1234567/follow" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
fmt.Fprintln(w, `{"id":1234567,"following":true}`)
return
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
rel, err := client.AccountFollow(123)
if err == nil {
t.Fatalf("should be fail: %v", err)
}
rel, err = client.AccountFollow(1234567)
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if rel.ID != 1234567 {
t.Fatalf("want %d but %d", 1234567, rel.ID)
}
if !rel.Following {
t.Fatalf("want %t but %t", true, rel.Following)
}
}
func TestAccountUnfollow(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/accounts/1234567/unfollow" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
fmt.Fprintln(w, `{"id":1234567,"following":false}`)
return
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
rel, err := client.AccountUnfollow(123)
if err == nil {
t.Fatalf("should be fail: %v", err)
}
rel, err = client.AccountUnfollow(1234567)
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if rel.ID != 1234567 {
t.Fatalf("want %d but %d", 1234567, rel.ID)
}
if rel.Following {
t.Fatalf("want %t but %t", false, rel.Following)
}
}