@@ -743,55 +743,35 @@ test('findOne: .except() - For the reference - Array', function(assert) {
743743 * HTTP Error Handling
744744 * !*/
745745
746- test ( 'findOne: should handle 404 Not Found error' , function ( assert ) {
747- const Query = Stack . ContentType ( contentTypes . invalid_type ) . Query ( ) ;
746+ test ( 'findOne: should handle 422 Unprocessable Entity error' , function ( assert ) {
747+ const Query = Stack . ContentType ( "invalid_content_type" ) . Query ( ) ;
748748
749749 Query
750750 . toJSON ( )
751751 . findOne ( )
752752 . then ( function success ( ) {
753- assert . fail ( "Expected 404 error but got a successful response." ) ;
753+ assert . fail ( "Expected 422 error but got a successful response." ) ;
754754 assert . end ( ) ;
755755 } , function error ( err ) {
756- assert . equal ( err . http_code , 404 , 'Should return HTTP status 404.' ) ;
757- assert . ok ( err . http_message , 'Error message should be present.' ) ;
758- console . error ( "Error:" , err . http_message ) ;
756+ assert . equal ( err . http_code , 422 , 'Should return HTTP status 422.' ) ;
757+ assert . ok ( err . http_message , 'Unprocessable Entity' ) ;
759758 assert . end ( ) ;
760759 } ) ;
761760} ) ;
762761
763- test ( 'findOne: should handle 401 Unauthorized error' , function ( assert ) {
762+ test ( 'findOne: should handle 412 Unauthorized error' , function ( assert ) {
764763 Stack . headers = { authorization : 'InvalidAPIKey' } ; // Simulating an invalid API key
765764 const Query = Stack . ContentType ( contentTypes . source ) . Query ( ) ;
766765
767766 Query
768767 . toJSON ( )
769768 . findOne ( )
770769 . then ( function success ( ) {
771- assert . fail ( "Expected 401 error but got a successful response." ) ;
770+ assert . fail ( "Expected 412 error but got a successful response." ) ;
772771 assert . end ( ) ;
773772 } , function error ( err ) {
774- assert . equal ( err . http_code , 401 , 'Should return HTTP status 401.' ) ;
775- assert . ok ( err . http_message , 'Error message should be present.' ) ;
776- console . error ( "Error:" , err . http_message ) ;
773+ assert . equal ( err . http_code , 412 , 'Should return HTTP status 412.' ) ;
774+ assert . ok ( err . http_message , 'Precondition Failed.' ) ;
777775 assert . end ( ) ;
778776 } ) ;
779777} ) ;
780-
781- test ( 'findOne: should handle 500 Internal Server Error' , function ( assert ) {
782- const mockStack = Contentstack . Stack ( { ...init . stack , host : 'invalid.host' } ) ; // Simulating a server error
783- const Query = mockStack . ContentType ( contentTypes . source ) . Query ( ) ;
784-
785- Query
786- . toJSON ( )
787- . findOne ( )
788- . then ( function success ( ) {
789- assert . fail ( "Expected 500 error but got a successful response." ) ;
790- assert . end ( ) ;
791- } , function error ( err ) {
792- assert . equal ( err . http_code , 500 , 'Should return HTTP status 500.' ) ;
793- assert . ok ( err . http_message , 'Error message should be present.' ) ;
794- console . error ( "Error:" , err . http_message ) ;
795- assert . end ( ) ;
796- } ) ;
797- } ) ;
0 commit comments