@@ -32,6 +32,34 @@ func TestCreateApp(t *testing.T) {
3232 expectedStatusCode int
3333 expectedErrorDetails * string
3434 }{
35+ {
36+ name : "should return 400 bad request when icon is not a single emoji" ,
37+ parameters : client.CreateAppParams {
38+ SkipPython : f .Ptr (false ),
39+ SkipSketch : f .Ptr (false ),
40+ },
41+ body : client.CreateAppRequest {
42+ Icon : f .Ptr ("invalid-icon" ),
43+ Name : "HelloWorld-2" ,
44+ Description : f .Ptr ("My HelloWorld description" ),
45+ },
46+ expectedStatusCode : http .StatusBadRequest ,
47+ expectedErrorDetails : f .Ptr ("invalid app: icon \" invalid-icon\" is not a valid single emoji" ),
48+ },
49+ {
50+ name : "should create app successfully when icon is empty" ,
51+ parameters : client.CreateAppParams {
52+ SkipPython : f .Ptr (false ),
53+ SkipSketch : f .Ptr (false ),
54+ },
55+ body : client.CreateAppRequest {
56+ Icon : nil ,
57+ Name : "HelloWorld-2" ,
58+ Description : f .Ptr ("My HelloWorld description" ),
59+ },
60+ expectedStatusCode : http .StatusCreated ,
61+ //expectedErrorDetails: f.Ptr("invalid app: icon cannot be empty"),
62+ },
3563 {
3664 name : "should return 201 Created on first successful creation" ,
3765 parameters : client.CreateAppParams {
@@ -192,7 +220,33 @@ func TestEditApp(t *testing.T) {
192220 require .Equal (t , renamedApp , detailsResp .JSON200 .Name )
193221 require .Equal (t , modifedIcon , * detailsResp .JSON200 .Icon )
194222 })
223+ t .Run ("RequestEmptyIcon_Success" , func (t * testing.T ) {
224+ createResp , err := httpClient .CreateAppWithResponse (
225+ t .Context (),
226+ & client.CreateAppParams {SkipSketch : f .Ptr (true )},
227+ client.CreateAppRequest {
228+ Icon : f .Ptr ("💻" ),
229+ Name : "new-valid-app-1" ,
230+ Description : f .Ptr ("My app description" ),
231+ },
232+ )
233+ require .NoError (t , err )
234+ require .Equal (t , http .StatusCreated , createResp .StatusCode ())
235+ require .NotNil (t , createResp .JSON201 )
236+
237+ validAppId := * createResp .JSON201 .Id
195238
239+ invalidIconBody := `{"icon": "","description": "modified", "example": false,"default": false}`
240+ editResp , err := httpClient .EditAppWithBody (
241+ t .Context (),
242+ validAppId ,
243+ "application/json" ,
244+ strings .NewReader (invalidIconBody ),
245+ )
246+ require .NoError (t , err )
247+ defer editResp .Body .Close ()
248+ require .Equal (t , http .StatusOK , editResp .StatusCode )
249+ })
196250 t .Run ("InvalidAppId_Fail" , func (t * testing.T ) {
197251 var actualResponseBody models.ErrorResponse
198252 editResp , err := httpClient .EditApp (
@@ -232,7 +286,7 @@ func TestEditApp(t *testing.T) {
232286 require .Equal (t , "unable to find the app" , actualResponseBody .Details )
233287 })
234288
235- t .Run ("InvalidRequestBody_Fail " , func (t * testing.T ) {
289+ t .Run ("InvalidRequestSintaxBody_Fail " , func (t * testing.T ) {
236290 createResp , err := httpClient .CreateAppWithResponse (
237291 t .Context (),
238292 & client.CreateAppParams {SkipSketch : f .Ptr (true )},
@@ -266,6 +320,40 @@ func TestEditApp(t *testing.T) {
266320 require .NoError (t , err )
267321 require .Equal (t , "invalid request" , actualResponseBody .Details )
268322 })
323+ t .Run ("InvalidRequestIcon_Fail" , func (t * testing.T ) {
324+ createResp , err := httpClient .CreateAppWithResponse (
325+ t .Context (),
326+ & client.CreateAppParams {SkipSketch : f .Ptr (true )},
327+ client.CreateAppRequest {
328+ Icon : f .Ptr ("💻" ),
329+ Name : "new-valid-app-2" ,
330+ Description : f .Ptr ("My app description" ),
331+ },
332+ )
333+ require .NoError (t , err )
334+ require .Equal (t , http .StatusCreated , createResp .StatusCode ())
335+ require .NotNil (t , createResp .JSON201 )
336+
337+ validAppId := * createResp .JSON201 .Id
338+
339+ var actualResponseBody models.ErrorResponse
340+ invalidIconBody := `{"name": "test", "icon": "💻 invalid"}`
341+ editResp , err := httpClient .EditAppWithBody (
342+ t .Context (),
343+ validAppId ,
344+ "application/json" ,
345+ strings .NewReader (invalidIconBody ),
346+ )
347+ require .NoError (t , err )
348+ defer editResp .Body .Close ()
349+
350+ require .Equal (t , http .StatusBadRequest , editResp .StatusCode )
351+ body , err := io .ReadAll (editResp .Body )
352+ require .NoError (t , err )
353+ err = json .Unmarshal (body , & actualResponseBody )
354+ require .NoError (t , err )
355+ require .Equal (t , "invalid app: icon \" 💻 invalid\" is not a valid single emoji" , actualResponseBody .Details )
356+ })
269357}
270358
271359func TestDeleteApp (t * testing.T ) {
0 commit comments