@@ -12,6 +12,7 @@ import (
1212
1313 "github.com/descope/go-sdk/descope"
1414 "github.com/descope/go-sdk/descope/api"
15+ "github.com/descope/go-sdk/descope/internal/utils"
1516 "github.com/stretchr/testify/assert"
1617 "github.com/stretchr/testify/require"
1718)
@@ -313,6 +314,7 @@ func TestSignUpNOTPNoUser(t *testing.T) {
313314 _ , err = a .NOTP ().SignUp (context .Background (), phone , nil , nil )
314315 require .NoError (t , err )
315316}
317+
316318func TestSignUpOrInNOTPNoLoginID (t * testing.T ) {
317319 a , err := newTestAuth (nil , func (_ * http.Request ) (* http.Response , error ) {
318320 return & http.Response {
@@ -324,3 +326,93 @@ func TestSignUpOrInNOTPNoLoginID(t *testing.T) {
324326 _ , err = a .NOTP ().SignUpOrIn (context .Background (), "" , nil )
325327 require .NoError (t , err )
326328}
329+
330+ func TestUpdateUserNOTPEmptyLoginID (t * testing.T ) {
331+ a , err := newTestAuth (nil , func (_ * http.Request ) (* http.Response , error ) {
332+ return nil , nil
333+ })
334+ require .NoError (t , err )
335+ _ , err = a .NOTP ().UpdateUser (context .Background (), "" , "" , nil , nil )
336+ require .Error (t , err )
337+ require .ErrorContains (t , err , utils .NewInvalidArgumentError ("loginID" ).Message )
338+ }
339+
340+ func TestUpdateUserNOTPMissingRefreshToken (t * testing.T ) {
341+ a , err := newTestAuth (nil , func (_ * http.Request ) (* http.Response , error ) {
342+ return nil , nil
343+ })
344+ require .NoError (t , err )
345+ _ , err = a .NOTP ().UpdateUser (context .Background (), "login-id" , "" , nil , nil )
346+ require .Error (t , err )
347+ assert .ErrorIs (t , err , descope .ErrRefreshToken )
348+ }
349+
350+ func TestUpdateUserNOTPWithoutOptions (t * testing.T ) {
351+ loginID := "943248329844"
352+ phone := "+111111111111"
353+ a , err := newTestAuth (nil , func (r * http.Request ) (* http.Response , error ) {
354+ assert .EqualValues (t , composeNOTPUpdateUserURL (), r .URL .RequestURI ())
355+
356+ body , err := readBodyMap (r )
357+ require .NoError (t , err )
358+ assert .EqualValues (t , loginID , body ["loginId" ])
359+ assert .EqualValues (t , phone , body ["phone" ])
360+ assert .Nil (t , body ["addToLoginIDs" ])
361+ assert .Nil (t , body ["onMergeUseExisting" ])
362+ assert .Nil (t , body ["templateOptions" ])
363+ u , p := getProjectAndJwt (r )
364+ assert .NotEmpty (t , u )
365+ assert .NotEmpty (t , p )
366+ resp := descope.NOTPResponse {}
367+ respBytes , err := utils .Marshal (resp )
368+ require .NoError (t , err )
369+ return & http.Response {StatusCode : http .StatusOK , Body : io .NopCloser (bytes .NewBuffer (respBytes ))}, nil
370+ })
371+ require .NoError (t , err )
372+ r := & http.Request {Header : http.Header {}}
373+ r .AddCookie (& http.Cookie {Name : descope .RefreshCookieName , Value : jwtTokenValid })
374+ _ , err = a .NOTP ().UpdateUser (context .Background (), loginID , phone , nil , r )
375+ require .NoError (t , err )
376+ }
377+
378+ func TestUpdateUserNOTPWithOptions (t * testing.T ) {
379+ loginID := "943248329844"
380+ phone := "+111111111111"
381+ options := & descope.NOTPUpdateOptions {
382+ AddToLoginIDs : true ,
383+ OnMergeUseExisting : true ,
384+ ProviderID : "provider-id" ,
385+ TemplateOptions : map [string ]string {
386+ "key1" : "value1" ,
387+ },
388+ Templates : & descope.NOTPTemplates {
389+ VerifyTemplateID : "verify-template-id" ,
390+ SuccessTemplateID : "success-template-id" ,
391+ ErrorTemplateID : "error-template-id" ,
392+ },
393+ }
394+ a , err := newTestAuth (nil , func (r * http.Request ) (* http.Response , error ) {
395+ assert .EqualValues (t , composeNOTPUpdateUserURL (), r .URL .RequestURI ())
396+
397+ body , err := readBodyMap (r )
398+ require .NoError (t , err )
399+ assert .EqualValues (t , loginID , body ["loginId" ])
400+ assert .EqualValues (t , phone , body ["phone" ])
401+ assert .EqualValues (t , true , body ["addToLoginIDs" ])
402+ assert .EqualValues (t , true , body ["onMergeUseExisting" ])
403+ assert .NotEmpty (t , body ["templates" ])
404+ assert .NotEmpty (t , body ["templateOptions" ])
405+ u , p := getProjectAndJwt (r )
406+ assert .NotEmpty (t , u )
407+ assert .NotEmpty (t , p )
408+ resp := descope.NOTPResponse {}
409+ respBytes , err := utils .Marshal (resp )
410+ require .NoError (t , err )
411+ return & http.Response {StatusCode : http .StatusOK , Body : io .NopCloser (bytes .NewBuffer (respBytes ))}, nil
412+ })
413+ require .NoError (t , err )
414+ r := & http.Request {Header : http.Header {}}
415+ r .AddCookie (& http.Cookie {Name : descope .RefreshCookieName , Value : jwtTokenValid })
416+ _ , err = a .NOTP ().UpdateUser (context .Background (), loginID , phone , options , r )
417+ require .NoError (t , err )
418+ }
0 commit comments