forked from bitcoin-sv/spv-wallet-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_contacts_test.go
78 lines (69 loc) · 2.6 KB
/
admin_contacts_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package walletclient
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/bitcoin-sv/spv-wallet-go-client/fixtures"
"github.com/bitcoin-sv/spv-wallet/models"
responsemodels "github.com/bitcoin-sv/spv-wallet/models/response"
"github.com/stretchr/testify/require"
)
// TestAdminContactActions testing Admin contacts methods
func TestAdminContactActions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case r.URL.Path == "/v1/admin/contact/search" && r.Method == http.MethodPost:
c := fixtures.Contact
c.ID = "1"
content := models.PagedResponse[*models.Contact]{
Content: []*models.Contact{c},
}
json.NewEncoder(w).Encode(content)
case r.URL.Path == "/v1/admin/contact/1" && r.Method == http.MethodPatch:
contact := fixtures.Contact
json.NewEncoder(w).Encode(contact)
case r.URL.Path == "/v1/admin/contact/1" && r.Method == http.MethodDelete:
w.WriteHeader(http.StatusOK)
case r.URL.Path == "/v1/admin/contact/accepted/1" && r.Method == http.MethodPatch:
contact := fixtures.Contact
contact.Status = responsemodels.ContactNotConfirmed
json.NewEncoder(w).Encode(contact)
case r.URL.Path == "/v1/admin/contact/rejected/1" && r.Method == http.MethodPatch:
contact := fixtures.Contact
contact.Status = responsemodels.ContactRejected
json.NewEncoder(w).Encode(contact)
default:
w.WriteHeader(http.StatusNotFound)
}
}))
defer server.Close()
client, err := NewWithAdminKey(server.URL, fixtures.XPrivString)
require.NoError(t, err)
require.NotNil(t, client.adminXPriv)
t.Run("AdminGetContacts", func(t *testing.T) {
contacts, err := client.AdminGetContacts(context.Background(), nil, nil, nil)
require.NoError(t, err)
require.Equal(t, "1", contacts.Content[0].ID)
})
t.Run("AdminUpdateContact", func(t *testing.T) {
contact, err := client.AdminUpdateContact(context.Background(), "1", "Jane Doe", nil)
require.NoError(t, err)
require.Equal(t, "Test User", contact.FullName)
})
t.Run("AdminDeleteContact", func(t *testing.T) {
err := client.AdminDeleteContact(context.Background(), "1")
require.NoError(t, err)
})
t.Run("AdminAcceptContact", func(t *testing.T) {
contact, err := client.AdminAcceptContact(context.Background(), "1")
require.NoError(t, err)
require.Equal(t, responsemodels.ContactNotConfirmed, contact.Status)
})
t.Run("AdminRejectContact", func(t *testing.T) {
contact, err := client.AdminRejectContact(context.Background(), "1")
require.NoError(t, err)
require.Equal(t, responsemodels.ContactRejected, contact.Status)
})
}