Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
akiyatomohiro committed Aug 29, 2024
1 parent c662af6 commit ef93f27
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions account/accountinfrastructure/accountmongo/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,67 @@ import (
"github.com/stretchr/testify/assert"
)

func TestUserRepo_FindAll(t *testing.T) {
wsid := user.NewWorkspaceID()
user1 := user.New().
NewID().
Email("[email protected]").
Workspace(wsid).
Name("foo").
MustBuild()
user2 := user.New().
NewID().
Email("[email protected]").
Workspace(wsid).
Name("hoge").
MustBuild()

tests := []struct {
Name string
RepoData, Expected []*user.User
}{
{
Name: "must find users",
RepoData: []*user.User{user1, user2},
Expected: []*user.User{user1, user2},
},
{
Name: "must not find any user",
RepoData: []*user.User{},
},
}

init := mongotest.Connect(t)

for _, tc := range tests {
tc := tc

t.Run(tc.Name, func(tt *testing.T) {
tt.Parallel()

client := mongox.NewClientWithDatabase(init(t))

repo := NewUser(client)
ctx := context.Background()
for _, u := range tc.RepoData {
err := repo.Save(ctx, u)
assert.NoError(tt, err)
}

got, err := repo.FindAll(ctx)
assert.NoError(tt, err)
for k, u := range got {
if u != nil {
assert.Equal(tt, tc.Expected[k].ID(), u.ID())
assert.Equal(tt, tc.Expected[k].Email(), u.Email())
assert.Equal(tt, tc.Expected[k].Name(), u.Name())
assert.Equal(tt, tc.Expected[k].Workspace(), u.Workspace())
}
}
})
}
}

func TestUserRepo_FindByID(t *testing.T) {
wsid := user.NewWorkspaceID()
user1 := user.New().
Expand Down

0 comments on commit ef93f27

Please sign in to comment.