File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 1
- function isOk ( status ) {
2
- return status === 200 ;
1
+ import validateHttpStatus from './utils/validate-http-status' ;
2
+
3
+ /**
4
+ * Validate HTTP Status code 200 type SUCCESS
5
+ *
6
+ * @param {integer } statusCode - The HTTP Status code
7
+ * @throws {HTTPStatusError } Will throw an error if the @param {statusCode} is different then 200
8
+ * @return {boolean }
9
+ */
10
+ function isOk ( statusCode ) {
11
+ return validateHttpStatus ( statusCode , 200 ) ;
3
12
}
4
13
5
14
export default isOk ;
Original file line number Diff line number Diff line change 1
1
import { isOk } from '../src' ;
2
2
3
3
describe ( 'isOk' , ( ) => {
4
- test ( 'it should test isOk status equal 200' , ( ) => {
4
+ test ( 'it should receive true when pass status 200' , ( ) => {
5
5
expect ( isOk ( 200 ) ) . toBeTruthy ( ) ;
6
6
} ) ;
7
7
8
- test ( 'it should test isOk status different then 201' , ( ) => {
9
- expect ( isOk ( 201 ) ) . toBeFalsy ( ) ;
8
+ test ( 'it should throw Error when pass status different than 200' , ( ) => {
9
+ const received = isOk ( 300 ) ;
10
+ expect ( received . message ) . toBe ( 'Expected a 200 response.' ) ;
10
11
} ) ;
11
12
} ) ;
You can’t perform that action at this time.
0 commit comments