2022-02-16 16:49:17 +01:00
package projection
import (
"testing"
2024-04-11 09:16:10 +02:00
"github.com/zitadel/zitadel/internal/domain"
2022-04-27 01:01:45 +02:00
"github.com/zitadel/zitadel/internal/eventstore"
2023-10-19 12:19:10 +02:00
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
2022-04-27 01:01:45 +02:00
"github.com/zitadel/zitadel/internal/repository/instance"
2023-12-08 16:30:55 +02:00
"github.com/zitadel/zitadel/internal/zerrors"
2022-02-16 16:49:17 +01: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
} {
{
name : "reduceSMTPConfigChanged" ,
args : args {
2023-10-19 12:19:10 +02:00
event : getEvent (
testEvent (
instance . SMTPConfigChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 06:27:29 +02:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
2024-04-11 09:16:10 +02:00
"description" : "test" ,
2022-02-16 16:49:17 +01:00
"tls" : true ,
"senderAddress" : "sender" ,
"senderName" : "name" ,
2023-08-29 09:08:24 +02:00
"replyToAddress" : "reply-to" ,
2022-02-16 16:49:17 +01:00
"host" : "host" ,
2024-09-12 06:27:29 +02:00
"user" : "user"
2022-02-16 16:49:17 +01:00
} ` ,
2023-10-19 12:19:10 +02:00
) ,
2024-09-12 06:27:29 +02:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigChangedEvent ] ) ,
2022-02-16 16:49:17 +01:00
} ,
2022-06-14 07:51:00 +02:00
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigChanged ,
2022-02-16 16:49:17 +01:00
want : wantReduce {
2023-10-19 12:19:10 +02:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2022-02-16 16:49:17 +01:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2022-02-16 16:49:17 +01:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
2024-09-12 06:27:29 +02:00
"test" ,
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4_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 06:27:29 +02:00
expectedArgs : [ ] interface { } {
2022-02-16 16:49:17 +01:00
true ,
"sender" ,
"name" ,
2023-08-29 09:08:24 +02:00
"reply-to" ,
2022-02-16 16:49:17 +01:00
"host" ,
"user" ,
2024-09-12 06:27:29 +02: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-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-09-12 06:27:29 +02:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
2024-04-11 09:16:10 +02:00
"test" ,
2024-09-12 06:27:29 +02: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-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)" ,
2024-09-12 06:27:29 +02:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4_smtp SET sender_address = $1 WHERE (id = $2) AND (instance_id = $3)" ,
2024-09-12 06:27:29 +02: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-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-09-12 06:27:29 +02:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
"test" ,
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4_http SET endpoint = $1 WHERE (id = $2) AND (instance_id = $3)" ,
2024-09-12 06:27:29 +02: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-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-09-12 06:27:29 +02: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-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)" ,
2024-09-12 06:27:29 +02:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4_http SET endpoint = $1 WHERE (id = $2) AND (instance_id = $3)" ,
2024-09-12 06:27:29 +02:00
expectedArgs : [ ] interface { } {
"endpoint" ,
"config-id" ,
2022-05-25 14:15:13 +02:00
"instance-id" ,
2022-02-16 16:49:17 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
2024-09-13 15:22:25 +02: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 {
{
expectedStmt : "INSERT INTO projections.smtp_configs4 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)" ,
expectedArgs : [ ] interface { } {
anyArg { } ,
anyArg { } ,
"instance-id" ,
"ro-id" ,
"agg-id" ,
"ro-id" ,
uint64 ( 15 ) ,
domain . SMTPConfigStateActive ,
"generic" ,
} ,
} ,
{
expectedStmt : "INSERT INTO projections.smtp_configs4_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)" ,
expectedArgs : [ ] interface { } {
"instance-id" ,
"ro-id" ,
true ,
"sender" ,
"name" ,
"reply-to" ,
"host" ,
"user" ,
anyArg { } ,
} ,
} ,
} ,
} ,
} ,
} ,
2022-02-16 16:49:17 +01:00
{
name : "reduceSMTPConfigAdded" ,
args : args {
2023-10-19 12:19:10 +02:00
event : getEvent (
testEvent (
instance . SMTPConfigAddedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 06:27:29 +02:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
2024-04-11 09:16:10 +02:00
"description" : "test" ,
2024-09-12 06:27:29 +02:00
"tls" : true ,
2022-02-16 16:49:17 +01:00
"senderAddress" : "sender" ,
"senderName" : "name" ,
2023-08-29 09:08:24 +02:00
"replyToAddress" : "reply-to" ,
2022-02-16 16:49:17 +01:00
"host" : "host" ,
"user" : "user" ,
"password" : {
"cryptoType" : 0 ,
"algorithm" : "RSA-265" ,
"keyId" : "key-id"
}
} ` ) ,
2024-09-12 06:27:29 +02:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigAddedEvent ] ) ,
2022-02-16 16:49:17 +01:00
} ,
2022-06-14 07:51:00 +02:00
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigAdded ,
2022-02-16 16:49:17 +01:00
want : wantReduce {
2023-10-19 12:19:10 +02:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2022-02-16 16:49:17 +01:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-09-13 15:22:25 +02:00
expectedStmt : "INSERT INTO projections.smtp_configs4 (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 16:49:17 +01:00
expectedArgs : [ ] interface { } {
anyArg { } ,
anyArg { } ,
2022-03-23 09:02:39 +01:00
"instance-id" ,
2024-09-12 06:27:29 +02:00
"ro-id" ,
"agg-id" ,
"config-id" ,
2022-02-16 16:49:17 +01:00
uint64 ( 15 ) ,
2024-09-12 06:27:29 +02:00
domain . SMTPConfigStateInactive ,
"test" ,
} ,
} ,
{
2024-09-13 15:22:25 +02:00
expectedStmt : "INSERT INTO projections.smtp_configs4_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 06:27:29 +02:00
expectedArgs : [ ] interface { } {
"instance-id" ,
"config-id" ,
2022-02-16 16:49:17 +01:00
true ,
"sender" ,
"name" ,
2023-08-29 09:08:24 +02:00
"reply-to" ,
2022-02-16 16:49:17 +01:00
"host" ,
"user" ,
anyArg { } ,
2024-09-12 06:27:29 +02: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-09-13 15:22:25 +02:00
expectedStmt : "INSERT INTO projections.smtp_configs4 (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 06:27:29 +02:00
expectedArgs : [ ] interface { } {
anyArg { } ,
anyArg { } ,
"instance-id" ,
"ro-id" ,
"agg-id" ,
"config-id" ,
uint64 ( 15 ) ,
domain . SMTPConfigStateInactive ,
2024-04-11 09:16:10 +02:00
"test" ,
} ,
} ,
2024-09-12 06:27:29 +02:00
{
2024-09-13 15:22:25 +02:00
expectedStmt : "INSERT INTO projections.smtp_configs4_http (instance_id, id, endpoint) VALUES ($1, $2, $3)" ,
2024-09-12 06:27:29 +02:00
expectedArgs : [ ] interface { } {
"instance-id" ,
"config-id" ,
"endpoint" ,
} ,
} ,
2024-04-11 09:16:10 +02:00
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigActivated" ,
args : args {
event : getEvent ( testEvent (
instance . SMTPConfigActivatedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 06:27:29 +02:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id"
2024-04-11 09:16:10 +02:00
} ` ) ,
2024-09-12 06:27:29 +02:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigActivatedEvent ] ) ,
2024-04-11 09:16:10 +02:00
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigActivated ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (NOT (id = $4)) AND (state = $5) AND (instance_id = $6)" ,
2024-09-12 06:27:29 +02:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateInactive ,
"config-id" ,
domain . SMTPConfigStateActive ,
"instance-id" ,
} ,
} ,
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-04-11 09:16:10 +02:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateActive ,
"config-id" ,
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigDeactivated" ,
args : args {
event : getEvent ( testEvent (
instance . SMTPConfigDeactivatedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 06:27:29 +02:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id"
2024-04-11 09:16:10 +02:00
} ` ) ,
2024-09-12 06:27:29 +02:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigDeactivatedEvent ] ) ,
2024-04-11 09:16:10 +02:00
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigDeactivated ,
want : wantReduce {
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
executer : & testExecuter {
executions : [ ] execution {
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)" ,
2024-04-11 09:16:10 +02:00
expectedArgs : [ ] interface { } {
anyArg { } ,
uint64 ( 15 ) ,
domain . SMTPConfigStateInactive ,
"config-id" ,
"instance-id" ,
2022-02-16 16:49:17 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
{
name : "reduceSMTPConfigPasswordChanged" ,
args : args {
2023-10-19 12:19:10 +02:00
event : getEvent (
testEvent (
instance . SMTPConfigPasswordChangedEventType ,
instance . AggregateType ,
[ ] byte ( ` {
2024-09-12 06:27:29 +02:00
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id" ,
2022-02-16 16:49:17 +01:00
"password" : {
"cryptoType" : 0 ,
"algorithm" : "RSA-265" ,
"keyId" : "key-id"
}
} ` ) ,
2024-09-12 06:27:29 +02:00
) , eventstore . GenericEventMapper [ instance . SMTPConfigPasswordChangedEvent ] ) ,
2022-02-16 16:49:17 +01:00
} ,
2022-06-14 07:51:00 +02:00
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigPasswordChanged ,
2022-02-16 16:49:17 +01:00
want : wantReduce {
2023-10-19 12:19:10 +02:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2022-02-16 16:49:17 +01:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4_smtp SET password = $1 WHERE (id = $2) AND (instance_id = $3)" ,
2022-02-16 16:49:17 +01:00
expectedArgs : [ ] interface { } {
anyArg { } ,
2024-09-12 06:27:29 +02:00
"config-id" ,
"instance-id" ,
} ,
} ,
{
2024-09-13 15:22:25 +02:00
expectedStmt : "UPDATE projections.smtp_configs4 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)" ,
2024-09-12 06:27:29 +02:00
expectedArgs : [ ] interface { } {
2022-02-16 16:49:17 +01:00
anyArg { } ,
2024-09-12 06:27:29 +02:00
uint64 ( 15 ) ,
2024-04-11 09:16:10 +02:00
"config-id" ,
2022-05-25 14:15:13 +02:00
"instance-id" ,
2022-02-16 16:49:17 +01:00
} ,
} ,
} ,
} ,
} ,
} ,
2023-08-18 14:22:57 +02:00
{
name : "reduceSMTPConfigRemoved" ,
args : args {
event : getEvent ( testEvent (
2023-10-19 12:19:10 +02:00
instance . SMTPConfigRemovedEventType ,
2023-08-18 14:22:57 +02:00
instance . AggregateType ,
2024-09-12 06:27:29 +02:00
[ ] byte ( ` {
"instance_id" : "instance-id" ,
"resource_owner" : "ro-id" ,
"aggregate_id" : "agg-id" ,
"id" : "config-id"
} ` ) ,
) , eventstore . GenericEventMapper [ instance . SMTPConfigRemovedEvent ] ) ,
2023-08-18 14:22:57 +02:00
} ,
reduce : ( & smtpConfigProjection { } ) . reduceSMTPConfigRemoved ,
want : wantReduce {
2023-10-19 12:19:10 +02:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2023-08-18 14:22:57 +02:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-09-13 15:22:25 +02:00
expectedStmt : "DELETE FROM projections.smtp_configs4 WHERE (id = $1) AND (instance_id = $2)" ,
2023-08-18 14:22:57 +02:00
expectedArgs : [ ] interface { } {
2024-04-11 09:16:10 +02:00
"config-id" ,
2023-08-18 14:22:57 +02:00
"instance-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
2022-10-20 13:36:52 +01:00
{
2022-11-10 11:59:33 +01:00
name : "instance reduceInstanceRemoved" ,
2022-10-20 13:36:52 +01:00
args : args {
2023-10-19 12:19:10 +02:00
event : getEvent (
testEvent (
instance . InstanceRemovedEventType ,
instance . AggregateType ,
nil ,
) , instance . InstanceRemovedEventMapper ) ,
2022-10-20 13:36:52 +01:00
} ,
reduce : reduceInstanceRemovedHelper ( SMTPConfigColumnInstanceID ) ,
want : wantReduce {
2023-10-19 12:19:10 +02:00
aggregateType : eventstore . AggregateType ( "instance" ) ,
sequence : 15 ,
2022-10-20 13:36:52 +01:00
executer : & testExecuter {
executions : [ ] execution {
{
2024-09-13 15:22:25 +02:00
expectedStmt : "DELETE FROM projections.smtp_configs4 WHERE (instance_id = $1)" ,
2022-10-20 13:36:52 +01:00
expectedArgs : [ ] interface { } {
"agg-id" ,
} ,
} ,
} ,
} ,
} ,
} ,
2022-02-16 16:49:17 +01:00
}
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
event := baseEvent ( t )
got , err := tt . reduce ( event )
2023-12-08 16:30:55 +02:00
if ok := zerrors . IsErrorInvalidArgument ( err ) ; ! ok {
2022-02-16 16:49:17 +01: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 13:36:52 +01:00
assertReduce ( t , got , err , SMTPConfigProjectionTable , tt . want )
2022-02-16 16:49:17 +01:00
} )
}
}