@@ -45,6 +45,42 @@ test.describe('Comments', () => {
4545 await expect ( page . locator ( `.card:not(.comment-form) .card-block:has-text("${ commentText } ")` ) ) . not . toBeVisible ( ) ;
4646 } ) ;
4747
48+ /**
49+ * Verifies the frontend handles HTTP 200 for comment deletion.
50+ *
51+ * The RealWorld spec uses 204 No Content for DELETE operations, which is
52+ * semantically correct (success with no response body). However, HTTP clients
53+ * should accept ANY 2XX status as success per RFC 9110.
54+ *
55+ * This test mocks a 200 response to verify the frontend doesn't break when
56+ * an implementation returns 200 instead of 204. This is good engineering
57+ * practice: clients should handle status code classes, not specific codes.
58+ */
59+ test ( 'should delete comment when server returns 200 instead of 204' , async ( { page } ) => {
60+ const commentText = 'Comment to test 200 status' ;
61+ await addComment ( page , commentText ) ;
62+ // Comment should be visible
63+ await expect ( page . locator ( `.card:not(.comment-form) .card-block:has-text("${ commentText } ")` ) ) . toBeVisible ( ) ;
64+
65+ // Intercept DELETE requests to comments and respond with 200 instead of 204
66+ await page . route ( '**/api/articles/*/comments/*' , async route => {
67+ if ( route . request ( ) . method ( ) === 'DELETE' ) {
68+ await route . fulfill ( {
69+ status : 200 ,
70+ contentType : 'application/json' ,
71+ body : JSON . stringify ( { } ) ,
72+ } ) ;
73+ } else {
74+ await route . continue ( ) ;
75+ }
76+ } ) ;
77+
78+ // Delete the comment
79+ await deleteComment ( page , commentText ) ;
80+ // Comment should no longer be visible (frontend should handle 200 the same as 204)
81+ await expect ( page . locator ( `.card:not(.comment-form) .card-block:has-text("${ commentText } ")` ) ) . not . toBeVisible ( ) ;
82+ } ) ;
83+
4884 test ( 'should display multiple comments' , async ( { page } ) => {
4985 const comment1 = 'First comment' ;
5086 const comment2 = 'Second comment' ;
0 commit comments