File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ import validateHttpStatus from './utils/validate-http-status' ;
2
+
3
+ /**
4
+ * @module isUnauthorized
5
+ * @description
6
+ * Validate HTTP Status code 401 type CLIENT ERROR
7
+ *
8
+ * @param {Integer } statusCode - The HTTP Status code
9
+ * @return {Boolean }
10
+ * @throws {HTTPStatusError } When the statusCode is different then 401
11
+ */
12
+ function isUnauthorized ( statusCode ) {
13
+ return validateHttpStatus ( statusCode , 401 ) ;
14
+ }
15
+
16
+ export default isUnauthorized ;
Original file line number Diff line number Diff line change
1
+ import { isUnauthorized } from '../src' ;
2
+
3
+ describe ( 'isMovedPermanently' , ( ) => {
4
+ test ( 'it should receive true when pass status 401' , ( ) => {
5
+ expect ( isUnauthorized ( 401 ) ) . toBeTruthy ( ) ;
6
+ } ) ;
7
+
8
+ test ( 'it should throw Error when pass status different than 401' , ( ) => {
9
+ const received = isUnauthorized ( 500 ) ;
10
+ expect ( received . message ) . toBe ( 'Expected a 401 response.' ) ;
11
+ } ) ;
12
+ } ) ;
You can’t perform that action at this time.
0 commit comments