Skip to content

Commit 7a0891f

Browse files
committed
feat: add findStatusByCode, findStatusByKey and updated tests
1 parent a858391 commit 7a0891f

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
export { default as isCreated } from './is-created';
22
export { default as isOk } from './is-ok';
3-
export { default as findHttpStatus } from './find-http-status';
3+
export { default as findStatus } from './utils/find-status';
4+
export {
5+
default as findStatusByCode
6+
} from './utils/find-status/find-status-by-code';
7+
export {
8+
default as findStatusByKey
9+
} from './utils/find-status/find-status-by-key';
410
export { default as validateHttpStatus } from './utils/validate-http-status';
511
export { default as HTTPStatusError } from './utils/http-status-error';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import findStatus from '.';
2+
3+
function findStatusByCode(statusCode) {
4+
return findStatus(statusCode);
5+
}
6+
7+
export default findStatusByCode;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import findStatus from '.';
2+
3+
function findStatusByKey(statusKey) {
4+
return findStatus(statusKey, 'key');
5+
}
6+
7+
export default findStatusByKey;

src/find-http-status.js src/utils/find-status/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import HTTP_STATUSES from './constants/http-statuses';
1+
import HTTP_STATUSES from '../../constants/http-statuses';
22

33
function findHttpStatus(value, field = 'code') {
44
return HTTP_STATUSES.find(httpStatus => httpStatus[field] === value);

tests/find-http-status.test.js tests/find-status.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { findHttpStatus } from '../src';
1+
import { findStatusByCode, findStatusByKey } from '../src';
22

3-
describe('findHttpStatus', () => {
4-
test('it should find http status by code', () => {
5-
const found = findHttpStatus(200);
3+
describe('findStatus', () => {
4+
test('it should find HTTP status by code', () => {
5+
const found = findStatusByCode(200);
66
const mockResponse = {
77
code: 200,
88
key: 'OK',
@@ -13,8 +13,8 @@ describe('findHttpStatus', () => {
1313
expect(found).toEqual(mockResponse);
1414
});
1515

16-
test('it should find http status by key', () => {
17-
const found = findHttpStatus('TOO_MANY_REQUESTS', 'key');
16+
test('it should find HTTP status by key', () => {
17+
const found = findStatusByKey('TOO_MANY_REQUESTS', 'key');
1818
const mockResponse = {
1919
code: 429,
2020
key: 'TOO_MANY_REQUESTS',

0 commit comments

Comments
 (0)