func TestShowUserOK(t *testing.T) { resource.Require(t, resource.Database) defer cleaner.DeleteCreatedEntities(DB)() controller, app := createControler(t) ctx := context.Background() userRepo := app.Users() identityRepo := app.Identities() user := account.User{ Email: "*****@*****.**", FullName: "A test user", ImageURL: "someURL", } err := userRepo.Create(ctx, &user) if err != nil { t.Fatal(err) } identity := account.Identity{ Username: "******", Provider: account.KeycloakIDP, ID: uuid.NewV4(), User: user, UserID: account.NullUUID{UUID: user.ID, Valid: true}, } err = identityRepo.Create(ctx, &identity) if err != nil { t.Fatal(err) } _, result := test.ShowUsersOK(t, nil, nil, controller, identity.ID.String()) assert.Equal(t, identity.ID.String(), *result.Data.ID) assert.Equal(t, user.FullName, *result.Data.Attributes.FullName) assert.Equal(t, user.ImageURL, *result.Data.Attributes.ImageURL) assert.Equal(t, identity.Provider, *result.Data.Attributes.Provider) assert.Equal(t, identity.Username, *result.Data.Attributes.Username) }
func TestListUserOK(t *testing.T) { resource.Require(t, resource.Database) defer cleaner.DeleteCreatedEntities(DB)() controller, app := createControler(t) ctx := context.Background() userRepo := app.Users() identityRepo := app.Identities() user := account.User{ Email: "*****@*****.**", FullName: "A test user", ImageURL: "someURL", } err := userRepo.Create(ctx, &user) if err != nil { t.Fatal(err) } identityGitHub := account.Identity{ Username: "******", Provider: "github-test", ID: uuid.NewV4(), User: user, UserID: account.NullUUID{UUID: user.ID, Valid: true}, } err = identityRepo.Create(ctx, &identityGitHub) if err != nil { t.Fatal(err) } identity := account.Identity{ Username: "******", Provider: account.KeycloakIDP, ID: uuid.NewV4(), User: user, UserID: account.NullUUID{UUID: user.ID, Valid: true}, } err = identityRepo.Create(ctx, &identity) if err != nil { t.Fatal(err) } user2 := account.User{ Email: "*****@*****.**", FullName: "A test user 2", ImageURL: "someURL", } err = userRepo.Create(ctx, &user2) if err != nil { t.Fatal(err) } identity2 := account.Identity{ Username: "******", Provider: account.KeycloakIDP, ID: uuid.NewV4(), User: user2, UserID: account.NullUUID{UUID: user2.ID, Valid: true}, } err = identityRepo.Create(ctx, &identity2) if err != nil { t.Fatal(err) } _, result := test.ListUsersOK(t, nil, nil, controller) assertUser(t, findUser(identity.ID, result.Data), user, identity) assertUser(t, findUser(identity2.ID, result.Data), user2, identity2) }