-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(account): add host field to workspace member
- Loading branch information
Showing
9 changed files
with
72 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
package user | ||
package workspace | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/reearth/reearthx/account/accountdomain/workspace" | ||
"github.com/reearth/reearthx/account/accountdomain/user" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInit(t *testing.T) { | ||
uid := NewID() | ||
tid := NewWorkspaceID() | ||
expectedSub := Auth{ | ||
uid := user.NewID() | ||
tid := NewID() | ||
expectedSub := user.Auth{ | ||
Provider: "###", | ||
Sub: "###", | ||
} | ||
tests := []struct { | ||
Name, Email, Username string | ||
Sub Auth | ||
UID *ID | ||
TID *WorkspaceID | ||
ExpectedUser *User | ||
ExpectedWorkspace *workspace.Workspace | ||
Sub user.Auth | ||
UID *user.ID | ||
TID *ID | ||
ExpectedUser *user.User | ||
ExpectedWorkspace *Workspace | ||
Err error | ||
}{ | ||
{ | ||
Name: "Success create user", | ||
Email: "[email protected]", | ||
Username: "nnn", | ||
Sub: Auth{ | ||
Sub: user.Auth{ | ||
Provider: "###", | ||
Sub: "###", | ||
}, | ||
UID: &uid, | ||
TID: &tid, | ||
ExpectedUser: New(). | ||
ExpectedUser: user.New(). | ||
ID(uid). | ||
Email("[email protected]"). | ||
Name("nnn"). | ||
Workspace(tid). | ||
Auths([]Auth{expectedSub}). | ||
Auths([]user.Auth{expectedSub}). | ||
MustBuild(), | ||
ExpectedWorkspace: workspace.New(). | ||
ExpectedWorkspace: New(). | ||
ID(tid). | ||
Name("nnn"). | ||
Members(map[ID]workspace.Member{uid: {Role: workspace.RoleOwner}}). | ||
Members(map[user.ID]Member{uid: {Role: RoleOwner}}). | ||
Personal(true). | ||
MustBuild(), | ||
Err: nil, | ||
|
@@ -52,23 +52,23 @@ func TestInit(t *testing.T) { | |
Name: "Success nil workspace id", | ||
Email: "[email protected]", | ||
Username: "nnn", | ||
Sub: Auth{ | ||
Sub: user.Auth{ | ||
Provider: "###", | ||
Sub: "###", | ||
}, | ||
UID: &uid, | ||
TID: nil, | ||
ExpectedUser: New(). | ||
ExpectedUser: user.New(). | ||
ID(uid). | ||
Email("[email protected]"). | ||
Name("nnn"). | ||
Workspace(tid). | ||
Auths([]Auth{expectedSub}). | ||
Auths([]user.Auth{expectedSub}). | ||
MustBuild(), | ||
ExpectedWorkspace: workspace.New(). | ||
ExpectedWorkspace: New(). | ||
NewID(). | ||
Name("nnn"). | ||
Members(map[ID]workspace.Member{uid: {Role: workspace.RoleOwner}}). | ||
Members(map[user.ID]Member{uid: {Role: RoleOwner}}). | ||
Personal(true). | ||
MustBuild(), | ||
Err: nil, | ||
|
@@ -77,23 +77,23 @@ func TestInit(t *testing.T) { | |
Name: "Success nil id", | ||
Email: "[email protected]", | ||
Username: "nnn", | ||
Sub: Auth{ | ||
Sub: user.Auth{ | ||
Provider: "###", | ||
Sub: "###", | ||
}, | ||
UID: nil, | ||
TID: &tid, | ||
ExpectedUser: New(). | ||
ExpectedUser: user.New(). | ||
NewID(). | ||
Email("[email protected]"). | ||
Name("nnn"). | ||
Workspace(tid). | ||
Auths([]Auth{expectedSub}). | ||
Auths([]user.Auth{expectedSub}). | ||
MustBuild(), | ||
ExpectedWorkspace: workspace.New(). | ||
ExpectedWorkspace: New(). | ||
ID(tid). | ||
Name("nnn"). | ||
Members(map[ID]workspace.Member{uid: {Role: workspace.RoleOwner}}). | ||
Members(map[user.ID]Member{uid: {Role: RoleOwner}}). | ||
Personal(true). | ||
MustBuild(), | ||
Err: nil, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package workspace | |
import ( | ||
"testing" | ||
|
||
"github.com/reearth/reearthx/account/accountdomain/user" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
|
@@ -143,21 +144,23 @@ func TestMembers_Join(t *testing.T) { | |
uid := NewUserID() | ||
uid2 := NewUserID() | ||
|
||
u := user.New().ID(uid).Name("test").Email("[email protected]").MustBuild().WithHost("reearth") | ||
|
||
// ok | ||
m := &Members{} | ||
assert.NoError(t, m.Join(uid, RoleOwner, uid2)) | ||
assert.NoError(t, m.Join(u, RoleOwner, uid2)) | ||
assert.Equal(t, map[UserID]Member{ | ||
uid: {Role: RoleOwner, InvitedBy: uid2}, | ||
uid: {Role: RoleOwner, InvitedBy: uid2, Host: "reearth"}, | ||
}, m.users) | ||
|
||
// fixed | ||
m = &Members{fixed: true} | ||
assert.Equal(t, ErrCannotModifyPersonalWorkspace, m.Join(uid, RoleOwner, uid2)) | ||
assert.Equal(t, ErrCannotModifyPersonalWorkspace, m.Join(u, RoleOwner, uid2)) | ||
assert.Nil(t, m.users) | ||
|
||
// already joined | ||
m = &Members{users: map[UserID]Member{uid: {Role: RoleOwner}}} | ||
assert.Equal(t, ErrUserAlreadyJoined, m.Join(uid, RoleOwner, uid2)) | ||
assert.Equal(t, ErrUserAlreadyJoined, m.Join(u, RoleOwner, uid2)) | ||
assert.Equal(t, map[UserID]Member{uid: {Role: RoleOwner}}, m.users) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ func TestWorkspace_Create(t *testing.T) { | |
db := accountmemory.New() | ||
|
||
u := user.New().NewID().Name("aaa").Email("[email protected]").Workspace(accountdomain.NewWorkspaceID()).MustBuild() | ||
_ = db.User.Save(ctx, u) | ||
workspaceUC := NewWorkspace(db, nil) | ||
op := &accountusecase.Operator{User: lo.ToPtr(u.ID())} | ||
ws, err := workspaceUC.Create(ctx, "workspace name", u.ID(), op) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters