From 894080ab8a3aed88f8395fb62cf3bacbd0334eff Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:36:04 +0530 Subject: [PATCH] Updated error codes in testcases --- test/entry/findone.js | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/test/entry/findone.js b/test/entry/findone.js index e082486e..130d336e 100755 --- a/test/entry/findone.js +++ b/test/entry/findone.js @@ -743,24 +743,23 @@ test('findOne: .except() - For the reference - Array', function(assert) { * HTTP Error Handling * !*/ -test('findOne: should handle 404 Not Found error', function(assert) { - const Query = Stack.ContentType(contentTypes.invalid_type).Query(); +test('findOne: should handle 422 Unprocessable Entity error', function(assert) { + const Query = Stack.ContentType("invalid_content_type").Query(); Query .toJSON() .findOne() .then(function success() { - assert.fail("Expected 404 error but got a successful response."); + assert.fail("Expected 422 error but got a successful response."); assert.end(); }, function error(err) { - assert.equal(err.http_code, 404, 'Should return HTTP status 404.'); - assert.ok(err.http_message, 'Error message should be present.'); - console.error("Error:", err.http_message); + assert.equal(err.http_code, 422, 'Should return HTTP status 422.'); + assert.ok(err.http_message, 'Unprocessable Entity'); assert.end(); }); }); -test('findOne: should handle 401 Unauthorized error', function(assert) { +test('findOne: should handle 412 Unauthorized error', function(assert) { Stack.headers = { authorization: 'InvalidAPIKey' }; // Simulating an invalid API key const Query = Stack.ContentType(contentTypes.source).Query(); @@ -768,30 +767,11 @@ test('findOne: should handle 401 Unauthorized error', function(assert) { .toJSON() .findOne() .then(function success() { - assert.fail("Expected 401 error but got a successful response."); + assert.fail("Expected 412 error but got a successful response."); assert.end(); }, function error(err) { - assert.equal(err.http_code, 401, 'Should return HTTP status 401.'); - assert.ok(err.http_message, 'Error message should be present.'); - console.error("Error:", err.http_message); + assert.equal(err.http_code, 412, 'Should return HTTP status 412.'); + assert.ok(err.http_message, 'Precondition Failed.'); assert.end(); }); }); - -test('findOne: should handle 500 Internal Server Error', function(assert) { - const mockStack = Contentstack.Stack({ ...init.stack, host: 'invalid.host' }); // Simulating a server error - const Query = mockStack.ContentType(contentTypes.source).Query(); - - Query - .toJSON() - .findOne() - .then(function success() { - assert.fail("Expected 500 error but got a successful response."); - assert.end(); - }, function error(err) { - assert.equal(err.http_code, 500, 'Should return HTTP status 500.'); - assert.ok(err.http_message, 'Error message should be present.'); - console.error("Error:", err.http_message); - assert.end(); - }); -}); \ No newline at end of file