GODT-2008: Add unit test asserting that primary address is listed first

This commit is contained in:
James Houlahan 2022-11-04 19:03:05 +01:00
parent 8a08d146bc
commit 4c4c592f31
1 changed files with 23 additions and 0 deletions

View File

@ -586,6 +586,29 @@ func TestBridge_DeleteOffline(t *testing.T) {
})
}
func TestBridge_UserInfo_Alias(t *testing.T) {
withEnv(t, func(ctx context.Context, s *server.Server, netCtl *liteapi.NetCtl, locator bridge.Locator, vaultKey []byte) {
withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) {
// Create a new user.
userID, _, err := s.CreateUser("primary", "primary@pm.me", []byte("password"))
require.NoError(t, err)
// Give the new user an alias.
require.NoError(t, getErr(s.CreateAddress(userID, "alias@pm.me", []byte("password"))))
// Login the user.
require.NoError(t, getErr(bridge.LoginFull(ctx, "primary", []byte("password"), nil, nil)))
// Get user info.
info, err := bridge.GetUserInfo(userID)
require.NoError(t, err)
// The user should have two addresses, the primary should be first.
require.Equal(t, []string{"primary@pm.me", "alias@pm.me"}, info.Addresses)
})
})
}
// getErr returns the error that was passed to it.
func getErr[T any](val T, err error) error {
return err