2022-02-16 15:49:17 +00:00
package projection
import (
"testing"
2024-04-11 07:16:10 +00:00
"github.com/zitadel/zitadel/internal/domain"
2022-04-26 23:01:45 +00:00
"github.com/zitadel/zitadel/internal/eventstore"
2023-10-19 10:19:10 +00:00
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
2022-04-26 23:01:45 +00:00
"github.com/zitadel/zitadel/internal/repository/instance"
2023-12-08 14:30:55 +00:00
"github.com/zitadel/zitadel/internal/zerrors"
2022-02-16 15:49:17 +00:00
)
func TestSMTPConfigProjection_reduces ( t * testing . T ) {
type args struct {
event func ( t * testing . T ) eventstore . Event
}
tests := [ ] struct {
name string
args args
reduce func ( event eventstore . Event ) ( * handler . Statement , error )
want wantReduce
} {
2024-10-04 09:34:44 +00:00
{
name : "reduceSMTPConfigChanged (no id)" ,
args : args {
event : getEvent (
testEvent (
instance . SMTPConfigChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"description" : "test" ,
"tls" : true ,
"senderAddress" : "sender" ,
"senderName" : "name" ,
"replyToAddress" : "reply-to" ,
"host" : "host" ,
"user" : "user"
} ` ,
) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigChangedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigChanged ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
"test" ,
"ro-id" ,
"instance-id" ,
} ,
} ,
{
expectedStmt : "UPDATE projections.smtp_configs5_smtp SET (tls, sender_address, sender_name, reply_to_address, host, username) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)" ,
expectedArgs : [ ] interface { } {
true ,
"sender" ,
"name" ,
"reply-to" ,
"host" ,
"user" ,
"ro-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
2022-02-16 15:49:17 +00:00
{
name : "reduceSMTPConfigChanged" ,
args : args {
2023-10-19 10:19:10 +00:00
event : getEvent (
testEvent (
instance . SMTPConfigChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 04:27:29 +00:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
2024-04-11 07:16:10 +00:00
"description" : "test" ,
2022-02-16 15:49:17 +00:00
"tls" : true ,
"senderAddress" : "sender" ,
"senderName" : "name" ,
2023-08-29 07:08:24 +00:00
"replyToAddress" : "reply-to" ,
2022-02-16 15:49:17 +00:00
"host" : "host" ,
2024-09-12 04:27:29 +00:00
"user" : "user"
2022-02-16 15:49:17 +00:00
} ` ,
2023-10-19 10:19:10 +00:00
) ,
2024-09-12 04:27:29 +00:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigChangedEvent ] ) ,
2022-02-16 15:49:17 +00:00
} ,
2022-06-14 05:51:00 +00:00
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigChanged ,
2022-02-16 15:49:17 +00:00
want : wantReduce {
2023-10-19 10:19:10 +00:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2022-02-16 15:49:17 +00:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2022-02-16 15:49:17 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
2024-09-12 04:27:29 +00:00
"test" ,
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5_smtp SET (tls, sender_address, sender_name, reply_to_address, host, username) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
2022-02-16 15:49:17 +00:00
true ,
"sender" ,
"name" ,
2023-08-29 07:08:24 +00:00
"reply-to" ,
2022-02-16 15:49:17 +00:00
"host" ,
"user" ,
2024-09-12 04:27:29 +00:00
"config-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigChanged, description" ,
args : args {
event : getEvent (
testEvent (
instance . SMTPConfigChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
"description" : "test"
} ` ,
) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigChangedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigChanged ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
2024-04-11 07:16:10 +00:00
"test" ,
2024-09-12 04:27:29 +00:00
"config-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigChanged, senderAddress" ,
args : args {
event : getEvent (
testEvent (
instance . SMTPConfigChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
"senderAddress" : "sender"
} ` ,
) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigChangedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigChanged ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5_smtp SET sender_address = $1 WHERE (id = $2) AND (instance_id = $3)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
"sender" ,
"config-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigHTTPChanged" ,
args : args {
event : getEvent (
testEvent (
instance . SMTPConfigHTTPChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
"description" : "test" ,
"endpoint" : "endpoint"
} ` ,
) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigHTTPChangedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigHTTPChanged ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
"test" ,
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5_http SET endpoint = $1 WHERE (id = $2) AND (instance_id = $3)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
"endpoint" ,
"config-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigHTTPChanged, description" ,
args : args {
event : getEvent (
testEvent (
instance . SMTPConfigHTTPChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
"description" : "test"
} ` ,
) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigHTTPChangedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigHTTPChanged ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
"test" ,
"config-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigHTTPChanged, endpoint" ,
args : args {
event : getEvent (
testEvent (
instance . SMTPConfigHTTPChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
"endpoint" : "endpoint"
} ` ,
) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigHTTPChangedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigHTTPChanged ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5_http SET endpoint = $1 WHERE (id = $2) AND (instance_id = $3)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
"endpoint" ,
"config-id" ,
2022-05-25 12:15:13 +00:00
"instance-id" ,
2022-02-16 15:49:17 +00:00
} ,
} ,
} ,
} ,
} ,
} ,
2024-09-13 13:22:25 +00:00
{
name : "reduceSMTPConfigAdded (no id)" ,
args : args {
event : getEvent (
testEvent (
instance . SMTPConfigAddedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"tls" : true ,
"senderAddress" : "sender" ,
"senderName" : "name" ,
"replyToAddress" : "reply-to" ,
"host" : "host" ,
"user" : "user" ,
"password" : {
"cryptoType" : 0 ,
"algorithm" : "RSA-265" ,
"keyId" : "key-id"
}
} ` ) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigAddedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigAdded ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "INSERT INTO projections.smtp_configs5 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)" ,
2024-09-13 13:22:25 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
anyArg { } ,
"instance-id" ,
"ro-id" ,
"agg-id" ,
"ro-id" ,
uint64 ( 15 ) ,
domain . SMTPConfigStateActive ,
"generic" ,
} ,
} ,
{
2024-10-04 09:34:44 +00:00
expectedStmt : "INSERT INTO projections.smtp_configs5_smtp (instance_id, id, tls, sender_address, sender_name, reply_to_address, host, username, password) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)" ,
2024-09-13 13:22:25 +00:00
expectedArgs : [ ] interface { } {
"instance-id" ,
"ro-id" ,
true ,
"sender" ,
"name" ,
"reply-to" ,
"host" ,
"user" ,
anyArg { } ,
} ,
} ,
} ,
} ,
} ,
} ,
2022-02-16 15:49:17 +00:00
{
name : "reduceSMTPConfigAdded" ,
args : args {
2023-10-19 10:19:10 +00:00
event : getEvent (
testEvent (
instance . SMTPConfigAddedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 04:27:29 +00:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
2024-04-11 07:16:10 +00:00
"description" : "test" ,
2024-09-12 04:27:29 +00:00
"tls" : true ,
2022-02-16 15:49:17 +00:00
"senderAddress" : "sender" ,
"senderName" : "name" ,
2023-08-29 07:08:24 +00:00
"replyToAddress" : "reply-to" ,
2022-02-16 15:49:17 +00:00
"host" : "host" ,
"user" : "user" ,
"password" : {
"cryptoType" : 0 ,
"algorithm" : "RSA-265" ,
"keyId" : "key-id"
}
} ` ) ,
2024-09-12 04:27:29 +00:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigAddedEvent ] ) ,
2022-02-16 15:49:17 +00:00
} ,
2022-06-14 05:51:00 +00:00
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigAdded ,
2022-02-16 15:49:17 +00:00
want : wantReduce {
2023-10-19 10:19:10 +00:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2022-02-16 15:49:17 +00:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "INSERT INTO projections.smtp_configs5 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)" ,
2022-02-16 15:49:17 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
anyArg { } ,
2022-03-23 08:02:39 +00:00
"instance-id" ,
2024-09-12 04:27:29 +00:00
"ro-id" ,
"agg-id" ,
"config-id" ,
2022-02-16 15:49:17 +00:00
uint64 ( 15 ) ,
2024-09-12 04:27:29 +00:00
domain . SMTPConfigStateInactive ,
"test" ,
} ,
} ,
{
2024-10-04 09:34:44 +00:00
expectedStmt : "INSERT INTO projections.smtp_configs5_smtp (instance_id, id, tls, sender_address, sender_name, reply_to_address, host, username, password) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
"instance-id" ,
"config-id" ,
2022-02-16 15:49:17 +00:00
true ,
"sender" ,
"name" ,
2023-08-29 07:08:24 +00:00
"reply-to" ,
2022-02-16 15:49:17 +00:00
"host" ,
"user" ,
anyArg { } ,
2024-09-12 04:27:29 +00:00
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigHTTPAdded" ,
args : args {
event : getEvent (
testEvent (
instance . SMTPConfigHTTPAddedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
"description" : "test" ,
"senderAddress" : "sender" ,
"endpoint" : "endpoint"
} ` ) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigHTTPAddedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigHTTPAdded ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "INSERT INTO projections.smtp_configs5 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
anyArg { } ,
"instance-id" ,
"ro-id" ,
"agg-id" ,
"config-id" ,
uint64 ( 15 ) ,
domain . SMTPConfigStateInactive ,
2024-04-11 07:16:10 +00:00
"test" ,
} ,
} ,
2024-09-12 04:27:29 +00:00
{
2024-10-04 09:34:44 +00:00
expectedStmt : "INSERT INTO projections.smtp_configs5_http (instance_id, id, endpoint) VALUES ($1, $2, $3)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
"instance-id" ,
"config-id" ,
"endpoint" ,
} ,
} ,
2024-04-11 07:16:10 +00:00
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigActivated" ,
args : args {
event : getEvent ( testEvent (
instance . SMTPConfigActivatedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 04:27:29 +00:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id"
2024-04-11 07:16:10 +00:00
} ` ) ,
2024-09-12 04:27:29 +00:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigActivatedEvent ] ) ,
2024-04-11 07:16:10 +00:00
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigActivated ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (NOT (id = $4)) AND (state = $5) AND (instance_id = $6)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateInactive ,
"config-id" ,
domain . SMTPConfigStateActive ,
"instance-id" ,
} ,
} ,
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-04-11 07:16:10 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateActive ,
"config-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
2024-10-04 09:34:44 +00:00
{
name : "reduceSMTPConfigActivated (no id)" ,
args : args {
event : getEvent ( testEvent (
instance . SMTPConfigActivatedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id"
} ` ) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigActivatedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigActivated ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (NOT (id = $4)) AND (state = $5) AND (instance_id = $6)" ,
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateInactive ,
"ro-id" ,
domain . SMTPConfigStateActive ,
"instance-id" ,
} ,
} ,
{
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateActive ,
"ro-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
2024-04-11 07:16:10 +00:00
{
name : "reduceSMTPConfigDeactivated" ,
args : args {
event : getEvent ( testEvent (
instance . SMTPConfigDeactivatedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 04:27:29 +00:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id"
2024-04-11 07:16:10 +00:00
} ` ) ,
2024-09-12 04:27:29 +00:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigDeactivatedEvent ] ) ,
2024-04-11 07:16:10 +00:00
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigDeactivated ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-04-11 07:16:10 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateInactive ,
"config-id" ,
"instance-id" ,
2022-02-16 15:49:17 +00:00
} ,
} ,
} ,
} ,
} ,
} ,
2024-10-04 09:34:44 +00:00
{
name : "reduceSMTPConfigDeactivated (no id)" ,
args : args {
event : getEvent ( testEvent (
instance . SMTPConfigDeactivatedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id"
} ` ) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigDeactivatedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigDeactivated ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateInactive ,
"ro-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
2022-02-16 15:49:17 +00:00
{
name : "reduceSMTPConfigPasswordChanged" ,
args : args {
2023-10-19 10:19:10 +00:00
event : getEvent (
testEvent (
instance . SMTPConfigPasswordChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 04:27:29 +00:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
2022-02-16 15:49:17 +00:00
"password" : {
"cryptoType" : 0 ,
"algorithm" : "RSA-265" ,
"keyId" : "key-id"
}
} ` ) ,
2024-09-12 04:27:29 +00:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigPasswordChangedEvent ] ) ,
2022-02-16 15:49:17 +00:00
} ,
2022-06-14 05:51:00 +00:00
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigPasswordChanged ,
2022-02-16 15:49:17 +00:00
want : wantReduce {
2023-10-19 10:19:10 +00:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2022-02-16 15:49:17 +00:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5_smtp SET password = $1 WHERE (id = $2) AND (instance_id = $3)" ,
2022-02-16 15:49:17 +00:00
expectedArgs : [ ] interface { } {
anyArg { } ,
2024-09-12 04:27:29 +00:00
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-10-04 09:34:44 +00:00
expectedStmt : "UPDATE projections.smtp_configs5 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)" ,
2024-09-12 04:27:29 +00:00
expectedArgs : [ ] interface { } {
2022-02-16 15:49:17 +00:00
anyArg { } ,
2024-09-12 04:27:29 +00:00
uint64 ( 15 ) ,
2024-04-11 07:16:10 +00:00
"config-id" ,
2022-05-25 12:15:13 +00:00
"instance-id" ,
2022-02-16 15:49:17 +00:00
} ,
} ,
} ,
} ,
} ,
} ,
2023-08-18 12:22:57 +00:00
{
name : "reduceSMTPConfigRemoved" ,
args : args {
event : getEvent ( testEvent (
2023-10-19 10:19:10 +00:00
instance . SMTPConfigRemovedEventType ,
2023-08-18 12:22:57 +00:00
instance . AggregateType ,
2024-09-12 04:27:29 +00:00
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id"
} ` ) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigRemovedEvent ] ) ,
2023-08-18 12:22:57 +00:00
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigRemoved ,
want : wantReduce {
2023-10-19 10:19:10 +00:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2023-08-18 12:22:57 +00:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-10-04 09:34:44 +00:00
expectedStmt : "DELETE FROM projections.smtp_configs5 WHERE (id = $1) AND (instance_id = $2)" ,
2023-08-18 12:22:57 +00:00
expectedArgs : [ ] interface { } {
2024-04-11 07:16:10 +00:00
"config-id" ,
2023-08-18 12:22:57 +00:00
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
2024-10-04 09:34:44 +00:00
{
name : "reduceSMTPConfigRemoved (no id)" ,
args : args {
event : getEvent ( testEvent (
instance . SMTPConfigRemovedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id"
} ` ) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigRemovedEvent ] ) ,
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigRemoved ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
expectedStmt : "DELETE FROM projections.smtp_configs5 WHERE (id = $1) AND (instance_id = $2)" ,
expectedArgs : [ ] interface { } {
"ro-id" ,
"instance-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 ( SMTPConfigColumnInstanceID ) ,
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-10-04 09:34:44 +00:00
expectedStmt : "DELETE FROM projections.smtp_configs5 WHERE (instance_id = $1)" ,
2022-10-20 12:36:52 +00:00
expectedArgs : [ ] interface { } {
"agg-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
2022-02-16 15:49:17 +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 {
2022-02-16 15:49:17 +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 , SMTPConfigProjectionTable , tt . want )
2022-02-16 15:49:17 +00:00
} )
}
}