func TestListIdentities(t *testing.T) {
	resource.Require(t, resource.Database)
	defer cleaner.DeleteCreatedEntities(DB)()

	service := goa.New("Test-Identities")
	app := gormapplication.NewGormDB(DB)
	identityController := NewIdentityController(service, app)
	_, ic := test.ListIdentityOK(t, service.Context, service, identityController)
	require.NotNil(t, ic)

	numberOfCurrentIdent := len(ic.Data)

	ctx := context.Background()

	identityRepo := app.Identities()

	identity := account.Identity{
		Username: "******",
		Provider: "test-idp",
		ID:       uuid.NewV4(),
	}

	err := identityRepo.Create(ctx, &identity)
	if err != nil {
		t.Fatal(err)
	}

	_, ic2 := test.ListIdentityOK(t, service.Context, service, identityController)
	require.NotNil(t, ic2)

	assert.Equal(t, numberOfCurrentIdent+1, len(ic2.Data))

	assertIdent(t, identity, findIdent(identity.ID, ic2.Data))

	identity2 := account.Identity{
		Username: "******",
		Provider: "test-idp",
		ID:       uuid.NewV4(),
	}

	err = identityRepo.Create(ctx, &identity2)
	if err != nil {
		t.Fatal(err)
	}

	_, ic3 := test.ListIdentityOK(t, service.Context, service, identityController)
	require.NotNil(t, ic3)
	assert.Equal(t, numberOfCurrentIdent+2, len(ic3.Data))

	assertIdent(t, identity, findIdent(identity.ID, ic3.Data))
	assertIdent(t, identity2, findIdent(identity2.ID, ic3.Data))
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
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)
}