package command import ( "context" "testing" "github.com/caos/zitadel/internal/errors" "github.com/caos/zitadel/internal/eventstore" "github.com/caos/zitadel/internal/repository/org" ) func TestAddOrg(t *testing.T) { type args struct { a *org.Aggregate name string } ctx := context.Background() agg := org.NewAggregate("test", "test") tests := []struct { name string args args want Want }{ { name: "invalid domain", args: args{ a: agg, name: "", }, want: Want{ ValidationErr: errors.ThrowInvalidArgument(nil, "ORG-mruNY", "Errors.Invalid.Argument"), }, }, { name: "correct", args: args{ a: agg, name: "caos ag", }, want: Want{ Commands: []eventstore.Command{ org.NewOrgAddedEvent(ctx, &agg.Aggregate, "caos ag"), org.NewDomainAddedEvent(ctx, &agg.Aggregate, "caos-ag.localhost"), org.NewDomainVerifiedEvent(ctx, &agg.Aggregate, "caos-ag.localhost"), org.NewDomainPrimarySetEvent(ctx, &agg.Aggregate, "caos-ag.localhost"), }, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { AssertValidation(t, AddOrg(tt.args.a, tt.args.name, "localhost"), nil, tt.want) }) } }