@@ -103,6 +103,32 @@ func (s *ApplicationSuite) Test_CreateApplication_expectBadRequestOnEmptyName()
103103 }
104104}
105105
106+ func (s * ApplicationSuite ) Test_CreateApplication_expectBadRequestOnTooLongSortKey () {
107+ s .db .User (5 )
108+
109+ test .WithUser (s .ctx , 5 )
110+ s .withFormData ("name=app&sortKey=" + strings .Repeat ("z" , 256 ))
111+ s .a .CreateApplication (s .ctx )
112+
113+ assert .Equal (s .T (), 400 , s .recorder .Code )
114+ if app , err := s .db .GetApplicationsByUser (5 ); assert .NoError (s .T (), err ) {
115+ assert .Empty (s .T (), app )
116+ }
117+ }
118+
119+ func (s * ApplicationSuite ) Test_CreateApplication_expectBadRequestOnInvalidSortKey () {
120+ s .db .User (5 )
121+
122+ test .WithUser (s .ctx , 5 )
123+ s .withFormData ("name=app&sortKey=a10" )
124+ s .a .CreateApplication (s .ctx )
125+
126+ assert .Equal (s .T (), 400 , s .recorder .Code )
127+ if app , err := s .db .GetApplicationsByUser (5 ); assert .NoError (s .T (), err ) {
128+ assert .Empty (s .T (), app )
129+ }
130+ }
131+
106132func (s * ApplicationSuite ) Test_CreateApplication_ignoresReadOnlyPropertiesInParams () {
107133 s .db .User (5 )
108134
@@ -764,6 +790,38 @@ func (s *ApplicationSuite) Test_UpdateApplication_duplicateSortKey() {
764790 assert .Equal (s .T (), 400 , s .recorder .Code )
765791}
766792
793+ func (s * ApplicationSuite ) Test_UpdateApplication_expectBadRequestOnTooLongSortKey () {
794+ user := s .db .User (5 )
795+ user .App (1 ) // sortKey=a0
796+
797+ s .withFormData ("name=new_name&sortKey=" + strings .Repeat ("z" , 256 ))
798+ test .WithUser (s .ctx , 5 )
799+ s .ctx .Params = gin.Params {{Key : "id" , Value : "1" }}
800+
801+ s .a .UpdateApplication (s .ctx )
802+
803+ assert .Equal (s .T (), 400 , s .recorder .Code )
804+ if app , err := s .db .GetApplicationByID (1 ); assert .NoError (s .T (), err ) {
805+ assert .Equal (s .T (), "a0" , app .SortKey )
806+ }
807+ }
808+
809+ func (s * ApplicationSuite ) Test_UpdateApplication_expectBadRequestOnInvalidSortKey () {
810+ user := s .db .User (5 )
811+ user .App (1 ) // sortKey=a0
812+
813+ s .withFormData ("name=new_name&sortKey=a10" )
814+ test .WithUser (s .ctx , 5 )
815+ s .ctx .Params = gin.Params {{Key : "id" , Value : "1" }}
816+
817+ s .a .UpdateApplication (s .ctx )
818+
819+ assert .Equal (s .T (), 400 , s .recorder .Code )
820+ if app , err := s .db .GetApplicationByID (1 ); assert .NoError (s .T (), err ) {
821+ assert .Equal (s .T (), "a0" , app .SortKey )
822+ }
823+ }
824+
767825func (s * ApplicationSuite ) withFormData (formData string ) {
768826 s .ctx .Request = httptest .NewRequest ("POST" , "/token" , strings .NewReader (formData ))
769827 s .ctx .Request .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
0 commit comments