@@ -3494,6 +3494,90 @@ func TestRevokeInvitation(t *testing.T) {
34943494 }
34953495}
34963496
3497+ func TestResendInvitation (t * testing.T ) {
3498+ tests := []struct {
3499+ scenario string
3500+ client * Client
3501+ options ResendInvitationOpts
3502+ expected Invitation
3503+ err bool
3504+ }{
3505+ {
3506+ scenario : "Request without API Key returns an error" ,
3507+ client : NewClient ("" ),
3508+ err : true ,
3509+ },
3510+ {
3511+ scenario : "Request returns Invitation" ,
3512+ client : NewClient ("test" ),
3513+ options : ResendInvitationOpts {
3514+ Invitation : "invitation_01E4ZCR3C56J083X43JQXF3JK5" ,
3515+ },
3516+ expected : Invitation {
3517+ ID : "invitation_01E4ZCR3C56J083X43JQXF3JK5" ,
3518+ 3519+ State : Pending ,
3520+ Token : "Z1uX3RbwcIl5fIGJJJCXXisdI" ,
3521+ AcceptInvitationUrl : "https://your-app.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI" ,
3522+ ExpiresAt : "2021-06-25T19:07:33.155Z" ,
3523+ CreatedAt : "2021-06-25T19:07:33.155Z" ,
3524+ UpdatedAt : "2021-06-25T19:07:33.155Z" ,
3525+ },
3526+ },
3527+ {
3528+ scenario : "Request returns 404 error for non-existent invitation" ,
3529+ client : NewClient ("test" ),
3530+ options : ResendInvitationOpts {
3531+ Invitation : "invitation_not_found" ,
3532+ },
3533+ err : true ,
3534+ },
3535+ {
3536+ scenario : "Request returns 400 error for expired invitation" ,
3537+ client : NewClient ("test" ),
3538+ options : ResendInvitationOpts {
3539+ Invitation : "invitation_expired" ,
3540+ },
3541+ err : true ,
3542+ },
3543+ {
3544+ scenario : "Request returns 400 error for revoked invitation" ,
3545+ client : NewClient ("test" ),
3546+ options : ResendInvitationOpts {
3547+ Invitation : "invitation_revoked" ,
3548+ },
3549+ err : true ,
3550+ },
3551+ {
3552+ scenario : "Request returns 400 error for accepted invitation" ,
3553+ client : NewClient ("test" ),
3554+ options : ResendInvitationOpts {
3555+ Invitation : "invitation_accepted" ,
3556+ },
3557+ err : true ,
3558+ },
3559+ }
3560+
3561+ for _ , test := range tests {
3562+ t .Run (test .scenario , func (t * testing.T ) {
3563+ server := httptest .NewServer (http .HandlerFunc (ResendInvitationTestHandler ))
3564+ defer server .Close ()
3565+
3566+ client := test .client
3567+ client .Endpoint = server .URL
3568+ client .HTTPClient = server .Client ()
3569+
3570+ invitation , err := client .ResendInvitation (context .Background (), test .options )
3571+ if test .err {
3572+ require .Error (t , err )
3573+ return
3574+ }
3575+ require .NoError (t , err )
3576+ require .Equal (t , test .expected , invitation )
3577+ })
3578+ }
3579+ }
3580+
34973581func TestGetLogoutURL (t * testing.T ) {
34983582 tests := []struct {
34993583 scenario string
@@ -3538,6 +3622,60 @@ func TestGetLogoutURL(t *testing.T) {
35383622 }
35393623}
35403624
3625+ func ResendInvitationTestHandler (w http.ResponseWriter , r * http.Request ) {
3626+ auth := r .Header .Get ("Authorization" )
3627+ if auth != "Bearer test" {
3628+ http .Error (w , "bad auth" , http .StatusUnauthorized )
3629+ return
3630+ }
3631+
3632+ var body []byte
3633+ var err error
3634+
3635+ switch r .URL .Path {
3636+ case "/user_management/invitations/invitation_01E4ZCR3C56J083X43JQXF3JK5/resend" :
3637+ body , err = json .Marshal (
3638+ Invitation {
3639+ ID : "invitation_01E4ZCR3C56J083X43JQXF3JK5" ,
3640+ 3641+ State : Pending ,
3642+ Token : "Z1uX3RbwcIl5fIGJJJCXXisdI" ,
3643+ AcceptInvitationUrl : "https://your-app.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI" ,
3644+ ExpiresAt : "2021-06-25T19:07:33.155Z" ,
3645+ CreatedAt : "2021-06-25T19:07:33.155Z" ,
3646+ UpdatedAt : "2021-06-25T19:07:33.155Z" ,
3647+ })
3648+ case "/user_management/invitations/invitation_not_found/resend" :
3649+ w .Header ().Set ("Content-Type" , "application/json" )
3650+ w .WriteHeader (http .StatusNotFound )
3651+ w .Write ([]byte (`{"message": "Invitation not found"}` ))
3652+ return
3653+ case "/user_management/invitations/invitation_expired/resend" :
3654+ w .Header ().Set ("Content-Type" , "application/json" )
3655+ w .WriteHeader (http .StatusBadRequest )
3656+ w .Write ([]byte (`{"code": "invite_expired", "message": "Invite has expired."}` ))
3657+ return
3658+ case "/user_management/invitations/invitation_revoked/resend" :
3659+ w .Header ().Set ("Content-Type" , "application/json" )
3660+ w .WriteHeader (http .StatusBadRequest )
3661+ w .Write ([]byte (`{"code": "invite_revoked", "message": "Invite has been revoked."}` ))
3662+ return
3663+ case "/user_management/invitations/invitation_accepted/resend" :
3664+ w .Header ().Set ("Content-Type" , "application/json" )
3665+ w .WriteHeader (http .StatusBadRequest )
3666+ w .Write ([]byte (`{"code": "invite_accepted", "message": "Invite has already been accepted."}` ))
3667+ return
3668+ }
3669+
3670+ if err != nil {
3671+ w .WriteHeader (http .StatusInternalServerError )
3672+ return
3673+ }
3674+
3675+ w .WriteHeader (http .StatusOK )
3676+ w .Write (body )
3677+ }
3678+
35413679func RevokeInvitationTestHandler (w http.ResponseWriter , r * http.Request ) {
35423680 auth := r .Header .Get ("Authorization" )
35433681 if auth != "Bearer test" {
0 commit comments