add source, history for statuses and option to update a status
This commit is contained in:
parent
791e6bb9de
commit
70cca3af11
4 changed files with 317 additions and 2 deletions
|
@ -172,6 +172,88 @@ func TestGetStatusContext(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetStatusSource(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/statuses/1234567/source" {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `{"id":"1234567","text":"Foo","spoiler_text":"Bar"}%`)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{
|
||||
Server: ts.URL,
|
||||
ClientID: "foo",
|
||||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, err := client.GetStatusSource(context.Background(), "123")
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
source, err := client.GetStatusSource(context.Background(), "1234567")
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
if source.ID != ID("1234567") {
|
||||
t.Fatalf("want %q but %q", "1234567", source.ID)
|
||||
}
|
||||
if source.Text != "Foo" {
|
||||
t.Fatalf("want %q but %q", "Foo", source.Text)
|
||||
}
|
||||
if source.SpoilerText != "Bar" {
|
||||
t.Fatalf("want %q but %q", "Bar", source.SpoilerText)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStatusHistory(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/statuses/1234567/history" {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `[{"content": "foo", "emojis":[{"shortcode":"💩", "url":"http://example.com", "static_url": "http://example.com/static"}]}, {"content": "bar", "emojis":[{"shortcode":"💩", "url":"http://example.com", "static_url": "http://example.com/static"}]}]`)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{
|
||||
Server: ts.URL,
|
||||
ClientID: "foo",
|
||||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, err := client.GetStatusHistory(context.Background(), "123")
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
statuses, err := client.GetStatusHistory(context.Background(), "1234567")
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
if len(statuses) != 2 {
|
||||
t.Fatalf("want len %q but got %q", "2", len(statuses))
|
||||
}
|
||||
if statuses[0].Content != "foo" {
|
||||
t.Fatalf("want %q but %q", "bar", statuses[0].Content)
|
||||
}
|
||||
if statuses[1].Content != "bar" {
|
||||
t.Fatalf("want %q but %q", "bar", statuses[1].Content)
|
||||
}
|
||||
if len(statuses[0].Emojis) != 1 {
|
||||
t.Fatal("should have emojis")
|
||||
}
|
||||
if statuses[0].Emojis[0].ShortCode != "💩" {
|
||||
t.Fatalf("want %q but %q", "💩", statuses[0].Emojis[0].ShortCode)
|
||||
}
|
||||
if statuses[0].Emojis[0].URL != "http://example.com" {
|
||||
t.Fatalf("want %q but %q", "https://example.com", statuses[0].Emojis[0].URL)
|
||||
}
|
||||
if statuses[0].Emojis[0].StaticURL != "http://example.com/static" {
|
||||
t.Fatalf("want %q but %q", "https://example.com/static", statuses[0].Emojis[0].StaticURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRebloggedBy(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/statuses/1234567/reblogged_by" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue