Skip to content

Commit 477ee91

Browse files
committed
feat: validators type server error
1 parent 79a4804 commit 477ee91

25 files changed

+386
-0
lines changed

src/validators/index.js

+26
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,29 @@ export {
4343
export { default as isUnauthorized } from './client-error/is-unauthorized';
4444

4545
// 5×× Server Error
46+
export { default as isBadGateway } from './server-error/is-bad-gateway';
47+
export { default as isGatewayTimeout } from './server-error/is-gateway-timeout';
48+
export {
49+
default as isHttpVersionNotSupported
50+
} from './server-error/is-http-version-not-supported';
51+
export {
52+
default as isInsufficientStorage
53+
} from './server-error/is-insufficient-storage';
54+
export {
55+
default as isInternalServerError
56+
} from './server-error/is-internal-server-error';
57+
export { default as isLoopDetected } from './server-error/is-loop-detected';
58+
export {
59+
default as isNetworkAuthenticationRequired
60+
} from './server-error/is-network-authentication-required';
61+
export {
62+
default as isNetworkConnectTimeoutError
63+
} from './server-error/is-network-connect-timeout-error';
64+
export { default as isNotExtended } from './server-error/is-not-extended';
65+
export { default as isNotImplemented } from './server-error/is-not-implemented';
66+
export {
67+
default as isServiceUnavailable
68+
} from './server-error/is-service-unavailable';
69+
export {
70+
default as isVariantAlsoNegotiates
71+
} from './server-error/is-variant-also-negotiates';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isBadGateway
5+
* @description
6+
* Validate HTTP Status code 502 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 502
11+
*/
12+
function isBadGateway(statusCode) {
13+
return validateHttpStatus(statusCode, 502);
14+
}
15+
16+
export default isBadGateway;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isGatewayTimeout
5+
* @description
6+
* Validate HTTP Status code 504 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 504
11+
*/
12+
function isGatewayTimeout(statusCode) {
13+
return validateHttpStatus(statusCode, 504);
14+
}
15+
16+
export default isGatewayTimeout;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isHttpVersionNotSupported
5+
* @description
6+
* Validate HTTP Status code 505 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 504
11+
*/
12+
function isHttpVersionNotSupported(statusCode) {
13+
return validateHttpStatus(statusCode, 505);
14+
}
15+
16+
export default isHttpVersionNotSupported;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isInsufficientStorage
5+
* @description
6+
* Validate HTTP Status code 507 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 507
11+
*/
12+
function isInsufficientStorage(statusCode) {
13+
return validateHttpStatus(statusCode, 507);
14+
}
15+
16+
export default isInsufficientStorage;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isInternalServerError
5+
* @description
6+
* Validate HTTP Status code 500 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 500
11+
*/
12+
function isInternalServerError(statusCode) {
13+
return validateHttpStatus(statusCode, 500);
14+
}
15+
16+
export default isInternalServerError;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isLoopDetected
5+
* @description
6+
* Validate HTTP Status code 508 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 508
11+
*/
12+
function isLoopDetected(statusCode) {
13+
return validateHttpStatus(statusCode, 508);
14+
}
15+
16+
export default isLoopDetected;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isNetworkAuthenticationRequired
5+
* @description
6+
* Validate HTTP Status code 511 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 511
11+
*/
12+
function isNetworkAuthenticationRequired(statusCode) {
13+
return validateHttpStatus(statusCode, 511);
14+
}
15+
16+
export default isNetworkAuthenticationRequired;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isNetworkConnectTimeoutError
5+
* @description
6+
* Validate HTTP Status code 599 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 599
11+
*/
12+
function isNetworkConnectTimeoutError(statusCode) {
13+
return validateHttpStatus(statusCode, 599);
14+
}
15+
16+
export default isNetworkConnectTimeoutError;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isNotExtended
5+
* @description
6+
* Validate HTTP Status code 510 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 510
11+
*/
12+
function isNotExtended(statusCode) {
13+
return validateHttpStatus(statusCode, 510);
14+
}
15+
16+
export default isNotExtended;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isNotImplemented
5+
* @description
6+
* Validate HTTP Status code 501 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 501
11+
*/
12+
function isNotImplemented(statusCode) {
13+
return validateHttpStatus(statusCode, 501);
14+
}
15+
16+
export default isNotImplemented;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isServiceUnavailable
5+
* @description
6+
* Validate HTTP Status code 503 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 503
11+
*/
12+
function isServiceUnavailable(statusCode) {
13+
return validateHttpStatus(statusCode, 503);
14+
}
15+
16+
export default isServiceUnavailable;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isVariantAlsoNegotiates
5+
* @description
6+
* Validate HTTP Status code 506 type SERVER ERROR
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 506
11+
*/
12+
function isVariantAlsoNegotiates(statusCode) {
13+
return validateHttpStatus(statusCode, 506);
14+
}
15+
16+
export default isVariantAlsoNegotiates;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isInternalServerError } from '../../../src';
2+
3+
describe('Validators: isInternalServerError (type server error)', () => {
4+
const STATUS_EXPECTED = 500;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isInternalServerError(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isInternalServerError(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isBadGateway } from '../../../src';
2+
3+
describe('Validators: isBadGateway (type server error)', () => {
4+
const STATUS_EXPECTED = 502;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isBadGateway(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isBadGateway(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isGatewayTimeout } from '../../../src';
2+
3+
describe('Validators: isGatewayTimeout (type server error)', () => {
4+
const STATUS_EXPECTED = 504;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isGatewayTimeout(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isGatewayTimeout(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isHttpVersionNotSupported } from '../../../src';
2+
3+
describe('Validators: isBadGateway (type server error)', () => {
4+
const STATUS_EXPECTED = 505;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isHttpVersionNotSupported(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isHttpVersionNotSupported(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isInsufficientStorage } from '../../../src';
2+
3+
describe('Validators: isInsufficientStorage (type server error)', () => {
4+
const STATUS_EXPECTED = 507;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isInsufficientStorage(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isInsufficientStorage(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isLoopDetected } from '../../../src';
2+
3+
describe('Validators: isLoopDetected (type server error)', () => {
4+
const STATUS_EXPECTED = 508;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isLoopDetected(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isLoopDetected(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isNetworkAuthenticationRequired } from '../../../src';
2+
3+
describe('Validators: isNetworkAuthenticationRequired (type server error)', () => {
4+
const STATUS_EXPECTED = 511;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isNetworkAuthenticationRequired(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isNetworkAuthenticationRequired(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isNetworkConnectTimeoutError } from '../../../src';
2+
3+
describe('Validators: isNetworkConnectTimeoutError (type server error)', () => {
4+
const STATUS_EXPECTED = 599;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isNetworkConnectTimeoutError(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isNetworkConnectTimeoutError(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isNotExtended } from '../../../src';
2+
3+
describe('Validators: isNotExtended (type server error)', () => {
4+
const STATUS_EXPECTED = 510;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isNotExtended(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isNotExtended(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isNotImplemented } from '../../../src';
2+
3+
describe('Validators: isNotImplemented (type server error)', () => {
4+
const STATUS_EXPECTED = 501;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isNotImplemented(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isNotImplemented(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isServiceUnavailable } from '../../../src';
2+
3+
describe('Validators: isServiceUnavailable (type server error)', () => {
4+
const STATUS_EXPECTED = 503;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isServiceUnavailable(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isServiceUnavailable(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});

0 commit comments

Comments
 (0)