@nymphjs/nymph 1.0.0-beta.120 → 1.0.0-beta.121

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.
@@ -6,1429 +6,1483 @@ import { guid } from '@nymphjs/guid';
6
6
  import { EntityUniqueConstraintError } from '../errors/index.js';
7
7
  import { TestBModel as TestBModelClass, TestModel as TestModelClass, TestEmptyModel as TestEmptyModelClass, } from '../testArtifacts.js';
8
8
  const __dirname = dirname(fileURLToPath(import.meta.url));
9
- export function EntitiesTest(nymph, it) {
10
- const TestModel = nymph.addEntityClass(TestModelClass);
11
- const TestBModel = nymph.addEntityClass(TestBModelClass);
12
- const TestEmptyModel = nymph.addEntityClass(TestEmptyModelClass);
13
- let testEntity;
14
- let testGuid;
15
- let refGuid;
16
- let createdMultiple = false;
17
- // The entities created by this function are required by many of the tests.
18
- async function createTestEntities() {
19
- if (testGuid != null) {
20
- return;
21
- }
22
- // Creating entity...
23
- testEntity = await TestModel.factory();
24
- // Saving entity...
25
- testEntity.name = 'Entity Test ' + new Date().toLocaleString();
26
- testEntity.null = null;
27
- testEntity.string = 'test';
28
- testEntity.array = [
29
- 'full',
30
- 'of',
31
- 'values',
32
- 500,
33
- { test: true },
34
- { nullbyte: '\\\x00\u0000 \x00' },
35
- ];
36
- testEntity.match = matchValue;
37
- testEntity.search = searchValue;
38
- testEntity.number = 30;
39
- testEntity.numberString = '30';
40
- testEntity.timestamp = Date.now();
41
- expect(await testEntity.$save()).toEqual(true);
42
- expect(testEntity.guid).not.toBeNull();
43
- testGuid = testEntity.guid;
44
- const entityReferenceTest = new TestModel();
45
- entityReferenceTest.string = 'wrong';
46
- entityReferenceTest.timestamp = (strtotime('-2 days') || 0) * 1000;
47
- expect(await entityReferenceTest.$save()).toEqual(true);
48
- refGuid = entityReferenceTest.guid;
49
- testEntity.reference = entityReferenceTest;
50
- testEntity.refArray = [entityReferenceTest];
51
- expect(await testEntity.$save()).toEqual(true);
52
- entityReferenceTest.test = 'good';
53
- expect(await entityReferenceTest.$save()).toEqual(true);
54
- // Test asynchronous getEntity.
55
- testEntity = (await nymph.getEntity({ class: TestModel }, testGuid));
56
- expect(testEntity).toBeInstanceOf(TestModel);
57
- expect(testEntity.guid).toEqual(testGuid);
58
- }
59
- // The entities created by this function are required by many of the tests.
60
- async function createMultipleTestEntities() {
61
- if (!createdMultiple) {
62
- createdMultiple = true;
63
- // Creating 100 entities...
64
- for (let i = 0; i < 100; i++) {
65
- const testEntity = await TestModel.factory();
66
- testEntity.name = `Multi Test ${i}`;
67
- // Reverse the number for sort testing.
68
- testEntity.number = 100 - i;
69
- testEntity.$removeTag('test');
70
- testEntity.$addTag('multiTest');
71
- expect(await testEntity.$save()).toEqual(true);
72
- // Pause for a few milliseconds so the cdate and mdate can be sorted.
73
- await new Promise((res) => setTimeout(() => res(1), 5));
9
+ export function EntitiesTest(nymph, describe, it) {
10
+ describe('Entity', () => {
11
+ const TestModel = nymph.addEntityClass(TestModelClass);
12
+ const TestBModel = nymph.addEntityClass(TestBModelClass);
13
+ const TestEmptyModel = nymph.addEntityClass(TestEmptyModelClass);
14
+ let testEntity;
15
+ let testGuid;
16
+ let refGuid;
17
+ let createdMultiple = false;
18
+ // The entities created by this function are required by many of the tests.
19
+ async function createTestEntities() {
20
+ if (testGuid != null) {
21
+ return;
74
22
  }
23
+ // Creating entity...
24
+ testEntity = await TestModel.factory();
25
+ // Saving entity...
26
+ testEntity.name = 'Entity Test ' + new Date().toLocaleString();
27
+ testEntity.null = null;
28
+ testEntity.string = 'test';
29
+ testEntity.array = [
30
+ 'full',
31
+ 'of',
32
+ 'values',
33
+ 500,
34
+ { test: true },
35
+ { nullbyte: '\\\x00\u0000 \x00' },
36
+ ];
37
+ testEntity.match = matchValue;
38
+ testEntity.search = searchValue;
39
+ testEntity.number = 30;
40
+ testEntity.numberString = '30';
41
+ testEntity.timestamp = Date.now();
42
+ expect(await testEntity.$save()).toEqual(true);
43
+ expect(testEntity.guid).not.toBeNull();
44
+ testGuid = testEntity.guid;
45
+ const entityReferenceTest = new TestModel();
46
+ entityReferenceTest.string = 'wrong';
47
+ entityReferenceTest.timestamp = (strtotime('-2 days') || 0) * 1000;
48
+ expect(await entityReferenceTest.$save()).toEqual(true);
49
+ refGuid = entityReferenceTest.guid;
50
+ testEntity.reference = entityReferenceTest;
51
+ testEntity.refArray = [entityReferenceTest];
52
+ expect(await testEntity.$save()).toEqual(true);
53
+ entityReferenceTest.test = 'good';
54
+ expect(await entityReferenceTest.$save()).toEqual(true);
55
+ // Test asynchronous getEntity.
56
+ testEntity = (await nymph.getEntity({ class: TestModel }, testGuid));
57
+ expect(testEntity).toBeInstanceOf(TestModel);
58
+ expect(testEntity.guid).toEqual(testGuid);
75
59
  }
76
- }
77
- it('delete old test data', async () => {
78
- let amodels = await nymph.getEntities({ class: TestModel });
79
- expect(Array.isArray(amodels)).toEqual(true);
80
- for (const cur of amodels) {
81
- expect(await cur.$delete()).toEqual(true);
82
- }
83
- amodels = await nymph.getEntities({ class: TestModel });
84
- expect(amodels.length).toEqual(0);
85
- let bmodels = await nymph.getEntities({ class: TestBModel });
86
- expect(Array.isArray(bmodels)).toEqual(true);
87
- for (const cur of bmodels) {
88
- expect(await cur.$delete()).toEqual(true);
89
- }
90
- bmodels = await nymph.getEntities({ class: TestBModel });
91
- expect(bmodels.length).toEqual(0);
92
- });
93
- it('create entity', async () => {
94
- await createTestEntities();
95
- });
96
- it("doesn't create empty entity", async () => {
97
- const testEntity = await TestEmptyModel.factory();
98
- expect(await testEntity.$save()).toBeFalsy();
99
- expect(testEntity.guid).toBeNull();
100
- });
101
- it('update mdate on save', async () => {
102
- await createTestEntities();
103
- const oldMdate = testEntity.mdate ?? Infinity;
104
- await new Promise((resolve) => setTimeout(() => resolve(true), 100));
105
- await testEntity.$save();
106
- expect(testEntity.mdate).toBeGreaterThan(oldMdate);
107
- });
108
- it('create multiple entities', async () => {
109
- return createMultipleTestEntities();
110
- });
111
- it('by guid', async () => {
112
- await createTestEntities();
113
- // Retrieving entity by GUID...
114
- let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
115
- expect(testEntity.$is(resultEntity)).toEqual(true);
116
- // Using class constructor...
117
- resultEntity = await TestModel.factory(testGuid);
118
- expect(testEntity.$is(resultEntity)).toEqual(true);
119
- // Testing wrong GUID...
120
- resultEntity = await nymph.getEntity({ class: TestModel }, guid());
121
- expect(testEntity.$is(resultEntity)).toEqual(false);
122
- });
123
- it('guaranteed guid', async () => {
124
- // Creating entity...
125
- const testEntity = await TestModel.factory();
126
- // Saving entity...
127
- testEntity.name = 'Entity Test ' + new Date().toLocaleString();
128
- testEntity.null = null;
129
- testEntity.string = 'test';
130
- testEntity.array = [];
131
- testEntity.match = matchValue;
132
- testEntity.number = 30;
133
- testEntity.numberString = '30';
134
- testEntity.timestamp = Date.now();
135
- // Get the guaranteed GUID.
136
- const testGuid = testEntity.$getGuaranteedGUID();
137
- expect(await testEntity.$save()).toEqual(true);
138
- expect(testEntity.guid).not.toBeNull();
139
- expect(testEntity.guid).toEqual(testGuid);
140
- // Retrieving entity by GUID...
141
- let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
142
- expect(testEntity.$is(resultEntity)).toEqual(true);
143
- // Delete the entity.
144
- expect(await testEntity.$delete()).toEqual(true);
145
- });
146
- it('create, list, and delete indexes', async () => {
147
- // Delete existing indexes.
148
- const existingIndexes = await nymph.getIndexes(TestModel.ETYPE);
149
- for (let index of existingIndexes) {
150
- await nymph.deleteIndex(TestModel.ETYPE, index.scope, index.name);
151
- }
152
- const existingBIndexes = await nymph.getIndexes(TestBModel.ETYPE);
153
- for (let index of existingBIndexes) {
154
- await nymph.deleteIndex(TestBModel.ETYPE, index.scope, index.name);
60
+ // The entities created by this function are required by many of the tests.
61
+ async function createMultipleTestEntities() {
62
+ if (!createdMultiple) {
63
+ createdMultiple = true;
64
+ // Creating 100 entities...
65
+ for (let i = 0; i < 100; i++) {
66
+ const testEntity = await TestModel.factory();
67
+ testEntity.name = `Multi Test ${i}`;
68
+ // Reverse the number for sort testing.
69
+ testEntity.number = 100 - i;
70
+ testEntity.$removeTag('test');
71
+ testEntity.$addTag('multiTest');
72
+ expect(await testEntity.$save()).toEqual(true);
73
+ // Pause for a few milliseconds so the cdate and mdate can be sorted.
74
+ await new Promise((res) => setTimeout(() => res(1), 5));
75
+ }
76
+ }
155
77
  }
156
- const sortByName = (arr) => {
157
- arr.sort((a, b) => a.name.localeCompare(b.name));
158
- return arr;
159
- };
160
- expect(await nymph.addIndex(TestModel.ETYPE, {
161
- scope: 'data',
162
- name: 'testindex',
163
- property: 'test',
164
- })).toEqual(true);
165
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
166
- { scope: 'data', name: 'testindex', property: 'test' },
167
- ]);
168
- expect(await nymph.addIndex(TestModel.ETYPE, {
169
- scope: 'data',
170
- name: 'secondone',
171
- property: 'match',
172
- })).toEqual(true);
173
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
174
- { scope: 'data', name: 'secondone', property: 'match' },
175
- { scope: 'data', name: 'testindex', property: 'test' },
176
- ]);
177
- expect(await nymph.addIndex(TestModel.ETYPE, {
178
- scope: 'references',
179
- name: 'refone',
180
- property: 'reference',
181
- })).toEqual(true);
182
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
183
- { scope: 'references', name: 'refone', property: 'reference' },
184
- { scope: 'data', name: 'secondone', property: 'match' },
185
- { scope: 'data', name: 'testindex', property: 'test' },
186
- ]);
187
- expect(await nymph.addIndex(TestModel.ETYPE, {
188
- scope: 'tokens',
189
- name: 'tokenone',
190
- property: 'search',
191
- })).toEqual(true);
192
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
193
- { scope: 'references', name: 'refone', property: 'reference' },
194
- { scope: 'data', name: 'secondone', property: 'match' },
195
- { scope: 'data', name: 'testindex', property: 'test' },
196
- { scope: 'tokens', name: 'tokenone', property: 'search' },
197
- ]);
198
- expect(await nymph.addIndex(TestBModel.ETYPE, {
199
- scope: 'data',
200
- name: 'flooflab',
201
- property: 'string',
202
- })).toEqual(true);
203
- expect(sortByName(await nymph.getIndexes(TestBModel.ETYPE))).toEqual([
204
- { scope: 'data', name: 'flooflab', property: 'string' },
205
- ]);
206
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
207
- { scope: 'references', name: 'refone', property: 'reference' },
208
- { scope: 'data', name: 'secondone', property: 'match' },
209
- { scope: 'data', name: 'testindex', property: 'test' },
210
- { scope: 'tokens', name: 'tokenone', property: 'search' },
211
- ]);
212
- expect(await nymph.deleteIndex(TestBModel.ETYPE, 'data', 'flooflab')).toEqual(true);
213
- expect(await nymph.getIndexes(TestBModel.ETYPE)).toEqual([]);
214
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
215
- { scope: 'references', name: 'refone', property: 'reference' },
216
- { scope: 'data', name: 'secondone', property: 'match' },
217
- { scope: 'data', name: 'testindex', property: 'test' },
218
- { scope: 'tokens', name: 'tokenone', property: 'search' },
219
- ]);
220
- expect(await nymph.deleteIndex(TestModel.ETYPE, 'data', 'testindex')).toEqual(true);
221
- expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
222
- { scope: 'references', name: 'refone', property: 'reference' },
223
- { scope: 'data', name: 'secondone', property: 'match' },
224
- { scope: 'tokens', name: 'tokenone', property: 'search' },
225
- ]);
226
- });
227
- it('transactions', async () => {
228
- await createTestEntities();
229
- // Verify not in a transaction.
230
- expect(await nymph.inTransaction()).toEqual(false);
231
- let transaction = await nymph.startTransaction('test');
232
- testEntity.$nymph = transaction;
233
- if (!(await transaction.inTransaction())) {
234
- console.log('This Nymph driver or database seems to not support transactions. Skipping transaction tests.');
78
+ it('delete old test data', async () => {
79
+ let amodels = await nymph.getEntities({ class: TestModel });
80
+ expect(Array.isArray(amodels)).toEqual(true);
81
+ for (const cur of amodels) {
82
+ expect(await cur.$delete()).toEqual(true);
83
+ }
84
+ amodels = await nymph.getEntities({ class: TestModel });
85
+ expect(amodels.length).toEqual(0);
86
+ let bmodels = await nymph.getEntities({ class: TestBModel });
87
+ expect(Array.isArray(bmodels)).toEqual(true);
88
+ for (const cur of bmodels) {
89
+ expect(await cur.$delete()).toEqual(true);
90
+ }
91
+ bmodels = await nymph.getEntities({ class: TestBModel });
92
+ expect(bmodels.length).toEqual(0);
93
+ });
94
+ it('create entity', async () => {
95
+ await createTestEntities();
96
+ });
97
+ it("doesn't create empty entity", async () => {
98
+ const testEntity = await TestEmptyModel.factory();
99
+ expect(await testEntity.$save()).toBeFalsy();
100
+ expect(testEntity.guid).toBeNull();
101
+ });
102
+ it('update mdate on save', async () => {
103
+ await createTestEntities();
104
+ const oldMdate = testEntity.mdate ?? Infinity;
105
+ await new Promise((resolve) => setTimeout(() => resolve(true), 100));
106
+ await testEntity.$save();
107
+ expect(testEntity.mdate).toBeGreaterThan(oldMdate);
108
+ });
109
+ it('create multiple entities', async () => {
110
+ return createMultipleTestEntities();
111
+ });
112
+ it('by guid', async () => {
113
+ await createTestEntities();
114
+ // Retrieving entity by GUID...
115
+ let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
116
+ expect(testEntity.$is(resultEntity)).toEqual(true);
117
+ // Using class constructor...
118
+ resultEntity = await TestModel.factory(testGuid);
119
+ expect(testEntity.$is(resultEntity)).toEqual(true);
120
+ // Testing wrong GUID...
121
+ resultEntity = await nymph.getEntity({ class: TestModel }, guid());
122
+ expect(testEntity.$is(resultEntity)).toEqual(false);
123
+ });
124
+ it('guaranteed guid', async () => {
125
+ // Creating entity...
126
+ const testEntity = await TestModel.factory();
127
+ // Saving entity...
128
+ testEntity.name = 'Entity Test ' + new Date().toLocaleString();
129
+ testEntity.null = null;
130
+ testEntity.string = 'test';
131
+ testEntity.array = [];
132
+ testEntity.match = matchValue;
133
+ testEntity.number = 30;
134
+ testEntity.numberString = '30';
135
+ testEntity.timestamp = Date.now();
136
+ // Get the guaranteed GUID.
137
+ const testGuid = testEntity.$getGuaranteedGUID();
138
+ expect(await testEntity.$save()).toEqual(true);
139
+ expect(testEntity.guid).not.toBeNull();
140
+ expect(testEntity.guid).toEqual(testGuid);
141
+ // Retrieving entity by GUID...
142
+ let resultEntity = await nymph.getEntity({ class: TestModel }, testGuid);
143
+ expect(testEntity.$is(resultEntity)).toEqual(true);
144
+ // Delete the entity.
145
+ expect(await testEntity.$delete()).toEqual(true);
146
+ });
147
+ it('create, list, and delete indexes', async () => {
148
+ // Delete existing indexes.
149
+ const existingIndexes = await nymph.getIndexes(TestModel.ETYPE);
150
+ for (let index of existingIndexes) {
151
+ await nymph.deleteIndex(TestModel.ETYPE, index.scope, index.name);
152
+ }
153
+ const existingBIndexes = await nymph.getIndexes(TestBModel.ETYPE);
154
+ for (let index of existingBIndexes) {
155
+ await nymph.deleteIndex(TestBModel.ETYPE, index.scope, index.name);
156
+ }
157
+ const sortByName = (arr) => {
158
+ arr.sort((a, b) => a.name.localeCompare(b.name));
159
+ return arr;
160
+ };
161
+ expect(await nymph.addIndex(TestModel.ETYPE, {
162
+ scope: 'data',
163
+ name: 'testindex',
164
+ property: 'test',
165
+ })).toEqual(true);
166
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
167
+ { scope: 'data', name: 'testindex', property: 'test' },
168
+ ]);
169
+ expect(await nymph.addIndex(TestModel.ETYPE, {
170
+ scope: 'data',
171
+ name: 'secondone',
172
+ property: 'match',
173
+ })).toEqual(true);
174
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
175
+ { scope: 'data', name: 'secondone', property: 'match' },
176
+ { scope: 'data', name: 'testindex', property: 'test' },
177
+ ]);
178
+ expect(await nymph.addIndex(TestModel.ETYPE, {
179
+ scope: 'references',
180
+ name: 'refone',
181
+ property: 'reference',
182
+ })).toEqual(true);
183
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
184
+ { scope: 'references', name: 'refone', property: 'reference' },
185
+ { scope: 'data', name: 'secondone', property: 'match' },
186
+ { scope: 'data', name: 'testindex', property: 'test' },
187
+ ]);
188
+ expect(await nymph.addIndex(TestModel.ETYPE, {
189
+ scope: 'tokens',
190
+ name: 'tokenone',
191
+ property: 'search',
192
+ })).toEqual(true);
193
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
194
+ { scope: 'references', name: 'refone', property: 'reference' },
195
+ { scope: 'data', name: 'secondone', property: 'match' },
196
+ { scope: 'data', name: 'testindex', property: 'test' },
197
+ { scope: 'tokens', name: 'tokenone', property: 'search' },
198
+ ]);
199
+ expect(await nymph.addIndex(TestBModel.ETYPE, {
200
+ scope: 'data',
201
+ name: 'flooflab',
202
+ property: 'string',
203
+ })).toEqual(true);
204
+ expect(sortByName(await nymph.getIndexes(TestBModel.ETYPE))).toEqual([
205
+ { scope: 'data', name: 'flooflab', property: 'string' },
206
+ ]);
207
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
208
+ { scope: 'references', name: 'refone', property: 'reference' },
209
+ { scope: 'data', name: 'secondone', property: 'match' },
210
+ { scope: 'data', name: 'testindex', property: 'test' },
211
+ { scope: 'tokens', name: 'tokenone', property: 'search' },
212
+ ]);
213
+ expect(await nymph.deleteIndex(TestBModel.ETYPE, 'data', 'flooflab')).toEqual(true);
214
+ expect(await nymph.getIndexes(TestBModel.ETYPE)).toEqual([]);
215
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
216
+ { scope: 'references', name: 'refone', property: 'reference' },
217
+ { scope: 'data', name: 'secondone', property: 'match' },
218
+ { scope: 'data', name: 'testindex', property: 'test' },
219
+ { scope: 'tokens', name: 'tokenone', property: 'search' },
220
+ ]);
221
+ expect(await nymph.deleteIndex(TestModel.ETYPE, 'data', 'testindex')).toEqual(true);
222
+ expect(sortByName(await nymph.getIndexes(TestModel.ETYPE))).toEqual([
223
+ { scope: 'references', name: 'refone', property: 'reference' },
224
+ { scope: 'data', name: 'secondone', property: 'match' },
225
+ { scope: 'tokens', name: 'tokenone', property: 'search' },
226
+ ]);
227
+ });
228
+ it('transactions', async () => {
229
+ await createTestEntities();
230
+ // Verify not in a transaction.
231
+ expect(await nymph.inTransaction()).toEqual(false);
232
+ let transaction = await nymph.startTransaction('test');
233
+ testEntity.$nymph = transaction;
234
+ if (!(await transaction.inTransaction())) {
235
+ console.log('This Nymph driver or database seems to not support transactions. Skipping transaction tests.');
236
+ await transaction.rollback('test');
237
+ return;
238
+ }
239
+ // Change a value in the test entity.
240
+ testEntity.string = 'bad value';
241
+ expect(await testEntity.$save()).toEqual(true);
242
+ // Rollback the transaction.
235
243
  await transaction.rollback('test');
236
- return;
237
- }
238
- // Change a value in the test entity.
239
- testEntity.string = 'bad value';
240
- expect(await testEntity.$save()).toEqual(true);
241
- // Rollback the transaction.
242
- await transaction.rollback('test');
243
- // Verify not in a transaction.
244
- expect(await transaction.inTransaction()).toEqual(false);
245
- // Verify the value is correct.
246
- await testEntity.$refresh();
247
- expect(testEntity.string).toEqual('test');
248
- // Start a new transaction.
249
- transaction = await nymph.startTransaction('test');
250
- testEntity.$nymph = transaction;
251
- // Verify in a transaction.
252
- expect(await transaction.inTransaction()).toEqual(true);
253
- // Delete the entity.
254
- expect(await testEntity.$delete()).toEqual(true);
255
- const resultEntity = await transaction.getEntity({ class: TestModel }, testGuid);
256
- expect(resultEntity).toBeNull();
257
- // Rollback the transaction.
258
- await transaction.rollback('test');
259
- // Verify not in a transaction.
260
- expect(await transaction.inTransaction()).toEqual(false);
261
- // Verify it's back.
262
- testEntity = (await transaction.getEntity({ class: TestModel }, testGuid));
263
- expect(testEntity.guid).toEqual(testGuid);
264
- // Start a new transaction with a dot in the name.
265
- transaction = await nymph.startTransaction('test.1');
266
- testEntity.$nymph = transaction;
267
- // Verify in a transaction.
268
- expect(await transaction.inTransaction()).toEqual(true);
269
- // Make a change.
270
- testEntity.string = 'fish';
271
- expect(await testEntity.$save()).toEqual(true);
272
- // Commit the transaction.
273
- await transaction.commit('test.1');
274
- testEntity.$nymph = nymph;
275
- // Verify not in a transaction.
276
- expect(await transaction.inTransaction()).toEqual(false);
277
- // Verify the value is correct.
278
- await testEntity.$refresh();
279
- expect(testEntity.string).toEqual('fish');
280
- // Finally, change it back.
281
- testEntity.string = 'test';
282
- expect(await testEntity.$save()).toEqual(true);
283
- // TODO: nested transactions
284
- });
285
- it('options', async () => {
286
- await createTestEntities();
287
- // Testing entity order, offset, limit...
288
- let resultEntities = await nymph.getEntities({
289
- class: TestModel,
290
- reverse: true,
291
- offset: 1,
292
- limit: 1,
293
- sort: 'cdate',
294
- }, { type: '&', tag: 'test' });
295
- expect(resultEntities.length).toEqual(1);
296
- expect(testEntity.$is(resultEntities[0])).toEqual(true);
297
- // Testing null sort...
298
- resultEntities = await nymph.getEntities({
299
- class: TestModel,
300
- reverse: true,
301
- sort: null,
302
- }, { type: '&', tag: 'test' });
303
- expect(testEntity.$inArray(resultEntities)).toEqual(true);
304
- });
305
- it('guid and tags', async () => {
306
- await createTestEntities();
307
- // Retrieving entity by GUID and tags...
308
- const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid, tag: 'test' });
309
- expect(testEntity.$is(resultEntity)).toEqual(true);
310
- });
311
- it('or selector', async () => {
312
- await createTestEntities();
313
- // Retrieving entity by GUID and tags...
314
- const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '|', guid: [testGuid, guid()] });
315
- expect(testEntity.$is(resultEntity)).toEqual(true);
316
- });
317
- it('wrong or selector', async () => {
318
- await createTestEntities();
319
- // Retrieving entity by GUID and tags...
320
- const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '|', guid: [guid(), guid()] });
321
- expect(testEntity.$is(resultEntity)).toEqual(false);
322
- });
323
- it('not guid', async () => {
324
- await createTestEntities();
325
- // Retrieving entity by !GUID...
326
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', '!guid': guid(), tag: 'test' });
327
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
328
- });
329
- it('not tags', async () => {
330
- await createTestEntities();
331
- // Retrieving entity by !tags...
332
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', guid: testGuid, '!tag': ['barbecue', 'pickles'] });
333
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
334
- });
335
- it('guid and wrong tags', async () => {
336
- await createTestEntities();
337
- // Testing GUID and wrong tags...
338
- const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid, tag: ['pickles'] });
339
- expect(resultEntity).toBeNull();
340
- });
341
- it('tags', async () => {
342
- await createTestEntities();
343
- // Retrieving entity by tags...
344
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' });
345
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
346
- });
347
- it('wrong tags', async () => {
348
- await createTestEntities();
349
- // Testing wrong tags...
350
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles' });
351
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
352
- });
353
- it('inclusive tags', async () => {
354
- await createTestEntities();
355
- // Retrieving entity by tags inclusively...
356
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '|', tag: ['pickles', 'test', 'barbecue'] });
357
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
358
- });
359
- it('wrong inclusive tags', async () => {
360
- await createTestEntities();
361
- // Testing wrong inclusive tags...
362
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '|', tag: ['pickles', 'barbecue'] });
363
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
364
- });
365
- it('mixed tags', async () => {
366
- await createTestEntities();
367
- // Retrieving entity by mixed tags...
368
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', tag: ['pickles', 'test', 'barbecue'] });
369
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
370
- });
371
- it('wrong inclusive mixed tags', async () => {
372
- await createTestEntities();
373
- // Testing wrong inclusive mixed tags...
374
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', tag: ['pickles', 'barbecue'] });
375
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
376
- });
377
- it('wrong exclusive mixed tags', async () => {
378
- await createTestEntities();
379
- // Testing wrong exclusive mixed tags...
380
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles' }, { type: '|', tag: ['test', 'barbecue'] });
381
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
382
- });
383
- it('defined', async () => {
384
- await createTestEntities();
385
- // Retrieving entity by defined...
386
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', defined: 'string' });
387
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
388
- });
389
- it('not defined', async () => {
390
- await createTestEntities();
391
- // Retrieving entity by !defined...
392
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!defined': 'pickles' });
393
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
394
- });
395
- it('defined in a not and clause', async () => {
396
- await createTestEntities();
397
- // Retrieving entity by defined in not and clause...
398
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '!&', defined: 'pickles' }, { type: '&', tag: 'test' });
399
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
400
- });
401
- it('equal', async () => {
402
- await createTestEntities();
403
- // Retrieving entity by equal...
404
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['string', 'test'] });
405
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
406
- // Retrieving entity by equal...
407
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['null', null] });
408
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
409
- // Retrieving entity by equal...
410
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['boolean', true] });
411
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
412
- // Retrieving entity by equal...
413
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['number', 30] });
414
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
415
- // Retrieving entity by equal...
416
- resultEntity = await nymph.getEntities({ class: TestModel }, {
417
- type: '&',
418
- equal: [
419
- 'array',
420
- [
421
- 'full',
422
- 'of',
423
- 'values',
424
- 500,
425
- { test: true },
426
- { nullbyte: '\\\x00\u0000 \x00' },
427
- ],
428
- ],
244
+ // Verify not in a transaction.
245
+ expect(await transaction.inTransaction()).toEqual(false);
246
+ // Verify the value is correct.
247
+ await testEntity.$refresh();
248
+ expect(testEntity.string).toEqual('test');
249
+ // Start a new transaction.
250
+ transaction = await nymph.startTransaction('test');
251
+ testEntity.$nymph = transaction;
252
+ // Verify in a transaction.
253
+ expect(await transaction.inTransaction()).toEqual(true);
254
+ // Delete the entity.
255
+ expect(await testEntity.$delete()).toEqual(true);
256
+ const resultEntity = await transaction.getEntity({ class: TestModel }, testGuid);
257
+ expect(resultEntity).toBeNull();
258
+ // Rollback the transaction.
259
+ await transaction.rollback('test');
260
+ // Verify not in a transaction.
261
+ expect(await transaction.inTransaction()).toEqual(false);
262
+ // Verify it's back.
263
+ testEntity = (await transaction.getEntity({ class: TestModel }, testGuid));
264
+ expect(testEntity.guid).toEqual(testGuid);
265
+ // Start a new transaction with a dot in the name.
266
+ transaction = await nymph.startTransaction('test.1');
267
+ testEntity.$nymph = transaction;
268
+ // Verify in a transaction.
269
+ expect(await transaction.inTransaction()).toEqual(true);
270
+ // Make a change.
271
+ testEntity.string = 'fish';
272
+ expect(await testEntity.$save()).toEqual(true);
273
+ // Commit the transaction.
274
+ await transaction.commit('test.1');
275
+ testEntity.$nymph = nymph;
276
+ // Verify not in a transaction.
277
+ expect(await transaction.inTransaction()).toEqual(false);
278
+ // Verify the value is correct.
279
+ await testEntity.$refresh();
280
+ expect(testEntity.string).toEqual('fish');
281
+ // Finally, change it back.
282
+ testEntity.string = 'test';
283
+ expect(await testEntity.$save()).toEqual(true);
284
+ // TODO: nested transactions
429
285
  });
