| 1 |
package proton_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/henrybear327/go-proton-api" |
| 8 |
"github.com/henrybear327/go-proton-api/server" |
| 9 |
"github.com/stretchr/testify/require" |
| 10 |
) |
| 11 |
|
| 12 |
func TestAddress_Types(t *testing.T) { |
| 13 |
s := server.New() |
| 14 |
defer s.Close() |
| 15 |
|
| 16 |
// Create a user on the server. |
| 17 |
userID, _, err := s.CreateUser("user", []byte("pass")) |
| 18 |
require.NoError(t, err) |
| 19 |
id2, err := s.CreateAddress(userID, "[email protected]", []byte("pass")) |
| 20 |
require.NoError(t, err) |
| 21 |
require.NoError(t, s.ChangeAddressType(userID, id2, proton.AddressTypeAlias)) |
| 22 |
id3, err := s.CreateAddress(userID, "[email protected]", []byte("pass")) |
| 23 |
require.NoError(t, err) |
| 24 |
require.NoError(t, s.ChangeAddressType(userID, id3, proton.AddressTypeCustom)) |
| 25 |
id4, err := s.CreateAddress(userID, "[email protected]", []byte("pass")) |
| 26 |
require.NoError(t, err) |
| 27 |
require.NoError(t, s.ChangeAddressType(userID, id4, proton.AddressTypePremium)) |
| 28 |
id5, err := s.CreateAddress(userID, "[email protected]", []byte("pass")) |
| 29 |
require.NoError(t, err) |
| 30 |
require.NoError(t, s.ChangeAddressType(userID, id5, proton.AddressTypeExternal)) |
| 31 |
|
| 32 |
m := proton.New( |
| 33 |
proton.WithHostURL(s.GetHostURL()), |
| 34 |
proton.WithTransport(proton.InsecureTransport()), |
| 35 |
) |
| 36 |
defer m.Close() |
| 37 |
|
| 38 |
// Create one session for the user. |
| 39 |
c, auth, err := m.NewClientWithLogin(context.Background(), "user", []byte("pass")) |
| 40 |
require.NoError(t, err) |
| 41 |
require.Equal(t, userID, auth.UserID) |
| 42 |
|
| 43 |
// Get addresses for the user. |
| 44 |
addrs, err := c.GetAddresses(context.Background()) |
| 45 |
require.NoError(t, err) |
| 46 |
|
| 47 |
for _, addr := range addrs { |
| 48 |
switch addr.ID { |
| 49 |
case id2: |
| 50 |
require.Equal(t, addr.Email, "[email protected]") |
| 51 |
require.Equal(t, addr.Type, proton.AddressTypeAlias) |
| 52 |
case id3: |
| 53 |
require.Equal(t, addr.Email, "[email protected]") |
| 54 |
require.Equal(t, addr.Type, proton.AddressTypeCustom) |
| 55 |
case id4: |
| 56 |
require.Equal(t, addr.Email, "[email protected]") |
| 57 |
require.Equal(t, addr.Type, proton.AddressTypePremium) |
| 58 |
case id5: |
| 59 |
require.Equal(t, addr.Email, "[email protected]") |
| 60 |
require.Equal(t, addr.Type, proton.AddressTypeExternal) |
| 61 |
default: |
| 62 |
require.Equal(t, addr.Email, "[email protected]") |
| 63 |
require.Equal(t, addr.Type, proton.AddressTypeOriginal) |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
} |