fix(projection): handle old event in feature (#2773)

This commit is contained in:
Silvan 2021-12-02 19:16:20 +01:00 committed by GitHub
parent 983382fcec
commit 45695d3198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 156 additions and 4 deletions

View File

@ -142,8 +142,14 @@ func (p *FeatureProjection) reduceFeatureSet(event eventstore.EventReader) (*han
if featureEvent.PasswordComplexityPolicy != nil {
cols = append(cols, handler.NewCol(FeaturePasswordComplexityPolicyCol, *featureEvent.PasswordComplexityPolicy))
}
if featureEvent.LabelPolicyPrivateLabel != nil {
cols = append(cols, handler.NewCol(FeatureLabelPolicyPrivateLabelCol, *featureEvent.LabelPolicyPrivateLabel))
if featureEvent.LabelPolicyPrivateLabel != nil || featureEvent.LabelPolicy != nil {
var value bool
if featureEvent.LabelPolicyPrivateLabel != nil {
value = *featureEvent.LabelPolicyPrivateLabel
} else {
value = *featureEvent.LabelPolicy
}
cols = append(cols, handler.NewCol(FeatureLabelPolicyPrivateLabelCol, value))
}
if featureEvent.LabelPolicyWatermark != nil {
cols = append(cols, handler.NewCol(FeatureLabelPolicyWatermarkCol, *featureEvent.LabelPolicyWatermark))

View File

@ -24,7 +24,7 @@ func TestFeatureProjection_reduces(t *testing.T) {
want wantReduce
}{
{
name: "org.reduceFeatureSet",
name: "org.reduceFeatureSet new",
args: args{
event: getEvent(testEvent(
repository.EventType(org.FeaturesSetEventType),
@ -96,6 +96,79 @@ func TestFeatureProjection_reduces(t *testing.T) {
},
},
},
{
name: "org.reduceFeatureSet old",
args: args{
event: getEvent(testEvent(
repository.EventType(org.FeaturesSetEventType),
org.AggregateType,
[]byte(`{
"tierName": "TierName",
"tierDescription": "TierDescription",
"state": 1,
"stateDescription": "StateDescription",
"auditLogRetention": 1,
"loginPolicyFactors": true,
"loginPolicyIDP": true,
"loginPolicyPasswordless": true,
"loginPolicyRegistration": true,
"loginPolicyUsernameLogin": true,
"loginPolicyPasswordReset": true,
"passwordComplexityPolicy": true,
"labelPolicy": true,
"labelPolicyWatermark": true,
"customDomain": true,
"privacyPolicy": true,
"metadataUser": true,
"customTextMessage": true,
"customTextLogin": true,
"lockoutPolicy": true,
"actions": true
}`),
), org.FeaturesSetEventMapper),
},
reduce: (&FeatureProjection{}).reduceFeatureSet,
want: wantReduce{
aggregateType: eventstore.AggregateType("org"),
sequence: 15,
previousSequence: 10,
projection: FeatureTable,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)",
expectedArgs: []interface{}{
"agg-id",
anyArg{},
uint64(15),
false,
"TierName",
"TierDescription",
domain.FeaturesStateActive,
"StateDescription",
time.Nanosecond,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
},
},
},
},
},
},
{
name: "org.reduceFeatureSet required values only",
args: args{
@ -154,7 +227,80 @@ func TestFeatureProjection_reduces(t *testing.T) {
},
},
{
name: "iam.reduceFeatureSet",
name: "iam.reduceFeatureSet old",
reduce: (&FeatureProjection{}).reduceFeatureSet,
args: args{
event: getEvent(testEvent(
repository.EventType(iam.FeaturesSetEventType),
iam.AggregateType,
[]byte(`{
"tierName": "TierName",
"tierDescription": "TierDescription",
"state": 1,
"stateDescription": "StateDescription",
"auditLogRetention": 1,
"loginPolicyFactors": true,
"loginPolicyIDP": true,
"loginPolicyPasswordless": true,
"loginPolicyRegistration": true,
"loginPolicyUsernameLogin": true,
"loginPolicyPasswordReset": true,
"passwordComplexityPolicy": true,
"labelPolicy": true,
"labelPolicyWatermark": true,
"customDomain": true,
"privacyPolicy": true,
"metadataUser": true,
"customTextMessage": true,
"customTextLogin": true,
"lockoutPolicy": true,
"actions": true
}`),
), iam.FeaturesSetEventMapper),
},
want: wantReduce{
aggregateType: eventstore.AggregateType("iam"),
sequence: 15,
previousSequence: 10,
projection: FeatureTable,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPSERT INTO zitadel.projections.features (aggregate_id, change_date, sequence, is_default, tier_name, tier_description, state, state_description, audit_log_retention, login_policy_factors, login_policy_idp, login_policy_passwordless, login_policy_registration, login_policy_username_login, login_policy_password_reset, password_complexity_policy, label_policy_private_label, label_policy_watermark, custom_domain, privacy_policy, metadata_user, custom_text_message, custom_text_login, lockout_policy, actions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)",
expectedArgs: []interface{}{
"agg-id",
anyArg{},
uint64(15),
true,
"TierName",
"TierDescription",
domain.FeaturesStateActive,
"StateDescription",
time.Nanosecond,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
},
},
},
},
},
},
{
name: "iam.reduceFeatureSet new",
reduce: (&FeatureProjection{}).reduceFeatureSet,
args: args{
event: getEvent(testEvent(