430
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
431
- // Retrieving entity by equal...
432
- resultEntity = await nymph.getEntities({ class: TestModel }, {
433
- type: '&',
434
- equal: ['match', matchValue],
286
+ it('options', async () => {
287
+ await createTestEntities();
288
+ // Testing entity order, offset, limit...
289
+ let resultEntities = await nymph.getEntities({
290
+ class: TestModel,
291
+ reverse: true,
292
+ offset: 1,
293
+ limit: 1,
294
+ sort: 'cdate',
295
+ }, { type: '&', tag: 'test' });
296
+ expect(resultEntities.length).toEqual(1);
297
+ expect(testEntity.$is(resultEntities[0])).toEqual(true);
298
+ // Testing null sort...
299
+ resultEntities = await nymph.getEntities({
300
+ class: TestModel,
301
+ reverse: true,
302
+ sort: null,
303
+ }, { type: '&', tag: 'test' });
304
+ expect(testEntity.$inArray(resultEntities)).toEqual(true);
435
305
  });
436
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
437
- });
438
- it('not equal', async () => {
439
- await createTestEntities();
440
- const referenceEntity = await TestModel.factory(refGuid);
441
- expect(referenceEntity.guid).toEqual(refGuid);
442
- // Retrieving entity by !equal...
443
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!equal': ['string', 'wrong'] });
444
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
445
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
446
- });
447
- it('like', async () => {
448
- await createTestEntities();
449
- // Retrieving entity by like...
450
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', like: ['string', 't_s%'] });
451
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
452
- });
453
- it('not like', async () => {
454
- await createTestEntities();
455
- const referenceEntity = await TestModel.factory(refGuid);
456
- expect(referenceEntity.guid).toEqual(refGuid);
457
- // Retrieving entity by !like...
458
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!like': ['string', 'wr_n%'] });
459
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
460
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
461
- });
462
- it('ilike', async () => {
463
- await createTestEntities();
464
- // Retrieving entity by ilike...
465
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ilike: ['string', 'T_s%'] });
466
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
467
- });
468
- it('not ilike', async () => {
469
- await createTestEntities();
470
- const referenceEntity = await TestModel.factory(refGuid);
471
- expect(referenceEntity.guid).toEqual(refGuid);
472
- // Retrieving entity by !ilike...
473
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!ilike': ['string', 'wr_n%'] });
474
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
475
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
476
- });
477
- it('like with wrong case', async () => {
478
- await createTestEntities();
479
- // Retrieving entity by like...
480
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', like: ['string', 'T_s%'] });
481
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
482
- });
483
- it('tags and equal', async () => {
484
- await createTestEntities();
485
- // Retrieving entity by tags and equal...
486
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', equal: ['string', 'test'] });
487
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
488
- });
489
- it('wrong tags right equal', async () => {
490
- await createTestEntities();
491
- // Testing wrong tags and right equal...
492
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles', equal: ['string', 'test'] });
493
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
494
- });
495
- it('right tags wrong equal', async () => {
496
- await createTestEntities();
497
- // Testing right tags and wrong equal...
498
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', equal: ['string', 'pickles'] });
499
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
500
- });
501
- it('wrong tags wrong equal', async () => {
502
- await createTestEntities();
503
- // Testing wrong tags and wrong equal...
504
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles', equal: ['string', 'pickles'] });
505
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
506
- });
507
- it('contain', async () => {
508
- await createTestEntities();
509
- // Retrieving entity by contain...
510
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', 'values'] });
511
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
512
- // Retrieving entity by contain...
513
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', 500] });
514
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
515
- // Retrieving entity by contain...
516
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', { test: true }] });
517
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
518
- });
519
- it('not contain', async () => {
520
- await createTestEntities();
521
- // Retrieving entity by !contain...
522
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', contain: ['array', 'pickles'] });
523
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
524
- });
525
- it('wrong contain', async () => {
526
- await createTestEntities();
527
- // Testing wrong contain...
528
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', 'pickles'] });
529
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
530
- // Testing wrong contain...
531
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['string', 'pickles'] });
532
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
533
- });
534
- it('match', async () => {
535
- await createTestEntities();
536
- // Retrieving entity by regex match...
537
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', match: ['match', '.*'] });
538
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
539
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', match: ['match', 'Edward McCheese'] });
540
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
541
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, {
542
- type: '|',
543
- match: [
544
- ['string', '[0-9]'],
545
- ['match', 'Edward McCheese'],
546
- ],
547
- });
548
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
549
- resultEntity = await nymph.getEntities({ class: TestModel }, {
550
- type: '&',
551
- tag: 'test',
552
- match: ['match', '[-a-zA-Z0-9+_]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9_]{2,4}'],
553
- });
554
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
555
- resultEntity = await nymph.getEntities({ class: TestModel }, {
556
- type: '&',
557
- tag: 'test',
558
- match: ['match', '\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}'],
559
- });
560
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
561
- });
562
- it('imatch', async () => {
563
- await createTestEntities();
564
- // Retrieving entity by regex match...
565
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', imatch: ['match', 'edward mccheese'] });
566
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
567
- });
568
- it('wrong match', async () => {
569
- await createTestEntities();
570
- // Testing wrong regex match...
571
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', match: ['match', '='] });
572
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
573
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickle', match: ['match', '.*'] });
574
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
575
- resultEntity = await nymph.getEntities({ class: TestModel }, {
576
- type: '|',
577
- match: [
578
- ['string', '[0-9]'],
579
- ['match', ',,'],
580
- ],
581
- });
582
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
583
- });
584
- it('match wrong case', async () => {
585
- await createTestEntities();
586
- // Retrieving entity by regex match...
587
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', match: ['match', 'edward mccheese'] });
588
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
589
- });
590
- it('match and equal inclusive', async () => {
591
- await createTestEntities();
592
- // Retrieving entity by regex + equal inclusively...
593
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', equal: ['string', 'pickles'], match: ['string', 'test'] });
594
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
595
- });
596
- it('basic search', async () => {
597
- await createTestEntities();
598
- // Retrieving entity by full text search...
599
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
600
- type: '&',
601
- tag: 'test',
602
- search: [
603
- 'search',
604
- 'Declaration of the thirteen united States of America',
605
- ],
606
- });
607
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
608
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, {
609
- type: '|',
610
- search: [
611
- ['string', 'pickle'],
612
- ['search', 'Declaration of the thirteen united States of America'],
613
- ],
614
- });
615
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
616
- resultEntity = await nymph.getEntities({ class: TestModel }, {
617
- type: '&',
618
- tag: 'test',
619
- search: ['search', 'July 4, 1776'],
620
- });
621
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
622
- });
623
- it('or search', async () => {
624
- await createTestEntities();
625
- // Retrieving entity by full text search...
626
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
627
- type: '&',
628
- tag: 'test',
629
- search: ['search', 'Declaration or pickles'],
630
- });
631
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
632
- });
633
- it('series search', async () => {
634
- await createTestEntities();
635
- // Retrieving entity by full text search...
636
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
637
- type: '&',
638
- tag: 'test',
639
- search: ['search', '"excited domestic insurrections"'],
640
- });
641
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
642
- resultEntity = await nymph.getEntities({ class: TestModel }, {
643
- type: '&',
644
- tag: 'test',
645
- search: ['search', "'exciting domestic insurrected'"],
646
- });
647
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
648
- });
649
- it('negated search', async () => {
650
- await createTestEntities();
651
- // Retrieving entity by full text search...
652
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
653
- type: '&',
654
- tag: 'test',
655
- search: ['search', '-pickle'],
656
- });
657
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
658
- });
659
- it('combined search', async () => {
660
- await createTestEntities();
661
- // Retrieving entity by full text search...
662
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
663
- type: '&',
664
- tag: 'test',
665
- search: ['search', 'Declaration -pickle'],
666
- });
667
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
668
- resultEntity = await nymph.getEntities({ class: TestModel }, {
669
- type: '&',
670
- tag: 'test',
671
- search: ['search', 'Declaration "General Congress"'],
672
- });
673
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
674
- });
675
- it('wrong search', async () => {
676
- await createTestEntities();
677
- // Testing wrong search...
678
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', search: ['search', 'pickles'] });
679
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
680
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickle', search: ['search', 'Declaration'] });
681
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
682
- resultEntity = await nymph.getEntities({ class: TestModel }, {
683
- type: '|',
684
- search: [
685
- ['string', 'pickle'],
686
- ['search', 'Hawaii'],
687
- ],
688
- });
689
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
690
- });
691
- it('search with only stop words', async () => {
692
- await createTestEntities();
693
- // Testing wrong search...
694
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', search: ['search', 'i am'] });
695
- expect(resultEntity).toEqual([]);
696
- });
697
- it('search must be case insensitive', async () => {
698
- await createTestEntities();
699
- // Retrieving entity by full text search...
700
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
701
- type: '&',
702
- tag: 'test',
703
- search: [
704
- 'search',
705
- 'DECLARATION OF THE THIRTEEN UNITED STATES OF AMERICA',
706
- ],
707
- });
708
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
709
- });
710
- it('search and equal inclusive', async () => {
711
- await createTestEntities();
712
- // Retrieving entity by fts + equal inclusively...
713
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', equal: ['string', 'pickles'], search: ['string', 'test'] });
714
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
715
- });
716
- it('greater than', async () => {
717
- await createTestEntities();
718
- // Retrieving entity by inequality...
719
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
720
- type: '|',
721
- gt: [
722
- ['number', 30],
723
- ['pickles', 100],
724
- ],
725
- });
726
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
727
- // Retrieving entity by inequality...
728
- resultEntity = await nymph.getEntities({ class: TestModel }, {
729
- type: '|',
730
- gt: [
731
- ['number', 31],
732
- ['pickles', 100],
733
- ],
734
- });
735
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
736
- // Retrieving entity by inequality...
737
- resultEntity = await nymph.getEntities({ class: TestModel }, {
738
- type: '|',
739
- gt: [
740
- ['number', 29],
741
- ['pickles', 100],
742
- ],
743
- });
744
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
745
- // Retrieving entity by inequality...
746
- resultEntity = await nymph.getEntities({ class: TestModel }, {
747
- type: '|',
748
- gt: [
749
- ['numberString', 30],
750
- ['pickles', 100],
751
- ],
752
- });
753
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
754
- // Retrieving entity by inequality...
755
- resultEntity = await nymph.getEntities({ class: TestModel }, {
756
- type: '|',
757
- gt: [
758
- ['numberString', 31],
759
- ['pickles', 100],
760
- ],
761
- });
762
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
763
- // Retrieving entity by inequality...
764
- resultEntity = await nymph.getEntities({ class: TestModel }, {
765
- type: '|',
766
- gt: [
767
- ['numberString', 29],
768
- ['pickles', 100],
769
- ],
770
- });
771
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
772
- });
773
- it('greater than or equal', async () => {
774
- await createTestEntities();
775
- // Retrieving entity by inequality...
776
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
777
- type: '|',
778
- gte: [
779
- ['number', 30],
780
- ['pickles', 100],
781
- ],
782
- });
783
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
784
- // Retrieving entity by inequality...
785
- resultEntity = await nymph.getEntities({ class: TestModel }, {
786
- type: '|',
787
- gte: [
788
- ['number', 31],
789
- ['pickles', 100],
790
- ],
791
- });
792
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
793
- // Retrieving entity by inequality...
794
- resultEntity = await nymph.getEntities({ class: TestModel }, {
795
- type: '|',
796
- gte: [
797
- ['number', 29],
798
- ['pickles', 100],
799
- ],
800
- });
801
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
802
- // Retrieving entity by inequality...
803
- resultEntity = await nymph.getEntities({ class: TestModel }, {
804
- type: '|',
805
- gte: [
806
- ['numberString', 30],
807
- ['pickles', 100],
808
- ],
809
- });
810
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
811
- // Retrieving entity by inequality...
812
- resultEntity = await nymph.getEntities({ class: TestModel }, {
813
- type: '|',
814
- gte: [
815
- ['numberString', 31],
816
- ['pickles', 100],
817
- ],
818
- });
819
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
820
- // Retrieving entity by inequality...
821
- resultEntity = await nymph.getEntities({ class: TestModel }, {
822
- type: '|',
823
- gte: [
824
- ['numberString', 29],
825
- ['pickles', 100],
826
- ],
827
- });
828
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
829
- });
830
- it('less than', async () => {
831
- await createTestEntities();
832
- // Retrieving entity by inequality...
833
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
834
- type: '|',
835
- lt: [
836
- ['number', 30],
837
- ['pickles', 100],
838
- ],
839
- });
840
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
841
- // Retrieving entity by inequality...
842
- resultEntity = await nymph.getEntities({ class: TestModel }, {
843
- type: '|',
844
- lt: [
845
- ['number', 31],
846
- ['pickles', 100],
847
- ],
848
- });
849
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
850
- // Retrieving entity by inequality...
851
- resultEntity = await nymph.getEntities({ class: TestModel }, {
852
- type: '|',
853
- lt: [
854
- ['number', 29],
855
- ['pickles', 100],
856
- ],
857
- });
858
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
859
- // Retrieving entity by inequality...
860
- resultEntity = await nymph.getEntities({ class: TestModel }, {
861
- type: '|',
862
- lt: [
863
- ['numberString', 30],
864
- ['pickles', 100],
865
- ],
866
- });
867
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
868
- // Retrieving entity by inequality...
869
- resultEntity = await nymph.getEntities({ class: TestModel }, {
870
- type: '|',
871
- lt: [
872
- ['numberString', 31],
873
- ['pickles', 100],
874
- ],
875
- });
876
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
877
- // Retrieving entity by inequality...
878
- resultEntity = await nymph.getEntities({ class: TestModel }, {
879
- type: '|',
880
- lt: [
881
- ['numberString', 29],
882
- ['pickles', 100],
883
- ],
884
- });
885
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
886
- });
887
- it('less than or equal', async () => {
888
- await createTestEntities();
889
- // Retrieving entity by inequality...
890
- let resultEntity = await nymph.getEntities({ class: TestModel }, {
891
- type: '|',
892
- lte: [
893
- ['number', 30],
894
- ['pickles', 100],
895
- ],
896
- });
897
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
898
- // Retrieving entity by inequality...
899
- resultEntity = await nymph.getEntities({ class: TestModel }, {
900
- type: '|',
901
- lte: [
902
- ['number', 31],
903
- ['pickles', 100],
904
- ],
905
- });
906
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
907
- // Retrieving entity by inequality...
908
- resultEntity = await nymph.getEntities({ class: TestModel }, {
909
- type: '|',
910
- lte: [
911
- ['number', 29],
912
- ['pickles', 100],
913
- ],
914
- });
915
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
916
- // Retrieving entity by inequality...
917
- resultEntity = await nymph.getEntities({ class: TestModel }, {
918
- type: '|',
919
- lte: [
920
- ['numberString', 30],
921
- ['pickles', 100],
922
- ],
923
- });
924
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
925
- // Retrieving entity by inequality...
926
- resultEntity = await nymph.getEntities({ class: TestModel }, {
927
- type: '|',
928
- lte: [
929
- ['numberString', 31],
930
- ['pickles', 100],
931
- ],
932
- });
933
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
934
- // Retrieving entity by inequality...
935
- resultEntity = await nymph.getEntities({ class: TestModel }, {
936
- type: '|',
937
- lte: [
938
- ['numberString', 29],
939
- ['pickles', 100],
940
- ],
941
- });
942
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
943
- });
944
- it('not inequality', async () => {
945
- await createTestEntities();
946
- // Retrieving entity by !inequality...
947
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', gte: ['number', 60] });
948
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
949
- });
950
- it('wrong inequality', async () => {
951
- await createTestEntities();
952
- // Testing wrong inequality...
953
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', lte: ['number', 29.99] });
954
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
955
- });
956
- it('greater than cdate', async () => {
957
- await createTestEntities();
958
- // Retrieving entity by time...
959
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gt: ['cdate', (testEntity.cdate ?? 0) - 120] });
960
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
961
- });
962
- it('wrong cdate', async () => {
963
- await createTestEntities();
964
- // Testing wrong time...
965
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gte: ['cdate', (testEntity.cdate ?? 0) + 1] });
966
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
967
- });
968
- it('time selector', async () => {
969
- await createTestEntities();
970
- const referenceEntity = await TestModel.factory(refGuid);
971
- // Retrieving entity by relative time...
972
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['timestamp', null, '-1 day'] });
973
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
974
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
975
- // Retrieving entity by relative time inclusively...
976
- resultEntity = await nymph.getEntities({ class: TestModel }, {
977
- type: '|',
978
- gt: [
979
- ['timestamp', null, '-1 day'],
980
- ['timestamp', null, '+5 days'],
981
- ],
982
- });
983
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
984
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
985
- // Retrieving entity by relative time...
986
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['timestamp', null, '-3 days'] });
987
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
988
- expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
989
- // Retrieving entity by relative time...
990
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['cdate', null, '-1 day'] });
991
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
992
- expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
993
- });
994
- it('wrong time selector', async () => {
995
- await createTestEntities();
996
- const referenceEntity = await TestModel.factory(refGuid);
997
- // Retrieving entity by relative time...
998
- let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gt: ['timestamp', null, '+1 day'] });
999
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1000
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1001
- // Retrieving entity by relative time...
1002
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', lt: ['timestamp', null, '-3 days'] });
1003
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1004
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1005
- // Retrieving entity by relative time...
1006
- resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gt: ['cdate', null, '+1 day'] });
1007
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1008
- expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1009
- });
1010
- it('references', async () => {
1011
- await createTestEntities();
1012
- // Testing referenced entities...
1013
- await testEntity.reference?.$wake();
1014
- expect(testEntity.reference?.test).toEqual('good');
1015
- // Testing referenced entity arrays...
1016
- await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1017
- expect(testEntity.refArray?.[0].test).toEqual('good');
1018
- });
1019
- it('ref', async () => {
1020
- await createTestEntities();
1021
- // Retrieving entity by reference...
1022
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', refGuid] });
1023
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1024
- });
1025
- it('not ref', async () => {
1026
- await createTestEntities();
1027
- // Retrieving entity by !reference...
1028
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', ref: ['reference', guid()] });
1029
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1030
- });
1031
- it('wrong ref', async () => {
1032
- await createTestEntities();
1033
- // Testing wrong reference...
1034
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', guid()] });
1035
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1036
- });
1037
- it('nonexistent ref', async () => {
1038
- await createTestEntities();
1039
- // Testing non-existent reference...
1040
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['pickle', refGuid] });
1041
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1042
- });
1043
- it('inclusive ref', async () => {
1044
- await createTestEntities();
1045
- // Retrieving entity by inclusive reference...
1046
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1047
- type: '|',
1048
- ref: [
1049
- ['reference', refGuid],
1050
- ['reference', guid()],
1051
- ],
1052
- });
1053
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1054
- });
1055
- it('wrong inclusive ref', async () => {
1056
- await createTestEntities();
1057
- // Testing wrong inclusive reference...
1058
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1059
- type: '|',
1060
- ref: [
1061
- ['reference', guid()],
1062
- ['reference', guid()],
1063
- ],
1064
- });
1065
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1066
- });
1067
- it('ref in an array', async () => {
1068
- await createTestEntities();
1069
- // Retrieving entity by array reference...
1070
- const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['refArray', refGuid] });
1071
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1072
- });
1073
- it('wrong ref in an array', async () => {
1074
- await createTestEntities();
1075
- // Testing wrong array reference...
1076
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1077
- type: '&',
1078
- ref: [
1079
- ['refArray', refGuid],
1080
- ['refArray', guid()],
1081
- ],
1082
- });
1083
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1084
- });
1085
- it('logic operations', async () => {
1086
- await createTestEntities();
1087
- // Testing logic operations...
1088
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1089
- type: '&',
1090
- '!ref': [
1091
- ['refArray', guid()],
1092
- ['refArray', guid()],
1093
- ],
1094
- '!lte': ['number', 29.99],
1095
- }, {
1096
- type: '|',
1097
- '!lte': [
1098
- ['number', 29.99],
1099
- ['number', 30],
1100
- ],
1101
- }, {
1102
- type: '!&',
1103
- '!equal': ['string', 'test'],
1104
- '!contain': [
1105
- ['array', 'full'],
1106
- ['array', 'of'],
1107
- ['array', 'values'],
1108
- ['array', 500],
1109
- ['array', { test: true }],
1110
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1111
- ],
1112
- }, {
1113
- type: '!|',
1114
- '!equal': ['string', 'test'],
1115
- contain: [
1116
- ['array', 'full'],
1117
- ['array', 'of'],
1118
- ['array', 'values'],
1119
- ['array', 500],
1120
- ],
1121
- });
1122
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1123
- });
1124
- it('count return', async () => {
1125
- await createTestEntities();
1126
- const result = await nymph.getEntities({ class: TestModel });
1127
- // Testing count return...
1128
- const resultCount = await nymph.getEntities({
1129
- class: TestModel,
1130
- return: 'count',
1131
- });
1132
- expect(resultCount).toBeGreaterThanOrEqual(1);
1133
- expect(resultCount).toEqual(result.length);
1134
- const resultSelectors = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', refGuid] });
1135
- // Testing count return with selectors...
1136
- const resultSelectorsCount = await nymph.getEntities({ class: TestModel, return: 'count' }, { type: '&', ref: ['reference', refGuid] });
1137
- expect(resultSelectorsCount).toBeGreaterThanOrEqual(1);
1138
- expect(resultSelectorsCount).toEqual(resultSelectors.length);
1139
- // Testing count return with limit...
1140
- const resultSelectorsLimit = await nymph.getEntities({
1141
- class: TestModel,
1142
- limit: 1,
1143
- return: 'count',
1144
- });
1145
- expect(resultSelectorsLimit).toEqual(1);
1146
- // Testing count return with limit...
1147
- const resultSelectorsSingle = await nymph.getEntity({
1148
- class: TestModel,
1149
- return: 'count',
1150
- });
1151
- expect(resultSelectorsSingle).toEqual(1);
1152
- // Testing empty count...
1153
- const resultSelectorsEmpty = await nymph.getEntities({ class: TestModel, return: 'count' }, { type: '&', ref: ['reference', guid()] });
1154
- expect(resultSelectorsEmpty).toEqual(0);
1155
- });
1156
- it('guid return', async () => {
1157
- await createTestEntities();
1158
- // Testing guid return using logic operations...
1159
- const resultGuid = await nymph.getEntities({ class: TestModel, return: 'guid' }, {
1160
- type: '&',
1161
- '!ref': [
1162
- ['refArray', guid()],
1163
- ['refArray', guid()],
1164
- ],
1165
- '!lte': ['number', 29.99],
1166
- }, {
1167
- type: '|',
1168
- '!lte': [
1169
- ['number', 29.99],
1170
- ['number', 30],
1171
- ],
1172
- }, {
1173
- type: '!&',
1174
- '!equal': ['string', 'test'],
1175
- '!contain': [
1176
- ['array', 'full'],
1177
- ['array', 'of'],
1178
- ['array', 'values'],
1179
- ['array', 500],
1180
- ['array', { test: true }],
1181
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1182
- ],
1183
- }, {
1184
- type: '!|',
1185
- '!equal': ['string', 'test'],
1186
- contain: [
1187
- ['array', 'full'],
1188
- ['array', 'of'],
1189
- ['array', 'values'],
1190
- ['array', 500],
1191
- ],
1192
- });
1193
- expect(resultGuid.indexOf(testEntity.guid ?? '')).toBeGreaterThan(-1);
1194
- });
1195
- it('object return', async () => {
1196
- await createTestEntities();
1197
- // Testing object return using logic operations...
1198
- const resultObjects = await nymph.getEntities({ class: TestModel, return: 'object' }, {
1199
- type: '&',
1200
- '!ref': [
1201
- ['refArray', guid()],
1202
- ['refArray', guid()],
1203
- ],
1204
- '!lte': ['number', 29.99],
1205
- }, {
1206
- type: '|',
1207
- '!lte': [
1208
- ['number', 29.99],
1209
- ['number', 30],
1210
- ],
1211
- }, {
1212
- type: '!&',
1213
- '!equal': ['string', 'test'],
1214
- '!contain': [
1215
- ['array', 'full'],
1216
- ['array', 'of'],
1217
- ['array', 'values'],
1218
- ['array', 500],
1219
- ['array', { test: true }],
1220
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1221
- ],
1222
- }, {
1223
- type: '!|',
1224
- '!equal': ['string', 'test'],
1225
- contain: [
1226
- ['array', 'full'],
1227
- ['array', 'of'],
1228
- ['array', 'values'],
1229
- ['array', 500],
1230
- ],
1231
- });
1232
- const resultObject = resultObjects.find((entity) => entity.guid === testEntity.guid);
1233
- expect(resultObject).toBeInstanceOf(Object);
1234
- expect(resultObject).not.toBeInstanceOf(TestModel);
1235
- expect(Array.isArray(resultObject?.tags)).toBeTruthy();
1236
- expect(resultObject?.string).toEqual('test');
1237
- });
1238
- it('deep selector', async () => {
1239
- await createTestEntities();
1240
- // Testing deep selectors...
1241
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1242
- type: '&',
1243
- '!ref': [
1244
- ['refArray', guid()],
1245
- ['refArray', guid()],
1246
- ],
1247
- '!lte': ['number', 29.99],
1248
- }, {
1249
- type: '&',
1250
- selector: [
1251
- {
1252
- type: '|',
1253
- '!lte': [
1254
- ['number', 29.99],
1255
- ['number', 30],
1256
- ],
1257
- },
1258
- {
1259
- type: '!&',
1260
- '!equal': ['string', 'test'],
1261
- '!contain': [
1262
- ['array', 'full'],
1263
- ['array', 'of'],
1264
- ['array', 'values'],
1265
- ['array', 500],
1266
- ['array', { test: true }],
1267
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1268
- ],
1269
- },
1270
- {
1271
- type: '!|',
1272
- '!equal': ['string', 'test'],
1273
- contain: [
1274
- ['array', 'full'],
1275
- ['array', 'of'],
1276
- ['array', 'values'],
1277
- ['array', 500],
1278
- ],
1279
- },
1280
- ],
1281
- });
1282
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1283
- const resultEntity2 = await nymph.getEntities({ class: TestModel }, {
1284
- type: '&',
1285
- '!ref': [
1286
- ['refArray', guid()],
1287
- ['refArray', guid()],
1288
- ],
1289
- '!lte': ['number', 29.99],
1290
- }, {
1291
- type: '|',
1292
- selector: [
1293
- {
1294
- type: '&',
1295
- '!lte': [
1296
- ['number', 29.99],
1297
- ['number', 30],
1298
- ],
1299
- },
1300
- {
1301
- type: '!&',
1302
- '!equal': ['string', 'test'],
1303
- '!contain': [
1304
- ['array', 'full'],
1305
- ['array', 'of'],
1306
- ['array', 'values'],
1307
- ['array', 500],
1308
- ['array', { test: true }],
1309
- ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1310
- ],
1311
- },
1312
- {
1313
- type: '&',
1314
- '!equal': ['string', 'test'],
1315
- contain: [
1316
- ['array', 'full'],
1317
- ['array', 'of'],
1318
- ['array', 'values'],
1319
- ['array', 500],
306
+ it('guid and tags', async () => {
307
+ await createTestEntities();
308
+ // Retrieving entity by GUID and tags...
309
+ const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid, tag: 'test' });
310
+ expect(testEntity.$is(resultEntity)).toEqual(true);
311
+ });
312
+ it('or selector', async () => {
313
+ await createTestEntities();
314
+ // Retrieving entity by GUID and tags...
315
+ const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '|', guid: [testGuid, guid()] });
316
+ expect(testEntity.$is(resultEntity)).toEqual(true);
317
+ });
318
+ it('wrong or selector', async () => {
319
+ await createTestEntities();
320
+ // Retrieving entity by GUID and tags...
321
+ const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '|', guid: [guid(), guid()] });
322
+ expect(testEntity.$is(resultEntity)).toEqual(false);
323
+ });
324
+ it('not guid', async () => {
325
+ await createTestEntities();
326
+ // Retrieving entity by !GUID...
327
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', '!guid': guid(), tag: 'test' });
328
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
329
+ });
330
+ it('not tags', async () => {
331
+ await createTestEntities();
332
+ // Retrieving entity by !tags...
333
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', guid: testGuid, '!tag': ['barbecue', 'pickles'] });
334
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
335
+ });
336
+ it('guid and wrong tags', async () => {
337
+ await createTestEntities();
338
+ // Testing GUID and wrong tags...
339
+ const resultEntity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid, tag: ['pickles'] });
340
+ expect(resultEntity).toBeNull();
341
+ });
342
+ it('tags', async () => {
343
+ await createTestEntities();
344
+ // Retrieving entity by tags...
345
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' });
346
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
347
+ });
348
+ it('wrong tags', async () => {
349
+ await createTestEntities();
350
+ // Testing wrong tags...
351
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles' });
352
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
353
+ });
354
+ it('inclusive tags', async () => {
355
+ await createTestEntities();
356
+ // Retrieving entity by tags inclusively...
357
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '|', tag: ['pickles', 'test', 'barbecue'] });
358
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
359
+ });
360
+ it('wrong inclusive tags', async () => {
361
+ await createTestEntities();
362
+ // Testing wrong inclusive tags...
363
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '|', tag: ['pickles', 'barbecue'] });
364
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
365
+ });
366
+ it('mixed tags', async () => {
367
+ await createTestEntities();
368
+ // Retrieving entity by mixed tags...
369
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', tag: ['pickles', 'test', 'barbecue'] });
370
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
371
+ });
372
+ it('wrong inclusive mixed tags', async () => {
373
+ await createTestEntities();
374
+ // Testing wrong inclusive mixed tags...
375
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', tag: ['pickles', 'barbecue'] });
376
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
377
+ });
378
+ it('wrong exclusive mixed tags', async () => {
379
+ await createTestEntities();
380
+ // Testing wrong exclusive mixed tags...
381
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles' }, { type: '|', tag: ['test', 'barbecue'] });
382
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
383
+ });
384
+ it('defined', async () => {
385
+ await createTestEntities();
386
+ // Retrieving entity by defined...
387
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', defined: 'string' });
388
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
389
+ });
390
+ it('not defined', async () => {
391
+ await createTestEntities();
392
+ // Retrieving entity by !defined...
393
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!defined': 'pickles' });
394
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
395
+ });
396
+ it('defined in a not and clause', async () => {
397
+ await createTestEntities();
398
+ // Retrieving entity by defined in not and clause...
399
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '!&', defined: 'pickles' }, { type: '&', tag: 'test' });
400
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
401
+ });
402
+ it('equal', async () => {
403
+ await createTestEntities();
404
+ // Retrieving entity by equal...
405
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['string', 'test'] });
406
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
407
+ // Retrieving entity by equal...
408
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['null', null] });
409
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
410
+ // Retrieving entity by equal...
411
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['boolean', true] });
412
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
413
+ // Retrieving entity by equal...
414
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', equal: ['number', 30] });
415
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
416
+ // Retrieving entity by equal...
417
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
418
+ type: '&',
419
+ equal: [
420
+ 'array',
421
+ [
422
+ 'full',
423
+ 'of',
424
+ 'values',
425
+ 500,
426
+ { test: true },
427
+ { nullbyte: '\\\x00\u0000 \x00' },
1320
428
  ],
1321
- },
1322
- ],
1323
- });
1324
- expect(testEntity.$inArray(resultEntity2)).toEqual(true);
1325
- const resultEntity3 = await nymph.getEntities({ class: TestModel }, {
1326
- type: '|',
1327
- selector: [
1328
- {
1329
- type: '&',
1330
- '!ref': ['refArray', guid()],
1331
- '!lte': ['number', 29.99],
1332
- },
1333
- { type: '&', gte: ['number', 16000] },
1334
- ],
1335
- });
1336
- expect(testEntity.$inArray(resultEntity3)).toEqual(true);
1337
- const resultEntity4 = await nymph.getEntities({ class: TestModel }, {
1338
- type: '|',
1339
- selector: [
1340
- {
1341
- type: '&',
1342
- '!ref': ['refArray', guid()],
1343
- '!lte': ['number', 29.99],
1344
- },
1345
- {
1346
- type: '&',
1347
- selector: {
429
+ ],
430
+ });
431
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
432
+ // Retrieving entity by equal...
433
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
434
+ type: '&',
435
+ equal: ['match', matchValue],
436
+ });
437
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
438
+ });
439
+ it('not equal', async () => {
440
+ await createTestEntities();
441
+ const referenceEntity = await TestModel.factory(refGuid);
442
+ expect(referenceEntity.guid).toEqual(refGuid);
443
+ // Retrieving entity by !equal...
444
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!equal': ['string', 'wrong'] });
445
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
446
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
447
+ });
448
+ it('like', async () => {
449
+ await createTestEntities();
450
+ // Retrieving entity by like...
451
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', like: ['string', 't_s%'] });
452
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
453
+ });
454
+ it('not like', async () => {
455
+ await createTestEntities();
456
+ const referenceEntity = await TestModel.factory(refGuid);
457
+ expect(referenceEntity.guid).toEqual(refGuid);
458
+ // Retrieving entity by !like...
459
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!like': ['string', 'wr_n%'] });
460
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
461
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
462
+ });
463
+ it('ilike', async () => {
464
+ await createTestEntities();
465
+ // Retrieving entity by ilike...
466
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ilike: ['string', 'T_s%'] });
467
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
468
+ });
469
+ it('not ilike', async () => {
470
+ await createTestEntities();
471
+ const referenceEntity = await TestModel.factory(refGuid);
472
+ expect(referenceEntity.guid).toEqual(refGuid);
473
+ // Retrieving entity by !ilike...
474
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', '!ilike': ['string', 'wr_n%'] });
475
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
476
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
477
+ });
478
+ it('like with wrong case', async () => {
479
+ await createTestEntities();
480
+ // Retrieving entity by like...
481
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', like: ['string', 'T_s%'] });
482
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
483
+ });
484
+ it('tags and equal', async () => {
485
+ await createTestEntities();
486
+ // Retrieving entity by tags and equal...
487
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', equal: ['string', 'test'] });
488
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
489
+ });
490
+ it('wrong tags right equal', async () => {
491
+ await createTestEntities();
492
+ // Testing wrong tags and right equal...
493
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles', equal: ['string', 'test'] });
494
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
495
+ });
496
+ it('right tags wrong equal', async () => {
497
+ await createTestEntities();
498
+ // Testing right tags and wrong equal...
499
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', equal: ['string', 'pickles'] });
500
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
501
+ });
502
+ it('wrong tags wrong equal', async () => {
503
+ await createTestEntities();
504
+ // Testing wrong tags and wrong equal...
505
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickles', equal: ['string', 'pickles'] });
506
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
507
+ });
508
+ it('contain', async () => {
509
+ await createTestEntities();
510
+ // Retrieving entity by contain...
511
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', 'values'] });
512
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
513
+ // Retrieving entity by contain...
514
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', 500] });
515
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
516
+ // Retrieving entity by contain...
517
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', { test: true }] });
518
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
519
+ });
520
+ it('not contain', async () => {
521
+ await createTestEntities();
522
+ // Retrieving entity by !contain...
523
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', contain: ['array', 'pickles'] });
524
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
525
+ });
526
+ it('wrong contain', async () => {
527
+ await createTestEntities();
528
+ // Testing wrong contain...
529
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['array', 'pickles'] });
530
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
531
+ // Testing wrong contain...
532
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', contain: ['string', 'pickles'] });
533
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
534
+ });
535
+ it('match', async () => {
536
+ await createTestEntities();
537
+ // Retrieving entity by regex match...
538
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', match: ['match', '.*'] });
539
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
540
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', match: ['match', 'Edward McCheese'] });
541
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
542
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, {
543
+ type: '|',
544
+ match: [
545
+ ['string', '[0-9]'],
546
+ ['match', 'Edward McCheese'],
547
+ ],
548
+ });
549
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
550
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
551
+ type: '&',
552
+ tag: 'test',
553
+ match: ['match', '[-a-zA-Z0-9+_]+@[-a-zA-Z0-9_]+.[-a-zA-Z0-9_]{2,4}'],
554
+ });
555
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
556
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
557
+ type: '&',
558
+ tag: 'test',
559
+ match: ['match', '\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}'],
560
+ });
561
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
562
+ });
563
+ it('imatch', async () => {
564
+ await createTestEntities();
565
+ // Retrieving entity by regex match...
566
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', imatch: ['match', 'edward mccheese'] });
567
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
568
+ });
569
+ it('wrong match', async () => {
570
+ await createTestEntities();
571
+ // Testing wrong regex match...
572
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', match: ['match', '='] });
573
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
574
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickle', match: ['match', '.*'] });
575
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
576
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
577
+ type: '|',
578
+ match: [
579
+ ['string', '[0-9]'],
580
+ ['match', ',,'],
581
+ ],
582
+ });
583
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
584
+ });
585
+ it('match wrong case', async () => {
586
+ await createTestEntities();
587
+ // Retrieving entity by regex match...
588
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', match: ['match', 'edward mccheese'] });
589
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
590
+ });
591
+ it('match and equal inclusive', async () => {
592
+ await createTestEntities();
593
+ // Retrieving entity by regex + equal inclusively...
594
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', equal: ['string', 'pickles'], match: ['string', 'test'] });
595
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
596
+ });
597
+ it('basic search', async () => {
598
+ await createTestEntities();
599
+ // Retrieving entity by full text search...
600
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
601
+ type: '&',
602
+ tag: 'test',
603
+ search: [
604
+ 'search',
605
+ 'Declaration of the thirteen united States of America',
606
+ ],
607
+ });
608
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
609
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, {
610
+ type: '|',
611
+ search: [
612
+ ['string', 'pickle'],
613
+ ['search', 'Declaration of the thirteen united States of America'],
614
+ ],
615
+ });
616
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
617
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
618
+ type: '&',
619
+ tag: 'test',
620
+ search: ['search', 'July 4, 1776'],
621
+ });
622
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
623
+ });
624
+ it('or search', async () => {
625
+ await createTestEntities();
626
+ // Retrieving entity by full text search...
627
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
628
+ type: '&',
629
+ tag: 'test',
630
+ search: ['search', 'Declaration or pickles'],
631
+ });
632
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
633
+ });
634
+ it('series search', async () => {
635
+ await createTestEntities();
636
+ // Retrieving entity by full text search...
637
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
638
+ type: '&',
639
+ tag: 'test',
640
+ search: ['search', '"excited domestic insurrections"'],
641
+ });
642
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
643
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
644
+ type: '&',
645
+ tag: 'test',
646
+ search: ['search', "'exciting domestic insurrected'"],
647
+ });
648
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
649
+ });
650
+ it('negated search', async () => {
651
+ await createTestEntities();
652
+ // Retrieving entity by full text search...
653
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
654
+ type: '&',
655
+ tag: 'test',
656
+ search: ['search', '-pickle'],
657
+ });
658
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
659
+ });
660
+ it('combined search', async () => {
661
+ await createTestEntities();
662
+ // Retrieving entity by full text search...
663
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
664
+ type: '&',
665
+ tag: 'test',
666
+ search: ['search', 'Declaration -pickle'],
667
+ });
668
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
669
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
670
+ type: '&',
671
+ tag: 'test',
672
+ search: ['search', 'Declaration "General Congress"'],
673
+ });
674
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
675
+ });
676
+ it('wrong search', async () => {
677
+ await createTestEntities();
678
+ // Testing wrong search...
679
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', search: ['search', 'pickles'] });
680
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
681
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'pickle', search: ['search', 'Declaration'] });
682
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
683
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
684
+ type: '|',
685
+ search: [
686
+ ['string', 'pickle'],
687
+ ['search', 'Hawaii'],
688
+ ],
689
+ });
690
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
691
+ });
692
+ it('search with only stop words', async () => {
693
+ await createTestEntities();
694
+ // Testing wrong search...
695
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', search: ['search', 'i am'] });
696
+ expect(resultEntity).toEqual([]);
697
+ });
698
+ it('search must be case insensitive', async () => {
699
+ await createTestEntities();
700
+ // Retrieving entity by full text search...
701
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
702
+ type: '&',
703
+ tag: 'test',
704
+ search: [
705
+ 'search',
706
+ 'DECLARATION OF THE THIRTEEN UNITED STATES OF AMERICA',
707
+ ],
708
+ });
709
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
710
+ });
711
+ it('search and equal inclusive', async () => {
712
+ await createTestEntities();
713
+ // Retrieving entity by fts + equal inclusively...
714
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '|', equal: ['string', 'pickles'], search: ['string', 'test'] });
715
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
716
+ });
717
+ it('greater than', async () => {
718
+ await createTestEntities();
719
+ // Retrieving entity by inequality...
720
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
721
+ type: '|',
722
+ gt: [
723
+ ['number', 30],
724
+ ['pickles', 100],
725
+ ],
726
+ });
727
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
728
+ // Retrieving entity by inequality...
729
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
730
+ type: '|',
731
+ gt: [
732
+ ['number', 31],
733
+ ['pickles', 100],
734
+ ],
735
+ });
736
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
737
+ // Retrieving entity by inequality...
738
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
739
+ type: '|',
740
+ gt: [
741
+ ['number', 29],
742
+ ['pickles', 100],
743
+ ],
744
+ });
745
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
746
+ // Retrieving entity by inequality...
747
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
748
+ type: '|',
749
+ gt: [
750
+ ['numberString', 30],
751
+ ['pickles', 100],
752
+ ],
753
+ });
754
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
755
+ // Retrieving entity by inequality...
756
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
757
+ type: '|',
758
+ gt: [
759
+ ['numberString', 31],
760
+ ['pickles', 100],
761
+ ],
762
+ });
763
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
764
+ // Retrieving entity by inequality...
765
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
766
+ type: '|',
767
+ gt: [
768
+ ['numberString', 29],
769
+ ['pickles', 100],
770
+ ],
771
+ });
772
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
773
+ });
774
+ it('greater than or equal', async () => {
775
+ await createTestEntities();
776
+ // Retrieving entity by inequality...
777
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
778
+ type: '|',
779
+ gte: [
780
+ ['number', 30],
781
+ ['pickles', 100],
782
+ ],
783
+ });
784
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
785
+ // Retrieving entity by inequality...
786
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
787
+ type: '|',
788
+ gte: [
789
+ ['number', 31],
790
+ ['pickles', 100],
791
+ ],
792
+ });
793
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
794
+ // Retrieving entity by inequality...
795
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
796
+ type: '|',
797
+ gte: [
798
+ ['number', 29],
799
+ ['pickles', 100],
800
+ ],
801
+ });
802
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
803
+ // Retrieving entity by inequality...
804
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
805
+ type: '|',
806
+ gte: [
807
+ ['numberString', 30],
808
+ ['pickles', 100],
809
+ ],
810
+ });
811
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
812
+ // Retrieving entity by inequality...
813
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
814
+ type: '|',
815
+ gte: [
816
+ ['numberString', 31],
817
+ ['pickles', 100],
818
+ ],
819
+ });
820
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
821
+ // Retrieving entity by inequality...
822
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
823
+ type: '|',
824
+ gte: [
825
+ ['numberString', 29],
826
+ ['pickles', 100],
827
+ ],
828
+ });
829
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
830
+ });
831
+ it('less than', async () => {
832
+ await createTestEntities();
833
+ // Retrieving entity by inequality...
834
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
835
+ type: '|',
836
+ lt: [
837
+ ['number', 30],
838
+ ['pickles', 100],
839
+ ],
840
+ });
841
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
842
+ // Retrieving entity by inequality...
843
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
844
+ type: '|',
845
+ lt: [
846
+ ['number', 31],
847
+ ['pickles', 100],
848
+ ],
849
+ });
850
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
851
+ // Retrieving entity by inequality...
852
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
853
+ type: '|',
854
+ lt: [
855
+ ['number', 29],
856
+ ['pickles', 100],
857
+ ],
858
+ });
859
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
860
+ // Retrieving entity by inequality...
861
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
862
+ type: '|',
863
+ lt: [
864
+ ['numberString', 30],
865
+ ['pickles', 100],
866
+ ],
867
+ });
868
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
869
+ // Retrieving entity by inequality...
870
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
871
+ type: '|',
872
+ lt: [
873
+ ['numberString', 31],
874
+ ['pickles', 100],
875
+ ],
876
+ });
877
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
878
+ // Retrieving entity by inequality...
879
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
880
+ type: '|',
881
+ lt: [
882
+ ['numberString', 29],
883
+ ['pickles', 100],
884
+ ],
885
+ });
886
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
887
+ });
888
+ it('less than or equal', async () => {
889
+ await createTestEntities();
890
+ // Retrieving entity by inequality...
891
+ let resultEntity = await nymph.getEntities({ class: TestModel }, {
892
+ type: '|',
893
+ lte: [
894
+ ['number', 30],
895
+ ['pickles', 100],
896
+ ],
897
+ });
898
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
899
+ // Retrieving entity by inequality...
900
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
901
+ type: '|',
902
+ lte: [
903
+ ['number', 31],
904
+ ['pickles', 100],
905
+ ],
906
+ });
907
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
908
+ // Retrieving entity by inequality...
909
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
910
+ type: '|',
911
+ lte: [
912
+ ['number', 29],
913
+ ['pickles', 100],
914
+ ],
915
+ });
916
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
917
+ // Retrieving entity by inequality...
918
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
919
+ type: '|',
920
+ lte: [
921
+ ['numberString', 30],
922
+ ['pickles', 100],
923
+ ],
924
+ });
925
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
926
+ // Retrieving entity by inequality...
927
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
928
+ type: '|',
929
+ lte: [
930
+ ['numberString', 31],
931
+ ['pickles', 100],
932
+ ],
933
+ });
934
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
935
+ // Retrieving entity by inequality...
936
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
937
+ type: '|',
938
+ lte: [
939
+ ['numberString', 29],
940
+ ['pickles', 100],
941
+ ],
942
+ });
943
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
944
+ });
945
+ it('not inequality', async () => {
946
+ await createTestEntities();
947
+ // Retrieving entity by !inequality...
948
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', gte: ['number', 60] });
949
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
950
+ });
951
+ it('wrong inequality', async () => {
952
+ await createTestEntities();
953
+ // Testing wrong inequality...
954
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', lte: ['number', 29.99] });
955
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
956
+ });
957
+ it('greater than cdate', async () => {
958
+ await createTestEntities();
959
+ // Retrieving entity by time...
960
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
961
+ type: '&',
962
+ tag: 'test',
963
+ gt: ['cdate', (testEntity.cdate ?? 0) - 120],
964
+ });
965
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
966
+ });
967
+ it('wrong cdate', async () => {
968
+ await createTestEntities();
969
+ // Testing wrong time...
970
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gte: ['cdate', (testEntity.cdate ?? 0) + 1] });
971
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
972
+ });
973
+ it('time selector', async () => {
974
+ await createTestEntities();
975
+ const referenceEntity = await TestModel.factory(refGuid);
976
+ // Retrieving entity by relative time...
977
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['timestamp', null, '-1 day'] });
978
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
979
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
980
+ // Retrieving entity by relative time inclusively...
981
+ resultEntity = await nymph.getEntities({ class: TestModel }, {
982
+ type: '|',
983
+ gt: [
984
+ ['timestamp', null, '-1 day'],
985
+ ['timestamp', null, '+5 days'],
986
+ ],
987
+ });
988
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
989
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
990
+ // Retrieving entity by relative time...
991
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['timestamp', null, '-3 days'] });
992
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
993
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
994
+ // Retrieving entity by relative time...
995
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', gt: ['cdate', null, '-1 day'] });
996
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
997
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(true);
998
+ });
999
+ it('wrong time selector', async () => {
1000
+ await createTestEntities();
1001
+ const referenceEntity = await TestModel.factory(refGuid);
1002
+ // Retrieving entity by relative time...
1003
+ let resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gt: ['timestamp', null, '+1 day'] });
1004
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1005
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1006
+ // Retrieving entity by relative time...
1007
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', lt: ['timestamp', null, '-3 days'] });
1008
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1009
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1010
+ // Retrieving entity by relative time...
1011
+ resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test', gt: ['cdate', null, '+1 day'] });
1012
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1013
+ expect(referenceEntity.$inArray(resultEntity)).toEqual(false);
1014
+ });
1015
+ it('references', async () => {
1016
+ await createTestEntities();
1017
+ // Testing referenced entities...
1018
+ await testEntity.reference?.$wake();
1019
+ expect(testEntity.reference?.test).toEqual('good');
1020
+ // Testing referenced entity arrays...
1021
+ await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1022
+ expect(testEntity.refArray?.[0].test).toEqual('good');
1023
+ });
1024
+ it('ref', async () => {
1025
+ await createTestEntities();
1026
+ // Retrieving entity by reference...
1027
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', refGuid] });
1028
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1029
+ });
1030
+ it('not ref', async () => {
1031
+ await createTestEntities();
1032
+ // Retrieving entity by !reference...
1033
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', tag: 'test' }, { type: '!&', ref: ['reference', guid()] });
1034
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1035
+ });
1036
+ it('wrong ref', async () => {
1037
+ await createTestEntities();
1038
+ // Testing wrong reference...
1039
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', guid()] });
1040
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1041
+ });
1042
+ it('nonexistent ref', async () => {
1043
+ await createTestEntities();
1044
+ // Testing non-existent reference...
1045
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['pickle', refGuid] });
1046
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1047
+ });
1048
+ it('inclusive ref', async () => {
1049
+ await createTestEntities();
1050
+ // Retrieving entity by inclusive reference...
1051
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1052
+ type: '|',
1053
+ ref: [
1054
+ ['reference', refGuid],
1055
+ ['reference', guid()],
1056
+ ],
1057
+ });
1058
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1059
+ });
1060
+ it('wrong inclusive ref', async () => {
1061
+ await createTestEntities();
1062
+ // Testing wrong inclusive reference...
1063
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1064
+ type: '|',
1065
+ ref: [
1066
+ ['reference', guid()],
1067
+ ['reference', guid()],
1068
+ ],
1069
+ });
1070
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1071
+ });
1072
+ it('ref in an array', async () => {
1073
+ await createTestEntities();
1074
+ // Retrieving entity by array reference...
1075
+ const resultEntity = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['refArray', refGuid] });
1076
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1077
+ });
1078
+ it('wrong ref in an array', async () => {
1079
+ await createTestEntities();
1080
+ // Testing wrong array reference...
1081
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1082
+ type: '&',
1083
+ ref: [
1084
+ ['refArray', refGuid],
1085
+ ['refArray', guid()],
1086
+ ],
1087
+ });
1088
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1089
+ });
1090
+ it('logic operations', async () => {
1091
+ await createTestEntities();
1092
+ // Testing logic operations...
1093
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1094
+ type: '&',
1095
+ '!ref': [
1096
+ ['refArray', guid()],
1097
+ ['refArray', guid()],
1098
+ ],
1099
+ '!lte': ['number', 29.99],
1100
+ }, {
1101
+ type: '|',
1102
+ '!lte': [
1103
+ ['number', 29.99],
1104
+ ['number', 30],
1105
+ ],
1106
+ }, {
1107
+ type: '!&',
1108
+ '!equal': ['string', 'test'],
1109
+ '!contain': [
1110
+ ['array', 'full'],
1111
+ ['array', 'of'],
1112
+ ['array', 'values'],
1113
+ ['array', 500],
1114
+ ['array', { test: true }],
1115
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1116
+ ],
1117
+ }, {
1118
+ type: '!|',
1119
+ '!equal': ['string', 'test'],
1120
+ contain: [
1121
+ ['array', 'full'],
1122
+ ['array', 'of'],
1123
+ ['array', 'values'],
1124
+ ['array', 500],
1125
+ ],
1126
+ });
1127
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1128
+ });
1129
+ it('count return', async () => {
1130
+ await createTestEntities();
1131
+ const result = await nymph.getEntities({ class: TestModel });
1132
+ // Testing count return...
1133
+ const resultCount = await nymph.getEntities({
1134
+ class: TestModel,
1135
+ return: 'count',
1136
+ });
1137
+ expect(resultCount).toBeGreaterThanOrEqual(1);
1138
+ expect(resultCount).toEqual(result.length);
1139
+ const resultSelectors = await nymph.getEntities({ class: TestModel }, { type: '&', ref: ['reference', refGuid] });
1140
+ // Testing count return with selectors...
1141
+ const resultSelectorsCount = await nymph.getEntities({ class: TestModel, return: 'count' }, { type: '&', ref: ['reference', refGuid] });
1142
+ expect(resultSelectorsCount).toBeGreaterThanOrEqual(1);
1143
+ expect(resultSelectorsCount).toEqual(resultSelectors.length);
1144
+ // Testing count return with limit...
1145
+ const resultSelectorsLimit = await nymph.getEntities({
1146
+ class: TestModel,
1147
+ limit: 1,
1148
+ return: 'count',
1149
+ });
1150
+ expect(resultSelectorsLimit).toEqual(1);
1151
+ // Testing count return with limit...
1152
+ const resultSelectorsSingle = await nymph.getEntity({
1153
+ class: TestModel,
1154
+ return: 'count',
1155
+ });
1156
+ expect(resultSelectorsSingle).toEqual(1);
1157
+ // Testing empty count...
1158
+ const resultSelectorsEmpty = await nymph.getEntities({ class: TestModel, return: 'count' }, { type: '&', ref: ['reference', guid()] });
1159
+ expect(resultSelectorsEmpty).toEqual(0);
1160
+ });
1161
+ it('guid return', async () => {
1162
+ await createTestEntities();
1163
+ // Testing guid return using logic operations...
1164
+ const resultGuid = await nymph.getEntities({ class: TestModel, return: 'guid' }, {
1165
+ type: '&',
1166
+ '!ref': [
1167
+ ['refArray', guid()],
1168
+ ['refArray', guid()],
1169
+ ],
1170
+ '!lte': ['number', 29.99],
1171
+ }, {
1172
+ type: '|',
1173
+ '!lte': [
1174
+ ['number', 29.99],
1175
+ ['number', 30],
1176
+ ],
1177
+ }, {
1178
+ type: '!&',
1179
+ '!equal': ['string', 'test'],
1180
+ '!contain': [
1181
+ ['array', 'full'],
1182
+ ['array', 'of'],
1183
+ ['array', 'values'],
1184
+ ['array', 500],
1185
+ ['array', { test: true }],
1186
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1187
+ ],
1188
+ }, {
1189
+ type: '!|',
1190
+ '!equal': ['string', 'test'],
1191
+ contain: [
1192
+ ['array', 'full'],
1193
+ ['array', 'of'],
1194
+ ['array', 'values'],
1195
+ ['array', 500],
1196
+ ],
1197
+ });
1198
+ expect(resultGuid.indexOf(testEntity.guid ?? '')).toBeGreaterThan(-1);
1199
+ });
1200
+ it('object return', async () => {
1201
+ await createTestEntities();
1202
+ // Testing object return using logic operations...
1203
+ const resultObjects = await nymph.getEntities({ class: TestModel, return: 'object' }, {
1204
+ type: '&',
1205
+ '!ref': [
1206
+ ['refArray', guid()],
1207
+ ['refArray', guid()],
1208
+ ],
1209
+ '!lte': ['number', 29.99],
1210
+ }, {
1211
+ type: '|',
1212
+ '!lte': [
1213
+ ['number', 29.99],
1214
+ ['number', 30],
1215
+ ],
1216
+ }, {
1217
+ type: '!&',
1218
+ '!equal': ['string', 'test'],
1219
+ '!contain': [
1220
+ ['array', 'full'],
1221
+ ['array', 'of'],
1222
+ ['array', 'values'],
1223
+ ['array', 500],
1224
+ ['array', { test: true }],
1225
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1226
+ ],
1227
+ }, {
1228
+ type: '!|',
1229
+ '!equal': ['string', 'test'],
1230
+ contain: [
1231
+ ['array', 'full'],
1232
+ ['array', 'of'],
1233
+ ['array', 'values'],
1234
+ ['array', 500],
1235
+ ],
1236
+ });
1237
+ const resultObject = resultObjects.find((entity) => entity.guid === testEntity.guid);
1238
+ expect(resultObject).toBeInstanceOf(Object);
1239
+ expect(resultObject).not.toBeInstanceOf(TestModel);
1240
+ expect(Array.isArray(resultObject?.tags)).toBeTruthy();
1241
+ expect(resultObject?.string).toEqual('test');
1242
+ });
1243
+ it('deep selector', async () => {
1244
+ await createTestEntities();
1245
+ // Testing deep selectors...
1246
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1247
+ type: '&',
1248
+ '!ref': [
1249
+ ['refArray', guid()],
1250
+ ['refArray', guid()],
1251
+ ],
1252
+ '!lte': ['number', 29.99],
1253
+ }, {
1254
+ type: '&',
1255
+ selector: [
1256
+ {
1257
+ type: '|',
1258
+ '!lte': [
1259
+ ['number', 29.99],
1260
+ ['number', 30],
1261
+ ],
1262
+ },
1263
+ {
1264
+ type: '!&',
1265
+ '!equal': ['string', 'test'],
1266
+ '!contain': [
1267
+ ['array', 'full'],
1268
+ ['array', 'of'],
1269
+ ['array', 'values'],
1270
+ ['array', 500],
1271
+ ['array', { test: true }],
1272
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1273
+ ],
1274
+ },
1275
+ {
1276
+ type: '!|',
1277
+ '!equal': ['string', 'test'],
1278
+ contain: [
1279
+ ['array', 'full'],
1280
+ ['array', 'of'],
1281
+ ['array', 'values'],
1282
+ ['array', 500],
1283
+ ],
1284
+ },
1285
+ ],
1286
+ });
1287
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1288
+ const resultEntity2 = await nymph.getEntities({ class: TestModel }, {
1289
+ type: '&',
1290
+ '!ref': [
1291
+ ['refArray', guid()],
1292
+ ['refArray', guid()],
1293
+ ],
1294
+ '!lte': ['number', 29.99],
1295
+ }, {
1296
+ type: '|',
1297
+ selector: [
1298
+ {
1299
+ type: '&',
1300
+ '!lte': [
1301
+ ['number', 29.99],
1302
+ ['number', 30],
1303
+ ],
1304
+ },
1305
+ {
1306
+ type: '!&',
1307
+ '!equal': ['string', 'test'],
1308
+ '!contain': [
1309
+ ['array', 'full'],
1310
+ ['array', 'of'],
1311
+ ['array', 'values'],
1312
+ ['array', 500],
1313
+ ['array', { test: true }],
1314
+ ['array', { nullbyte: '\\\x00\u0000 \x00' }],
1315
+ ],
1316
+ },
1317
+ {
1318
+ type: '&',
1319
+ '!equal': ['string', 'test'],
1320
+ contain: [
1321
+ ['array', 'full'],
1322
+ ['array', 'of'],
1323
+ ['array', 'values'],
1324
+ ['array', 500],
1325
+ ],
1326
+ },
1327
+ ],
1328
+ });
1329
+ expect(testEntity.$inArray(resultEntity2)).toEqual(true);
1330
+ const resultEntity3 = await nymph.getEntities({ class: TestModel }, {
1331
+ type: '|',
1332
+ selector: [
1333
+ {
1334
+ type: '&',
1335
+ '!ref': ['refArray', guid()],
1336
+ '!lte': ['number', 29.99],
1337
+ },
1338
+ { type: '&', gte: ['number', 16000] },
1339
+ ],
1340
+ });
1341
+ expect(testEntity.$inArray(resultEntity3)).toEqual(true);
1342
+ const resultEntity4 = await nymph.getEntities({ class: TestModel }, {
1343
+ type: '|',
1344
+ selector: [
1345
+ {
1346
+ type: '&',
1347
+ '!ref': ['refArray', guid()],
1348
+ '!lte': ['number', 29.99],
1349
+ },
1350
+ {
1348
1351
  type: '&',
1349
- selector: { type: '&', gte: ['number', 16000] },
1352
+ selector: {
1353
+ type: '&',
1354
+ selector: { type: '&', gte: ['number', 16000] },
1355
+ },
1350
1356
  },
1351
- },
1352
- ],
1357
+ ],
1358
+ });
1359
+ expect(testEntity.$inArray(resultEntity4)).toEqual(true);
1353
1360
  });
