1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | const assert = require("assert");
|
20 | const joi = require("joi");
|
21 | const mocha_1 = require("mocha");
|
22 | const schemas_1 = require("../schemas");
|
23 | mocha_1.describe('#isJoi()', async function () {
|
24 | mocha_1.describe('joi values', async function () {
|
25 | mocha_1.it('alternatives schema should be detected as joi object', function () {
|
26 | const SCHEMA = joi.alternatives();
|
27 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
28 | assert.equal(IS_JOI, true);
|
29 | assert.strictEqual(IS_JOI, true);
|
30 | });
|
31 | mocha_1.it('array schema should be detected as joi object', function () {
|
32 | const SCHEMA = joi.array();
|
33 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
34 | assert.equal(IS_JOI, true);
|
35 | assert.strictEqual(IS_JOI, true);
|
36 | });
|
37 | mocha_1.it('binary schema should be detected as joi object', function () {
|
38 | const SCHEMA = joi.binary();
|
39 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
40 | assert.equal(IS_JOI, true);
|
41 | assert.strictEqual(IS_JOI, true);
|
42 | });
|
43 | mocha_1.it('bool schema should be detected as joi object', function () {
|
44 | const SCHEMA = joi.bool();
|
45 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
46 | assert.equal(IS_JOI, true);
|
47 | assert.strictEqual(IS_JOI, true);
|
48 | });
|
49 | mocha_1.it('boolean schema should be detected as joi object', function () {
|
50 | const SCHEMA = joi.boolean();
|
51 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
52 | assert.equal(IS_JOI, true);
|
53 | assert.strictEqual(IS_JOI, true);
|
54 | });
|
55 | mocha_1.it('date schema should be detected as joi object', function () {
|
56 | const SCHEMA = joi.date();
|
57 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
58 | assert.equal(IS_JOI, true);
|
59 | assert.strictEqual(IS_JOI, true);
|
60 | });
|
61 | mocha_1.it('func schema should be detected as joi object', function () {
|
62 | const SCHEMA = joi.func();
|
63 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
64 | assert.equal(IS_JOI, true);
|
65 | assert.strictEqual(IS_JOI, true);
|
66 | });
|
67 | mocha_1.it('lazy schema should be detected as joi object', function () {
|
68 | const SCHEMA = joi.lazy(() => joi.object());
|
69 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
70 | assert.equal(IS_JOI, true);
|
71 | assert.strictEqual(IS_JOI, true);
|
72 | });
|
73 | mocha_1.it('number schema should be detected as joi object', function () {
|
74 | const SCHEMA = joi.number();
|
75 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
76 | assert.equal(IS_JOI, true);
|
77 | assert.strictEqual(IS_JOI, true);
|
78 | });
|
79 | mocha_1.it('object schema should be detected as joi object', function () {
|
80 | const SCHEMA = joi.object();
|
81 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
82 | assert.equal(IS_JOI, true);
|
83 | assert.strictEqual(IS_JOI, true);
|
84 | });
|
85 | mocha_1.it('string schema should be detected as joi object', function () {
|
86 | const SCHEMA = joi.string();
|
87 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
88 | assert.equal(IS_JOI, true);
|
89 | assert.strictEqual(IS_JOI, true);
|
90 | });
|
91 | mocha_1.it('symbol schema should be detected as joi object', function () {
|
92 | const SCHEMA = joi.symbol();
|
93 | const IS_JOI = schemas_1.isJoi(SCHEMA);
|
94 | assert.equal(IS_JOI, true);
|
95 | assert.strictEqual(IS_JOI, true);
|
96 | });
|
97 | });
|
98 | mocha_1.describe('non-joi values', async function () {
|
99 | mocha_1.it('array should NOT be detected as joi object', function () {
|
100 | const VALUE = [];
|
101 | const IS_JOI = schemas_1.isJoi(VALUE);
|
102 | assert.equal(IS_JOI, false);
|
103 | assert.strictEqual(IS_JOI, false);
|
104 | });
|
105 | mocha_1.it('binary should NOT be detected as joi object', function () {
|
106 | const VALUE = Buffer.alloc(5979);
|
107 | const IS_JOI = schemas_1.isJoi(VALUE);
|
108 | assert.equal(IS_JOI, false);
|
109 | assert.strictEqual(IS_JOI, false);
|
110 | });
|
111 | mocha_1.it('booleans should NOT be detected as joi object', function () {
|
112 | const VALUE_1 = false;
|
113 | const VALUE_2 = true;
|
114 | const IS_JOI_1 = schemas_1.isJoi(VALUE_1);
|
115 | const IS_JOI_2 = schemas_1.isJoi(VALUE_2);
|
116 | assert.equal(IS_JOI_1, false);
|
117 | assert.strictEqual(IS_JOI_1, false);
|
118 | assert.equal(IS_JOI_2, false);
|
119 | assert.strictEqual(IS_JOI_2, false);
|
120 | });
|
121 | mocha_1.it('date should NOT be detected as joi object', function () {
|
122 | const VALUE = new Date();
|
123 | const IS_JOI = schemas_1.isJoi(VALUE);
|
124 | assert.equal(IS_JOI, false);
|
125 | assert.strictEqual(IS_JOI, false);
|
126 | });
|
127 | mocha_1.it('functions should NOT be detected as joi object', function () {
|
128 | const VALUE_1 = () => "TM";
|
129 | const VALUE_2 = function () { return "1979-09-05"; };
|
130 | const IS_JOI_1 = schemas_1.isJoi(VALUE_1);
|
131 | const IS_JOI_2 = schemas_1.isJoi(VALUE_2);
|
132 | assert.equal(IS_JOI_1, false);
|
133 | assert.strictEqual(IS_JOI_1, false);
|
134 | assert.equal(IS_JOI_2, false);
|
135 | assert.strictEqual(IS_JOI_2, false);
|
136 | });
|
137 | mocha_1.it('numbers should NOT be detected as joi object', function () {
|
138 | for (let i = 5979; i <= 23979; i++) {
|
139 | const IS_JOI = schemas_1.isJoi(i);
|
140 | assert.equal(IS_JOI, false);
|
141 | assert.strictEqual(IS_JOI, false);
|
142 | }
|
143 | });
|
144 | mocha_1.it('object should NOT be detected as joi object', function () {
|
145 | const VALUE = {
|
146 | 'TM': '1979-09-05',
|
147 | 'MK': 23979,
|
148 | };
|
149 | const IS_JOI = schemas_1.isJoi(VALUE);
|
150 | assert.equal(IS_JOI, false);
|
151 | assert.strictEqual(IS_JOI, false);
|
152 | });
|
153 | mocha_1.it('string should NOT be detected as joi object', function () {
|
154 | const VALUE = "TM+MK";
|
155 | const IS_JOI = schemas_1.isJoi(VALUE);
|
156 | assert.equal(IS_JOI, false);
|
157 | assert.strictEqual(IS_JOI, false);
|
158 | });
|
159 | mocha_1.it('symbol should NOT be detected as joi object', function () {
|
160 | const VALUE = Symbol("TM+MK");
|
161 | const IS_JOI = schemas_1.isJoi(VALUE);
|
162 | assert.equal(IS_JOI, false);
|
163 | assert.strictEqual(IS_JOI, false);
|
164 | });
|
165 | });
|
166 | });
|
167 |
|
\ | No newline at end of file |