@onehat/data 1.6.6 → 1.6.7
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.
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { OneHatData } from '../../src/OneHatData';
|
|
2
|
+
import GroupsDefinition from '../fixtures/Definitions/Groups';
|
|
3
|
+
import GroupsUsersDefinition from '../fixtures/Definitions/GroupsUsers';
|
|
4
|
+
import UsersDefinition from '../fixtures/Definitions/Users';
|
|
5
|
+
import groupsUserData from '../fixtures/Data/GroupsUser';
|
|
6
|
+
import KeyValues from '../../src/Schema/KeyValues';
|
|
7
|
+
|
|
2
8
|
|
|
3
9
|
// NOTE: Cypress can't handle async functions for beforeEach,
|
|
4
10
|
// so we have to manually apply it to every test. Ugh!
|
|
@@ -110,7 +116,7 @@ describe('OneHatData', function() {
|
|
|
110
116
|
(async function() {
|
|
111
117
|
await beforeEach();
|
|
112
118
|
|
|
113
|
-
const repository = this.oneHatData.createRepository('bar');
|
|
119
|
+
const repository = await this.oneHatData.createRepository('bar');
|
|
114
120
|
expect(repository.id).to.be.not.eq(this.repository.id);
|
|
115
121
|
|
|
116
122
|
afterEach();
|
|
@@ -128,7 +134,7 @@ describe('OneHatData', function() {
|
|
|
128
134
|
{ name: 'baz', },
|
|
129
135
|
]);
|
|
130
136
|
const schemas = oneHatData.schemas;
|
|
131
|
-
oneHatData.createRepositories(schemas);
|
|
137
|
+
await oneHatData.createRepositories(schemas);
|
|
132
138
|
|
|
133
139
|
const result = oneHatData.getAllRepositories();
|
|
134
140
|
expect(_.size(result)).to.be.eq(3);
|
|
@@ -147,7 +153,7 @@ describe('OneHatData', function() {
|
|
|
147
153
|
{ name: 'bar', },
|
|
148
154
|
{ name: 'baz', },
|
|
149
155
|
]);
|
|
150
|
-
oneHatData.createBoundRepositories();
|
|
156
|
+
await oneHatData.createBoundRepositories();
|
|
151
157
|
|
|
152
158
|
const schemas = oneHatData.schemas;
|
|
153
159
|
let bound = 0;
|
|
@@ -183,13 +189,35 @@ describe('OneHatData', function() {
|
|
|
183
189
|
oneHatData.createSchemas([
|
|
184
190
|
{ name: 'foo', },
|
|
185
191
|
]);
|
|
186
|
-
oneHatData.createBoundRepositories();
|
|
192
|
+
await oneHatData.createBoundRepositories();
|
|
187
193
|
expect(oneHatData.hasRepository('foo')).to.be.true;
|
|
188
194
|
|
|
189
195
|
afterEach();
|
|
190
196
|
})();
|
|
191
197
|
});
|
|
192
198
|
|
|
199
|
+
it('Entity.getAssociatedRepository', function() {
|
|
200
|
+
(async function() {
|
|
201
|
+
await beforeEach();
|
|
202
|
+
|
|
203
|
+
const oneHatData = new OneHatData();
|
|
204
|
+
|
|
205
|
+
await oneHatData.createSchemas([
|
|
206
|
+
GroupsDefinition,
|
|
207
|
+
GroupsUsersDefinition,
|
|
208
|
+
UsersDefinition,
|
|
209
|
+
]);
|
|
210
|
+
await oneHatData.createBoundRepositories();
|
|
211
|
+
const GroupsUsers = oneHatData.getRepository('GroupsUsers');
|
|
212
|
+
const groupsUser = await GroupsUsers.add(groupsUserData);
|
|
213
|
+
const Users = groupsUser.getAssociatedRepository('Users');
|
|
214
|
+
|
|
215
|
+
expect(Users).to.be.not.null;
|
|
216
|
+
|
|
217
|
+
afterEach();
|
|
218
|
+
})();
|
|
219
|
+
});
|
|
220
|
+
|
|
193
221
|
it('hasRepositoryWithId', function() {
|
|
194
222
|
(async function() {
|
|
195
223
|
await beforeEach();
|
|
@@ -264,9 +292,9 @@ describe('OneHatData', function() {
|
|
|
264
292
|
await beforeEach();
|
|
265
293
|
|
|
266
294
|
const oneHatData = this.oneHatData;
|
|
267
|
-
oneHatData.createRepository('bar');
|
|
268
|
-
oneHatData.createRepository('bar');
|
|
269
|
-
oneHatData.createRepository('bar');
|
|
295
|
+
await oneHatData.createRepository('bar');
|
|
296
|
+
await oneHatData.createRepository('bar');
|
|
297
|
+
await oneHatData.createRepository('bar');
|
|
270
298
|
const result = oneHatData.getRepositoriesBySchema(this.schema);
|
|
271
299
|
expect(_.size(result)).to.be.eq(4);
|
|
272
300
|
|
|
@@ -274,22 +302,22 @@ describe('OneHatData', function() {
|
|
|
274
302
|
})();
|
|
275
303
|
});
|
|
276
304
|
|
|
277
|
-
it('createGlobalErrorHandler', function() {
|
|
278
|
-
|
|
279
|
-
|
|
305
|
+
// it('createGlobalErrorHandler', function() {
|
|
306
|
+
// (async function() {
|
|
307
|
+
// await beforeEach();
|
|
280
308
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
309
|
+
// let message = '';
|
|
310
|
+
// const oneHatData = this.oneHatData,
|
|
311
|
+
// errorHandler = (a, b) => {
|
|
312
|
+
// debugger;
|
|
313
|
+
// };
|
|
314
|
+
// oneHatData.createGlobalErrorHandler(errorHandler);
|
|
315
|
+
// oneHatData.emitError();
|
|
316
|
+
// expect(message).to.be.eq('Test here');
|
|
289
317
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
});
|
|
318
|
+
// afterEach();
|
|
319
|
+
// })();
|
|
320
|
+
// });
|
|
293
321
|
|
|
294
322
|
it('setOptionsOnAllRepositories', function() {
|
|
295
323
|
(async function() {
|
|
@@ -323,14 +351,16 @@ describe('OneHatData', function() {
|
|
|
323
351
|
await beforeEach();
|
|
324
352
|
|
|
325
353
|
const oneHatData = new OneHatData();
|
|
326
|
-
|
|
354
|
+
|
|
355
|
+
await oneHatData.createSchemas([
|
|
327
356
|
{ name: 'foo', },
|
|
328
357
|
{ name: 'bar', },
|
|
329
358
|
{ name: 'baz', },
|
|
330
359
|
])
|
|
331
|
-
.createBoundRepositories()
|
|
332
|
-
|
|
333
|
-
|
|
360
|
+
.createBoundRepositories();
|
|
361
|
+
|
|
362
|
+
// NOTE: Can't chain getAllRepositories() because we have to wait for createBoundRepositories to finish
|
|
363
|
+
const repositories = oneHatData.getAllRepositories();
|
|
334
364
|
expect(_.size(repositories)).to.be.eq(3);
|
|
335
365
|
|
|
336
366
|
afterEach();
|
|
@@ -349,8 +379,8 @@ describe('OneHatData', function() {
|
|
|
349
379
|
{ key: '4', value: 'four', },
|
|
350
380
|
{ key: '5', value: 'five', },
|
|
351
381
|
],
|
|
352
|
-
repository = oneHatData.createRepository({
|
|
353
|
-
schema:
|
|
382
|
+
repository = await oneHatData.createRepository({
|
|
383
|
+
schema: KeyValues,
|
|
354
384
|
data,
|
|
355
385
|
});
|
|
356
386
|
|
|
@@ -18,12 +18,45 @@ describe('CurrencyProperty', function() {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it('default value', function() {
|
|
21
|
-
const property = this.property,
|
|
22
|
-
rawValue = property.getDefaultValue();
|
|
23
|
-
property.pauseEvents();
|
|
24
|
-
property.setValue(rawValue);
|
|
25
|
-
property.resumeEvents();
|
|
26
21
|
expect(this.property.submitValue).to.be.eq('0.00');
|
|
22
|
+
|
|
23
|
+
const rawValue = this.property.getDefaultValue();
|
|
24
|
+
this.property.setValue(rawValue);
|
|
25
|
+
expect(this.property.submitValue).to.be.eq('0.00');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('isZero', function() {
|
|
29
|
+
this.property.setValue('0.00');
|
|
30
|
+
expect(this.property.isZero).to.be.true;
|
|
31
|
+
|
|
32
|
+
this.property.setValue('0.01');
|
|
33
|
+
expect(this.property.isZero).to.be.false;
|
|
34
|
+
|
|
35
|
+
this.property.setValue('-0.01');
|
|
36
|
+
expect(this.property.isZero).to.be.false;
|
|
37
|
+
|
|
38
|
+
this.property.setValue(null);
|
|
39
|
+
expect(this.property.isZero).to.be.false;
|
|
40
|
+
|
|
41
|
+
this.property.setValue();
|
|
42
|
+
expect(this.property.isZero).to.be.false;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('hasValue', function() {
|
|
46
|
+
this.property.setValue('0.00');
|
|
47
|
+
expect(this.property.hasValue).to.be.true;
|
|
48
|
+
|
|
49
|
+
this.property.setValue('0.01');
|
|
50
|
+
expect(this.property.hasValue).to.be.true;
|
|
51
|
+
|
|
52
|
+
this.property.setValue('-0.01');
|
|
53
|
+
expect(this.property.hasValue).to.be.true;
|
|
54
|
+
|
|
55
|
+
this.property.setValue(null);
|
|
56
|
+
expect(this.property.hasValue).to.be.false;
|
|
57
|
+
|
|
58
|
+
this.property.setValue();
|
|
59
|
+
expect(this.property.hasValue).to.be.false;
|
|
27
60
|
});
|
|
28
61
|
|
|
29
62
|
});
|
|
@@ -41,8 +74,8 @@ describe('CurrencyProperty', function() {
|
|
|
41
74
|
});
|
|
42
75
|
|
|
43
76
|
it('numeric string', function() {
|
|
44
|
-
const parsed = this.property.parse('This is 1234 dollars.');
|
|
45
|
-
expect(parsed).to.be.eq(1234);
|
|
77
|
+
const parsed = this.property.parse('This is $1234.56 dollars.');
|
|
78
|
+
expect(parsed).to.be.eq(1234.56);
|
|
46
79
|
});
|
|
47
80
|
|
|
48
81
|
it('non-numeric string', function() {
|
package/package.json
CHANGED
package/src/Property/Currency.js
CHANGED
|
@@ -64,6 +64,28 @@ export default class CurrencyProperty extends Property {
|
|
|
64
64
|
return this.parsedValue;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Determines if a currency is equal to 0.00
|
|
69
|
+
* Returns false if no value set.
|
|
70
|
+
*/
|
|
71
|
+
get isZero() {
|
|
72
|
+
if (this.isDestroyed) {
|
|
73
|
+
throw Error('this.isZero is no longer valid. Property has been destroyed.');
|
|
74
|
+
}
|
|
75
|
+
return this.parsedValue === 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Determines if a currency has a non-null value
|
|
80
|
+
*/
|
|
81
|
+
get hasValue() {
|
|
82
|
+
if (this.isDestroyed) {
|
|
83
|
+
throw Error('this.hasValue is no longer valid. Property has been destroyed.');
|
|
84
|
+
}
|
|
85
|
+
console.log(this.parsedValue);
|
|
86
|
+
return !_.isNil(this.parsedValue);
|
|
87
|
+
}
|
|
88
|
+
|
|
67
89
|
};
|
|
68
90
|
|
|
69
91
|
CurrencyProperty.className = 'Currency';
|