-
Notifications
You must be signed in to change notification settings - Fork 1
/
accounts_test.go
78 lines (65 loc) · 1.99 KB
/
accounts_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 xesende
import (
"net/http/httptest"
"net/url"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAccounts(t *testing.T) {
const (
id = "accountid"
uri = "http://someaccount"
reference = "EX093052"
label = "My account"
address = "443523"
accountType = "Professional"
messagesRemaining = 2322
role = "CoolUser"
settingsURI = "http://somesettings"
)
var (
expiresOn = time.Date(2012, 1, 1, 12, 0, 5, 0, time.UTC)
expiresOnStr = "2012-01-01T12:00:05"
)
h := newRecordingHandler(`<?xml version="1.0" encoding="utf-8"?>
<accounts xmlns="http://api.esendex.com/ns/">
<account id="`+id+`" uri="`+uri+`">
<reference>`+reference+`</reference>
<label>`+label+`</label>
<address>`+address+`</address>
<type>`+accountType+`</type>
<messagesremaining>`+strconv.Itoa(messagesRemaining)+`</messagesremaining>
<expireson>`+expiresOnStr+`</expireson>
<role>`+role+`</role>
<settings uri="`+settingsURI+`" />
</account>
</accounts>`, 200, map[string]string{})
s := httptest.NewServer(h)
defer s.Close()
client := New("user", "pass")
client.BaseURL, _ = url.Parse(s.URL)
result, err := client.Accounts()
assert := assert.New(t)
assert.Nil(err)
assert.Equal("GET", h.Request.Method)
assert.Equal("/v1.0/accounts", h.Request.URL.String())
if user, pass, ok := h.Request.BasicAuth(); assert.True(ok) {
assert.Equal("user", user)
assert.Equal("pass", pass)
}
if assert.Equal(1, len(result.Accounts)) {
account := result.Accounts[0]
assert.Equal(id, account.ID)
assert.Equal(uri, account.URI)
assert.Equal(reference, account.Reference)
assert.Equal(label, account.Label)
assert.Equal(address, account.Address)
assert.Equal(accountType, account.Type)
assert.Equal(messagesRemaining, account.MessagesRemaining)
assert.Equal(expiresOn, account.ExpiresOn)
assert.Equal(role, account.Role)
assert.Equal(settingsURI, account.SettingsURI)
}
}