2021-11-30 07:57:51 +00:00
|
|
|
package projection
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"testing"
|
|
|
|
|
2023-12-05 17:01:03 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-10-19 10:19:10 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
2022-10-20 12:36:52 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2022-11-30 16:01:17 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/user"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2021-11-30 07:57:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserProjection_reduces(t *testing.T) {
|
|
|
|
type args struct {
|
2022-01-03 08:19:07 +00:00
|
|
|
event func(t *testing.T) eventstore.Event
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
2022-01-03 08:19:07 +00:00
|
|
|
reduce func(event eventstore.Event) (*handler.Statement, error)
|
2021-11-30 07:57:51 +00:00
|
|
|
want wantReduce
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "reduceHumanAdded",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanAddedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "user-name",
|
|
|
|
"firstName": "first-name",
|
|
|
|
"lastName": "last-name",
|
|
|
|
"nickName": "nick-name",
|
|
|
|
"displayName": "display-name",
|
|
|
|
"preferredLanguage": "ch-DE",
|
|
|
|
"gender": 1,
|
2022-05-20 14:32:06 +00:00
|
|
|
"email": "email@zitadel.com",
|
2024-03-28 06:21:21 +00:00
|
|
|
"phone": "+41 00 000 00 00",
|
|
|
|
"changeRequired": true
|
2021-11-30 07:57:51 +00:00
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanAddedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanAdded,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
anyArg{},
|
|
|
|
anyArg{},
|
|
|
|
"ro-id",
|
2022-03-23 08:02:39 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
domain.UserStateActive,
|
2021-11-30 07:57:51 +00:00
|
|
|
uint64(15),
|
|
|
|
"user-name",
|
2022-01-14 09:45:50 +00:00
|
|
|
domain.UserTypeHuman,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone, password_change_required) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
"first-name",
|
|
|
|
"last-name",
|
|
|
|
&sql.NullString{String: "nick-name", Valid: true},
|
|
|
|
&sql.NullString{String: "display-name", Valid: true},
|
|
|
|
&sql.NullString{String: "ch-DE", Valid: true},
|
|
|
|
&sql.NullInt16{Int16: int16(domain.GenderFemale), Valid: true},
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2021-11-30 07:57:51 +00:00
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
2024-03-28 06:21:21 +00:00
|
|
|
true,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2022-07-06 12:09:49 +00:00
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1Added",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1AddedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "user-name",
|
|
|
|
"firstName": "first-name",
|
|
|
|
"lastName": "last-name",
|
|
|
|
"nickName": "nick-name",
|
|
|
|
"displayName": "display-name",
|
|
|
|
"preferredLanguage": "ch-DE",
|
|
|
|
"gender": 1,
|
2022-05-20 14:32:06 +00:00
|
|
|
"email": "email@zitadel.com",
|
2021-11-30 07:57:51 +00:00
|
|
|
"phone": "+41 00 000 00 00"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanAddedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanAdded,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
anyArg{},
|
|
|
|
anyArg{},
|
|
|
|
"ro-id",
|
2022-03-23 08:02:39 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
domain.UserStateActive,
|
2021-11-30 07:57:51 +00:00
|
|
|
uint64(15),
|
|
|
|
"user-name",
|
2022-01-14 09:45:50 +00:00
|
|
|
domain.UserTypeHuman,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone, password_change_required) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
"first-name",
|
|
|
|
"last-name",
|
|
|
|
&sql.NullString{String: "nick-name", Valid: true},
|
|
|
|
&sql.NullString{String: "display-name", Valid: true},
|
|
|
|
&sql.NullString{String: "ch-DE", Valid: true},
|
|
|
|
&sql.NullInt16{Int16: int16(domain.GenderFemale), Valid: true},
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2021-11-30 07:57:51 +00:00
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
2024-03-28 06:21:21 +00:00
|
|
|
false,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2022-07-06 12:09:49 +00:00
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanAdded NULLs",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanAddedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "user-name",
|
|
|
|
"firstName": "first-name",
|
|
|
|
"lastName": "last-name",
|
2022-05-20 14:32:06 +00:00
|
|
|
"email": "email@zitadel.com"
|
2021-11-30 07:57:51 +00:00
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanAddedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanAdded,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
anyArg{},
|
|
|
|
anyArg{},
|
|
|
|
"ro-id",
|
2022-03-23 08:02:39 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
domain.UserStateActive,
|
2021-11-30 07:57:51 +00:00
|
|
|
uint64(15),
|
|
|
|
"user-name",
|
2022-01-14 09:45:50 +00:00
|
|
|
domain.UserTypeHuman,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone, password_change_required) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
"first-name",
|
|
|
|
"last-name",
|
|
|
|
&sql.NullString{},
|
|
|
|
&sql.NullString{},
|
|
|
|
&sql.NullString{String: "und", Valid: false},
|
|
|
|
&sql.NullInt16{},
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2021-11-30 07:57:51 +00:00
|
|
|
&sql.NullString{},
|
2024-03-28 06:21:21 +00:00
|
|
|
false,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2022-07-06 12:09:49 +00:00
|
|
|
&sql.NullString{String: "", Valid: false},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanRegistered",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanRegisteredType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "user-name",
|
|
|
|
"firstName": "first-name",
|
|
|
|
"lastName": "last-name",
|
|
|
|
"nickName": "nick-name",
|
|
|
|
"displayName": "display-name",
|
|
|
|
"preferredLanguage": "ch-DE",
|
|
|
|
"gender": 1,
|
2022-05-20 14:32:06 +00:00
|
|
|
"email": "email@zitadel.com",
|
2024-03-28 06:21:21 +00:00
|
|
|
"phone": "+41 00 000 00 00",
|
|
|
|
"changeRequired": true
|
2021-11-30 07:57:51 +00:00
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanRegisteredEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanRegistered,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
anyArg{},
|
|
|
|
anyArg{},
|
|
|
|
"ro-id",
|
2022-03-23 08:02:39 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
domain.UserStateActive,
|
2021-11-30 07:57:51 +00:00
|
|
|
uint64(15),
|
|
|
|
"user-name",
|
2022-01-14 09:45:50 +00:00
|
|
|
domain.UserTypeHuman,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone, password_change_required) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
"first-name",
|
|
|
|
"last-name",
|
|
|
|
&sql.NullString{String: "nick-name", Valid: true},
|
|
|
|
&sql.NullString{String: "display-name", Valid: true},
|
|
|
|
&sql.NullString{String: "ch-DE", Valid: true},
|
|
|
|
&sql.NullInt16{Int16: int16(domain.GenderFemale), Valid: true},
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2021-11-30 07:57:51 +00:00
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
2024-03-28 06:21:21 +00:00
|
|
|
true,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2022-07-06 12:09:49 +00:00
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1Registered",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1RegisteredType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "user-name",
|
|
|
|
"firstName": "first-name",
|
|
|
|
"lastName": "last-name",
|
|
|
|
"nickName": "nick-name",
|
|
|
|
"displayName": "display-name",
|
|
|
|
"preferredLanguage": "ch-DE",
|
|
|
|
"gender": 1,
|
2022-05-20 14:32:06 +00:00
|
|
|
"email": "email@zitadel.com",
|
2021-11-30 07:57:51 +00:00
|
|
|
"phone": "+41 00 000 00 00"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanRegisteredEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanRegistered,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
anyArg{},
|
|
|
|
anyArg{},
|
|
|
|
"ro-id",
|
2022-03-23 08:02:39 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
domain.UserStateActive,
|
2021-11-30 07:57:51 +00:00
|
|
|
uint64(15),
|
|
|
|
"user-name",
|
2022-01-14 09:45:50 +00:00
|
|
|
domain.UserTypeHuman,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone, password_change_required) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
"first-name",
|
|
|
|
"last-name",
|
|
|
|
&sql.NullString{String: "nick-name", Valid: true},
|
|
|
|
&sql.NullString{String: "display-name", Valid: true},
|
|
|
|
&sql.NullString{String: "ch-DE", Valid: true},
|
|
|
|
&sql.NullInt16{Int16: int16(domain.GenderFemale), Valid: true},
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2021-11-30 07:57:51 +00:00
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
2024-03-28 06:21:21 +00:00
|
|
|
false,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2022-07-06 12:09:49 +00:00
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanRegistered NULLs",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanRegisteredType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "user-name",
|
|
|
|
"firstName": "first-name",
|
|
|
|
"lastName": "last-name",
|
2022-05-20 14:32:06 +00:00
|
|
|
"email": "email@zitadel.com"
|
2021-11-30 07:57:51 +00:00
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanRegisteredEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanRegistered,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
anyArg{},
|
|
|
|
anyArg{},
|
|
|
|
"ro-id",
|
2022-03-23 08:02:39 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
domain.UserStateActive,
|
2021-11-30 07:57:51 +00:00
|
|
|
uint64(15),
|
|
|
|
"user-name",
|
2022-01-14 09:45:50 +00:00
|
|
|
domain.UserTypeHuman,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_humans (user_id, instance_id, first_name, last_name, nick_name, display_name, preferred_language, gender, email, phone, password_change_required) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
"first-name",
|
|
|
|
"last-name",
|
|
|
|
&sql.NullString{},
|
|
|
|
&sql.NullString{},
|
|
|
|
&sql.NullString{String: "und", Valid: false},
|
|
|
|
&sql.NullInt16{},
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2021-11-30 07:57:51 +00:00
|
|
|
&sql.NullString{},
|
2024-03-28 06:21:21 +00:00
|
|
|
false,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_notifications (user_id, instance_id, last_email, last_phone, password_set) VALUES ($1, $2, $3, $4, $5)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2022-07-06 12:09:49 +00:00
|
|
|
&sql.NullString{String: "", Valid: false},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-25 10:35:38 +00:00
|
|
|
{
|
|
|
|
name: "reduceHumanInitCodeAdded",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanInitialCodeAddedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanInitialCodeAddedEventMapper),
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanInitCodeAdded,
|
2022-01-25 10:35:38 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2022-01-25 10:35:38 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET state = $1 WHERE (id = $2) AND (instance_id = $3)",
|
2022-01-25 10:35:38 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
domain.UserStateInitial,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1InitCodeAdded",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1InitialCodeAddedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanInitialCodeAddedEventMapper),
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanInitCodeAdded,
|
2022-01-25 10:35:38 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2022-01-25 10:35:38 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET state = $1 WHERE (id = $2) AND (instance_id = $3)",
|
2022-01-25 10:35:38 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
domain.UserStateInitial,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanInitCodeSucceeded",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanInitializedCheckSucceededType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanInitializedCheckSucceededEventMapper),
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanInitCodeSucceeded,
|
2022-01-25 10:35:38 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2022-01-25 10:35:38 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET state = $1 WHERE (id = $2) AND (instance_id = $3)",
|
2022-01-25 10:35:38 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
domain.UserStateActive,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1InitCodeAdded",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1InitializedCheckSucceededType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanInitializedCheckSucceededEventMapper),
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanInitCodeSucceeded,
|
2022-01-25 10:35:38 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2022-01-25 10:35:38 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET state = $1 WHERE (id = $2) AND (instance_id = $3)",
|
2022-01-25 10:35:38 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
domain.UserStateActive,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
{
|
|
|
|
name: "reduceUserLocked",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserLockedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.UserLockedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceUserLocked,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
domain.UserStateLocked,
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserUnlocked",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserUnlockedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.UserUnlockedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceUserUnlocked,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
domain.UserStateActive,
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserDeactivated",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserDeactivatedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.UserDeactivatedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceUserDeactivated,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
domain.UserStateInactive,
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserReactivated",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserReactivatedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.UserReactivatedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceUserReactivated,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, state, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
domain.UserStateActive,
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserRemoved",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserRemovedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.UserRemovedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceUserRemoved,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "DELETE FROM projections.users11 WHERE (id = $1) AND (instance_id = $2)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserUserNameChanged",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserUserNameChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "username"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.UsernameChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceUserNameChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, username, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
"username",
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-28 11:18:31 +00:00
|
|
|
{
|
|
|
|
name: "reduceDomainClaimed",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserDomainClaimedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2022-07-28 11:18:31 +00:00
|
|
|
"username": "id@temporary.domain"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.DomainClaimedEventMapper),
|
2022-07-28 11:18:31 +00:00
|
|
|
},
|
|
|
|
reduce: (&userProjection{}).reduceDomainClaimed,
|
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2022-07-28 11:18:31 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, username, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
2022-07-28 11:18:31 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
"id@temporary.domain",
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
{
|
|
|
|
name: "reduceHumanProfileChanged",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanProfileChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"firstName": "first-name",
|
|
|
|
"lastName": "last-name",
|
|
|
|
"nickName": "nick-name",
|
|
|
|
"displayName": "display-name",
|
|
|
|
"preferredLanguage": "ch-DE",
|
|
|
|
"gender": 3
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanProfileChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanProfileChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET (first_name, last_name, nick_name, display_name, preferred_language, gender) = ($1, $2, $3, $4, $5, $6) WHERE (user_id = $7) AND (instance_id = $8)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"first-name",
|
|
|
|
"last-name",
|
|
|
|
"nick-name",
|
|
|
|
"display-name",
|
|
|
|
"ch-DE",
|
|
|
|
domain.GenderDiverse,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1ProfileChanged",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1ProfileChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"firstName": "first-name",
|
|
|
|
"lastName": "last-name",
|
|
|
|
"nickName": "nick-name",
|
|
|
|
"displayName": "display-name",
|
|
|
|
"preferredLanguage": "ch-DE",
|
|
|
|
"gender": 3
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanProfileChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanProfileChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET (first_name, last_name, nick_name, display_name, preferred_language, gender) = ($1, $2, $3, $4, $5, $6) WHERE (user_id = $7) AND (instance_id = $8)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"first-name",
|
|
|
|
"last-name",
|
|
|
|
"nick-name",
|
|
|
|
"display-name",
|
|
|
|
"ch-DE",
|
|
|
|
domain.GenderDiverse,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanPhoneChanged",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanPhoneChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"phone": "+41 00 000 00 00"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanPhoneChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanPhoneChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.PhoneNumber("+41 00 000 00 00"),
|
2021-11-30 07:57:51 +00:00
|
|
|
false,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET last_phone = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1PhoneChanged",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1PhoneChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"phone": "+41 00 000 00 00"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanPhoneChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanPhoneChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.PhoneNumber("+41 00 000 00 00"),
|
2021-11-30 07:57:51 +00:00
|
|
|
false,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET last_phone = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
&sql.NullString{String: "+41 00 000 00 00", Valid: true},
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanPhoneRemoved",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanPhoneRemovedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanPhoneRemovedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanPhoneRemoved,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET (last_phone, verified_phone) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1PhoneRemoved",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1PhoneRemovedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanPhoneRemovedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanPhoneRemoved,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET (phone, is_phone_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET (last_phone, verified_phone) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanPhoneVerified",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanPhoneVerifiedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanPhoneVerifiedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanPhoneVerified,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET is_phone_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
true,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET verified_phone = last_phone WHERE (user_id = $1) AND (instance_id = $2)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1PhoneVerified",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1PhoneVerifiedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanPhoneVerifiedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanPhoneVerified,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET is_phone_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
true,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET verified_phone = last_phone WHERE (user_id = $1) AND (instance_id = $2)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanEmailChanged",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanEmailChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2022-05-20 14:32:06 +00:00
|
|
|
"email": "email@zitadel.com"
|
2021-11-30 07:57:51 +00:00
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanEmailChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanEmailChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET (email, is_email_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2021-11-30 07:57:51 +00:00
|
|
|
false,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET last_email = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
&sql.NullString{String: "email@zitadel.com", Valid: true},
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1EmailChanged",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1EmailChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2022-05-20 14:32:06 +00:00
|
|
|
"email": "email@zitadel.com"
|
2021-11-30 07:57:51 +00:00
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanEmailChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanEmailChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET (email, is_email_verified) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
2023-03-14 19:20:38 +00:00
|
|
|
domain.EmailAddress("email@zitadel.com"),
|
2021-11-30 07:57:51 +00:00
|
|
|
false,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET last_email = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
&sql.NullString{String: "email@zitadel.com", Valid: true},
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanEmailVerified",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanEmailVerifiedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanEmailVerifiedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanEmailVerified,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET is_email_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
true,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET verified_email = last_email WHERE (user_id = $1) AND (instance_id = $2)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceUserV1EmailVerified",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.UserV1EmailVerifiedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanEmailVerifiedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanEmailVerified,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET is_email_verified = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
true,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-06 12:09:49 +00:00
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET verified_email = last_email WHERE (user_id = $1) AND (instance_id = $2)",
|
2022-07-06 12:09:49 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanAvatarAdded",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanAvatarAddedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"storeKey": "users/agg-id/avatar"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.HumanAvatarAddedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanAvatarAdded,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET avatar_key = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"users/agg-id/avatar",
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanAvatarRemoved",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanAvatarRemovedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.HumanAvatarRemovedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceHumanAvatarRemoved,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET avatar_key = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
nil,
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-03-28 06:21:21 +00:00
|
|
|
{
|
|
|
|
name: "reduceHumanPasswordChanged",
|
|
|
|
args: args{
|
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanPasswordChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
|
|
|
"changeRequired": true
|
|
|
|
}`),
|
|
|
|
), user.HumanPasswordChangedEventMapper),
|
|
|
|
},
|
|
|
|
reduce: (&userProjection{}).reduceHumanPasswordChanged,
|
|
|
|
want: wantReduce{
|
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET password_change_required = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
|
|
|
expectedArgs: []interface{}{
|
|
|
|
true,
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET password_set = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
|
|
|
expectedArgs: []interface{}{
|
|
|
|
true,
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceHumanPasswordChanged, false",
|
|
|
|
args: args{
|
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.HumanPasswordChangedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
|
|
|
"changeRequired": false
|
|
|
|
}`),
|
|
|
|
), user.HumanPasswordChangedEventMapper),
|
|
|
|
},
|
|
|
|
reduce: (&userProjection{}).reduceHumanPasswordChanged,
|
|
|
|
want: wantReduce{
|
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
|
|
|
expectedStmt: "UPDATE projections.users11_humans SET password_change_required = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
|
|
|
expectedArgs: []interface{}{
|
|
|
|
false,
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
expectedStmt: "UPDATE projections.users11_notifications SET password_set = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
|
|
|
expectedArgs: []interface{}{
|
|
|
|
true,
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
{
|
|
|
|
name: "reduceMachineAddedEvent no description",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.MachineAddedEventType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "username",
|
|
|
|
"name": "machine-name"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.MachineAddedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceMachineAdded,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
anyArg{},
|
|
|
|
anyArg{},
|
|
|
|
"ro-id",
|
2022-03-23 08:02:39 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
domain.UserStateActive,
|
2021-11-30 07:57:51 +00:00
|
|
|
uint64(15),
|
|
|
|
"username",
|
2022-01-14 09:45:50 +00:00
|
|
|
domain.UserTypeMachine,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_machines (user_id, instance_id, name, description, access_token_type) VALUES ($1, $2, $3, $4, $5)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
"machine-name",
|
|
|
|
&sql.NullString{},
|
2023-02-08 08:06:34 +00:00
|
|
|
domain.OIDCTokenTypeBearer,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceMachineAddedEvent",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.MachineAddedEventType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"username": "username",
|
|
|
|
"name": "machine-name",
|
|
|
|
"description": "description"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.MachineAddedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceMachineAdded,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11 (id, creation_date, change_date, resource_owner, instance_id, state, sequence, username, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
anyArg{},
|
|
|
|
anyArg{},
|
|
|
|
"ro-id",
|
2022-03-23 08:02:39 +00:00
|
|
|
"instance-id",
|
2022-01-25 10:35:38 +00:00
|
|
|
domain.UserStateActive,
|
2021-11-30 07:57:51 +00:00
|
|
|
uint64(15),
|
|
|
|
"username",
|
2022-01-14 09:45:50 +00:00
|
|
|
domain.UserTypeMachine,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "INSERT INTO projections.users11_machines (user_id, instance_id, name, description, access_token_type) VALUES ($1, $2, $3, $4, $5)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
"machine-name",
|
|
|
|
&sql.NullString{String: "description", Valid: true},
|
2023-02-08 08:06:34 +00:00
|
|
|
domain.OIDCTokenTypeBearer,
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceMachineChangedEvent",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.MachineChangedEventType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"name": "machine-name",
|
|
|
|
"description": "description"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.MachineChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceMachineChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_machines SET (name, description) = ($1, $2) WHERE (user_id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"machine-name",
|
|
|
|
"description",
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceMachineChangedEvent name",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.MachineChangedEventType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"name": "machine-name"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.MachineChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceMachineChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_machines SET name = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"machine-name",
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceMachineChangedEvent description",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.MachineChangedEventType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2021-11-30 07:57:51 +00:00
|
|
|
"description": "description"
|
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.MachineChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceMachineChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_machines SET description = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2021-11-30 07:57:51 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"description",
|
|
|
|
"agg-id",
|
2022-05-25 12:15:13 +00:00
|
|
|
"instance-id",
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reduceMachineChangedEvent no values",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.MachineChangedEventType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.MachineChangedEventMapper),
|
2021-11-30 07:57:51 +00:00
|
|
|
},
|
2022-06-14 05:51:00 +00:00
|
|
|
reduce: (&userProjection{}).reduceMachineChanged,
|
2021-11-30 07:57:51 +00:00
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2021-11-30 07:57:51 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-01-31 19:52:47 +00:00
|
|
|
{
|
|
|
|
name: "reduceMachineSecretSet",
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.MachineSecretSetType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{
|
2023-12-05 17:01:03 +00:00
|
|
|
"clientSecret": {"CryptoType":1,"Algorithm":"bcrypt","Crypted":"deadbeef"}
|
2023-01-31 19:52:47 +00:00
|
|
|
}`),
|
2023-10-19 10:19:10 +00:00
|
|
|
), user.MachineSecretSetEventMapper),
|
2023-01-31 19:52:47 +00:00
|
|
|
},
|
|
|
|
reduce: (&userProjection{}).reduceMachineSecretSet,
|
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2023-01-31 19:52:47 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2023-01-31 19:52:47 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_machines SET secret = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2023-01-31 19:52:47 +00:00
|
|
|
expectedArgs: []interface{}{
|
2023-12-05 17:01:03 +00:00
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeHash,
|
|
|
|
Algorithm: "bcrypt",
|
|
|
|
Crypted: []byte{117, 230, 157, 109, 231, 159},
|
|
|
|
},
|
2023-01-31 19:52:47 +00:00
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-12-05 17:01:03 +00:00
|
|
|
name: "reduceMachineSecretRemoved",
|
2023-01-31 19:52:47 +00:00
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
user.MachineSecretRemovedType,
|
|
|
|
user.AggregateType,
|
|
|
|
[]byte(`{}`),
|
|
|
|
), user.MachineSecretRemovedEventMapper),
|
2023-01-31 19:52:47 +00:00
|
|
|
},
|
|
|
|
reduce: (&userProjection{}).reduceMachineSecretRemoved,
|
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: user.AggregateType,
|
|
|
|
sequence: 15,
|
2023-01-31 19:52:47 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
2023-01-31 19:52:47 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
anyArg{},
|
|
|
|
uint64(15),
|
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "UPDATE projections.users11_machines SET secret = $1 WHERE (user_id = $2) AND (instance_id = $3)",
|
2023-01-31 19:52:47 +00:00
|
|
|
expectedArgs: []interface{}{
|
2023-12-05 17:01:03 +00:00
|
|
|
nil,
|
2023-01-31 19:52:47 +00:00
|
|
|
"agg-id",
|
|
|
|
"instance-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-11-30 16:01:17 +00:00
|
|
|
{
|
|
|
|
name: "org reduceOwnerRemoved",
|
|
|
|
reduce: (&userProjection{}).reduceOwnerRemoved,
|
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
org.OrgRemovedEventType,
|
|
|
|
org.AggregateType,
|
|
|
|
nil,
|
|
|
|
), org.OrgRemovedEventMapper),
|
2022-11-30 16:01:17 +00:00
|
|
|
},
|
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: eventstore.AggregateType("org"),
|
|
|
|
sequence: 15,
|
2022-11-30 16:01:17 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "DELETE FROM projections.users11 WHERE (instance_id = $1) AND (resource_owner = $2)",
|
2022-11-30 16:01:17 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"instance-id",
|
|
|
|
"agg-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-10-20 12:36:52 +00:00
|
|
|
{
|
2022-11-10 10:59:33 +00:00
|
|
|
name: "instance reduceInstanceRemoved",
|
2022-10-20 12:36:52 +00:00
|
|
|
args: args{
|
2023-10-19 10:19:10 +00:00
|
|
|
event: getEvent(
|
|
|
|
testEvent(
|
|
|
|
instance.InstanceRemovedEventType,
|
|
|
|
instance.AggregateType,
|
|
|
|
nil,
|
|
|
|
), instance.InstanceRemovedEventMapper),
|
2022-10-20 12:36:52 +00:00
|
|
|
},
|
|
|
|
reduce: reduceInstanceRemovedHelper(UserInstanceIDCol),
|
|
|
|
want: wantReduce{
|
2023-10-19 10:19:10 +00:00
|
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
|
|
sequence: 15,
|
2022-10-20 12:36:52 +00:00
|
|
|
executer: &testExecuter{
|
|
|
|
executions: []execution{
|
|
|
|
{
|
2024-03-28 06:21:21 +00:00
|
|
|
expectedStmt: "DELETE FROM projections.users11 WHERE (instance_id = $1)",
|
2022-10-20 12:36:52 +00:00
|
|
|
expectedArgs: []interface{}{
|
|
|
|
"agg-id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-11-30 07:57:51 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
event := baseEvent(t)
|
|
|
|
got, err := tt.reduce(event)
|
2023-12-08 14:30:55 +00:00
|
|
|
if ok := zerrors.IsErrorInvalidArgument(err); !ok {
|
2021-11-30 07:57:51 +00:00
|
|
|
t.Errorf("no wrong event mapping: %v, got: %v", err, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
event = tt.args.event(t)
|
|
|
|
got, err = tt.reduce(event)
|
2022-10-20 12:36:52 +00:00
|
|
|
assertReduce(t, got, err, UserTable, tt.want)
|
2021-11-30 07:57:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|