File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import HTTP_STATUSES from './constants/http-statuses' ;
2+
3+ function findHttpStatus ( value , field = 'code' ) {
4+ return HTTP_STATUSES . find ( httpStatus => httpStatus [ field ] === value ) ;
5+ }
6+
7+ export default findHttpStatus ;
Original file line number Diff line number Diff line change 11export { default as isCreated } from './is-created' ;
22export { default as isOk } from './is-ok' ;
3+ export { default as findHttpStatus } from './find-http-status' ;
Original file line number Diff line number Diff line change 1+ import { findHttpStatus } from '../src' ;
2+
3+ describe ( 'findHttpStatus' , ( ) => {
4+ test ( 'it should find http status by code' , ( ) => {
5+ const found = findHttpStatus ( 200 ) ;
6+ const mockResponse = {
7+ code : 200 ,
8+ key : 'OK' ,
9+ message : 'OK' ,
10+ category : 'SUCCESS'
11+ } ;
12+
13+ expect ( found ) . toEqual ( mockResponse ) ;
14+ } ) ;
15+
16+ test ( 'it should find http status by key' , ( ) => {
17+ const found = findHttpStatus ( 'TOO_MANY_REQUESTS' , 'key' ) ;
18+ const mockResponse = {
19+ code : 429 ,
20+ key : 'TOO_MANY_REQUESTS' ,
21+ message : 'Too Many Requests' ,
22+ category : 'CLIENT_ERROR'
23+ } ;
24+
25+ expect ( found ) . toEqual ( mockResponse ) ;
26+ } ) ;
27+ } ) ;
You can’t perform that action at this time.
0 commit comments