2022-02-21 12:22:20 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-09-06 13:11:36 +00:00
|
|
|
"errors"
|
2022-02-21 12:22:20 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-09-06 13:11:36 +00:00
|
|
|
"github.com/muhlemmer/gu"
|
2022-04-20 14:59:37 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-11-22 10:56:43 +00:00
|
|
|
"go.uber.org/mock/gomock"
|
2022-04-20 14:59:37 +00:00
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/id"
|
|
|
|
id_mock "github.com/zitadel/zitadel/internal/id/mock"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2022-02-21 12:22:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommandSide_AddSMSConfigTwilio(t *testing.T) {
|
|
|
|
type fields struct {
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore func(*testing.T) *eventstore.Eventstore
|
2022-02-21 12:22:20 +00:00
|
|
|
idGenerator id.Generator
|
|
|
|
alg crypto.EncryptionAlgorithm
|
|
|
|
}
|
|
|
|
type args struct {
|
2024-09-06 13:11:36 +00:00
|
|
|
ctx context.Context
|
|
|
|
sms *AddTwilioConfig
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
2024-09-06 13:11:36 +00:00
|
|
|
{
|
|
|
|
name: "add sms config twilio, missing resourceowner",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
sms: &AddTwilioConfig{},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-ZLrZhKSKq0", "Errors.ResourceOwnerMissing"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
{
|
|
|
|
name: "add sms config twilio, ok",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
instance.NewSMSConfigTwilioAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
2024-09-06 13:11:36 +00:00
|
|
|
"description",
|
2023-10-19 10:19:10 +00:00
|
|
|
"sid",
|
|
|
|
"senderName",
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("token"),
|
|
|
|
},
|
2024-09-26 07:14:33 +00:00
|
|
|
"",
|
2023-10-19 10:19:10 +00:00
|
|
|
),
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "providerid"),
|
|
|
|
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
},
|
|
|
|
args: args{
|
2024-09-06 13:11:36 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
sms: &AddTwilioConfig{
|
2024-09-26 07:14:33 +00:00
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
Description: "description",
|
|
|
|
SID: "sid",
|
|
|
|
Token: "token",
|
|
|
|
SenderNumber: "senderName",
|
|
|
|
VerifyServiceSID: "",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
2022-04-05 05:58:09 +00:00
|
|
|
ResourceOwner: "INSTANCE",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: tt.fields.eventstore(t),
|
2022-04-20 14:59:37 +00:00
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
smsEncryption: tt.fields.alg,
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
err := r.AddSMSConfigTwilio(tt.args.ctx, tt.args.sms)
|
2022-02-21 12:22:20 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
2024-09-06 13:11:36 +00:00
|
|
|
assertObjectDetails(t, tt.res.want, tt.args.sms.Details)
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_ChangeSMSConfigTwilio(t *testing.T) {
|
|
|
|
type fields struct {
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore func(*testing.T) *eventstore.Eventstore
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type args struct {
|
2024-09-06 13:11:36 +00:00
|
|
|
ctx context.Context
|
|
|
|
sms *ChangeTwilioConfig
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
2024-09-06 13:11:36 +00:00
|
|
|
|
2022-02-21 12:22:20 +00:00
|
|
|
{
|
2024-09-06 13:11:36 +00:00
|
|
|
name: "resourceowner empty, invalid argument error",
|
2022-02-21 12:22:20 +00:00
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
2024-09-06 13:11:36 +00:00
|
|
|
sms: &ChangeTwilioConfig{},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-RHXryJwmFG", "Errors.ResourceOwnerMissing"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "id empty, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
sms: &ChangeTwilioConfig{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-gMr93iNhTR", "Errors.IDMissing"))
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms not existing, not found error",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2024-09-06 13:11:36 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
sms: &ChangeTwilioConfig{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
ID: "id",
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowNotFound(nil, "COMMAND-MUY0IFAf8O", "Errors.SMSConfig.NotFound"))
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-09-06 13:11:36 +00:00
|
|
|
name: "no changes",
|
2022-02-21 12:22:20 +00:00
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-24 16:21:34 +00:00
|
|
|
instance.NewSMSConfigTwilioAddedEvent(
|
2022-02-21 12:22:20 +00:00
|
|
|
context.Background(),
|
2022-04-05 05:58:09 +00:00
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
2022-02-21 12:22:20 +00:00
|
|
|
"providerid",
|
2024-09-06 13:11:36 +00:00
|
|
|
"description",
|
2022-02-21 12:22:20 +00:00
|
|
|
"sid",
|
|
|
|
"senderName",
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("token"),
|
|
|
|
},
|
2024-09-26 07:14:33 +00:00
|
|
|
"",
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
2024-09-06 13:11:36 +00:00
|
|
|
sms: &ChangeTwilioConfig{
|
2024-09-26 07:14:33 +00:00
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
ID: "providerid",
|
|
|
|
SID: gu.Ptr("sid"),
|
|
|
|
Token: gu.Ptr("token"),
|
|
|
|
SenderNumber: gu.Ptr("senderName"),
|
|
|
|
VerifyServiceSID: gu.Ptr(""),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms config twilio change, ok",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-24 16:21:34 +00:00
|
|
|
instance.NewSMSConfigTwilioAddedEvent(
|
2022-02-21 12:22:20 +00:00
|
|
|
context.Background(),
|
2022-04-05 05:58:09 +00:00
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
2022-02-21 12:22:20 +00:00
|
|
|
"providerid",
|
2024-09-06 13:11:36 +00:00
|
|
|
"description",
|
2022-02-21 12:22:20 +00:00
|
|
|
"sid",
|
|
|
|
"token",
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("token"),
|
|
|
|
},
|
2024-09-26 07:14:33 +00:00
|
|
|
"verifyServiceSid",
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
newSMSConfigTwilioChangedEvent(
|
|
|
|
context.Background(),
|
|
|
|
"providerid",
|
|
|
|
"sid2",
|
|
|
|
"senderName2",
|
2024-09-06 13:11:36 +00:00
|
|
|
"description2",
|
2024-09-26 07:14:33 +00:00
|
|
|
"verifyServiceSid2",
|
2023-10-19 10:19:10 +00:00
|
|
|
),
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
2024-09-06 13:11:36 +00:00
|
|
|
sms: &ChangeTwilioConfig{
|
2024-09-26 07:14:33 +00:00
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
ID: "providerid",
|
|
|
|
Description: gu.Ptr("description2"),
|
|
|
|
SID: gu.Ptr("sid2"),
|
|
|
|
Token: gu.Ptr("token2"),
|
|
|
|
SenderNumber: gu.Ptr("senderName2"),
|
|
|
|
VerifyServiceSID: gu.Ptr("verifyServiceSid2"),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
2022-04-05 05:58:09 +00:00
|
|
|
ResourceOwner: "INSTANCE",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: tt.fields.eventstore(t),
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
err := r.ChangeSMSConfigTwilio(tt.args.ctx, tt.args.sms)
|
2022-02-21 12:22:20 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
2024-09-06 13:11:36 +00:00
|
|
|
assertObjectDetails(t, tt.res.want, tt.args.sms.Details)
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-06 13:11:36 +00:00
|
|
|
func TestCommandSide_AddSMSConfigHTTP(t *testing.T) {
|
2022-02-21 12:22:20 +00:00
|
|
|
type fields struct {
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore func(t *testing.T) *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
alg crypto.EncryptionAlgorithm
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
http *AddSMSHTTP
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "add sms config http, resource owner missing",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
http: &AddSMSHTTP{},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-huy99qWjX4", "Errors.ResourceOwnerMissing"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add sms config http, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(),
|
|
|
|
expectPush(
|
|
|
|
instance.NewSMSConfigHTTPAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
"description",
|
|
|
|
"endpoint",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "providerid"),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
http: &AddSMSHTTP{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
Description: "description",
|
|
|
|
Endpoint: "endpoint",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore(t),
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
smsEncryption: tt.fields.alg,
|
|
|
|
}
|
|
|
|
err := r.AddSMSConfigHTTP(tt.args.ctx, tt.args.http)
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assertObjectDetails(t, tt.res.want, tt.args.http.Details)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_ChangeSMSConfigHTTP(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore func(*testing.T) *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
http *ChangeSMSHTTP
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "resourceowner empty, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
http: &ChangeSMSHTTP{},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-M622CFQnwK", "Errors.ResourceOwnerMissing"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "id empty, precondition error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
http: &ChangeSMSHTTP{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-phyb2e4Kll", "Errors.IDMissing"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms not existing, not found error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
http: &ChangeSMSHTTP{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
ID: "id",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowNotFound(nil, "COMMAND-6NW4I5Kqzj", "Errors.SMSConfig.NotFound"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no changes",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigHTTPAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
"description",
|
|
|
|
"endpoint",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
http: &ChangeSMSHTTP{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
ID: "providerid",
|
|
|
|
Endpoint: gu.Ptr("endpoint"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms config http change, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigHTTPAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
"description",
|
|
|
|
"endpoint",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
|
|
|
newSMSConfigHTTPChangedEvent(
|
|
|
|
context.Background(),
|
|
|
|
"providerid",
|
|
|
|
"endpoint2",
|
|
|
|
"description2",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
http: &ChangeSMSHTTP{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
ID: "providerid",
|
|
|
|
Description: gu.Ptr("description2"),
|
|
|
|
Endpoint: gu.Ptr("endpoint2"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore(t),
|
|
|
|
}
|
|
|
|
err := r.ChangeSMSConfigHTTP(tt.args.ctx, tt.args.http)
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assertObjectDetails(t, tt.res.want, tt.args.http.Details)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommandSide_ActivateSMSConfig(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore func(*testing.T) *eventstore.Eventstore
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type args struct {
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx context.Context
|
|
|
|
instanceID string
|
|
|
|
id string
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
2024-09-06 13:11:36 +00:00
|
|
|
name: "resourceowner empty, invalid error",
|
2022-02-21 12:22:20 +00:00
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-EFgoOg997V", "Errors.ResourceOwnerMissing"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "id empty, invalid error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-jJ6TVqzvjp", "Errors.IDMissing"))
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms not existing, not found error",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "id",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowNotFound(nil, "COMMAND-9ULtp9PH5E", "Errors.SMSConfig.NotFound"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms existing, already active",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigTwilioAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
"description",
|
|
|
|
"sid",
|
|
|
|
"sender-name",
|
|
|
|
&crypto.CryptoValue{},
|
2024-09-26 07:14:33 +00:00
|
|
|
"",
|
2024-09-06 13:11:36 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigActivatedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "providerid",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowPreconditionFailed(nil, "COMMAND-B25GFeIvRi", "Errors.SMSConfig.AlreadyActive"))
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms config twilio activate, ok",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-24 16:21:34 +00:00
|
|
|
instance.NewSMSConfigTwilioAddedEvent(
|
2022-02-21 12:22:20 +00:00
|
|
|
context.Background(),
|
2022-04-05 05:58:09 +00:00
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
2022-02-21 12:22:20 +00:00
|
|
|
"providerid",
|
2024-09-06 13:11:36 +00:00
|
|
|
"description",
|
2022-02-21 12:22:20 +00:00
|
|
|
"sid",
|
|
|
|
"sender-name",
|
|
|
|
&crypto.CryptoValue{},
|
2024-09-26 07:14:33 +00:00
|
|
|
"",
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2024-09-06 13:11:36 +00:00
|
|
|
instance.NewSMSConfigActivatedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "providerid",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms config http activate, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigHTTPAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
"description",
|
|
|
|
"endpoint",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
|
|
|
instance.NewSMSConfigActivatedEvent(
|
2023-10-19 10:19:10 +00:00
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "providerid",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
2022-04-05 05:58:09 +00:00
|
|
|
ResourceOwner: "INSTANCE",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: tt.fields.eventstore(t),
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2022-06-13 06:34:11 +00:00
|
|
|
got, err := r.ActivateSMSConfig(tt.args.ctx, tt.args.instanceID, tt.args.id)
|
2022-02-21 12:22:20 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
2024-08-12 20:32:01 +00:00
|
|
|
assertObjectDetails(t, tt.res.want, got)
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-06 13:11:36 +00:00
|
|
|
func TestCommandSide_DeactivateSMSConfig(t *testing.T) {
|
2022-02-21 12:22:20 +00:00
|
|
|
type fields struct {
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore func(*testing.T) *eventstore.Eventstore
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type args struct {
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx context.Context
|
|
|
|
instanceID string
|
|
|
|
id string
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
2024-09-06 13:11:36 +00:00
|
|
|
}{{
|
|
|
|
name: "resourceowner empty, invalid error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-V9NWOZj8Gi", "Errors.ResourceOwnerMissing"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
{
|
|
|
|
name: "id empty, invalid error",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
args: args{
|
2024-09-06 13:11:36 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-xs1ah1v1CL", "Errors.IDMissing"))
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms not existing, not found error",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "id",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowNotFound(nil, "COMMAND-La91dGNhbM", "Errors.SMSConfig.NotFound"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms config twilio deactivate, already deactivated",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigTwilioAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
"description",
|
|
|
|
"sid",
|
|
|
|
"sender-name",
|
|
|
|
&crypto.CryptoValue{},
|
2024-09-26 07:14:33 +00:00
|
|
|
"",
|
2024-09-06 13:11:36 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigActivatedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigDeactivatedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "providerid",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowPreconditionFailed(nil, "COMMAND-OSZAEkYvk7", "Errors.SMSConfig.AlreadyDeactivated"))
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms config twilio deactivate, ok",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-24 16:21:34 +00:00
|
|
|
instance.NewSMSConfigTwilioAddedEvent(
|
2022-02-21 12:22:20 +00:00
|
|
|
context.Background(),
|
2022-04-05 05:58:09 +00:00
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
2022-02-21 12:22:20 +00:00
|
|
|
"providerid",
|
2024-09-06 13:11:36 +00:00
|
|
|
"description",
|
2022-02-21 12:22:20 +00:00
|
|
|
"sid",
|
|
|
|
"sender-name",
|
|
|
|
&crypto.CryptoValue{},
|
2024-09-26 07:14:33 +00:00
|
|
|
"",
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
2024-09-06 13:11:36 +00:00
|
|
|
instance.NewSMSConfigActivatedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
|
|
|
instance.NewSMSConfigDeactivatedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "providerid",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms config http deactivate, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigHTTPAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
"description",
|
|
|
|
"endpoint",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigActivatedEvent(
|
2022-02-21 12:22:20 +00:00
|
|
|
context.Background(),
|
2022-04-05 05:58:09 +00:00
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
2022-02-21 12:22:20 +00:00
|
|
|
"providerid",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
instance.NewSMSConfigDeactivatedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "providerid",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
2022-04-05 05:58:09 +00:00
|
|
|
ResourceOwner: "INSTANCE",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: tt.fields.eventstore(t),
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2022-06-13 06:34:11 +00:00
|
|
|
got, err := r.DeactivateSMSConfig(tt.args.ctx, tt.args.instanceID, tt.args.id)
|
2022-02-21 12:22:20 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
2024-08-12 20:32:01 +00:00
|
|
|
assertObjectDetails(t, tt.res.want, got)
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 10:39:38 +00:00
|
|
|
func TestCommandSide_RemoveSMSConfig(t *testing.T) {
|
2022-02-21 12:22:20 +00:00
|
|
|
type fields struct {
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore func(*testing.T) *eventstore.Eventstore
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type args struct {
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx context.Context
|
|
|
|
instanceID string
|
|
|
|
id string
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.ObjectDetails
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
2024-09-06 13:11:36 +00:00
|
|
|
name: "resourceowner empty, invalid error",
|
2022-02-21 12:22:20 +00:00
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(),
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-cw0NSJsn1v", "Errors.ResourceOwnerMissing"))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "id empty, invalid error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowInvalidArgument(nil, "COMMAND-Qrz7lvdC4c", "Errors.IDMissing"))
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sms not existing, not found error",
|
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "id",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
2024-09-06 13:11:36 +00:00
|
|
|
err: func(err error) bool {
|
|
|
|
return errors.Is(err, zerrors.ThrowNotFound(nil, "COMMAND-povEVHPCkV", "Errors.SMSConfig.NotFound"))
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-09-06 13:11:36 +00:00
|
|
|
name: "sms config remove, twilio, ok",
|
2022-02-21 12:22:20 +00:00
|
|
|
fields: fields{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: expectEventstore(
|
2022-02-21 12:22:20 +00:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
2022-03-24 16:21:34 +00:00
|
|
|
instance.NewSMSConfigTwilioAddedEvent(
|
2022-02-21 12:22:20 +00:00
|
|
|
context.Background(),
|
2022-04-05 05:58:09 +00:00
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
2022-02-21 12:22:20 +00:00
|
|
|
"providerid",
|
2024-09-06 13:11:36 +00:00
|
|
|
"description",
|
2022-02-21 12:22:20 +00:00
|
|
|
"sid",
|
|
|
|
"sender-name",
|
|
|
|
&crypto.CryptoValue{},
|
2024-09-26 07:14:33 +00:00
|
|
|
"",
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 10:19:10 +00:00
|
|
|
instance.NewSMSConfigRemovedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
2022-02-21 12:22:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
2022-04-05 05:58:09 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "providerid",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
2022-04-05 05:58:09 +00:00
|
|
|
ResourceOwner: "INSTANCE",
|
2022-02-21 12:22:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-09-06 13:11:36 +00:00
|
|
|
{
|
|
|
|
name: "sms config remove, http, ok",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
instance.NewSMSConfigHTTPAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
"description",
|
|
|
|
"endpoint",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
|
|
|
instance.NewSMSConfigRemovedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
"providerid",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
instanceID: "INSTANCE",
|
|
|
|
id: "providerid",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "INSTANCE",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
2024-09-06 13:11:36 +00:00
|
|
|
eventstore: tt.fields.eventstore(t),
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2022-06-10 10:39:38 +00:00
|
|
|
got, err := r.RemoveSMSConfig(tt.args.ctx, tt.args.instanceID, tt.args.id)
|
2022-02-21 12:22:20 +00:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
2024-08-12 20:32:01 +00:00
|
|
|
assertObjectDetails(t, tt.res.want, got)
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-26 07:14:33 +00:00
|
|
|
func newSMSConfigTwilioChangedEvent(ctx context.Context, id, sid, senderName, description, verifyServiceSid string) *instance.SMSConfigTwilioChangedEvent {
|
2022-03-24 16:21:34 +00:00
|
|
|
changes := []instance.SMSConfigTwilioChanges{
|
|
|
|
instance.ChangeSMSConfigTwilioSID(sid),
|
|
|
|
instance.ChangeSMSConfigTwilioSenderNumber(senderName),
|
2024-09-06 13:11:36 +00:00
|
|
|
instance.ChangeSMSConfigTwilioDescription(description),
|
2024-09-26 07:14:33 +00:00
|
|
|
instance.ChangeSMSConfigTwilioVerifyServiceSID(verifyServiceSid),
|
2022-02-21 12:22:20 +00:00
|
|
|
}
|
2022-03-24 16:21:34 +00:00
|
|
|
event, _ := instance.NewSMSConfigTwilioChangedEvent(ctx,
|
2022-04-05 05:58:09 +00:00
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
2022-02-21 12:22:20 +00:00
|
|
|
id,
|
|
|
|
changes,
|
|
|
|
)
|
|
|
|
return event
|
|
|
|
}
|
2024-09-06 13:11:36 +00:00
|
|
|
|
|
|
|
func newSMSConfigHTTPChangedEvent(ctx context.Context, id, endpoint, description string) *instance.SMSConfigHTTPChangedEvent {
|
|
|
|
changes := []instance.SMSConfigHTTPChanges{
|
|
|
|
instance.ChangeSMSConfigHTTPEndpoint(endpoint),
|
|
|
|
instance.ChangeSMSConfigHTTPDescription(description),
|
|
|
|
}
|
|
|
|
event, _ := instance.NewSMSConfigHTTPChangedEvent(ctx,
|
|
|
|
&instance.NewAggregate("INSTANCE").Aggregate,
|
|
|
|
id,
|
|
|
|
changes,
|
|
|
|
)
|
|
|
|
return event
|
|
|
|
}
|