From 1078d683961b525b0decef079ee2b9149ae94d68 Mon Sep 17 00:00:00 2001 From: Matous Jobanek Date: Mon, 13 Jan 2025 10:26:48 +0100 Subject: [PATCH] align UserSignup hepler functions (#445) --- pkg/test/usersignup/usersignup.go | 48 ++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/pkg/test/usersignup/usersignup.go b/pkg/test/usersignup/usersignup.go index a6ad1d20..2a4cc326 100644 --- a/pkg/test/usersignup/usersignup.go +++ b/pkg/test/usersignup/usersignup.go @@ -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)}, }) } @@ -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) @@ -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)