Skip to content

Commit 59fe538

Browse files
committed
feat: isUnauthorized validation
1 parent 90984c0 commit 59fe538

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/is-unauthorized.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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;

tests/is-unauthorized.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
});

0 commit comments

Comments
 (0)