2025-05-08 07:42:53 +02:00
|
|
|
package repository_test
|
2025-04-29 06:03:47 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-05-06 07:18:11 +02:00
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
2025-05-08 07:42:53 +02:00
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database/dbmock"
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database/repository"
|
|
|
|
"go.uber.org/mock/gomock"
|
2025-04-29 06:03:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestQueryUser(t *testing.T) {
|
2025-05-26 08:20:14 +02:00
|
|
|
t.Skip("tests are meant as examples and are not real tests")
|
2025-04-29 06:03:47 +02:00
|
|
|
t.Run("User filters", func(t *testing.T) {
|
2025-05-08 07:42:53 +02:00
|
|
|
client := dbmock.NewMockClient(gomock.NewController(t))
|
|
|
|
|
|
|
|
user := repository.UserRepository(client)
|
2025-04-30 09:30:48 +02:00
|
|
|
u, err := user.Get(context.Background(),
|
2025-05-06 07:18:11 +02:00
|
|
|
database.WithCondition(
|
|
|
|
database.And(
|
|
|
|
database.Or(
|
2025-04-30 09:30:48 +02:00
|
|
|
user.IDCondition("test"),
|
|
|
|
user.IDCondition("2"),
|
|
|
|
),
|
2025-05-06 07:18:11 +02:00
|
|
|
user.UsernameCondition(database.TextOperationStartsWithIgnoreCase, "test"),
|
2025-04-29 06:03:47 +02:00
|
|
|
),
|
|
|
|
),
|
2025-05-06 07:18:11 +02:00
|
|
|
database.WithOrderBy(user.CreatedAtColumn()),
|
2025-04-30 09:30:48 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, u)
|
2025-04-29 06:03:47 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("machine and human filters", func(t *testing.T) {
|
2025-05-08 07:42:53 +02:00
|
|
|
client := dbmock.NewMockClient(gomock.NewController(t))
|
|
|
|
|
|
|
|
user := repository.UserRepository(client)
|
2025-04-29 06:03:47 +02:00
|
|
|
machine := user.Machine()
|
|
|
|
human := user.Human()
|
2025-05-06 07:18:11 +02:00
|
|
|
email, err := human.GetEmail(context.Background(), database.And(
|
|
|
|
user.UsernameCondition(database.TextOperationStartsWithIgnoreCase, "test"),
|
|
|
|
database.Or(
|
|
|
|
machine.DescriptionCondition(database.TextOperationStartsWithIgnoreCase, "test"),
|
|
|
|
human.EmailVerifiedCondition(true),
|
|
|
|
database.IsNotNull(machine.DescriptionColumn()),
|
2025-04-29 06:03:47 +02:00
|
|
|
),
|
2025-04-30 09:30:48 +02:00
|
|
|
))
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, email)
|
2025-04-29 06:03:47 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type dbInstruction string
|
|
|
|
|
|
|
|
func TestArg(t *testing.T) {
|
|
|
|
var bla any = "asdf"
|
|
|
|
instr, ok := bla.(dbInstruction)
|
|
|
|
assert.False(t, ok)
|
|
|
|
assert.Empty(t, instr)
|
|
|
|
bla = dbInstruction("asdf")
|
|
|
|
instr, ok = bla.(dbInstruction)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, instr, dbInstruction("asdf"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWriteUser(t *testing.T) {
|
2025-05-26 08:20:14 +02:00
|
|
|
t.Skip("tests are meant as examples and are not real tests")
|
2025-04-29 06:03:47 +02:00
|
|
|
t.Run("update user", func(t *testing.T) {
|
2025-05-08 07:42:53 +02:00
|
|
|
user := repository.UserRepository(nil)
|
2025-05-06 07:18:11 +02:00
|
|
|
user.Human().Update(context.Background(), user.IDCondition("test"), user.SetUsername("test"))
|
2025-04-29 06:03:47 +02:00
|
|
|
})
|
|
|
|
}
|