@@ -702,15 +702,39 @@ func TestActivationCodeVerification(t *testing.T) {
702702 member2Await := await .Member2 ()
703703 route := hostAwait .RegistrationServiceURL
704704
705- verifySuccessful := func (t * testing.T , targetCluster string ) {
705+ verifySuccessful := func (t * testing.T , targetCluster string , existingUserSignup , deactivateSignup bool ) {
706706 // given
707707 event := testsocialevent .NewSocialEvent (hostAwait .Namespace , commonsocialevent .NewName (),
708708 testsocialevent .WithUserTier ("deactivate80" ),
709709 testsocialevent .WithSpaceTier ("base1ns6didler" ),
710710 testsocialevent .WithTargetCluster (targetCluster ))
711711 err := hostAwait .CreateWithCleanup (t , event )
712712 require .NoError (t , err )
713- userSignup , token := signup (t , hostAwait )
713+ userSignup := & toolchainv1alpha1.UserSignup {}
714+ token , userName := "" , ""
715+ if existingUserSignup {
716+ // create a user signup before using the activation code
717+ userSignup , token = signup (t , hostAwait )
718+ cleanup .AddCleanTasks (t , hostAwait .Client , userSignup )
719+ userName = userSignup .Name
720+
721+ if deactivateSignup {
722+ // deactivate the UserSignup to test the deactivation path
723+ _ , err = wait .For (t , hostAwait .Awaitility , & toolchainv1alpha1.UserSignup {}).
724+ Update (userName , hostAwait .Namespace ,
725+ func (us * toolchainv1alpha1.UserSignup ) {
726+ states .SetDeactivated (us , true )
727+ })
728+ require .NoError (t , err )
729+ t .Logf ("user signup '%s' deactivated" , userName )
730+ }
731+ } else {
732+ // create only the identity and token for calling the activation-code endpoint.
733+ // the signup should be created by the activation-code endpoint.
734+ identity , _ , tokenValue := userToken (t )
735+ token = tokenValue
736+ userName = identity .Username
737+ }
714738
715739 // when call verification endpoint with a valid activation code
716740 NewHTTPRequest (t ).
@@ -719,22 +743,23 @@ func TestActivationCodeVerification(t *testing.T) {
719743 // then
720744 // ensure the UserSignup is in "pending approval" condition,
721745 // because in these series of parallel tests, automatic approval is disabled ¯\_(ツ)_/¯
722- _ , err = hostAwait .WaitForUserSignup (t , userSignup . Name ,
746+ userSignup , err = hostAwait .WaitForUserSignup (t , userName ,
723747 wait .UntilUserSignupHasLabel (toolchainv1alpha1 .SocialEventUserSignupLabelKey , event .Name ),
724748 wait .UntilUserSignupHasConditions (wait .ConditionSet (wait .Default (), wait .PendingApproval ())... ))
749+ cleanup .AddCleanTasks (t , hostAwait .Client , userSignup )
725750 require .NoError (t , err )
726751 // explicitly approve the usersignup (see above, config for parallel test has automatic approval disabled)
727- userSignup , err = wait .For (t , hostAwait .Awaitility , & toolchainv1alpha1.UserSignup {}).
728- Update (userSignup . Name , hostAwait .Namespace ,
752+ _ , err = wait .For (t , hostAwait .Awaitility , & toolchainv1alpha1.UserSignup {}).
753+ Update (userName , hostAwait .Namespace ,
729754 func (us * toolchainv1alpha1.UserSignup ) {
730755 states .SetApprovedManually (us , true )
731756 })
732757 require .NoError (t , err )
733- t .Logf ("user signup '%s' approved" , userSignup . Name )
758+ t .Logf ("user signup '%s' approved" , userName )
734759
735760 // check that the MUR and Space are configured as expected
736761 // Wait for the UserSignup to have the desired state
737- userSignup , err = hostAwait .WaitForUserSignup (t , userSignup . Name ,
762+ userSignup , err = hostAwait .WaitForUserSignup (t , userName ,
738763 wait .UntilUserSignupHasCompliantUsername (),
739764 wait .UntilUserSignupHasTargetCluster (targetCluster ))
740765 require .NoError (t , err )
@@ -761,11 +786,19 @@ func TestActivationCodeVerification(t *testing.T) {
761786 }
762787
763788 t .Run ("verification successful with no target cluster" , func (t * testing.T ) {
764- verifySuccessful (t , "" )
789+ verifySuccessful (t , "" , true , false )
765790 })
766791
767792 t .Run ("verification successful with target cluster" , func (t * testing.T ) {
768- verifySuccessful (t , member2Await .ClusterName )
793+ verifySuccessful (t , member2Await .ClusterName , true , false )
794+ })
795+
796+ t .Run ("UserSignup doesn't exist yet it should be created" , func (t * testing.T ) {
797+ verifySuccessful (t , member2Await .ClusterName , false , false )
798+ })
799+
800+ t .Run ("UserSignup is deactivated it should be reactivated" , func (t * testing.T ) {
801+ verifySuccessful (t , member2Await .ClusterName , true , true )
769802 })
770803
771804 t .Run ("verification failed" , func (t * testing.T ) {
@@ -930,11 +963,7 @@ func signup(t *testing.T, hostAwait *wait.HostAwaitility) (*toolchainv1alpha1.Us
930963 route := hostAwait .RegistrationServiceURL
931964
932965 // Create a token and identity to sign up with
933- identity := commonauth .NewIdentity ()
934- emailValue := identity .Username + "@some.domain"
935- emailClaim := commonauth .WithEmailClaim (emailValue )
936- token , err := commonauth .GenerateSignedE2ETestToken (* identity , emailClaim )
937- require .NoError (t , err )
966+ identity , emailValue , token := userToken (t )
938967
939968 // Call the signup endpoint
940969 NewHTTPRequest (t ).InvokeEndpoint ("POST" , route + "/api/v1/signup" , token , "" , http .StatusAccepted )
@@ -950,6 +979,15 @@ func signup(t *testing.T, hostAwait *wait.HostAwaitility) (*toolchainv1alpha1.Us
950979 return userSignup , token
951980}
952981
982+ func userToken (t * testing.T ) (* commonauth.Identity , string , string ) {
983+ identity := commonauth .NewIdentity ()
984+ emailValue := identity .Username + "@some.domain"
985+ emailClaim := commonauth .WithEmailClaim (emailValue )
986+ token , err := commonauth .GenerateSignedE2ETestToken (* identity , emailClaim )
987+ require .NoError (t , err )
988+ return identity , emailValue , token
989+ }
990+
953991func signupHasExpectedDates (startDate , endDate time.Time ) func (c * GetSignupClient ) {
954992 return func (c * GetSignupClient ) {
955993 responseStartDate , err := time .Parse (time .RFC3339 , c .responseBody ["startDate" ].(string ))
0 commit comments