1354
- expect(testEntity.$inArray(resultEntity4)).toEqual(true);
1355
- });
1356
- it('wrong deep selector', async () => {
1357
- // Testing wrong deep selectors...
1358
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1359
- type: '&',
1360
- selector: [
1361
- {
1362
- type: '&',
1363
- '!ref': ['refArray', guid()],
1364
- '!lte': ['number', 29.99],
1365
- },
1366
- { type: '&', gte: ['number', 16000] },
1367
- ],
1361
+ it('wrong deep selector', async () => {
1362
+ // Testing wrong deep selectors...
1363
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1364
+ type: '&',
1365
+ selector: [
1366
+ {
1367
+ type: '&',
1368
+ '!ref': ['refArray', guid()],
1369
+ '!lte': ['number', 29.99],
1370
+ },
1371
+ { type: '&', gte: ['number', 16000] },
1372
+ ],
1373
+ });
1374
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1368
1375
  });
1369
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1370
- });
1371
- it('qref', async () => {
1372
- await createTestEntities();
1373
- // Retrieving entity by qref...
1374
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1375
- type: '&',
1376
- qref: [
1377
- 'reference',
1378
- [{ class: TestModel }, { type: '&', equal: ['test', 'good'] }],
1379
- ],
1380
- });
1381
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1382
- });
1383
- it('not qref', async () => {
1384
- await createTestEntities();
1385
- // Retrieving entity by !qref...
1386
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1387
- type: '&',
1388
- '!qref': [
1389
- 'reference',
1390
- [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
1391
- ],
1392
- });
1393
- expect(testEntity.$inArray(resultEntity)).toEqual(true);
1394
- });
1395
- it('wrong qref class', async () => {
1396
- await createTestEntities();
1397
- // Testing wrong qref...
1398
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1399
- type: '&',
1400
- qref: [
1401
- 'reference',
1402
- [{ class: TestBModel }, { type: '&', equal: ['test', 'good'] }],
1403
- ],
1404
- });
1405
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1406
- });
1407
- it('wrong qref data', async () => {
1408
- await createTestEntities();
1409
- // Testing wrong qref...
1410
- const resultEntity = await nymph.getEntities({ class: TestModel }, {
1411
- type: '&',
1412
- qref: [
1413
- 'reference',
1414
- [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
1415
- ],
1416
- });
1417
- expect(testEntity.$inArray(resultEntity)).toEqual(false);
1418
- });
1419
- it('cdate and mdate sort option', async () => {
1420
- await createMultipleTestEntities();
1421
- for (const sort of ['cdate', 'mdate']) {
1376
+ it('qref', async () => {
1377
+ await createTestEntities();
1378
+ // Retrieving entity by qref...
1379
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1380
+ type: '&',
1381
+ qref: [
1382
+ 'reference',
1383
+ [{ class: TestModel }, { type: '&', equal: ['test', 'good'] }],
1384
+ ],
1385
+ });
1386
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1387
+ });
1388
+ it('not qref', async () => {
1389
+ await createTestEntities();
1390
+ // Retrieving entity by !qref...
1391
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1392
+ type: '&',
1393
+ '!qref': [
1394
+ 'reference',
1395
+ [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
1396
+ ],
1397
+ });
1398
+ expect(testEntity.$inArray(resultEntity)).toEqual(true);
1399
+ });
1400
+ it('wrong qref class', async () => {
1401
+ await createTestEntities();
1402
+ // Testing wrong qref...
1403
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1404
+ type: '&',
1405
+ qref: [
1406
+ 'reference',
1407
+ [{ class: TestBModel }, { type: '&', equal: ['test', 'good'] }],
1408
+ ],
1409
+ });
1410
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1411
+ });
1412
+ it('wrong qref data', async () => {
1413
+ await createTestEntities();
1414
+ // Testing wrong qref...
1415
+ const resultEntity = await nymph.getEntities({ class: TestModel }, {
1416
+ type: '&',
1417
+ qref: [
1418
+ 'reference',
1419
+ [{ class: TestModel }, { type: '&', equal: ['test', 'pickles'] }],
1420
+ ],
1421
+ });
1422
+ expect(testEntity.$inArray(resultEntity)).toEqual(false);
1423
+ });
1424
+ it('cdate and mdate sort option', async () => {
1425
+ await createMultipleTestEntities();
1426
+ for (const sort of ['cdate', 'mdate']) {
1427
+ // Retrieving entities sorted...
1428
+ let resultEntities = await nymph.getEntities({
1429
+ class: TestModel,
1430
+ sort,
1431
+ });
1432
+ expect(resultEntities.length).toBeGreaterThan(100);
1433
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1434
+ expect(resultEntities[i + 1][sort]).toBeGreaterThan(resultEntities[i][sort] ?? 0);
1435
+ }
1436
+ // And test the same with guid return...
1437
+ let resultGuids = await nymph.getEntities({
1438
+ class: TestModel,
1439
+ sort,
1440
+ return: 'guid',
1441
+ });
1442
+ expect(resultGuids.length).toBeGreaterThan(100);
1443
+ for (let i = 0; i < resultGuids.length - 1; i++) {
1444
+ expect(resultGuids[i]).toEqual(resultEntities[i].guid);
1445
+ }
1446
+ // Retrieving entities reverse sorted...
1447
+ resultEntities = await nymph.getEntities({
1448
+ class: TestModel,
1449
+ sort,
1450
+ reverse: true,
1451
+ });
1452
+ expect(resultEntities.length).toBeGreaterThan(100);
1453
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1454
+ expect(resultEntities[i + 1][sort]).toBeLessThan(resultEntities[i][sort] ?? 0);
1455
+ }
1456
+ // And again with other selectors.
1457
+ // Retrieving entities sorted...
1458
+ resultEntities = await nymph.getEntities({ class: TestModel, sort }, { type: '&', match: ['name', '^Multi Test '] });
1459
+ expect(resultEntities.length).toEqual(100);
1460
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1461
+ expect(resultEntities[i + 1][sort]).toBeGreaterThan(resultEntities[i][sort] ?? 0);
1462
+ }
1463
+ // Retrieving entities reverse sorted...
1464
+ resultEntities = await nymph.getEntities({ class: TestModel, sort, reverse: true }, { type: '&', match: ['name', '^Multi Test '] });
1465
+ expect(resultEntities.length).toEqual(100);
1466
+ for (let i = 0; i < resultEntities.length - 1; i++) {
1467
+ expect(resultEntities[i + 1][sort]).toBeLessThan(resultEntities[i][sort] ?? 0);
1468
+ }
1469
+ }
1470
+ });
1471
+ it('property sort option', async () => {
1472
+ await createMultipleTestEntities();
1422
1473
  // Retrieving entities sorted...
1423
- let resultEntities = await nymph.getEntities({ class: TestModel, sort });
1474
+ let resultEntities = await nymph.getEntities({
1475
+ class: TestModel,
1476
+ sort: 'number',
1477
+ });
1424
1478
  expect(resultEntities.length).toBeGreaterThan(100);
1425
1479
  for (let i = 0; i < resultEntities.length - 1; i++) {
1426
- expect(resultEntities[i + 1][sort]).toBeGreaterThan(resultEntities[i][sort] ?? 0);
1480
+ expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThanOrEqual(resultEntities[i].number ?? 0);
1427
1481
  }
1428
1482
  // And test the same with guid return...
1429
1483
  let resultGuids = await nymph.getEntities({
1430
1484
  class: TestModel,
1431
- sort,
1485
+ sort: 'number',
1432
1486
  return: 'guid',
1433
1487
  });
1434
1488
  expect(resultGuids.length).toBeGreaterThan(100);
@@ -1438,345 +1492,307 @@ export function EntitiesTest(nymph, it) {
1438
1492
  // Retrieving entities reverse sorted...
1439
1493
  resultEntities = await nymph.getEntities({
1440
1494
  class: TestModel,
1441
- sort,
1495
+ sort: 'number',
1442
1496
  reverse: true,
1443
1497
  });
1444
1498
  expect(resultEntities.length).toBeGreaterThan(100);
1445
1499
  for (let i = 0; i < resultEntities.length - 1; i++) {
1446
- expect(resultEntities[i + 1][sort]).toBeLessThan(resultEntities[i][sort] ?? 0);
1500
+ expect(resultEntities[i + 1].number ?? 0).toBeLessThanOrEqual(resultEntities[i].number ?? Infinity);
1447
1501
  }
1448
1502
  // And again with other selectors.
1449
1503
  // Retrieving entities sorted...
1450
- resultEntities = await nymph.getEntities({ class: TestModel, sort }, { type: '&', match: ['name', '^Multi Test '] });
1504
+ resultEntities = await nymph.getEntities({ class: TestModel, sort: 'number' }, { type: '&', match: ['name', '^Multi Test '] });
1451
1505
  expect(resultEntities.length).toEqual(100);
1452
1506
  for (let i = 0; i < resultEntities.length - 1; i++) {
1453
- expect(resultEntities[i + 1][sort]).toBeGreaterThan(resultEntities[i][sort] ?? 0);
1507
+ expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThan(resultEntities[i].number ?? 0);
1508
+ expect(resultEntities[i].name).toEqual(`Multi Test ${100 - (resultEntities[i].number ?? 0)}`);
1454
1509
  }
1455
1510
  // Retrieving entities reverse sorted...
1456
- resultEntities = await nymph.getEntities({ class: TestModel, sort, reverse: true }, { type: '&', match: ['name', '^Multi Test '] });
1511
+ resultEntities = await nymph.getEntities({ class: TestModel, sort: 'number', reverse: true }, { type: '&', match: ['name', '^Multi Test '] });
1457
1512
  expect(resultEntities.length).toEqual(100);
1458
1513
  for (let i = 0; i < resultEntities.length - 1; i++) {
1459
- expect(resultEntities[i + 1][sort]).toBeLessThan(resultEntities[i][sort] ?? 0);
1514
+ expect(resultEntities[i + 1].number ?? 0).toBeLessThan(resultEntities[i].number ?? Infinity);
1515
+ expect(resultEntities[i].name).toEqual(`Multi Test ${100 - (resultEntities[i].number ?? 0)}`);
1460
1516
  }
1461
- }
1462
- });
1463
- it('property sort option', async () => {
1464
- await createMultipleTestEntities();
1465
- // Retrieving entities sorted...
1466
- let resultEntities = await nymph.getEntities({
1467
- class: TestModel,
1468
- sort: 'number',
1469
- });
1470
- expect(resultEntities.length).toBeGreaterThan(100);
1471
- for (let i = 0; i < resultEntities.length - 1; i++) {
1472
- expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThanOrEqual(resultEntities[i].number ?? 0);
1473
- }
1474
- // And test the same with guid return...
1475
- let resultGuids = await nymph.getEntities({
1476
- class: TestModel,
1477
- sort: 'number',
1478
- return: 'guid',
1479
- });
1480
- expect(resultGuids.length).toBeGreaterThan(100);
1481
- for (let i = 0; i < resultGuids.length - 1; i++) {
1482
- expect(resultGuids[i]).toEqual(resultEntities[i].guid);
1483
- }
1484
- // Retrieving entities reverse sorted...
1485
- resultEntities = await nymph.getEntities({
1486
- class: TestModel,
1487
- sort: 'number',
1488
- reverse: true,
1489
- });
1490
- expect(resultEntities.length).toBeGreaterThan(100);
1491
- for (let i = 0; i < resultEntities.length - 1; i++) {
1492
- expect(resultEntities[i + 1].number ?? 0).toBeLessThanOrEqual(resultEntities[i].number ?? Infinity);
1493
- }
1494
- // And again with other selectors.
1495
- // Retrieving entities sorted...
1496
- resultEntities = await nymph.getEntities({ class: TestModel, sort: 'number' }, { type: '&', match: ['name', '^Multi Test '] });
1497
- expect(resultEntities.length).toEqual(100);
1498
- for (let i = 0; i < resultEntities.length - 1; i++) {
1499
- expect(resultEntities[i + 1].number ?? Infinity).toBeGreaterThan(resultEntities[i].number ?? 0);
1500
- expect(resultEntities[i].name).toEqual(`Multi Test ${100 - (resultEntities[i].number ?? 0)}`);
1501
- }
1502
- // Retrieving entities reverse sorted...
1503
- resultEntities = await nymph.getEntities({ class: TestModel, sort: 'number', reverse: true }, { type: '&', match: ['name', '^Multi Test '] });
1504
- expect(resultEntities.length).toEqual(100);
1505
- for (let i = 0; i < resultEntities.length - 1; i++) {
1506
- expect(resultEntities[i + 1].number ?? 0).toBeLessThan(resultEntities[i].number ?? Infinity);
1507
- expect(resultEntities[i].name).toEqual(`Multi Test ${100 - (resultEntities[i].number ?? 0)}`);
1508
- }
1509
- });
1510
- it('delete reference', async () => {
1511
- await createTestEntities();
1512
- // Deleting referenced entities...
1513
- await testEntity.reference?.$wake();
1514
- expect(await testEntity.reference?.$delete()).toEqual(true);
1515
- await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1516
- expect(testEntity.reference?.guid).toBeNull();
1517
- });
1518
- it('delete', async () => {
1519
- await createTestEntities();
1520
- // Deleting entity...
1521
- expect(await testEntity.$delete()).toEqual(true);
1522
- expect(testEntity.guid).toBeNull();
1523
- const entity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid });
1524
- expect(entity).toBeNull();
1525
- });
1526
- it('allows non-duplicate unique strings', async () => {
1527
- // Creating entity...
1528
- const uniqueEntityA = await TestModel.factory();
1529
- uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1530
- uniqueEntityA.uniques = ['test a'];
1531
- // Saving entity...
1532
- expect(await uniqueEntityA.$save()).toEqual(true);
1533
- expect(uniqueEntityA.guid).not.toBeNull();
1534
- // Creating entity...
1535
- const uniqueEntityB = await TestModel.factory();
1536
- uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1537
- uniqueEntityB.uniques = ['test b'];
1538
- // Saving entity...
1539
- expect(await uniqueEntityB.$save()).toEqual(true);
1540
- expect(uniqueEntityB.guid).not.toBeNull();
1541
- expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
1542
- expect(await uniqueEntityA.$delete()).toEqual(true);
1543
- expect(await uniqueEntityB.$delete()).toEqual(true);
1544
- });
1545
- it('throws on duplicate unique strings', async () => {
1546
- // Creating entity...
1547
- const uniqueEntityA = await TestModel.factory();
1548
- uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1549
- uniqueEntityA.uniques = ['test a'];
1550
- // Saving entity...
1551
- expect(await uniqueEntityA.$save()).toEqual(true);
1552
- expect(uniqueEntityA.guid).not.toBeNull();
1553
- // Creating entity...
1554
- const uniqueEntityB = await TestModel.factory();
1555
- uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1556
- uniqueEntityB.uniques = ['test a'];
1557
- // Saving entity...
1558
- try {
1559
- await uniqueEntityB.$save();
1560
- throw Error("Shouldn't get past the uniqueness check.");
1561
- }
1562
- catch (e) {
1563
- expect(e).toBeInstanceOf(EntityUniqueConstraintError);
1564
- }
1565
- expect(uniqueEntityB.guid).toBeNull();
1566
- expect(await uniqueEntityA.$delete()).toEqual(true);
1567
- });
1568
- it('allows duplicate unique string if first transaction is rolled back', async () => {
1569
- // Creating transaction entity...
1570
- const tnymphA = await nymph.startTransaction('test-unique-a');
1571
- const TestModelA = tnymphA.getEntityClass(TestModel);
1572
- const uniqueEntityA = await TestModelA.factory();
1573
- uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1574
- uniqueEntityA.uniques = ['test a'];
1575
- // Saving entity...
1576
- expect(await uniqueEntityA.$save()).toEqual(true);
1577
- expect(uniqueEntityA.guid).not.toBeNull();
1578
- // Rolling back transaction...
1579
- expect(await tnymphA.rollback('test-unique-a')).toEqual(true);
1580
- // Creating transaction entity...
1581
- const tnymphB = await nymph.startTransaction('test-unique-b');
1582
- const TestModelB = tnymphB.getEntityClass(TestModel);
1583
- const uniqueEntityB = await TestModelB.factory();
1584
- uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1585
- uniqueEntityB.uniques = ['test a'];
1586
- // Saving entity...
1587
- expect(await uniqueEntityB.$save()).toEqual(true);
1588
- expect(uniqueEntityB.guid).not.toBeNull();
1589
- expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
1590
- expect(await tnymphB.commit('test-unique-b')).toEqual(true);
1591
- const uniqueEntityACheck = await nymph.getEntity({ class: TestModel }, { type: '&', guid: uniqueEntityA.guid ?? '' });
1592
- expect(uniqueEntityACheck).toBeNull();
1593
- const uniqueEntityBCheck = await nymph.getEntity({ class: TestModel }, { type: '&', guid: uniqueEntityB.guid ?? '' });
1594
- expect(uniqueEntityBCheck).not.toBeNull();
1595
- if (uniqueEntityBCheck != null) {
1596
- expect(await uniqueEntityBCheck.$delete()).toEqual(true);
1597
- }
1517
+ });
1518
+ it('delete reference', async () => {
1519
+ await createTestEntities();
1520
+ // Deleting referenced entities...
1521
+ await testEntity.reference?.$wake();
1522
+ expect(await testEntity.reference?.$delete()).toEqual(true);
1523
+ await Promise.all(testEntity.refArray?.map((e) => e.$wake()) || []);
1524
+ expect(testEntity.reference?.guid).toBeNull();
1525
+ });
1526
+ it('delete', async () => {
1527
+ await createTestEntities();
1528
+ // Deleting entity...
1529
+ expect(await testEntity.$delete()).toEqual(true);
1530
+ expect(testEntity.guid).toBeNull();
1531
+ const entity = await nymph.getEntity({ class: TestModel }, { type: '&', guid: testGuid });
1532
+ expect(entity).toBeNull();
1533
+ });
1534
+ it('allows non-duplicate unique strings', async () => {
1535
+ // Creating entity...
1536
+ const uniqueEntityA = await TestModel.factory();
1537
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1538
+ uniqueEntityA.uniques = ['test a'];
1539
+ // Saving entity...
1540
+ expect(await uniqueEntityA.$save()).toEqual(true);
1541
+ expect(uniqueEntityA.guid).not.toBeNull();
1542
+ // Creating entity...
1543
+ const uniqueEntityB = await TestModel.factory();
1544
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1545
+ uniqueEntityB.uniques = ['test b'];
1546
+ // Saving entity...
1547
+ expect(await uniqueEntityB.$save()).toEqual(true);
1548
+ expect(uniqueEntityB.guid).not.toBeNull();
1549
+ expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
1550
+ expect(await uniqueEntityA.$delete()).toEqual(true);
1551
+ expect(await uniqueEntityB.$delete()).toEqual(true);
1552
+ });
1553
+ it('throws on duplicate unique strings', async () => {
1554
+ // Creating entity...
1555
+ const uniqueEntityA = await TestModel.factory();
1556
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1557
+ uniqueEntityA.uniques = ['test a'];
1558
+ // Saving entity...
1559
+ expect(await uniqueEntityA.$save()).toEqual(true);
1560
+ expect(uniqueEntityA.guid).not.toBeNull();
1561
+ // Creating entity...
1562
+ const uniqueEntityB = await TestModel.factory();
1563
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1564
+ uniqueEntityB.uniques = ['test a'];
1565
+ // Saving entity...
1566
+ try {
1567
+ await uniqueEntityB.$save();
1568
+ throw Error("Shouldn't get past the uniqueness check.");
1569
+ }
1570
+ catch (e) {
1571
+ expect(e).toBeInstanceOf(EntityUniqueConstraintError);
1572
+ }
1573
+ expect(uniqueEntityB.guid).toBeNull();
1574
+ expect(await uniqueEntityA.$delete()).toEqual(true);
1575
+ });
1576
+ it('allows duplicate unique string if first transaction is rolled back', async () => {
1577
+ // Creating transaction entity...
1578
+ const tnymphA = await nymph.startTransaction('test-unique-a');
1579
+ const TestModelA = tnymphA.getEntityClass(TestModel);
1580
+ const uniqueEntityA = await TestModelA.factory();
1581
+ uniqueEntityA.name = 'Entity Test ' + new Date().toLocaleString();
1582
+ uniqueEntityA.uniques = ['test a'];
1583
+ // Saving entity...
1584
+ expect(await uniqueEntityA.$save()).toEqual(true);
1585
+ expect(uniqueEntityA.guid).not.toBeNull();
1586
+ // Rolling back transaction...
1587
+ expect(await tnymphA.rollback('test-unique-a')).toEqual(true);
1588
+ // Creating transaction entity...
1589
+ const tnymphB = await nymph.startTransaction('test-unique-b');
1590
+ const TestModelB = tnymphB.getEntityClass(TestModel);
1591
+ const uniqueEntityB = await TestModelB.factory();
1592
+ uniqueEntityB.name = 'Entity Test ' + new Date().toLocaleString();
1593
+ uniqueEntityB.uniques = ['test a'];
1594
+ // Saving entity...
1595
+ expect(await uniqueEntityB.$save()).toEqual(true);
1596
+ expect(uniqueEntityB.guid).not.toBeNull();
1597
+ expect(uniqueEntityA.guid).not.toEqual(uniqueEntityB.guid);
1598
+ expect(await tnymphB.commit('test-unique-b')).toEqual(true);
1599
+ const uniqueEntityACheck = await nymph.getEntity({ class: TestModel }, { type: '&', guid: uniqueEntityA.guid ?? '' });
1600
+ expect(uniqueEntityACheck).toBeNull();
1601
+ const uniqueEntityBCheck = await nymph.getEntity({ class: TestModel }, { type: '&', guid: uniqueEntityB.guid ?? '' });
1602
+ expect(uniqueEntityBCheck).not.toBeNull();
1603
+ if (uniqueEntityBCheck != null) {
1604
+ expect(await uniqueEntityBCheck.$delete()).toEqual(true);
1605
+ }
1606
+ });
1598
1607
  });
