Merge pull request #8 from 178inaba/follow
Add ID to Relationship, add follow unfollow test
This commit is contained in:
commit
5d72d54344
11
accounts.go
11
accounts.go
|
@ -68,11 +68,12 @@ 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 {
|
||||||
Following bool `json:"following"`
|
ID int64 `json:"id"`
|
||||||
FollowedBy bool `json:"followed_by"`
|
Following bool `json:"following"`
|
||||||
Blocking bool `json:"blocking"`
|
FollowedBy bool `json:"followed_by"`
|
||||||
Muting bool `json:"muting"`
|
Blocking bool `json:"blocking"`
|
||||||
Requested bool `json:"requested"`
|
Muting bool `json:"muting"`
|
||||||
|
Requested bool `json:"requested"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountFollow follow the account.
|
// AccountFollow follow the account.
|
||||||
|
|
74
accounts_test.go
Normal file
74
accounts_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user