Skip to content

Commit a858391

Browse files
committed
refactor: isOk method add params to documentation and tests messages to better readable
1 parent 4639ff9 commit a858391

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/is-ok.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
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);
312
}
413

514
export default isOk;

tests/is-ok.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { isOk } from '../src';
22

33
describe('isOk', () => {
4-
test('it should test isOk status equal 200', () => {
4+
test('it should receive true when pass status 200', () => {
55
expect(isOk(200)).toBeTruthy();
66
});
77

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.');
1011
});
1112
});

0 commit comments

Comments
 (0)