1599
1608
  }
1600
- export function UIDTest(nymph, it) {
1601
- it('delete old test data', async () => {
1602
- expect(await nymph.deleteUID('TestUID')).toEqual(true);
1603
- expect(await nymph.deleteUID('NewUID')).toEqual(true);
1604
- });
1605
- it('new UID', async () => {
1606
- expect(await nymph.newUID('TestUID')).toEqual(1);
1607
- });
1608
- it('increment UID', async () => {
1609
- expect(await nymph.newUID('TestUID')).toEqual(2);
1610
- });
1611
- it('retrieve UID', async () => {
1612
- expect(await nymph.getUID('TestUID')).toEqual(2);
1613
- });
1614
- it('rename UID', async () => {
1615
- expect(await nymph.renameUID('TestUID', 'NewUID')).toEqual(true);
1616
- expect(await nymph.getUID('TestUID')).toBeNull();
1617
- expect(await nymph.getUID('NewUID')).toEqual(2);
1618
- expect(await nymph.renameUID('NewUID', 'TestUID')).toEqual(true);
1619
- expect(await nymph.getUID('NewUID')).toBeNull();
1620
- expect(await nymph.getUID('TestUID')).toEqual(2);
1621
- });
1622
- it('set UID', async () => {
1623
- expect(await nymph.setUID('TestUID', 5)).toEqual(true);
1624
- expect(await nymph.getUID('TestUID')).toEqual(5);
1625
- });
1626
- it('delete UID', async () => {
1627
- expect(await nymph.deleteUID('TestUID')).toEqual(true);
1628
- expect(await nymph.getUID('TestUID')).toBeNull();
1609
+ export function UIDTest(nymph, describe, it) {
1610
+ describe('UID', () => {
1611
+ it('delete old test data', async () => {
1612
+ expect(await nymph.deleteUID('TestUID')).toEqual(true);
1613
+ expect(await nymph.deleteUID('NewUID')).toEqual(true);
1614
+ });
1615
+ it('new UID', async () => {
1616
+ expect(await nymph.newUID('TestUID')).toEqual(1);
1617
+ });
1618
+ it('increment UID', async () => {
1619
+ expect(await nymph.newUID('TestUID')).toEqual(2);
1620
+ });
1621
+ it('retrieve UID', async () => {
1622
+ expect(await nymph.getUID('TestUID')).toEqual(2);
1623
+ });
1624
+ it('rename UID', async () => {
1625
+ expect(await nymph.renameUID('TestUID', 'NewUID')).toEqual(true);
1626
+ expect(await nymph.getUID('TestUID')).toBeNull();
1627
+ expect(await nymph.getUID('NewUID')).toEqual(2);
1628
+ expect(await nymph.renameUID('NewUID', 'TestUID')).toEqual(true);
1629
+ expect(await nymph.getUID('NewUID')).toBeNull();
1630
+ expect(await nymph.getUID('TestUID')).toEqual(2);
1631
+ });
1632
+ it('set UID', async () => {
1633
+ expect(await nymph.setUID('TestUID', 5)).toEqual(true);
1634
+ expect(await nymph.getUID('TestUID')).toEqual(5);
1635
+ });
1636
+ it('delete UID', async () => {
1637
+ expect(await nymph.deleteUID('TestUID')).toEqual(true);
1638
+ expect(await nymph.getUID('TestUID')).toBeNull();
1639
+ });
1629
1640
  });
1630
1641
  }
1631
- export function ExportImportTest(nymph, it) {
1632
- const TestModel = nymph.addEntityClass(TestModelClass);
1633
- const TestBModel = nymph.addEntityClass(TestBModelClass);
1634
- async function deleteTestData() {
1635
- let all = await nymph.getEntities({ class: TestModel });
1636
- expect(Array.isArray(all)).toEqual(true);
1637
- for (const cur of all) {
1638
- expect(await cur.$delete()).toEqual(true);
1639
- }
1640
- all = await nymph.getEntities({ class: TestModel });
1641
- expect(all.length).toEqual(0);
1642
- all = await nymph.getEntities({ class: TestBModel });
1643
- expect(Array.isArray(all)).toEqual(true);
1644
- for (const cur of all) {
1645
- expect(await cur.$delete()).toEqual(true);
1646
- }
1647
- all = await nymph.getEntities({ class: TestBModel });
1648
- expect(all.length).toEqual(0);
1649
- expect(await nymph.deleteUID('TestUID')).toEqual(true);
1650
- expect(await nymph.deleteUID('TestUID2')).toEqual(true);
1651
- }
1652
- async function checkEntityDataAndCount() {
1653
- expect(await nymph.getUID('TestUID')).toEqual(2);
1654
- expect(await nymph.getUID('TestUID2')).toEqual(1);
1655
- const models = await nymph.getEntities({ class: TestModel });
1656
- const bmodels = await nymph.getEntities({ class: TestBModel });
1657
- expect(models.length).toEqual(30);
1658
- expect(bmodels.length).toEqual(30);
1659
- for (const model of models) {
1660
- expect(model.name).toMatch(/^Entity Test /);
1661
- expect(model.null).toBeDefined();
1662
- expect(model.null).toBeNull();
1663
- expect(model.string).toEqual('test');
1664
- expect(model.array).toEqual([
1665
- 'full',
1666
- 'of',
1667
- 'values',
1668
- 500,
1669
- { test: true },
1670
- { nullbyte: '\\\x00\u0000 \x00' },
1671
- ]);
1672
- expect(model.match).toEqual(matchValue);
1673
- expect(model.number).toEqual(30);
1674
- expect(model.numberString).toEqual('30');
1675
- expect(model.timestamp).toBeGreaterThanOrEqual(strtotime('-2 minutes') || 0);
1676
- expect(model.index).toMatch(/^\d+a$/);
1677
- await model.reference?.$wake();
1678
- expect(model.reference?.guid).not.toBeNull();
1679
- expect(model.reference?.string).toEqual('another');
1680
- expect(model.reference?.index).toMatch(/^\d+b$/);
1681
- expect(model.index?.substring(0, -1)).toEqual(model.reference?.index?.substring(0, -1));
1682
- expect(model.reference?.$inArray(bmodels)).toEqual(true);
1683
- await Promise.all(model.refArray?.map((e) => e.$wake()) || []);
1684
- expect(model.refArray?.[0].guid).not.toBeNull();
1685
- expect(model.refArray?.[0].guid).toEqual(model.reference?.guid);
1686
- }
1687
- }
1688
- it('delete old test data', async () => {
1689
- await deleteTestData();
1690
- });
1691
- it('setup data', async () => {
1692
- expect(await nymph.newUID('TestUID')).toEqual(1);
1693
- expect(await nymph.newUID('TestUID')).toEqual(2);
1694
- expect(await nymph.newUID('TestUID2')).toEqual(1);
1695
- for (let i = 0; i < 30; i++) {
1696
- // Creating entity...
1697
- const testEntity = await TestModel.factory();
1698
- // Saving entity...
1699
- testEntity.name = 'Entity Test ' + new Date().toLocaleString();
1700
- testEntity.null = null;
1701
- testEntity.string = 'test';
1702
- testEntity.array = [
1703
- 'full',
1704
- 'of',
1705
- 'values',
1706
- 500,
1707
- { test: true },
1708
- { nullbyte: '\\\x00\u0000 \x00' },
1709
- ];
1710
- testEntity.match = matchValue;
1711
- testEntity.number = 30;
1712
- testEntity.numberString = '30';
1713
- testEntity.timestamp = Date.now();
1714
- testEntity.index = i + 'a';
1715
- const entityReferenceTest = await TestBModel.factory();
1716
- entityReferenceTest.string = 'another';
1717
- entityReferenceTest.index = i + 'b';
1718
- expect(await entityReferenceTest.$save()).toEqual(true);
1719
- testEntity.reference = entityReferenceTest;
1720
- testEntity.refArray = [entityReferenceTest];
1721
- expect(await testEntity.$save()).toEqual(true);
1642
+ export function ExportImportTest(nymph, describe, it) {
1643
+ describe('Export/Import', () => {
1644
+ const TestModel = nymph.addEntityClass(TestModelClass);
1645
+ const TestBModel = nymph.addEntityClass(TestBModelClass);
1646
+ async function deleteTestData() {
1647
+ let all = await nymph.getEntities({ class: TestModel });
1648
+ expect(Array.isArray(all)).toEqual(true);
1649
+ for (const cur of all) {
1650
+ expect(await cur.$delete()).toEqual(true);
1651
+ }
1652
+ all = await nymph.getEntities({ class: TestModel });
1653
+ expect(all.length).toEqual(0);
1654
+ all = await nymph.getEntities({ class: TestBModel });
1655
+ expect(Array.isArray(all)).toEqual(true);
1656
+ for (const cur of all) {
1657
+ expect(await cur.$delete()).toEqual(true);
1658
+ }
1659
+ all = await nymph.getEntities({ class: TestBModel });
1660
+ expect(all.length).toEqual(0);
1661
+ expect(await nymph.deleteUID('TestUID')).toEqual(true);
1662
+ expect(await nymph.deleteUID('TestUID2')).toEqual(true);
1722
1663
  }
1723
- await checkEntityDataAndCount();
1724
- });
1725
- it('needs migration', async () => {
1726
- expect(await nymph.needsMigration()).toEqual(false);
1727
- });
1728
- it('export data', async () => {
1729
- expect(await nymph.export(__dirname + '/testentityexport.nex')).toEqual(true);
1730
- });
1731
- it('delete test data again', async () => {
1732
- await deleteTestData();
1733
- });
1734
- it('import data', async () => {
1735
- expect(await nymph.getUID('TestUID')).toBeNull();
1736
- expect(await nymph.getUID('TestUID2')).toBeNull();
1737
- const models = await nymph.getEntities({ class: TestModel });
1738
- const bmodels = await nymph.getEntities({ class: TestBModel });
1739
- expect(models.length).toEqual(0);
1740
- expect(bmodels.length).toEqual(0);
1741
- expect(await nymph.import(__dirname + '/testentityexport.nex', {
1742
- ignoreUnknownETypes: true,
1743
- })).toEqual(true);
1744
- await checkEntityDataAndCount();
1745
- fs.unlinkSync(__dirname + '/testentityexport.nex');
1746
- });
1747
- it('import tokens only', async () => {
1748
- const model = await nymph.getEntity({ class: TestModel });
1749
- expect(model).not.toBeNull();
1750
- if (model != null) {
1751
- const data = model.$getData(true);
1752
- // These should not actually be saved in the DB.
1753
- data.number = 424242424242;
1754
- // But this should become searchable.
1755
- data.search = 'peanuts and pickles on a hot bun';
1756
- const sdata = Object.fromEntries(Object.entries(data).map(([name, value]) => [
1757
- name,
1758
- JSON.stringify(value),
1759
- ]));
1760
- if (model.guid == null || model.cdate == null || model.mdate == null) {
1761
- throw new Error('Model data is wrong.');
1664
+ async function checkEntityDataAndCount() {
1665
+ expect(await nymph.getUID('TestUID')).toEqual(2);
1666
+ expect(await nymph.getUID('TestUID2')).toEqual(1);
1667
+ const models = await nymph.getEntities({ class: TestModel });
1668
+ const bmodels = await nymph.getEntities({ class: TestBModel });
1669
+ expect(models.length).toEqual(30);
1670
+ expect(bmodels.length).toEqual(30);
1671
+ for (const model of models) {
1672
+ expect(model.name).toMatch(/^Entity Test /);
1673
+ expect(model.null).toBeDefined();
1674
+ expect(model.null).toBeNull();
1675
+ expect(model.string).toEqual('test');
1676
+ expect(model.array).toEqual([
1677
+ 'full',
1678
+ 'of',
1679
+ 'values',
1680
+ 500,
1681
+ { test: true },
1682
+ { nullbyte: '\\\x00\u0000 \x00' },
1683
+ ]);
1684
+ expect(model.match).toEqual(matchValue);
1685
+ expect(model.number).toEqual(30);
1686
+ expect(model.numberString).toEqual('30');
1687
+ expect(model.timestamp).toBeGreaterThanOrEqual(strtotime('-2 minutes') || 0);
1688
+ expect(model.index).toMatch(/^\d+a$/);
1689
+ await model.reference?.$wake();
1690
+ expect(model.reference?.guid).not.toBeNull();
1691
+ expect(model.reference?.string).toEqual('another');
1692
+ expect(model.reference?.index).toMatch(/^\d+b$/);
1693
+ expect(model.index?.substring(0, -1)).toEqual(model.reference?.index?.substring(0, -1));
1694
+ expect(model.reference?.$inArray(bmodels)).toEqual(true);
1695
+ await Promise.all(model.refArray?.map((e) => e.$wake()) || []);
1696
+ expect(model.refArray?.[0].guid).not.toBeNull();
1697
+ expect(model.refArray?.[0].guid).toEqual(model.reference?.guid);
1762
1698
  }
1763
- await nymph.importEntityTokens({
1764
- guid: model.guid,
1765
- // Again, these should not actually be changed in the DB.
1766
- cdate: model.cdate + 1000,
1767
- mdate: model.mdate + 1000,
1768
- tags: [...model.tags, 'helicopter'],
1769
- sdata,
1770
- etype: TestModel.ETYPE,
1771
- });
1772
- const modelCheck = await nymph.getEntity({ class: TestModel }, { type: '&', search: ['search', '"peanuts and pickles on a hot bun"'] });
1773
- expect(modelCheck?.guid).toEqual(model.guid);
1774
- expect(modelCheck?.cdate).toEqual(model.cdate);
1775
- expect(modelCheck?.mdate).toEqual(model.mdate);
1776
- expect(modelCheck?.$hasTag('helicopter')).toEqual(false);
1777
- expect(modelCheck?.number).not.toEqual(424242424242);
1778
- expect(modelCheck?.search).not.toEqual('peanuts and pickles on a hot bun');
1779
1699
  }
1700
+ it('delete old test data', async () => {
1701
+ await deleteTestData();
1702
+ });
1703
+ it('setup data', async () => {
1704
+ expect(await nymph.newUID('TestUID')).toEqual(1);
1705
+ expect(await nymph.newUID('TestUID')).toEqual(2);
1706
+ expect(await nymph.newUID('TestUID2')).toEqual(1);
1707
+ for (let i = 0; i < 30; i++) {
1708
+ // Creating entity...
1709
+ const testEntity = await TestModel.factory();
1710
+ // Saving entity...
1711
+ testEntity.name = 'Entity Test ' + new Date().toLocaleString();
1712
+ testEntity.null = null;
1713
+ testEntity.string = 'test';
1714
+ testEntity.array = [
1715
+ 'full',
1716
+ 'of',
1717
+ 'values',
1718
+ 500,
1719
+ { test: true },
1720
+ { nullbyte: '\\\x00\u0000 \x00' },
1721
+ ];
1722
+ testEntity.match = matchValue;
1723
+ testEntity.number = 30;
1724
+ testEntity.numberString = '30';
1725
+ testEntity.timestamp = Date.now();
1726
+ testEntity.index = i + 'a';
1727
+ const entityReferenceTest = await TestBModel.factory();
1728
+ entityReferenceTest.string = 'another';
1729
+ entityReferenceTest.index = i + 'b';
1730
+ expect(await entityReferenceTest.$save()).toEqual(true);
1731
+ testEntity.reference = entityReferenceTest;
1732
+ testEntity.refArray = [entityReferenceTest];
1733
+ expect(await testEntity.$save()).toEqual(true);
1734
+ }
1735
+ await checkEntityDataAndCount();
1736
+ });
1737
+ it('needs migration', async () => {
1738
+ expect(await nymph.needsMigration()).toEqual(false);
1739
+ });
1740
+ it('export data', async () => {
1741
+ expect(await nymph.export(__dirname + '/testentityexport.nex')).toEqual(true);
1742
+ });
1743
+ it('delete test data again', async () => {
1744
+ await deleteTestData();
1745
+ });
1746
+ it('import data', async () => {
1747
+ expect(await nymph.getUID('TestUID')).toBeNull();
1748
+ expect(await nymph.getUID('TestUID2')).toBeNull();
1749
+ const models = await nymph.getEntities({ class: TestModel });
1750
+ const bmodels = await nymph.getEntities({ class: TestBModel });
1751
+ expect(models.length).toEqual(0);
1752
+ expect(bmodels.length).toEqual(0);
1753
+ expect(await nymph.import(__dirname + '/testentityexport.nex', {
1754
+ ignoreUnknownETypes: true,
1755
+ })).toEqual(true);
1756
+ await checkEntityDataAndCount();
1757
+ fs.unlinkSync(__dirname + '/testentityexport.nex');
1758
+ });
1759
+ it('import tokens only', async () => {
1760
+ const model = await nymph.getEntity({ class: TestModel });
1761
+ expect(model).not.toBeNull();
1762
+ if (model != null) {
1763
+ const data = model.$getData(true);
1764
+ // These should not actually be saved in the DB.
1765
+ data.number = 424242424242;
1766
+ // But this should become searchable.
1767
+ data.search = 'peanuts and pickles on a hot bun';
1768
+ const sdata = Object.fromEntries(Object.entries(data).map(([name, value]) => [
1769
+ name,
1770
+ JSON.stringify(value),
1771
+ ]));
1772
+ if (model.guid == null || model.cdate == null || model.mdate == null) {
1773
+ throw new Error('Model data is wrong.');
1774
+ }
1775
+ await nymph.importEntityTokens({
1776
+ guid: model.guid,
1777
+ // Again, these should not actually be changed in the DB.
1778
+ cdate: model.cdate + 1000,
1779
+ mdate: model.mdate + 1000,
1780
+ tags: [...model.tags, 'helicopter'],
1781
+ sdata,
1782
+ etype: TestModel.ETYPE,
1783
+ });
1784
+ const modelCheck = await nymph.getEntity({ class: TestModel }, {
1785
+ type: '&',
1786
+ search: ['search', '"peanuts and pickles on a hot bun"'],
1787
+ });
1788
+ expect(modelCheck?.guid).toEqual(model.guid);
1789
+ expect(modelCheck?.cdate).toEqual(model.cdate);
1790
+ expect(modelCheck?.mdate).toEqual(model.mdate);
1791
+ expect(modelCheck?.$hasTag('helicopter')).toEqual(false);
1792
+ expect(modelCheck?.number).not.toEqual(424242424242);
1793
+ expect(modelCheck?.search).not.toEqual('peanuts and pickles on a hot bun');
1794
+ }
1795
+ });
1780
1796
  });
1781
1797
  }
1782
1798
  const matchValue = `Hello, my name is Edward McCheese. It is a pleasure to meet you. As you can see, I have several hats of the most pleasant nature.