Skip to content

Updated error codes in testcases #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 9 additions & 29 deletions test/entry/findone.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,55 +743,35 @@ 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();

Query
.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();
});
});
Loading