Get/set/delete trusted users. Tweak friends list struct

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-07-03 00:51:55 -04:00
parent 12e801f83c
commit 6ffcf70090
5 changed files with 227 additions and 63 deletions
+82
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"testing"
"time"
@@ -112,6 +113,15 @@ var expectedRelationships = []Relationship{
},
}
var expectedRelationships2 = []Relationship{
{
ID: "r9_1re60i",
User: "test3",
UserID: "t2_test3",
Created: &Timestamp{time.Date(2020, 3, 6, 2, 27, 0, 0, time.UTC)},
},
}
func TestAccountService_Info(t *testing.T) {
setup()
defer teardown()
@@ -230,3 +240,75 @@ func TestAccountService_Blocked(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expectedRelationships, relationships)
}
func TestAccountService_Messaging(t *testing.T) {
setup()
defer teardown()
blob := readFileContents(t, "testdata/account/messaging.json")
mux.HandleFunc("/prefs/messaging", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
fmt.Fprint(w, blob)
})
blocked, trusted, _, err := client.Account.Messaging(ctx)
assert.NoError(t, err)
assert.Equal(t, expectedRelationships, blocked)
assert.Equal(t, expectedRelationships2, trusted)
}
func TestAccountService_Trusted(t *testing.T) {
setup()
defer teardown()
blob := readFileContents(t, "testdata/account/trusted.json")
mux.HandleFunc("/prefs/trusted", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
fmt.Fprint(w, blob)
})
relationships, _, err := client.Account.Trusted(ctx)
assert.NoError(t, err)
assert.Equal(t, expectedRelationships, relationships)
}
func TestAccountService_AddTrusted(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/api/add_whitelisted", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method)
form := url.Values{}
form.Set("api_type", "json")
form.Set("name", "test123")
err := r.ParseForm()
assert.NoError(t, err)
assert.Equal(t, form, r.Form)
})
_, err := client.Account.AddTrusted(ctx, "test123")
assert.NoError(t, err)
}
func TestAccountService_RemoveTrusted(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/api/remove_whitelisted", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method)
form := url.Values{}
form.Set("name", "test123")
err := r.ParseForm()
assert.NoError(t, err)
assert.Equal(t, form, r.Form)
})
_, err := client.Account.RemoveTrusted(ctx, "test123")
assert.NoError(t, err)
}