-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontacts_test.go
65 lines (55 loc) · 1.69 KB
/
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
// Copyright (c) David Bond, Tailscale Inc, & Contributors
// SPDX-License-Identifier: MIT
package tailscale
import (
"context"
"encoding/json"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClient_Contacts(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
expectedContacts := &Contacts{
Account: Contact{
Email: "[email protected]",
FallbackEmail: "[email protected]",
NeedsVerification: false,
},
Support: Contact{
Email: "[email protected]",
NeedsVerification: false,
},
Security: Contact{
Email: "[email protected]",
FallbackEmail: "[email protected]",
NeedsVerification: true,
},
}
server.ResponseBody = expectedContacts
actualContacts, err := client.Contacts().Get(context.Background())
assert.NoError(t, err)
assert.Equal(t, http.MethodGet, server.Method)
assert.Equal(t, "/api/v2/tailnet/example.com/contacts", server.Path)
assert.Equal(t, expectedContacts, actualContacts)
}
func TestClient_UpdateContact(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
server.ResponseBody = nil
email := "[email protected]"
updateRequest := UpdateContactRequest{
Email: &email,
}
err := client.Contacts().Update(context.Background(), ContactAccount, updateRequest)
assert.NoError(t, err)
assert.Equal(t, http.MethodPatch, server.Method)
assert.Equal(t, "/api/v2/tailnet/example.com/contacts/account", server.Path)
var receivedRequest UpdateContactRequest
err = json.Unmarshal(server.Body.Bytes(), &receivedRequest)
assert.NoError(t, err)
assert.EqualValues(t, updateRequest, receivedRequest)
}