Repository navigation
Expand file tree
/
Copy pathapi_key_test.go
More file actions
67 lines (50 loc) · 1.49 KB
/
Copy pathapi_key_test.go
File metadata and controls
67 lines (50 loc) · 1.49 KB
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
package easypost
import (
"reflect"
)
func (c *ClientTests) TestApiKeysAll() {
client := c.ProdClient()
assert, require := c.Assert(), c.Require()
apiKeys, err := client.GetAPIKeys()
require.NoError(err)
assert.NotNil(apiKeys)
}
func (c *ClientTests) TestApiKeysForParentUser() {
client := c.ProdClient()
assert, require := c.Assert(), c.Require()
authenticatedUser, err := client.RetrieveMe()
require.NoError(err)
apiKeys, err := client.GetAPIKeysForUser(authenticatedUser.ID)
require.NoError(err)
assert.NotNil(apiKeys)
}
func (c *ClientTests) TestApiKeysRetrieveChildUser() {
client := c.ProdClient()
assert, require := c.Assert(), c.Require()
fakeChildUserID := "user_123456789"
apiKeys, err := client.GetAPIKeysForUser(fakeChildUserID)
require.Error(err)
assert.Nil(apiKeys)
assert.Equal(reflect.TypeOf(&FilteringError{}), reflect.TypeOf(err))
}
func (c *ClientTests) TestApiKeyLifecycle() {
client := c.ReferralClient()
assert, require := c.Assert(), c.Require()
// Create an API key
apiKey, err := client.CreateAPIKey("production")
require.NoError(err)
assert.NotNil(apiKey)
assert.Contains(apiKey.ID, "ak_")
assert.Equal("production", apiKey.Mode)
// Disable the API key
apiKey, err = client.DisableAPIKey(apiKey.ID)
require.NoError(err)
assert.False(apiKey.Active)
// Enable the API key
apiKey, err = client.EnableAPIKey(apiKey.ID)
require.NoError(err)
assert.True(apiKey.Active)
// Delete the API key
err = client.DeleteAPIKey(apiKey.ID)
require.NoError(err)
}