File tree Expand file tree Collapse file tree 16 files changed +233
-6
lines changed
tests/validators/redirection Expand file tree Collapse file tree 16 files changed +233
-6
lines changed Original file line number Diff line number Diff line change @@ -22,9 +22,24 @@ export { default as isAlreadyReported } from './success/is-already-reported';
22
22
export { default as isImUsed } from './success/is-im-used' ;
23
23
24
24
// 3×× Redirection
25
+ export {
26
+ default as isMultipleChoices
27
+ } from './redirection/is-multiple-choices' ;
25
28
export {
26
29
default as isMovedPermanently
27
30
} 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' ;
28
41
29
42
// 4×× Client Error
30
43
export { default as isUnauthorized } from './client-error/is-unauthorized' ;
44
+
45
+ // 5×× Server Error
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change 1
1
import { isMovedPermanently } from '../../../src' ;
2
2
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 ( ) ;
6
8
} ) ;
7
9
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.` ) ;
11
13
} ) ;
12
14
} ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments