Skip to content

Commit

Permalink
align UserSignup hepler functions (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek authored Jan 13, 2025
1 parent ee211ba commit 1078d68
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions pkg/test/usersignup/usersignup.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,29 @@ func WithAccountID(accountID string) Modifier {
}
}

// ApprovedManually sets the UserSignup states to [`approved`]
func ApprovedManually() Modifier {
// ApprovedManuallyAgo sets the UserSignup state to `approved` and adds a status condition
func ApprovedManuallyAgo(before time.Duration) Modifier {
return func(userSignup *toolchainv1alpha1.UserSignup) {
states.SetApprovedManually(userSignup, true)
userSignup.Status.Conditions = condition.AddStatusConditions(userSignup.Status.Conditions,
toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.UserSignupApproved,
Status: corev1.ConditionTrue,
Reason: toolchainv1alpha1.UserSignupApprovedByAdminReason,
LastTransitionTime: metav1.Time{Time: time.Now().Add(-before)},
})
}
}

// ApprovedManuallyAgo sets the UserSignup state to `approved` and adds a status condition
func ApprovedManuallyAgo(before time.Duration) Modifier {
// ApprovedAutomaticallyAgo sets the UserSignup state to `approved` and adds a status condition
func ApprovedAutomaticallyAgo(before time.Duration) Modifier {
return func(userSignup *toolchainv1alpha1.UserSignup) {
states.SetApprovedManually(userSignup, true)
userSignup.Status.Conditions = condition.AddStatusConditions(userSignup.Status.Conditions,
toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.UserSignupApproved,
Status: corev1.ConditionTrue,
Reason: toolchainv1alpha1.UserSignupApprovedByAdminReason,
Reason: toolchainv1alpha1.UserSignupApprovedAutomaticallyReason,
LastTransitionTime: metav1.Time{Time: time.Now().Add(-before)},
})
}
Expand All @@ -66,7 +73,21 @@ func Deactivated() Modifier {
}
}

func DeactivatedWithLastTransitionTime(before time.Duration) Modifier {
func VerificationRequired() Modifier {
return func(userSignup *toolchainv1alpha1.UserSignup) {
states.SetVerificationRequired(userSignup, true)
}
}

// ApprovedManually sets the UserSignup states to [`approved`]
func ApprovedManually() Modifier {
return func(userSignup *toolchainv1alpha1.UserSignup) {
states.SetApprovedManually(userSignup, true)
}
}

// DeactivatedAgo sets the UserSignup states to [`deactivated`] and adds a status condition
func DeactivatedAgo(before time.Duration) Modifier {
return func(userSignup *toolchainv1alpha1.UserSignup) {
states.SetDeactivated(userSignup, true)

Expand All @@ -81,7 +102,20 @@ func DeactivatedWithLastTransitionTime(before time.Duration) Modifier {
}
}

func VerificationRequired(before time.Duration) Modifier {
// BannedAgo adds the banned status condition
func BannedAgo(before time.Duration) Modifier {
return func(userSignup *toolchainv1alpha1.UserSignup) {
userSignup.Status.Conditions = condition.AddStatusConditions(userSignup.Status.Conditions,
toolchainv1alpha1.Condition{
Type: toolchainv1alpha1.UserSignupComplete,
Status: corev1.ConditionTrue,
Reason: toolchainv1alpha1.UserSignupUserBannedReason,
LastTransitionTime: metav1.Time{Time: time.Now().Add(-before)},
})
}
}

func VerificationRequiredAgo(before time.Duration) Modifier {
return func(userSignup *toolchainv1alpha1.UserSignup) {
states.SetVerificationRequired(userSignup, true)

Expand Down

0 comments on commit 1078d68

Please sign in to comment.