mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-19 05:21:31 +00:00
fix: return correct empty flow if not found (#3749)
This commit is contained in:
parent
e0dd84367e
commit
b0436c995b
@ -63,7 +63,7 @@ type Flow struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetFlow(ctx context.Context, flowType domain.FlowType, orgID string) (*Flow, error) {
|
func (q *Queries) GetFlow(ctx context.Context, flowType domain.FlowType, orgID string) (*Flow, error) {
|
||||||
query, scan := prepareFlowQuery()
|
query, scan := prepareFlowQuery(flowType)
|
||||||
stmt, args, err := query.Where(
|
stmt, args, err := query.Where(
|
||||||
sq.Eq{
|
sq.Eq{
|
||||||
FlowsTriggersColumnFlowType.identifier(): flowType,
|
FlowsTriggersColumnFlowType.identifier(): flowType,
|
||||||
@ -188,7 +188,7 @@ func prepareTriggerActionsQuery() (sq.SelectBuilder, func(*sql.Rows) ([]*Action,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareFlowQuery() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
func prepareFlowQuery(flowType domain.FlowType) (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||||
return sq.Select(
|
return sq.Select(
|
||||||
ActionColumnID.identifier(),
|
ActionColumnID.identifier(),
|
||||||
ActionColumnCreationDate.identifier(),
|
ActionColumnCreationDate.identifier(),
|
||||||
@ -211,6 +211,7 @@ func prepareFlowQuery() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
|||||||
func(rows *sql.Rows) (*Flow, error) {
|
func(rows *sql.Rows) (*Flow, error) {
|
||||||
flow := &Flow{
|
flow := &Flow{
|
||||||
TriggerActions: make(map[domain.TriggerType][]*Action),
|
TriggerActions: make(map[domain.TriggerType][]*Action),
|
||||||
|
Type: flowType,
|
||||||
}
|
}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
|
@ -8,6 +8,8 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
sq "github.com/Masterminds/squirrel"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/domain"
|
"github.com/zitadel/zitadel/internal/domain"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,7 +26,9 @@ func Test_FlowPrepares(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "prepareFlowQuery no result",
|
name: "prepareFlowQuery no result",
|
||||||
prepare: prepareFlowQuery,
|
prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||||
|
return prepareFlowQuery(domain.FlowTypeExternalAuthentication)
|
||||||
|
},
|
||||||
want: want{
|
want: want{
|
||||||
sqlExpectations: mockQueries(
|
sqlExpectations: mockQueries(
|
||||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||||
@ -47,11 +51,16 @@ func Test_FlowPrepares(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
object: &Flow{TriggerActions: map[domain.TriggerType][]*Action{}},
|
object: &Flow{
|
||||||
|
TriggerActions: map[domain.TriggerType][]*Action{},
|
||||||
|
Type: domain.FlowTypeExternalAuthentication,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prepareFlowQuery one action",
|
name: "prepareFlowQuery one action",
|
||||||
prepare: prepareFlowQuery,
|
prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||||
|
return prepareFlowQuery(domain.FlowTypeExternalAuthentication)
|
||||||
|
},
|
||||||
want: want{
|
want: want{
|
||||||
sqlExpectations: mockQueries(
|
sqlExpectations: mockQueries(
|
||||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||||
@ -130,7 +139,9 @@ func Test_FlowPrepares(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prepareFlowQuery multiple actions",
|
name: "prepareFlowQuery multiple actions",
|
||||||
prepare: prepareFlowQuery,
|
prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||||
|
return prepareFlowQuery(domain.FlowTypeExternalAuthentication)
|
||||||
|
},
|
||||||
want: want{
|
want: want{
|
||||||
sqlExpectations: mockQueries(
|
sqlExpectations: mockQueries(
|
||||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||||
@ -237,7 +248,9 @@ func Test_FlowPrepares(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prepareFlowQuery no action",
|
name: "prepareFlowQuery no action",
|
||||||
prepare: prepareFlowQuery,
|
prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||||
|
return prepareFlowQuery(domain.FlowTypeExternalAuthentication)
|
||||||
|
},
|
||||||
want: want{
|
want: want{
|
||||||
sqlExpectations: mockQueries(
|
sqlExpectations: mockQueries(
|
||||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||||
@ -303,7 +316,9 @@ func Test_FlowPrepares(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prepareFlowQuery sql err",
|
name: "prepareFlowQuery sql err",
|
||||||
prepare: prepareFlowQuery,
|
prepare: func() (sq.SelectBuilder, func(*sql.Rows) (*Flow, error)) {
|
||||||
|
return prepareFlowQuery(domain.FlowTypeExternalAuthentication)
|
||||||
|
},
|
||||||
want: want{
|
want: want{
|
||||||
sqlExpectations: mockQueryErr(
|
sqlExpectations: mockQueryErr(
|
||||||
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
regexp.QuoteMeta(`SELECT projections.actions.id,`+
|
||||||
|
Loading…
x
Reference in New Issue
Block a user