Skip to content

Commit a182da6

Browse files
committed
refactor: valitate methods moved to directory validators
1 parent 98f5978 commit a182da6

File tree

14 files changed

+113
-16
lines changed

14 files changed

+113
-16
lines changed

src/index.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
export { default as findStatus } from './utils/find-status/index';
2-
export {
3-
default as findStatusByCode
4-
} from './utils/find-status/find-status-by-code';
5-
export {
6-
default as findStatusByKey
7-
} from './utils/find-status/find-status-by-key';
8-
export { default as validateHttpStatus } from './utils/validate-http-status';
91
export { default as HTTPStatusError } from './errors/http-status-error';
10-
export { default as isCreated } from './is-created';
11-
export { default as isOk } from './is-ok';
12-
export { default as isMovedPermanently } from './is-moved-permanently';
13-
export { default as isUnauthorized } from './is-unauthorized';
2+
export * from './utils';
3+
export * from './validators';

src/utils/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as findStatus } from './find-status';
2+
export { default as findStatusByCode } from './find-status/find-status-by-code';
3+
export { default as findStatusByKey } from './find-status/find-status-by-key';

src/is-unauthorized.js renamed to src/validators/client-error/is-unauthorized.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import validateHttpStatus from './utils/validate-http-status';
1+
import validateHttpStatus from '../validate-http-status';
22

33
/**
44
* @module isUnauthorized

src/validators/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export { default as validateHttpStatus } from './validate-http-status';
2+
3+
// 1×× Informational
4+
export { default as isContinue } from './informational/is-continue';
5+
export { default as isProcessing } from './informational/is-processing';
6+
export {
7+
default as isSwitchingProtocols
8+
} from './informational/is-switching-protocols';
9+
10+
// 2×× Success
11+
export { default as isCreated } from './success/is-created';
12+
export { default as isOk } from './success/is-ok';
13+
14+
// 3×× Redirection
15+
export {
16+
default as isMovedPermanently
17+
} from './redirection/is-moved-permanently';
18+
19+
// 4×× Client Error
20+
export { default as isUnauthorized } from './client-error/is-unauthorized';
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 isContinue
5+
* @description
6+
* Validate HTTP Status code 100 type INFORMATIONAL
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 100
11+
*/
12+
function isContinue(statusCode) {
13+
return validateHttpStatus(statusCode, 100);
14+
}
15+
16+
export default isContinue;
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 isProcessing
5+
* @description
6+
* Validate HTTP Status code 102 type INFORMATIONAL
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 102
11+
*/
12+
function isProcessing(statusCode) {
13+
return validateHttpStatus(statusCode, 102);
14+
}
15+
16+
export default isProcessing;
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 isSwitchingProtocols
5+
* @description
6+
* Validate HTTP Status code 101 type INFORMATIONAL
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 101
11+
*/
12+
function isSwitchingProtocols(statusCode) {
13+
return validateHttpStatus(statusCode, 101);
14+
}
15+
16+
export default isSwitchingProtocols;

src/is-moved-permanently.js renamed to src/validators/redirection/is-moved-permanently.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import validateHttpStatus from './utils/validate-http-status';
1+
import validateHttpStatus from '../validate-http-status';
22

33
/**
44
* @module isMovedPermanently

src/is-created.js renamed to src/validators/success/is-created.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import validateHttpStatus from './utils/validate-http-status';
1+
import validateHttpStatus from '../validate-http-status';
22

33
/**
44
* @module isCreated

src/is-ok.js renamed to src/validators/success/is-ok.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import validateHttpStatus from './utils/validate-http-status';
1+
import validateHttpStatus from '../validate-http-status';
22

33
/**
44
* @module isOk

tests/is-continue.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { isContinue } from '../src';
2+
3+
describe('isContinue', () => {
4+
test('it should receive true when pass status 100', () => {
5+
expect(isContinue(100)).toBeTruthy();
6+
});
7+
8+
test('it should throw Error when pass status different than 100', () => {
9+
const received = isContinue(300);
10+
expect(received.message).toBe('Expected a 100 response.');
11+
});
12+
});

tests/is-processing.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { isProcessing } from '../src';
2+
3+
describe('isProcessing', () => {
4+
test('it should receive true when pass status 102', () => {
5+
expect(isProcessing(102)).toBeTruthy();
6+
});
7+
8+
test('it should throw Error when pass status different than 102', () => {
9+
const received = isProcessing(300);
10+
expect(received.message).toBe('Expected a 102 response.');
11+
});
12+
});

tests/is-switching-protocols.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { isSwitchingProtocols } from '../src';
2+
3+
describe('isSwitchingProtocols', () => {
4+
test('it should receive true when pass status 101', () => {
5+
expect(isSwitchingProtocols(101)).toBeTruthy();
6+
});
7+
8+
test('it should throw Error when pass status different than 101', () => {
9+
const received = isSwitchingProtocols(300);
10+
expect(received.message).toBe('Expected a 101 response.');
11+
});
12+
});

0 commit comments

Comments
 (0)