@@ -485,9 +485,9 @@ func TestUserHandler_UpdateAddress(t *testing.T) {
485485 body : `{"street":"...","city":"...","state":"...","postal_code":"...","country":"..."}` ,
486486 mockUserReturnMid : userForToken ,
487487 mockUserErrMid : nil ,
488- mockAddrUpdateErr : nil , // Won't be called
489- expectedStatus : http .StatusBadRequest ,
490- expectedBody : `{"error":"invalid user ID in URL"}` ,
488+ mockAddrUpdateErr : nil ,
489+ expectedStatus : http .StatusNotFound ,
490+ expectedBody : "404 page not found" ,
491491 },
492492 {
493493 name : "Failure - Invalid Address ID in URL" ,
@@ -496,9 +496,9 @@ func TestUserHandler_UpdateAddress(t *testing.T) {
496496 body : `{"street":"...","city":"...","state":"...","postal_code":"...","country":"..."}` ,
497497 mockUserReturnMid : userForToken ,
498498 mockUserErrMid : nil ,
499- mockAddrUpdateErr : nil , // Won't be called
500- expectedStatus : http .StatusBadRequest ,
501- expectedBody : `{"error":"invalid address ID format"}` ,
499+ mockAddrUpdateErr : nil ,
500+ expectedStatus : http .StatusNotFound ,
501+ expectedBody : "404 page not found" ,
502502 },
503503 {
504504 name : "Failure - Unauthorized (Different User ID)" ,
@@ -563,8 +563,8 @@ func TestUserHandler_UpdateAddress(t *testing.T) {
563563 // Setup inside t.Run
564564 mockUserRepo , mockAddressRepo , _ , _ , router := setupUserHandlerTest (t )
565565
566- // Mock middleware check ( only if token is expected and UserID is valid)
567- if tc .targetUserIDStr != "not-a-uuid" && tc .expectedBody != `{"error":"authorization header required"}` {
566+ // Mock middleware check only if token is expected and BOTH IDs in URL are valid format
567+ if tc .targetUserIDStr != "not-a-uuid" && tc .targetAddrIDStr != "not-a-uuid" && tc . expectedBody != `{"error":"authorization header required"}` {
568568 mockUserRepo .On ("FindByID" , mock .Anything , testUserID ).Return (tc .mockUserReturnMid , tc .mockUserErrMid ).Once ()
569569 }
570570
@@ -642,19 +642,19 @@ func TestUserHandler_DeleteAddress(t *testing.T) {
642642 targetAddrIDStr : testAddressID .String (),
643643 mockUserReturnMid : userForToken ,
644644 mockUserErrMid : nil ,
645- mockAddrDeleteErr : nil , // Won't be called
646- expectedStatus : http .StatusBadRequest ,
647- expectedBody : `{"error":"invalid user ID in URL"}` ,
645+ mockAddrDeleteErr : nil ,
646+ expectedStatus : http .StatusNotFound ,
647+ expectedBody : "404 page not found" ,
648648 },
649649 {
650650 name : "Failure - Invalid Address ID in URL" ,
651651 targetUserIDStr : testUserID .String (),
652652 targetAddrIDStr : "not-a-uuid" ,
653653 mockUserReturnMid : userForToken ,
654654 mockUserErrMid : nil ,
655- mockAddrDeleteErr : nil , // Won't be called
656- expectedStatus : http .StatusBadRequest ,
657- expectedBody : `{"error":"invalid address ID format"}` ,
655+ mockAddrDeleteErr : nil ,
656+ expectedStatus : http .StatusNotFound ,
657+ expectedBody : "404 page not found" ,
658658 },
659659 {
660660 name : "Failure - Unauthorized (Different User ID)" ,
@@ -714,8 +714,8 @@ func TestUserHandler_DeleteAddress(t *testing.T) {
714714 // Setup inside t.Run
715715 mockUserRepo , mockAddressRepo , _ , _ , router := setupUserHandlerTest (t )
716716
717- // Mock middleware check ( only if token is expected and UserID is valid)
718- if tc .targetUserIDStr != "not-a-uuid" && tc .expectedBody != `{"error":"authorization header required"}` {
717+ // Mock middleware check only if token is expected and BOTH IDs in URL are valid format
718+ if tc .targetUserIDStr != "not-a-uuid" && tc .targetAddrIDStr != "not-a-uuid" && tc . expectedBody != `{"error":"authorization header required"}` {
719719 mockUserRepo .On ("FindByID" , mock .Anything , testUserID ).Return (tc .mockUserReturnMid , tc .mockUserErrMid ).Once ()
720720 }
721721
@@ -778,28 +778,28 @@ func TestUserHandler_SetDefaultAddress(t *testing.T) {
778778 mockUserReturnMid : userForToken ,
779779 mockUserErrMid : nil ,
780780 mockAddrSetDefaultErr : nil ,
781- expectedStatus : http .StatusOK , // Or StatusNoContent depending on handler implementation
782- expectedBody : `{"message":"address set as default"}` , // Assuming a success message
781+ expectedStatus : http .StatusOK ,
782+ expectedBody : "" ,
783783 },
784784 {
785785 name : "Failure - Invalid User ID in URL" ,
786786 targetUserIDStr : "not-a-uuid" ,
787787 targetAddrIDStr : testAddressID .String (),
788788 mockUserReturnMid : userForToken ,
789789 mockUserErrMid : nil ,
790- mockAddrSetDefaultErr : nil , // Won't be called
791- expectedStatus : http .StatusBadRequest ,
792- expectedBody : `{"error":"invalid user ID in URL"}` ,
790+ mockAddrSetDefaultErr : nil ,
791+ expectedStatus : http .StatusNotFound ,
792+ expectedBody : "404 page not found" ,
793793 },
794794 {
795795 name : "Failure - Invalid Address ID in URL" ,
796796 targetUserIDStr : testUserID .String (),
797797 targetAddrIDStr : "not-a-uuid" ,
798798 mockUserReturnMid : userForToken ,
799799 mockUserErrMid : nil ,
800- mockAddrSetDefaultErr : nil , // Won't be called
801- expectedStatus : http .StatusBadRequest ,
802- expectedBody : `{"error":"invalid address ID format"}` ,
800+ mockAddrSetDefaultErr : nil ,
801+ expectedStatus : http .StatusNotFound ,
802+ expectedBody : "404 page not found" ,
803803 },
804804 {
805805 name : "Failure - Unauthorized (Different User ID)" ,
@@ -859,8 +859,8 @@ func TestUserHandler_SetDefaultAddress(t *testing.T) {
859859 // Setup inside t.Run
860860 mockUserRepo , mockAddressRepo , _ , _ , router := setupUserHandlerTest (t )
861861
862- // Mock middleware check ( only if token is expected and UserID is valid)
863- if tc .targetUserIDStr != "not-a-uuid" && tc .expectedBody != `{"error":"authorization header required"}` {
862+ // Mock middleware check only if token is expected and BOTH IDs in URL are valid format
863+ if tc .targetUserIDStr != "not-a-uuid" && tc .targetAddrIDStr != "not-a-uuid" && tc . expectedBody != `{"error":"authorization header required"}` {
864864 mockUserRepo .On ("FindByID" , mock .Anything , testUserID ).Return (tc .mockUserReturnMid , tc .mockUserErrMid ).Once ()
865865 }
866866
@@ -887,8 +887,10 @@ func TestUserHandler_SetDefaultAddress(t *testing.T) {
887887
888888 assert .Equal (t , tc .expectedStatus , rr .Code )
889889 // Check for specific success message or ignore body for non-error cases if needed
890- if tc .expectedStatus >= 400 || tc .expectedBody != "" { // Check body for errors or specific success messages
890+ if tc .expectedStatus >= 400 || ( tc .expectedStatus < 300 && tc . expectedBody != "" ) { // Check body for errors or specific success messages
891891 assert .Contains (t , rr .Body .String (), tc .expectedBody )
892+ } else if tc .expectedStatus < 300 && tc .expectedBody == "" { // Check for empty body on success if expected
893+ assert .Empty (t , rr .Body .String ())
892894 }
893895 mockUserRepo .AssertExpectations (t )
894896 mockAddressRepo .AssertExpectations (t )
0 commit comments