functional-models 1.0.27 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc +9 -15
- package/cucumber.js +10 -0
- package/dist/src/constants.d.ts +14 -0
- package/dist/src/constants.js +19 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +9 -0
- package/dist/src/errors.js +15 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +39 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interfaces.d.ts +145 -0
- package/dist/src/interfaces.js +5 -0
- package/dist/src/interfaces.js.map +1 -0
- package/dist/src/lazy.d.ts +2 -0
- package/dist/src/lazy.js +37 -0
- package/dist/src/lazy.js.map +1 -0
- package/dist/src/methods.d.ts +4 -0
- package/dist/src/methods.js +18 -0
- package/dist/src/methods.js.map +1 -0
- package/dist/src/models.d.ts +3 -0
- package/dist/src/models.js +128 -0
- package/dist/src/models.js.map +1 -0
- package/dist/src/properties.d.ts +16 -0
- package/dist/src/properties.js +208 -0
- package/dist/src/properties.js.map +1 -0
- package/dist/src/serialization.d.ts +3 -0
- package/dist/src/serialization.js +49 -0
- package/dist/src/serialization.js.map +1 -0
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.js +44 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/validation.d.ts +29 -0
- package/dist/src/validation.js +286 -0
- package/dist/src/validation.js.map +1 -0
- package/dist/stepDefinitions/oldSteps.d.ts +1 -0
- package/dist/stepDefinitions/oldSteps.js +191 -0
- package/dist/stepDefinitions/oldSteps.js.map +1 -0
- package/dist/stepDefinitions/tssteps.d.ts +1 -0
- package/dist/stepDefinitions/tssteps.js +96 -0
- package/dist/stepDefinitions/tssteps.js.map +1 -0
- package/dist/test/src/errors.test.d.ts +1 -0
- package/dist/test/src/errors.test.js +33 -0
- package/dist/test/src/errors.test.js.map +1 -0
- package/dist/test/src/lazy.test.d.ts +1 -0
- package/dist/test/src/lazy.test.js +28 -0
- package/dist/test/src/lazy.test.js.map +1 -0
- package/dist/test/src/methods.test.d.ts +1 -0
- package/dist/test/src/methods.test.js +48 -0
- package/dist/test/src/methods.test.js.map +1 -0
- package/dist/test/src/models.test.d.ts +1 -0
- package/dist/test/src/models.test.js +395 -0
- package/dist/test/src/models.test.js.map +1 -0
- package/dist/test/src/properties.test.d.ts +1 -0
- package/dist/test/src/properties.test.js +724 -0
- package/dist/test/src/properties.test.js.map +1 -0
- package/dist/test/src/serialization.test.d.ts +1 -0
- package/dist/test/src/serialization.test.js +91 -0
- package/dist/test/src/serialization.test.js.map +1 -0
- package/dist/test/src/utils.test.d.ts +1 -0
- package/dist/test/src/utils.test.js +81 -0
- package/dist/test/src/utils.test.js.map +1 -0
- package/dist/test/src/validation.test.d.ts +1 -0
- package/dist/test/src/validation.test.js +612 -0
- package/dist/test/src/validation.test.js.map +1 -0
- package/features/arrayFields.feature +7 -7
- package/features/basic-ts.feature +13 -0
- package/features/functions.feature +2 -3
- package/package.json +35 -10
- package/src/constants.ts +15 -0
- package/src/{errors.js → errors.ts} +6 -4
- package/src/index.ts +12 -0
- package/src/interfaces.ts +323 -0
- package/src/lazy.ts +24 -0
- package/src/methods.ts +30 -0
- package/src/models.ts +183 -0
- package/src/properties.ts +375 -0
- package/src/serialization.ts +39 -0
- package/src/{utils.js → utils.ts} +16 -26
- package/src/validation.ts +390 -0
- package/{features/stepDefinitions/steps.js → stepDefinitions/oldSteps.ts} +76 -53
- package/stepDefinitions/tssteps.ts +107 -0
- package/test/src/errors.test.ts +31 -0
- package/test/src/{lazy.test.js → lazy.test.ts} +4 -4
- package/test/src/methods.test.ts +45 -0
- package/test/src/models.test.ts +417 -0
- package/test/src/{properties.test.js → properties.test.ts} +251 -58
- package/test/src/serialization.test.ts +80 -0
- package/test/src/{utils.test.js → utils.test.ts} +29 -7
- package/test/src/{validation.test.js → validation.test.ts} +278 -210
- package/tsconfig.json +100 -0
- package/src/constants.js +0 -19
- package/src/functions.js +0 -7
- package/src/index.js +0 -10
- package/src/lazy.js +0 -19
- package/src/models.js +0 -152
- package/src/properties.js +0 -313
- package/src/serialization.js +0 -50
- package/src/validation.js +0 -285
- package/test/base/index.test.js +0 -5
- package/test/src/functions.test.js +0 -45
- package/test/src/index.test.js +0 -5
- package/test/src/models.test.js +0 -380
- package/test/src/serialization.test.js +0 -127
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const chai_1 = require("chai");
|
|
16
|
+
const sinon_1 = __importDefault(require("sinon"));
|
|
17
|
+
const properties_1 = require("../../src/properties");
|
|
18
|
+
const validation_1 = require("../../src/validation");
|
|
19
|
+
const models_1 = require("../../src/models");
|
|
20
|
+
const TestModel1 = (0, models_1.BaseModel)('TestModel1', {
|
|
21
|
+
properties: {
|
|
22
|
+
name: (0, properties_1.TextProperty)(),
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
describe('/src/properties.ts', () => {
|
|
26
|
+
describe('#EmailProperty()', () => {
|
|
27
|
+
describe('#createGetter()', () => {
|
|
28
|
+
it('should be able to create without a config', () => {
|
|
29
|
+
chai_1.assert.doesNotThrow(() => {
|
|
30
|
+
(0, properties_1.EmailProperty)();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it('should always have the value passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const PropertyInstance = (0, properties_1.EmailProperty)({});
|
|
35
|
+
const getter = PropertyInstance.createGetter('testme@email.com');
|
|
36
|
+
const actual = yield getter();
|
|
37
|
+
const expected = 'testme@email.com';
|
|
38
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
39
|
+
}));
|
|
40
|
+
});
|
|
41
|
+
describe('#getValidator()', () => {
|
|
42
|
+
it('should return and validate successful with basic input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const PropertyInstance = (0, properties_1.EmailProperty)({});
|
|
44
|
+
const getter = PropertyInstance.createGetter('testme@email.com');
|
|
45
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
const actual = yield validator(null, {});
|
|
48
|
+
const expected = 0;
|
|
49
|
+
chai_1.assert.equal(actual.length, expected);
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('#BooleanProperty()', () => {
|
|
54
|
+
it('should be able to create without a config', () => {
|
|
55
|
+
chai_1.assert.doesNotThrow(() => {
|
|
56
|
+
(0, properties_1.BooleanProperty)();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('#getValidator()', () => {
|
|
60
|
+
it('should return and validate successful with basic input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
const PropertyInstance = (0, properties_1.BooleanProperty)({});
|
|
62
|
+
const getter = PropertyInstance.createGetter(true);
|
|
63
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
const actual = yield validator(null, {});
|
|
66
|
+
const expected = 0;
|
|
67
|
+
chai_1.assert.equal(actual.length, expected);
|
|
68
|
+
}));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('#ConstantValueProperty()', () => {
|
|
72
|
+
describe('#createGetter()', () => {
|
|
73
|
+
it('should always have the value passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
const PropertyInstance = (0, properties_1.ConstantValueProperty)('constant');
|
|
75
|
+
const getter = PropertyInstance.createGetter('changed');
|
|
76
|
+
const actual = yield getter();
|
|
77
|
+
const expected = 'constant';
|
|
78
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
describe('#getValidator()', () => {
|
|
82
|
+
it('should return and validate successful with basic input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const PropertyInstance = (0, properties_1.ConstantValueProperty)('constant');
|
|
84
|
+
const getter = PropertyInstance.createGetter('changed');
|
|
85
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
const actual = yield validator(null, {});
|
|
88
|
+
const expected = 0;
|
|
89
|
+
chai_1.assert.equal(actual.length, expected);
|
|
90
|
+
}));
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('#ObjectProperty()', () => {
|
|
94
|
+
describe('#createGetter()', () => {
|
|
95
|
+
it('should be able to create without a config', () => {
|
|
96
|
+
chai_1.assert.doesNotThrow(() => {
|
|
97
|
+
(0, properties_1.ObjectProperty)();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it('should be able to get the object passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
const PropertyInstance = (0, properties_1.ObjectProperty)({});
|
|
102
|
+
const getter = PropertyInstance.createGetter({
|
|
103
|
+
my: 'object',
|
|
104
|
+
complex: { it: 'is' },
|
|
105
|
+
});
|
|
106
|
+
const actual = yield getter();
|
|
107
|
+
const expected = { my: 'object', complex: { it: 'is' } };
|
|
108
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
109
|
+
}));
|
|
110
|
+
});
|
|
111
|
+
describe('#getValidator()', () => {
|
|
112
|
+
it('should return and validate successful with basic input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const PropertyInstance = (0, properties_1.ObjectProperty)({});
|
|
114
|
+
const getter = PropertyInstance.createGetter({
|
|
115
|
+
my: 'object',
|
|
116
|
+
complex: { it: 'is' },
|
|
117
|
+
});
|
|
118
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
const actual = yield validator(null, {});
|
|
121
|
+
const expected = 0;
|
|
122
|
+
chai_1.assert.equal(actual.length, expected);
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('#NumberProperty()', () => {
|
|
127
|
+
describe('#createGetter()', () => {
|
|
128
|
+
it('should be able to create without a config', () => {
|
|
129
|
+
chai_1.assert.doesNotThrow(() => {
|
|
130
|
+
(0, properties_1.NumberProperty)();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
it('should be able to create even with a null config', () => {
|
|
134
|
+
chai_1.assert.doesNotThrow(() => {
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
(0, properties_1.NumberProperty)(null);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it('should be able to get the number passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const PropertyInstance = (0, properties_1.NumberProperty)({});
|
|
141
|
+
const getter = PropertyInstance.createGetter(5);
|
|
142
|
+
const actual = yield getter();
|
|
143
|
+
const expected = 5;
|
|
144
|
+
chai_1.assert.equal(actual, expected);
|
|
145
|
+
}));
|
|
146
|
+
it('should be able to get float passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
const PropertyInstance = (0, properties_1.NumberProperty)({});
|
|
148
|
+
const getter = PropertyInstance.createGetter(5.123);
|
|
149
|
+
const actual = yield getter();
|
|
150
|
+
const expected = 5.123;
|
|
151
|
+
chai_1.assert.equal(actual, expected);
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
154
|
+
describe('#getValidator()', () => {
|
|
155
|
+
it('should return and validate successful with basic input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
+
const PropertyInstance = (0, properties_1.NumberProperty)({});
|
|
157
|
+
const getter = PropertyInstance.createGetter(5);
|
|
158
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
const actual = yield validator(null, {});
|
|
161
|
+
const expected = 0;
|
|
162
|
+
chai_1.assert.equal(actual.length, expected);
|
|
163
|
+
}));
|
|
164
|
+
it('should return and validate successful with a basic float', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
const PropertyInstance = (0, properties_1.NumberProperty)({});
|
|
166
|
+
const getter = PropertyInstance.createGetter(5.123);
|
|
167
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
const actual = yield validator(null, {});
|
|
170
|
+
const expected = 0;
|
|
171
|
+
chai_1.assert.equal(actual.length, expected);
|
|
172
|
+
}));
|
|
173
|
+
it('should return with errors with a non integer input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
const PropertyInstance = (0, properties_1.NumberProperty)({});
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
const getter = PropertyInstance.createGetter('string');
|
|
177
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
const actual = yield validator(null, {});
|
|
180
|
+
const expected = 1;
|
|
181
|
+
chai_1.assert.equal(actual.length, expected);
|
|
182
|
+
}));
|
|
183
|
+
it('should return with errors with a value=5 and maxValue=3', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
+
const PropertyInstance = (0, properties_1.NumberProperty)({ maxValue: 3 });
|
|
185
|
+
const getter = PropertyInstance.createGetter(5);
|
|
186
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
const actual = yield validator();
|
|
189
|
+
const expected = 1;
|
|
190
|
+
chai_1.assert.equal(actual.length, expected);
|
|
191
|
+
}));
|
|
192
|
+
it('should return with errors with a value=2 and minValue=3', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
+
const PropertyInstance = (0, properties_1.NumberProperty)({ minValue: 3 });
|
|
194
|
+
const getter = PropertyInstance.createGetter(2);
|
|
195
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
const actual = yield validator();
|
|
198
|
+
const expected = 1;
|
|
199
|
+
chai_1.assert.equal(actual.length, expected);
|
|
200
|
+
}));
|
|
201
|
+
it('should return with no errors with a value=3 and minValue=3 and maxValue=3', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
202
|
+
const PropertyInstance = (0, properties_1.NumberProperty)({ minValue: 3, maxValue: 3 });
|
|
203
|
+
const getter = PropertyInstance.createGetter(3);
|
|
204
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
205
|
+
// @ts-ignore
|
|
206
|
+
const actual = yield validator();
|
|
207
|
+
const expected = 0;
|
|
208
|
+
chai_1.assert.equal(actual.length, expected);
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('#IntegerProperty()', () => {
|
|
213
|
+
it('should be able to create even with a null config', () => {
|
|
214
|
+
chai_1.assert.doesNotThrow(() => {
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
(0, properties_1.IntegerProperty)(null);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
describe('#createGetter()', () => {
|
|
220
|
+
it('should be able to create without a config', () => {
|
|
221
|
+
chai_1.assert.doesNotThrow(() => {
|
|
222
|
+
(0, properties_1.IntegerProperty)();
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
it('should be able to get the number passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
226
|
+
const PropertyInstance = (0, properties_1.IntegerProperty)({});
|
|
227
|
+
const getter = PropertyInstance.createGetter(5);
|
|
228
|
+
const actual = yield getter();
|
|
229
|
+
const expected = 5;
|
|
230
|
+
chai_1.assert.equal(actual, expected);
|
|
231
|
+
}));
|
|
232
|
+
});
|
|
233
|
+
describe('#getValidator()', () => {
|
|
234
|
+
it('should return and validate successful with basic input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
235
|
+
const PropertyInstance = (0, properties_1.IntegerProperty)({});
|
|
236
|
+
const getter = PropertyInstance.createGetter(5);
|
|
237
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
238
|
+
// @ts-ignore
|
|
239
|
+
const actual = yield validator();
|
|
240
|
+
const expected = 0;
|
|
241
|
+
chai_1.assert.equal(actual.length, expected);
|
|
242
|
+
}));
|
|
243
|
+
it('should return errors with a basic float', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
244
|
+
const PropertyInstance = (0, properties_1.IntegerProperty)({});
|
|
245
|
+
const getter = PropertyInstance.createGetter(5.123);
|
|
246
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
const actual = yield validator();
|
|
249
|
+
const expected = 1;
|
|
250
|
+
chai_1.assert.equal(actual.length, expected);
|
|
251
|
+
}));
|
|
252
|
+
it('should return with errors with a non integer input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
253
|
+
const PropertyInstance = (0, properties_1.IntegerProperty)({});
|
|
254
|
+
// @ts-ignore
|
|
255
|
+
const getter = PropertyInstance.createGetter('string');
|
|
256
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
257
|
+
// @ts-ignore
|
|
258
|
+
const actual = yield validator();
|
|
259
|
+
const expected = 1;
|
|
260
|
+
chai_1.assert.equal(actual.length, expected);
|
|
261
|
+
}));
|
|
262
|
+
it('should return with errors with a value=5 and maxValue=3', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
263
|
+
const PropertyInstance = (0, properties_1.IntegerProperty)({ maxValue: 3 });
|
|
264
|
+
const getter = PropertyInstance.createGetter(5);
|
|
265
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
266
|
+
// @ts-ignore
|
|
267
|
+
const actual = yield validator();
|
|
268
|
+
const expected = 1;
|
|
269
|
+
chai_1.assert.equal(actual.length, expected);
|
|
270
|
+
}));
|
|
271
|
+
it('should return with errors with a value=2 and minValue=3', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
272
|
+
const PropertyInstance = (0, properties_1.IntegerProperty)({ minValue: 3 });
|
|
273
|
+
const getter = PropertyInstance.createGetter(2);
|
|
274
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
275
|
+
// @ts-ignore
|
|
276
|
+
const actual = yield validator();
|
|
277
|
+
const expected = 1;
|
|
278
|
+
chai_1.assert.equal(actual.length, expected);
|
|
279
|
+
}));
|
|
280
|
+
it('should return with no errors with a value=3 and minValue=3 and maxValue=3', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
+
const PropertyInstance = (0, properties_1.IntegerProperty)({ minValue: 3, maxValue: 3 });
|
|
282
|
+
const getter = PropertyInstance.createGetter(3);
|
|
283
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
284
|
+
// @ts-ignore
|
|
285
|
+
const actual = yield validator();
|
|
286
|
+
const expected = 0;
|
|
287
|
+
chai_1.assert.equal(actual.length, expected);
|
|
288
|
+
}));
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
describe('#TextProperty()', () => {
|
|
292
|
+
it('should be able to create even with a null config', () => {
|
|
293
|
+
chai_1.assert.doesNotThrow(() => {
|
|
294
|
+
// @ts-ignore
|
|
295
|
+
(0, properties_1.TextProperty)(null);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
describe('#createGetter()', () => {
|
|
299
|
+
it('should be able to create without a config', () => {
|
|
300
|
+
chai_1.assert.doesNotThrow(() => {
|
|
301
|
+
(0, properties_1.TextProperty)();
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
it('should be able to get the value passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
305
|
+
const PropertyInstance = (0, properties_1.TextProperty)({});
|
|
306
|
+
const getter = PropertyInstance.createGetter('basic input');
|
|
307
|
+
const actual = yield getter();
|
|
308
|
+
const expected = 'basic input';
|
|
309
|
+
chai_1.assert.equal(actual, expected);
|
|
310
|
+
}));
|
|
311
|
+
});
|
|
312
|
+
describe('#getValidator()', () => {
|
|
313
|
+
it('should return and validate successful with basic input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
314
|
+
const PropertyInstance = (0, properties_1.TextProperty)({});
|
|
315
|
+
const getter = PropertyInstance.createGetter('basic input');
|
|
316
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
317
|
+
// @ts-ignore
|
|
318
|
+
const actual = yield validator();
|
|
319
|
+
const expected = 0;
|
|
320
|
+
chai_1.assert.equal(actual.length, expected);
|
|
321
|
+
}));
|
|
322
|
+
it('should return with errors with a value=5', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
323
|
+
const PropertyInstance = (0, properties_1.TextProperty)({});
|
|
324
|
+
// @ts-ignore
|
|
325
|
+
const getter = PropertyInstance.createGetter(5);
|
|
326
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
327
|
+
// @ts-ignore
|
|
328
|
+
const actual = yield validator();
|
|
329
|
+
const expected = 1;
|
|
330
|
+
chai_1.assert.equal(actual.length, expected);
|
|
331
|
+
}));
|
|
332
|
+
it('should return with errors with a value="hello" and maxLength=3', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
|
+
const PropertyInstance = (0, properties_1.TextProperty)({ maxLength: 3 });
|
|
334
|
+
const getter = PropertyInstance.createGetter('hello');
|
|
335
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
336
|
+
// @ts-ignore
|
|
337
|
+
const actual = yield validator();
|
|
338
|
+
const expected = 1;
|
|
339
|
+
chai_1.assert.equal(actual.length, expected);
|
|
340
|
+
}));
|
|
341
|
+
it('should return with errors with a value="hello" and minLength=10', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
342
|
+
const PropertyInstance = (0, properties_1.TextProperty)({ minLength: 10 });
|
|
343
|
+
const getter = PropertyInstance.createGetter('hello');
|
|
344
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
345
|
+
// @ts-ignore
|
|
346
|
+
const actual = yield validator();
|
|
347
|
+
const expected = 1;
|
|
348
|
+
chai_1.assert.equal(actual.length, expected);
|
|
349
|
+
}));
|
|
350
|
+
it('should return with no errors with a value="hello" and minLength=5 and maxLength=5', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
351
|
+
const PropertyInstance = (0, properties_1.TextProperty)({ minLength: 5, maxLength: 5 });
|
|
352
|
+
const getter = PropertyInstance.createGetter('hello');
|
|
353
|
+
const validator = PropertyInstance.getValidator(getter);
|
|
354
|
+
// @ts-ignore
|
|
355
|
+
const actual = yield validator();
|
|
356
|
+
const expected = 0;
|
|
357
|
+
chai_1.assert.equal(actual.length, expected);
|
|
358
|
+
}));
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
describe('#ArrayProperty()', () => {
|
|
362
|
+
describe('#createGetter()', () => {
|
|
363
|
+
it('should return an array passed in without issue', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
364
|
+
const theProperty = (0, properties_1.ArrayProperty)({});
|
|
365
|
+
const getter = theProperty.createGetter([1, 2, 3]);
|
|
366
|
+
const actual = yield getter();
|
|
367
|
+
const expected = [1, 2, 3];
|
|
368
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
369
|
+
}));
|
|
370
|
+
it('should return an array passed in without issue, even if no config is passed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
371
|
+
const theProperty = (0, properties_1.ArrayProperty)();
|
|
372
|
+
const getter = theProperty.createGetter([1, 2, 3]);
|
|
373
|
+
const actual = yield getter();
|
|
374
|
+
const expected = [1, 2, 3];
|
|
375
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
376
|
+
}));
|
|
377
|
+
it('should return an empty array if defaultValue is not changed in config and null is passed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
378
|
+
const theProperty = (0, properties_1.ArrayProperty)();
|
|
379
|
+
// @ts-ignore
|
|
380
|
+
const getter = theProperty.createGetter(null);
|
|
381
|
+
const actual = yield getter();
|
|
382
|
+
const expected = [];
|
|
383
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
384
|
+
}));
|
|
385
|
+
it('should return the passed in defaultValue if set in config and null is passed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
386
|
+
const theProperty = (0, properties_1.ArrayProperty)({ defaultValue: [1, 2, 3] });
|
|
387
|
+
// @ts-ignore
|
|
388
|
+
const getter = theProperty.createGetter(null);
|
|
389
|
+
const actual = yield getter();
|
|
390
|
+
const expected = [1, 2, 3];
|
|
391
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
392
|
+
}));
|
|
393
|
+
});
|
|
394
|
+
describe('#getValidator()', () => {
|
|
395
|
+
it('should validate an array passed in without issue', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
396
|
+
const theProperty = (0, properties_1.ArrayProperty)({});
|
|
397
|
+
const getter = theProperty.createGetter([1, 2, 3]);
|
|
398
|
+
const validator = theProperty.getValidator(getter);
|
|
399
|
+
// @ts-ignore
|
|
400
|
+
const actual = yield validator();
|
|
401
|
+
const expected = [];
|
|
402
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
403
|
+
}));
|
|
404
|
+
it('should error an array passed in when it doesnt have the right types', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
405
|
+
const theProperty = (0, properties_1.ArrayProperty)({
|
|
406
|
+
validators: [(0, validation_1.arrayType)(validation_1.TYPE_PRIMITIVES.integer)],
|
|
407
|
+
});
|
|
408
|
+
const getter = theProperty.createGetter([1, 'string', 3]);
|
|
409
|
+
const validator = theProperty.getValidator(getter);
|
|
410
|
+
// @ts-ignore
|
|
411
|
+
const actual = yield validator();
|
|
412
|
+
const expected = 1;
|
|
413
|
+
chai_1.assert.deepEqual(actual.length, expected);
|
|
414
|
+
}));
|
|
415
|
+
it('should validate an array with [4,4,5,5,6,6] when choices are [4,5,6]', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
416
|
+
const theProperty = (0, properties_1.ArrayProperty)({ choices: [4, 5, 6] });
|
|
417
|
+
const getter = theProperty.createGetter([4, 4, 5, 5, 6, 6]);
|
|
418
|
+
const validator = theProperty.getValidator(getter);
|
|
419
|
+
// @ts-ignore
|
|
420
|
+
const actual = yield validator();
|
|
421
|
+
const expected = [];
|
|
422
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
423
|
+
}));
|
|
424
|
+
it('should return errors when an array with [4,4,3,5,5,6,6] when choices are [4,5,6]', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
425
|
+
const theProperty = (0, properties_1.ArrayProperty)({ choices: [4, 5, 6] });
|
|
426
|
+
const getter = theProperty.createGetter([4, 4, 3, 5, 5, 6, 6]);
|
|
427
|
+
const validator = theProperty.getValidator(getter);
|
|
428
|
+
// @ts-ignore
|
|
429
|
+
const actual = yield validator();
|
|
430
|
+
const expected = 1;
|
|
431
|
+
chai_1.assert.equal(actual.length, expected);
|
|
432
|
+
}));
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
describe('#Property()', () => {
|
|
436
|
+
it('should throw an exception if a type is not provided', () => {
|
|
437
|
+
chai_1.assert.throws(() => {
|
|
438
|
+
// @ts-ignore
|
|
439
|
+
(0, properties_1.Property)(undefined, {});
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
it('should throw an exception if a type is not provided, and config is null', () => {
|
|
443
|
+
chai_1.assert.throws(() => {
|
|
444
|
+
// @ts-ignore
|
|
445
|
+
(0, properties_1.Property)(undefined, null);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
it('should throw an exception if config.valueSelector is not a function but is set', () => {
|
|
449
|
+
chai_1.assert.throws(() => {
|
|
450
|
+
// @ts-ignore
|
|
451
|
+
(0, properties_1.Property)('MyProperty', { valueSelector: 'blah' });
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
it('should not throw an exception if config.valueSelector is a function', () => {
|
|
455
|
+
chai_1.assert.doesNotThrow(() => {
|
|
456
|
+
(0, properties_1.Property)('MyProperty', { valueSelector: () => ({}) });
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
it('should not throw an exception if config is null', () => {
|
|
460
|
+
chai_1.assert.doesNotThrow(() => {
|
|
461
|
+
// @ts-ignore
|
|
462
|
+
(0, properties_1.Property)('MyProperty', null);
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
describe('#getConstantValue()', () => {
|
|
466
|
+
it('should provide undefined if no config', () => {
|
|
467
|
+
// @ts-ignore
|
|
468
|
+
const instance = (0, properties_1.Property)('MyTYpe', null);
|
|
469
|
+
const actual = instance.getConstantValue();
|
|
470
|
+
const expected = undefined;
|
|
471
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
describe('#getPropertyType()', () => {
|
|
475
|
+
it('should use the type that is passed in via config', () => {
|
|
476
|
+
const instance = (0, properties_1.Property)('OverrideMe', { type: 'ExtendedType' });
|
|
477
|
+
const actual = instance.getPropertyType();
|
|
478
|
+
const expected = 'ExtendedType';
|
|
479
|
+
chai_1.assert.equal(actual, expected);
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
describe('#getConfig()', () => {
|
|
483
|
+
it('should provide the config that is passed in ', () => {
|
|
484
|
+
// @ts-ignore
|
|
485
|
+
const instance = (0, properties_1.Property)('MyTYpe', { custom: 'value' });
|
|
486
|
+
const actual = instance.getConfig();
|
|
487
|
+
const expected = { custom: 'value' };
|
|
488
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
489
|
+
});
|
|
490
|
+
it('should provide {} if no config', () => {
|
|
491
|
+
// @ts-ignore
|
|
492
|
+
const instance = (0, properties_1.Property)('MyTYpe', null);
|
|
493
|
+
const actual = instance.getConfig();
|
|
494
|
+
const expected = {};
|
|
495
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
describe('#getDefaultValue()', () => {
|
|
499
|
+
it('should provide undefined if no config', () => {
|
|
500
|
+
// @ts-ignore
|
|
501
|
+
const instance = (0, properties_1.Property)('MyTYpe', null);
|
|
502
|
+
const actual = instance.getDefaultValue();
|
|
503
|
+
const expected = undefined;
|
|
504
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
505
|
+
});
|
|
506
|
+
it('should provide the defaultValue that is passed in if no value', () => {
|
|
507
|
+
// @ts-ignore
|
|
508
|
+
const instance = (0, properties_1.Property)('MyTYpe', { defaultValue: 'test-me' });
|
|
509
|
+
const actual = instance.getDefaultValue();
|
|
510
|
+
const expected = 'test-me';
|
|
511
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
describe('#getChoices()', () => {
|
|
515
|
+
it('should provide [] if no config', () => {
|
|
516
|
+
// @ts-ignore
|
|
517
|
+
const instance = (0, properties_1.Property)('MyTYpe', null);
|
|
518
|
+
const actual = instance.getChoices();
|
|
519
|
+
const expected = [];
|
|
520
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
521
|
+
});
|
|
522
|
+
it('should provide the choices that are passed in ', () => {
|
|
523
|
+
// @ts-ignore
|
|
524
|
+
const instance = (0, properties_1.Property)('MyTYpe', { choices: [1, 2, 3] });
|
|
525
|
+
const actual = instance.getChoices();
|
|
526
|
+
const expected = [1, 2, 3];
|
|
527
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
describe('#createGetter()', () => {
|
|
531
|
+
it('should return a function even if config.value is set to a value', () => {
|
|
532
|
+
const instance = (0, properties_1.Property)('MyProperty', { value: 'my-value' });
|
|
533
|
+
const actual = instance.createGetter('not-my-value');
|
|
534
|
+
chai_1.assert.isFunction(actual);
|
|
535
|
+
});
|
|
536
|
+
it('should return the value passed into config.value regardless of what is passed into the createGetter', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
537
|
+
const instance = (0, properties_1.Property)('MyProperty', { value: 'my-value' });
|
|
538
|
+
const actual = yield instance.createGetter('not-my-value')();
|
|
539
|
+
const expected = 'my-value';
|
|
540
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
541
|
+
}));
|
|
542
|
+
it('should return the value passed into createGetter when config.value is not set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
543
|
+
const instance = (0, properties_1.Property)('MyProperty');
|
|
544
|
+
const actual = yield instance.createGetter('my-value')();
|
|
545
|
+
const expected = 'my-value';
|
|
546
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
547
|
+
}));
|
|
548
|
+
it('should return the value of the function passed into createGetter when config.value is not set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
549
|
+
const instance = (0, properties_1.Property)('MyProperty');
|
|
550
|
+
const actual = yield instance.createGetter(() => 'my-value')();
|
|
551
|
+
const expected = 'my-value';
|
|
552
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
553
|
+
}));
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
describe('#UniqueId()', () => {
|
|
557
|
+
describe('#createGetter()', () => {
|
|
558
|
+
it('should call createUuid only once even if called twice', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
559
|
+
const uniqueProperty = (0, properties_1.UniqueId)({});
|
|
560
|
+
// @ts-ignore
|
|
561
|
+
const getter = uniqueProperty.createGetter(undefined);
|
|
562
|
+
const first = yield getter();
|
|
563
|
+
const second = yield getter();
|
|
564
|
+
chai_1.assert.deepEqual(first, second);
|
|
565
|
+
}));
|
|
566
|
+
it('should use the uuid passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
567
|
+
const uniqueProperty = (0, properties_1.UniqueId)({});
|
|
568
|
+
const getter = uniqueProperty.createGetter('my-uuid');
|
|
569
|
+
const actual = yield getter();
|
|
570
|
+
const expected = 'my-uuid';
|
|
571
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
572
|
+
}));
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
describe('#DateProperty()', () => {
|
|
576
|
+
it('should allow creation without a config', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
577
|
+
const proto = (0, properties_1.DateProperty)();
|
|
578
|
+
const instance = proto.createGetter(new Date());
|
|
579
|
+
chai_1.assert.isOk(yield instance());
|
|
580
|
+
}));
|
|
581
|
+
it('should create a new date once when config.autoNow=true and called multiple times', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
582
|
+
const proto = (0, properties_1.DateProperty)({ autoNow: true });
|
|
583
|
+
const instance = proto.createGetter(undefined);
|
|
584
|
+
const first = yield instance();
|
|
585
|
+
const second = yield instance();
|
|
586
|
+
const third = yield instance();
|
|
587
|
+
chai_1.assert.deepEqual(first, second);
|
|
588
|
+
chai_1.assert.deepEqual(first, third);
|
|
589
|
+
}));
|
|
590
|
+
it('should use the date passed in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
591
|
+
const proto = (0, properties_1.DateProperty)({ autoNow: true });
|
|
592
|
+
const date = new Date();
|
|
593
|
+
const instance = proto.createGetter(date);
|
|
594
|
+
const actual = yield instance();
|
|
595
|
+
const expected = date;
|
|
596
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
597
|
+
}));
|
|
598
|
+
it('should return null, if null config is passed and no value created.', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
599
|
+
// @ts-ignore
|
|
600
|
+
const proto = (0, properties_1.DateProperty)(null);
|
|
601
|
+
const date = null;
|
|
602
|
+
const instance = proto.createGetter(date);
|
|
603
|
+
const actual = yield instance();
|
|
604
|
+
const expected = null;
|
|
605
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
606
|
+
}));
|
|
607
|
+
});
|
|
608
|
+
describe('#ReferenceProperty()', () => {
|
|
609
|
+
it('should throw an exception if a model value is not passed in', () => {
|
|
610
|
+
chai_1.assert.throws(() => {
|
|
611
|
+
const input = ['obj-id'];
|
|
612
|
+
// @ts-ignore
|
|
613
|
+
const actual = (0, properties_1.ReferenceProperty)(null, {});
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
describe('#meta.getReferencedModel()', () => {
|
|
617
|
+
it('should return the same value passed in as the model', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
618
|
+
const property = (0, properties_1.ReferenceProperty)(TestModel1);
|
|
619
|
+
const actual = property.getReferencedModel();
|
|
620
|
+
const expected = TestModel1;
|
|
621
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
622
|
+
}));
|
|
623
|
+
it('should allow a function input for model to allow delayed creation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
624
|
+
const property = (0, properties_1.ReferenceProperty)(() => TestModel1);
|
|
625
|
+
const actual = property.getReferencedModel();
|
|
626
|
+
const expected = TestModel1;
|
|
627
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
628
|
+
}));
|
|
629
|
+
});
|
|
630
|
+
describe('#createGetter()', () => {
|
|
631
|
+
it('should return "obj-id" when no fetcher is used', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
632
|
+
const actual = yield (0, properties_1.ReferenceProperty)(TestModel1, {}).createGetter('obj-id')();
|
|
633
|
+
const expected = 'obj-id';
|
|
634
|
+
chai_1.assert.equal(actual, expected);
|
|
635
|
+
}));
|
|
636
|
+
it('should allow null as the input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
637
|
+
const actual = yield (0, properties_1.ReferenceProperty)(TestModel1, {}).createGetter(null)();
|
|
638
|
+
const expected = null;
|
|
639
|
+
chai_1.assert.equal(actual, expected);
|
|
640
|
+
}));
|
|
641
|
+
it('should return "obj-id" from {}.id when no fetcher is used', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
642
|
+
const actual = yield (0, properties_1.ReferenceProperty)(TestModel1, {}).createGetter(
|
|
643
|
+
// @ts-ignore
|
|
644
|
+
{ id: 'obj-id' })();
|
|
645
|
+
const expected = 'obj-id';
|
|
646
|
+
chai_1.assert.equal(actual, expected);
|
|
647
|
+
}));
|
|
648
|
+
it('should return 123 from {}.id when no fetcher is used', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
649
|
+
const actual = yield (0, properties_1.ReferenceProperty)(TestModel1, {}).createGetter(123)();
|
|
650
|
+
const expected = 123;
|
|
651
|
+
chai_1.assert.equal(actual, expected);
|
|
652
|
+
}));
|
|
653
|
+
it('should return name:"switch-a-roo" when switch-a-roo fetcher is used', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
654
|
+
const actual = (yield (0, properties_1.ReferenceProperty)(TestModel1, {
|
|
655
|
+
fetcher: () => __awaiter(void 0, void 0, void 0, function* () { return ({ id: 'obj-id', name: 'switch-a-roo' }); }),
|
|
656
|
+
}).createGetter('obj-id')());
|
|
657
|
+
const expected = 'switch-a-roo';
|
|
658
|
+
chai_1.assert.deepEqual(actual.get.name(), expected);
|
|
659
|
+
}));
|
|
660
|
+
it('should return "obj-id" if no config passed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
661
|
+
// @ts-ignore
|
|
662
|
+
const actual = (yield (0, properties_1.ReferenceProperty)(TestModel1, null).createGetter('obj-id')());
|
|
663
|
+
const expected = 'obj-id';
|
|
664
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
665
|
+
}));
|
|
666
|
+
it('should return null when fetcher is used, but the instance value passed in is empty', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
667
|
+
const actual = (yield (0, properties_1.ReferenceProperty)(TestModel1, {
|
|
668
|
+
fetcher: () => __awaiter(void 0, void 0, void 0, function* () { return ({ id: 'obj-id', name: 'switch-a-roo' }); }),
|
|
669
|
+
}).createGetter(null)());
|
|
670
|
+
const expected = null;
|
|
671
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
672
|
+
}));
|
|
673
|
+
it('should provide the passed in model and the instance values when switch-a-roo fetcher is used', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
674
|
+
const input = 'obj-id';
|
|
675
|
+
const fetcher = sinon_1.default.stub().callsFake((modelName, id) => ({ id }));
|
|
676
|
+
yield (0, properties_1.ReferenceProperty)(TestModel1, {
|
|
677
|
+
fetcher,
|
|
678
|
+
}).createGetter(input)();
|
|
679
|
+
const actual = fetcher.getCall(0).args[0];
|
|
680
|
+
const expected = TestModel1;
|
|
681
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
682
|
+
}));
|
|
683
|
+
it('should take the smartObject as a value', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
684
|
+
const id = 'obj-id';
|
|
685
|
+
const proto = (0, models_1.BaseModel)('name', {
|
|
686
|
+
properties: {
|
|
687
|
+
id: (0, properties_1.UniqueId)({ value: id }),
|
|
688
|
+
name: (0, properties_1.TextProperty)({}),
|
|
689
|
+
},
|
|
690
|
+
});
|
|
691
|
+
const input = proto.create({ id, name: 'name' });
|
|
692
|
+
const instance = (yield (0, properties_1.ReferenceProperty)(TestModel1, {}).createGetter(input)());
|
|
693
|
+
const actual = yield instance.get.id();
|
|
694
|
+
const expected = 'obj-id';
|
|
695
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
696
|
+
}));
|
|
697
|
+
describe('#toObj()', () => {
|
|
698
|
+
it('should use the getId of the smartObject passed in when toObj is called', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
699
|
+
const proto = (0, models_1.BaseModel)('name', {
|
|
700
|
+
properties: {
|
|
701
|
+
id: (0, properties_1.UniqueId)({ value: 'obj-id' }),
|
|
702
|
+
name: (0, properties_1.TextProperty)({}),
|
|
703
|
+
},
|
|
704
|
+
});
|
|
705
|
+
const input = proto.create({ id: 'obj-id', name: 'name' });
|
|
706
|
+
const instance = (yield (0, properties_1.ReferenceProperty)(TestModel1, {}).createGetter(input)());
|
|
707
|
+
const actual = yield instance.toObj();
|
|
708
|
+
const expected = 'obj-id';
|
|
709
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
710
|
+
}));
|
|
711
|
+
it('should return "obj-id" when switch-a-roo fetcher is used and toObj is called', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
712
|
+
const input = 'obj-id';
|
|
713
|
+
const instance = (yield (0, properties_1.ReferenceProperty)(TestModel1, {
|
|
714
|
+
fetcher: () => Promise.resolve({ id: 'obj-id', prop: 'switch-a-roo' }),
|
|
715
|
+
}).createGetter(input)());
|
|
716
|
+
const actual = yield instance.toObj();
|
|
717
|
+
const expected = 'obj-id';
|
|
718
|
+
chai_1.assert.deepEqual(actual, expected);
|
|
719
|
+
}));
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
//# sourceMappingURL=properties.test.js.map
|