Skip to content

Commit 79a4804

Browse files
committed
feat: validators type redirection
1 parent d983bdd commit 79a4804

16 files changed

+233
-6
lines changed

src/validators/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,24 @@ export { default as isAlreadyReported } from './success/is-already-reported';
2222
export { default as isImUsed } from './success/is-im-used';
2323

2424
// 3×× Redirection
25+
export {
26+
default as isMultipleChoices
27+
} from './redirection/is-multiple-choices';
2528
export {
2629
default as isMovedPermanently
2730
} from './redirection/is-moved-permanently';
31+
export { default as isFound } from './redirection/is-found';
32+
export { default as isSeeOther } from './redirection/is-see-other';
33+
export { default as isNotModified } from './redirection/is-not-modified';
34+
export { default as isUseProxy } from './redirection/is-use-proxy';
35+
export {
36+
default as isTemporaryRedirect
37+
} from './redirection/is-temporary-redirect';
38+
export {
39+
default as isPermanentRedirect
40+
} from './redirection/is-permanent-redirect';
2841

2942
// 4×× Client Error
3043
export { default as isUnauthorized } from './client-error/is-unauthorized';
44+
45+
// 5×× Server Error
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isFound
5+
* @description
6+
* Validate HTTP Status code 302 type REDIRECTION
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 302
11+
*/
12+
function isFound(statusCode) {
13+
return validateHttpStatus(statusCode, 302);
14+
}
15+
16+
export default isFound;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isMultipleChoices
5+
* @description
6+
* Validate HTTP Status code 300 type REDIRECTION
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 300
11+
*/
12+
function isMultipleChoices(statusCode) {
13+
return validateHttpStatus(statusCode, 300);
14+
}
15+
16+
export default isMultipleChoices;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isNotModified
5+
* @description
6+
* Validate HTTP Status code 304 type REDIRECTION
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 304
11+
*/
12+
function isNotModified(statusCode) {
13+
return validateHttpStatus(statusCode, 304);
14+
}
15+
16+
export default isNotModified;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isPermanentRedirect
5+
* @description
6+
* Validate HTTP Status code 308 type REDIRECTION
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 308
11+
*/
12+
function isPermanentRedirect(statusCode) {
13+
return validateHttpStatus(statusCode, 308);
14+
}
15+
16+
export default isPermanentRedirect;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isSeeOther
5+
* @description
6+
* Validate HTTP Status code 303 type REDIRECTION
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 303
11+
*/
12+
function isSeeOther(statusCode) {
13+
return validateHttpStatus(statusCode, 303);
14+
}
15+
16+
export default isSeeOther;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isTemporaryRedirect
5+
* @description
6+
* Validate HTTP Status code 307 type REDIRECTION
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 307
11+
*/
12+
function isTemporaryRedirect(statusCode) {
13+
return validateHttpStatus(statusCode, 307);
14+
}
15+
16+
export default isTemporaryRedirect;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isUseproxy
5+
* @description
6+
* Validate HTTP Status code 305 type REDIRECTION
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 305
11+
*/
12+
function isUseproxy(statusCode) {
13+
return validateHttpStatus(statusCode, 305);
14+
}
15+
16+
export default isUseproxy;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isFound } from '../../../src';
2+
3+
describe('Validators: isFound (type redirection)', () => {
4+
const STATUS_EXPECTED = 302;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isFound(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isFound(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { isMovedPermanently } from '../../../src';
22

3-
describe('isMovedPermanently', () => {
4-
test('it should receive true when pass status 301', () => {
5-
expect(isMovedPermanently(301)).toBeTruthy();
3+
describe('Validators: isMovedPermanently (type redirection)', () => {
4+
const STATUS_EXPECTED = 301;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isMovedPermanently(STATUS_EXPECTED)).toBeTruthy();
68
});
79

8-
test('it should throw Error when pass status different than 301', () => {
9-
const received = isMovedPermanently(400);
10-
expect(received.message).toBe('Expected a 301 response.');
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isMovedPermanently(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
1113
});
1214
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isMultipleChoices } from '../../../src';
2+
3+
describe('Validators: isMultipleChoices (type redirection)', () => {
4+
const STATUS_EXPECTED = 300;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isMultipleChoices(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isMultipleChoices(304);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isNotModified } from '../../../src';
2+
3+
describe('Validators: isNotModified (type redirection)', () => {
4+
const STATUS_EXPECTED = 304;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isNotModified(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isNotModified(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isPermanentRedirect } from '../../../src';
2+
3+
describe('Validators: isPermanentRedirect (type redirection)', () => {
4+
const STATUS_EXPECTED = 308;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isPermanentRedirect(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isPermanentRedirect(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isSeeOther } from '../../../src';
2+
3+
describe('Validators: isSeeOther (type redirection)', () => {
4+
const STATUS_EXPECTED = 303;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isSeeOther(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isSeeOther(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isTemporaryRedirect } from '../../../src';
2+
3+
describe('Validators: isTemporaryRedirect (type redirection)', () => {
4+
const STATUS_EXPECTED = 307;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isTemporaryRedirect(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isTemporaryRedirect(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isUseProxy } from '../../../src';
2+
3+
describe('Validators: isSeeOther (type redirection)', () => {
4+
const STATUS_EXPECTED = 305;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isUseProxy(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isUseProxy(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});

0 commit comments

Comments
 (0)