@@ -783,6 +783,7 @@ describe("user controller test", () => {
783783 } ) ;
784784 } ) ;
785785 describe ( "update name" , ( ) => {
786+ const blocklistContainsMock = vi . spyOn ( BlocklistDal , "contains" ) ;
786787 const getPartialUserMock = vi . spyOn ( UserDal , "getPartialUser" ) ;
787788 const updateNameMock = vi . spyOn ( UserDal , "updateName" ) ;
788789 const addImportantLogMock = vi . spyOn ( LogDal , "addImportantLog" ) ;
@@ -791,6 +792,7 @@ describe("user controller test", () => {
791792 getPartialUserMock . mockReset ( ) ;
792793 updateNameMock . mockReset ( ) ;
793794 addImportantLogMock . mockReset ( ) ;
795+ blocklistContainsMock . mockReset ( ) ;
794796 } ) ;
795797
796798 it ( "should update the username" , async ( ) => {
@@ -819,6 +821,23 @@ describe("user controller test", () => {
819821 uid
820822 ) ;
821823 } ) ;
824+
825+ it ( "should fail if username is blocked" , async ( ) => {
826+ //GIVEN
827+ blocklistContainsMock . mockResolvedValue ( true ) ;
828+
829+ //WHEN
830+ const { body } = await mockApp
831+ . patch ( "/users/name" )
832+ . set ( "authorization" , `Uid ${ uid } ` )
833+ . send ( { name : "newName" } )
834+ . expect ( 409 ) ;
835+
836+ //THEN
837+ expect ( body . message ) . toEqual ( "Username blocked" ) ;
838+ expect ( updateNameMock ) . not . toHaveBeenCalled ( ) ;
839+ } ) ;
840+
822841 it ( "should fail for banned users" , async ( ) => {
823842 //GIVEN
824843 getPartialUserMock . mockResolvedValue ( { banned : true } as any ) ;
0 commit comments