Skip to content

Commit d983bdd

Browse files
committed
tests: http statuses type success
1 parent a182da6 commit d983bdd

30 files changed

+325
-65
lines changed

src/validators/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ export {
88
} from './informational/is-switching-protocols';
99

1010
// 2×× Success
11-
export { default as isCreated } from './success/is-created';
1211
export { default as isOk } from './success/is-ok';
12+
export { default as isCreated } from './success/is-created';
13+
export { default as isAccepted } from './success/is-accepted';
14+
export {
15+
default as isNonAuthoritativeInformation
16+
} from './success/is-non-authoritative-information';
17+
export { default as isNoContent } from './success/is-no-content';
18+
export { default as isResetContent } from './success/is-reset-content';
19+
export { default as isPartialContent } from './success/is-partial-content';
20+
export { default as isMultiStatus } from './success/is-multi-status';
21+
export { default as isAlreadyReported } from './success/is-already-reported';
22+
export { default as isImUsed } from './success/is-im-used';
1323

1424
// 3×× Redirection
1525
export {

src/validators/success/is-accepted.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isAccepted
5+
* @description
6+
* Validate HTTP Status code 202 type SUCCESS
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 202
11+
*/
12+
function isAccepted(statusCode) {
13+
return validateHttpStatus(statusCode, 202);
14+
}
15+
16+
export default isAccepted;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isAlreadyReported
5+
* @description
6+
* Validate HTTP Status code 208 type SUCCESS
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 208
11+
*/
12+
function isAlreadyReported(statusCode) {
13+
return validateHttpStatus(statusCode, 208);
14+
}
15+
16+
export default isAlreadyReported;

src/validators/success/is-im-used.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isImUsed
5+
* @description
6+
* Validate HTTP Status code 226 type SUCCESS
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 226
11+
*/
12+
function isImUsed(statusCode) {
13+
return validateHttpStatus(statusCode, 226);
14+
}
15+
16+
export default isImUsed;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isMultiStatus
5+
* @description
6+
* Validate HTTP Status code 207 type SUCCESS
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 207
11+
*/
12+
function isMultiStatus(statusCode) {
13+
return validateHttpStatus(statusCode, 207);
14+
}
15+
16+
export default isMultiStatus;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isNoContent
5+
* @description
6+
* Validate HTTP Status code 204 type SUCCESS
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 204
11+
*/
12+
function isNoContent(statusCode) {
13+
return validateHttpStatus(statusCode, 204);
14+
}
15+
16+
export default isNoContent;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isNonAuthoritativeInformation
5+
* @description
6+
* Validate HTTP Status code 203 type SUCCESS
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 203
11+
*/
12+
function isNonAuthoritativeInformation(statusCode) {
13+
return validateHttpStatus(statusCode, 203);
14+
}
15+
16+
export default isNonAuthoritativeInformation;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isPartialContent
5+
* @description
6+
* Validate HTTP Status code 206 type SUCCESS
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 206
11+
*/
12+
function isPartialContent(statusCode) {
13+
return validateHttpStatus(statusCode, 206);
14+
}
15+
16+
export default isPartialContent;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import validateHttpStatus from '../validate-http-status';
2+
3+
/**
4+
* @module isResetContent
5+
* @description
6+
* Validate HTTP Status code 205 type SUCCESS
7+
*
8+
* @param {Integer} statusCode - The HTTP Status code
9+
* @return {Boolean}
10+
* @throws {HTTPStatusError} When the statusCode is different then 205
11+
*/
12+
function isResetContent(statusCode) {
13+
return validateHttpStatus(statusCode, 205);
14+
}
15+
16+
export default isResetContent;

tests/is-continue.test.js

-12
This file was deleted.

tests/is-created.test.js

-12
This file was deleted.

tests/is-ok.test.js

-12
This file was deleted.

tests/is-processing.test.js

-12
This file was deleted.

tests/is-switching-protocols.test.js

-12
This file was deleted.

tests/is-unauthorized.test.js tests/validators/client-error/is-unauthorized.test.js

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

33
describe('isMovedPermanently', () => {
44
test('it should receive true when pass status 401', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isContinue } from '../../../src';
2+
3+
describe('Validators: isContinue (type informational)', () => {
4+
const STATUS_EXPECTED = 100;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isContinue(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isContinue(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isProcessing } from '../../../src';
2+
3+
describe('Validators: isProcessing (type informational)', () => {
4+
const STATUS_EXPECTED = 102;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isProcessing(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isProcessing(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isSwitchingProtocols } from '../../../src';
2+
3+
describe('Validators: isSwitchingProtocols (type informational)', () => {
4+
const STATUS_EXPECTED = 101;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isSwitchingProtocols(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isSwitchingProtocols(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});

tests/is-moved-permanently.test.js tests/validators/redirection/is-moved-permanently.test.js

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

33
describe('isMovedPermanently', () => {
44
test('it should receive true when pass status 301', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isAccepted } from '../../../src';
2+
3+
describe('Validators: isAccepted (type success)', () => {
4+
const STATUS_EXPECTED = 202;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isAccepted(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isAccepted(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isAlreadyReported } from '../../../src';
2+
3+
describe('Validators: isAlreadyReported (type success)', () => {
4+
const STATUS_EXPECTED = 208;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isAlreadyReported(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isAlreadyReported(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isCreated } from '../../../src';
2+
3+
describe('Validators: isCreated (type success)', () => {
4+
const STATUS_EXPECTED = 201;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isCreated(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isCreated(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isImUsed } from '../../../src';
2+
3+
describe('Validators: isImUsed (type success)', () => {
4+
const STATUS_EXPECTED = 226;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isImUsed(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isImUsed(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isMultiStatus } from '../../../src';
2+
3+
describe('Validators: isMultiStatus (type success)', () => {
4+
const STATUS_EXPECTED = 207;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isMultiStatus(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isMultiStatus(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isNoContent } from '../../../src';
2+
3+
describe('Validators: isNoContent (type success)', () => {
4+
const STATUS_EXPECTED = 204;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isNoContent(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isNoContent(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isNonAuthoritativeInformation } from '../../../src';
2+
3+
describe('Validators: isNonAuthoritativeInformation (type success)', () => {
4+
const STATUS_EXPECTED = 203;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isNonAuthoritativeInformation(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isNonAuthoritativeInformation(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isOk } from '../../../src';
2+
3+
describe('Validators: isOk (type success)', () => {
4+
const STATUS_EXPECTED = 200;
5+
6+
test(`it should receive true when pass status ${STATUS_EXPECTED}`, () => {
7+
expect(isOk(STATUS_EXPECTED)).toBeTruthy();
8+
});
9+
10+
test(`it should throw Error when pass status different than ${STATUS_EXPECTED}`, () => {
11+
const received = isOk(300);
12+
expect(received.message).toBe(`Expected a ${STATUS_EXPECTED} response.`);
13+
});
14+
});

0 commit comments

Comments
 (0)