@futdevpro/fsm-dynamo 1.15.7 → 1.15.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/_ag_frontend-structure.mdc +5 -5
- package/.dynamo/version-bump.config.json +5 -0
- package/.github/workflows/main.yml +427 -394
- package/.husky/pre-commit +1 -0
- package/build/_models/control-models/error.control-model.d.ts +5 -0
- package/build/_models/control-models/error.control-model.d.ts.map +1 -1
- package/build/_models/control-models/error.control-model.js +16 -0
- package/build/_models/control-models/error.control-model.js.map +1 -1
- package/build/_models/data-models/errors.data-model.d.ts +2 -1
- package/build/_models/data-models/errors.data-model.d.ts.map +1 -1
- package/build/_models/data-models/errors.data-model.js +4 -3
- package/build/_models/data-models/errors.data-model.js.map +1 -1
- package/build/_models/types/db-filter.type.d.ts +1 -1
- package/build/_models/types/db-filter.type.d.ts.map +1 -1
- package/nodemon.json +2 -1
- package/package.json +64 -34
- package/pipeline.cicd.config.json +128 -0
- package/src/_collections/utils/async.util.spec.ts +354 -0
- package/src/_collections/utils/data.util.spec.ts +345 -0
- package/src/_collections/utils/json-error-helper.util.spec.ts +521 -0
- package/src/_collections/utils/math/box-bounds.spec.ts +74 -0
- package/src/_collections/utils/utilities.util.spec.ts +201 -0
- package/src/_models/control-models/error.control-model.spec.ts +37 -0
- package/src/_models/control-models/error.control-model.ts +18 -0
- package/src/_models/control-models/http/http-error-response.control-model.spec.ts +116 -0
- package/src/_models/control-models/http/http-headers.control-model.spec.ts +25 -0
- package/src/_models/control-models/http/http-response.model-base.spec.ts +46 -0
- package/src/_models/control-models/server-status.control-model.spec.ts +66 -0
- package/src/_models/control-models/service-endpoint-settings-base.control-model.spec.ts +145 -0
- package/src/_models/data-models/errors.data-model.spec.ts +71 -0
- package/src/_models/data-models/errors.data-model.ts +4 -4
- package/src/_models/data-models/metadata.data-model.spec.ts +184 -0
- package/src/_models/types/db-filter.type.ts +1 -2
- package/src/_modules/ai/_modules/anthropic/_models/aai-call-settings.control-model.spec.ts +28 -0
- package/src/_modules/ai/_modules/anthropic/_models/aai-settings.control-model.spec.ts +22 -0
- package/src/_modules/ai/_modules/google-ai/_models/gai-call-settings.control-model.spec.ts +28 -0
- package/src/_modules/ai/_modules/google-ai/_models/gai-settings.control-model.spec.ts +22 -0
- package/src/_modules/ai/_modules/local-ai/_models/lai-call-settings.control-model.spec.ts +28 -0
- package/src/_modules/ai/_modules/local-ai/_models/lai-settings.control-model.spec.ts +22 -0
- package/src/_modules/ai/_modules/open-ai/_models/oai-call-settings.control-model.spec.ts +28 -0
- package/src/_modules/ai/_modules/open-ai/_models/oai-settings.control-model.spec.ts +22 -0
- package/src/_modules/ci-tools/_models/cit-ci-result-info.data-models.spec.ts +58 -0
- package/src/_modules/data-handler/_models/data-handler-settings.control-model.spec.ts +110 -0
- package/src/_modules/data-handler/_models/data-handler.control-model.spec.ts +445 -0
- package/src/_modules/data-handler/_models/data-list-handler.control-model.spec.ts +263 -0
- package/src/_modules/data-handler/_models/data-search-handler.control-model.spec.ts +417 -0
- package/src/_modules/data-handler/_models/list-collector-data-handler.control-model.spec.ts +374 -0
- package/src/_modules/messaging/_models/msg-conversation.data-model.spec.ts +69 -0
- package/src/_modules/messaging/_models/msg-message.data-model.spec.ts +79 -0
- package/src/_modules/pipe/_collections/utils/pip-json-pipe.util.spec.ts +62 -0
- package/src/_modules/pipe/_collections/utils/pip-multi-pipe-pipe.util.spec.ts +10 -3
- package/futdevpro-fsm-dynamo-01.15.7.tgz +0 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { DyFM_ListCollectorDataHandler } from './list-collector-data-handler.control-model';
|
|
2
|
+
import { DyFM_Metadata } from '../../../_models/data-models/metadata.data-model';
|
|
3
|
+
import { DyFM_ListCollectorDataHandler_Settings } from './data-handler-settings.control-model';
|
|
4
|
+
import { DyFM_Error } from '../../../_models/control-models/error.control-model';
|
|
5
|
+
|
|
6
|
+
class TestCollector extends DyFM_Metadata {
|
|
7
|
+
items?: TestItem[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class TestItem extends DyFM_Metadata {
|
|
11
|
+
name?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('| DyFM_ListCollectorDataHandler', (): void => {
|
|
15
|
+
let handler: DyFM_ListCollectorDataHandler<TestCollector, TestItem>;
|
|
16
|
+
let settings: DyFM_ListCollectorDataHandler_Settings<TestCollector, TestItem>;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
settings = {
|
|
20
|
+
name: 'TestCollectorHandler',
|
|
21
|
+
listKey: 'items',
|
|
22
|
+
get: async (loadBy?: string): Promise<TestCollector> => {
|
|
23
|
+
return {
|
|
24
|
+
_id: loadBy || 'default',
|
|
25
|
+
items: [
|
|
26
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
27
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
28
|
+
],
|
|
29
|
+
} as TestCollector;
|
|
30
|
+
},
|
|
31
|
+
setItem: async (item: TestItem, collectorId?: string): Promise<TestItem> => item,
|
|
32
|
+
deleteItem: async (id: string, collectorId?: string): Promise<void> => {},
|
|
33
|
+
defaultValue: { _id: 'default', items: [] } as TestCollector,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
handler = new DyFM_ListCollectorDataHandler<TestCollector, TestItem>(settings);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('| should create an instance with settings', (): void => {
|
|
40
|
+
expect(handler).toBeTruthy();
|
|
41
|
+
expect(handler.name).toBe('TestCollectorHandler');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('| should have dataList$ observable', (): void => {
|
|
45
|
+
expect(handler.dataList$).toBeTruthy();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('| should have activeItem$ observable', (): void => {
|
|
49
|
+
expect(handler.activeItem$).toBeTruthy();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('| should get empty dataList initially', (): void => {
|
|
53
|
+
expect(handler.dataList).toEqual([]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('| should set active item', (): void => {
|
|
57
|
+
const item = { _id: '1', name: 'item1' } as TestItem;
|
|
58
|
+
handler.setActiveItem(item);
|
|
59
|
+
|
|
60
|
+
handler.activeItem$.subscribe(activeItem => {
|
|
61
|
+
expect(activeItem).toEqual(item);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('| should clear data and active item', (): void => {
|
|
66
|
+
handler.clear();
|
|
67
|
+
|
|
68
|
+
expect(handler.dataList).toEqual([]);
|
|
69
|
+
handler.activeItem$.subscribe(activeItem => {
|
|
70
|
+
expect(activeItem).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('| should throw error when adding item without data', async (): Promise<void> => {
|
|
75
|
+
handler.clear();
|
|
76
|
+
const newItem = { _id: '3', name: 'item3' } as TestItem;
|
|
77
|
+
|
|
78
|
+
await expectAsync(handler.addItem(newItem)).toBeRejectedWith(jasmine.any(DyFM_Error));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('| should throw error when removing item without data', async (): Promise<void> => {
|
|
82
|
+
// Test case for lines 204-212: removeItem throws error when list not found
|
|
83
|
+
handler.clear();
|
|
84
|
+
|
|
85
|
+
await expectAsync(handler.removeItem('1')).toBeRejectedWith(jasmine.any(DyFM_Error));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('| should remove item with deleteItem', async (): Promise<void> => {
|
|
89
|
+
// Test case for lines 213-226: removeItem with deleteItem
|
|
90
|
+
// Use updateData to bypass the problematic post-process that expects an array
|
|
91
|
+
await handler.updateData({
|
|
92
|
+
_id: 'test',
|
|
93
|
+
items: [
|
|
94
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
95
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
96
|
+
],
|
|
97
|
+
} as TestCollector);
|
|
98
|
+
const deleteItemSpy = spyOn(handler as any, 'deleteItem').and.returnValue(Promise.resolve());
|
|
99
|
+
|
|
100
|
+
await handler.removeItem('1');
|
|
101
|
+
|
|
102
|
+
expect(deleteItemSpy).toHaveBeenCalledWith('1', undefined);
|
|
103
|
+
expect(handler.dataList.find(i => i._id === '1')).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('| should remove item without deleteItem', async (): Promise<void> => {
|
|
107
|
+
// Test case for lines 213-226: removeItem without deleteItem
|
|
108
|
+
settings.deleteItem = undefined;
|
|
109
|
+
handler = new DyFM_ListCollectorDataHandler<TestCollector, TestItem>(settings);
|
|
110
|
+
// Use updateData to bypass the problematic post-process that expects an array
|
|
111
|
+
await handler.updateData({
|
|
112
|
+
_id: 'test',
|
|
113
|
+
items: [
|
|
114
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
115
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
116
|
+
],
|
|
117
|
+
} as TestCollector);
|
|
118
|
+
|
|
119
|
+
await handler.removeItem('1');
|
|
120
|
+
|
|
121
|
+
expect(handler.dataList.find(i => i._id === '1')).toBeUndefined();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('| should clear active item when removing active item', async (): Promise<void> => {
|
|
125
|
+
// Test case for lines 223-225: clear active item when removing
|
|
126
|
+
// Use updateData to bypass the problematic post-process that expects an array
|
|
127
|
+
await handler.updateData({
|
|
128
|
+
_id: 'test',
|
|
129
|
+
items: [
|
|
130
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
131
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
132
|
+
],
|
|
133
|
+
} as TestCollector);
|
|
134
|
+
handler.setActiveItem(handler.dataList[0]);
|
|
135
|
+
|
|
136
|
+
await handler.removeItem(handler.dataList[0]._id);
|
|
137
|
+
|
|
138
|
+
handler.activeItem$.subscribe(activeItem => {
|
|
139
|
+
expect(activeItem).toBeNull();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('| should throw error when updating item without data', async (): Promise<void> => {
|
|
144
|
+
// Test case for lines 238-246: updateItem throws error when list not found
|
|
145
|
+
handler.clear();
|
|
146
|
+
const item = { _id: '1', name: 'item1' } as TestItem;
|
|
147
|
+
|
|
148
|
+
await expectAsync(handler.updateItem(item)).toBeRejectedWith(jasmine.any(DyFM_Error));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('| should update item with setItem', async (): Promise<void> => {
|
|
152
|
+
// Test case for lines 247-269: updateItem with setItem
|
|
153
|
+
// Use updateData to bypass the problematic post-process that expects an array
|
|
154
|
+
await handler.updateData({
|
|
155
|
+
_id: 'test',
|
|
156
|
+
items: [
|
|
157
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
158
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
159
|
+
],
|
|
160
|
+
} as TestCollector);
|
|
161
|
+
const setItemSpy = spyOn(handler as any, 'setItem').and.returnValue(Promise.resolve(handler.dataList[0]));
|
|
162
|
+
|
|
163
|
+
const updatedItem = { _id: '1', name: 'updated' } as TestItem;
|
|
164
|
+
await handler.updateItem(updatedItem);
|
|
165
|
+
|
|
166
|
+
expect(setItemSpy).toHaveBeenCalledWith(updatedItem, undefined);
|
|
167
|
+
expect(handler.dataList.find(i => i._id === '1')?.name).toBe('updated');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('| should update item without setItem', async (): Promise<void> => {
|
|
171
|
+
// Test case for lines 247-269: updateItem without setItem
|
|
172
|
+
settings.setItem = undefined;
|
|
173
|
+
handler = new DyFM_ListCollectorDataHandler<TestCollector, TestItem>(settings);
|
|
174
|
+
// Use updateData to bypass the problematic post-process that expects an array
|
|
175
|
+
await handler.updateData({
|
|
176
|
+
_id: 'test',
|
|
177
|
+
items: [
|
|
178
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
179
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
180
|
+
],
|
|
181
|
+
} as TestCollector);
|
|
182
|
+
|
|
183
|
+
const updatedItem = { _id: '1', name: 'updated' } as TestItem;
|
|
184
|
+
await handler.updateItem(updatedItem);
|
|
185
|
+
|
|
186
|
+
expect(handler.dataList.find(i => i._id === '1')?.name).toBe('updated');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('| should throw error when updating non-existent item', async (): Promise<void> => {
|
|
190
|
+
// Test case for lines 260-268: updateItem throws error when item not found
|
|
191
|
+
// Use updateData to bypass the problematic post-process that expects an array
|
|
192
|
+
await handler.updateData({
|
|
193
|
+
_id: 'test',
|
|
194
|
+
items: [
|
|
195
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
196
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
197
|
+
],
|
|
198
|
+
} as TestCollector);
|
|
199
|
+
const nonExistentItem = { _id: '999', name: 'not found' } as TestItem;
|
|
200
|
+
|
|
201
|
+
await expectAsync(handler.updateItem(nonExistentItem)).toBeRejected();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('| should addItem with setItem and dontSendUpdate false', async (): Promise<void> => {
|
|
205
|
+
// Test case for lines 173-193: addItem with setItem
|
|
206
|
+
await handler.updateData({
|
|
207
|
+
_id: 'test',
|
|
208
|
+
items: [],
|
|
209
|
+
} as TestCollector);
|
|
210
|
+
const setItemSpy = spyOn(handler as any, 'setItem').and.returnValue(Promise.resolve({ _id: '3', name: 'item3' }));
|
|
211
|
+
|
|
212
|
+
const newItem = { _id: '3', name: 'item3' } as TestItem;
|
|
213
|
+
await handler.addItem(newItem, undefined, false);
|
|
214
|
+
|
|
215
|
+
expect(setItemSpy).toHaveBeenCalled();
|
|
216
|
+
expect(handler.activeItem_BS.value).toEqual(newItem);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('| should addItem with setItem and dontSendUpdate true', async (): Promise<void> => {
|
|
220
|
+
// Test case for lines 173-193: addItem with dontSendUpdate
|
|
221
|
+
// When dontSendUpdate is true, setItem should NOT be called (line 185: if (this.setItem && !dontSendUpdate))
|
|
222
|
+
await handler.updateData({
|
|
223
|
+
_id: 'test',
|
|
224
|
+
items: [],
|
|
225
|
+
} as TestCollector);
|
|
226
|
+
const setItemSpy = spyOn(handler as any, 'setItem').and.returnValue(Promise.resolve({ _id: '3', name: 'item3' }));
|
|
227
|
+
|
|
228
|
+
const newItem = { _id: '3', name: 'item3' } as TestItem;
|
|
229
|
+
await handler.addItem(newItem, undefined, true);
|
|
230
|
+
|
|
231
|
+
expect(setItemSpy).not.toHaveBeenCalled();
|
|
232
|
+
expect(handler.activeItem_BS.value).toEqual(newItem);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('| should addItem without setItem', async (): Promise<void> => {
|
|
236
|
+
// Test case for lines 173-193: addItem without setItem
|
|
237
|
+
settings.setItem = undefined;
|
|
238
|
+
handler = new DyFM_ListCollectorDataHandler<TestCollector, TestItem>(settings);
|
|
239
|
+
await handler.updateData({
|
|
240
|
+
_id: 'test',
|
|
241
|
+
items: [],
|
|
242
|
+
} as TestCollector);
|
|
243
|
+
|
|
244
|
+
const newItem = { _id: '3', name: 'item3' } as TestItem;
|
|
245
|
+
await handler.addItem(newItem);
|
|
246
|
+
|
|
247
|
+
expect(handler.dataList.find(i => i._id === '3')).toBeDefined();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('| should addItem with collectorId', async (): Promise<void> => {
|
|
251
|
+
// Test case for lines 173-193: addItem with collectorId
|
|
252
|
+
await handler.updateData({
|
|
253
|
+
_id: 'test',
|
|
254
|
+
items: [],
|
|
255
|
+
} as TestCollector);
|
|
256
|
+
const setItemSpy = spyOn(handler as any, 'setItem').and.returnValue(Promise.resolve({ _id: '3', name: 'item3' }));
|
|
257
|
+
|
|
258
|
+
const newItem = { _id: '3', name: 'item3' } as TestItem;
|
|
259
|
+
await handler.addItem(newItem, 'collectorId');
|
|
260
|
+
|
|
261
|
+
expect(setItemSpy).toHaveBeenCalledWith(newItem, 'collectorId');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('| should addItem when listKey does not exist', async (): Promise<void> => {
|
|
265
|
+
// Test case for line 183: addItem when listKey does not exist
|
|
266
|
+
await handler.updateData({
|
|
267
|
+
_id: 'test',
|
|
268
|
+
} as TestCollector);
|
|
269
|
+
|
|
270
|
+
const newItem = { _id: '3', name: 'item3' } as TestItem;
|
|
271
|
+
await handler.addItem(newItem);
|
|
272
|
+
|
|
273
|
+
expect(handler.dataList.find(i => i._id === '3')).toBeDefined();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('| should removeItem when item not found', async (): Promise<void> => {
|
|
277
|
+
// Test case for lines 203-226: removeItem when index === -1
|
|
278
|
+
await handler.updateData({
|
|
279
|
+
_id: 'test',
|
|
280
|
+
items: [
|
|
281
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
282
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
283
|
+
],
|
|
284
|
+
} as TestCollector);
|
|
285
|
+
|
|
286
|
+
await handler.removeItem('999');
|
|
287
|
+
|
|
288
|
+
// Should not throw, just do nothing
|
|
289
|
+
expect(handler.dataList.length).toBe(2);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('| should removeItem with collectorId parameter', async (): Promise<void> => {
|
|
293
|
+
// Test case for lines 203-226: removeItem with collectorId
|
|
294
|
+
await handler.updateData({
|
|
295
|
+
_id: 'test',
|
|
296
|
+
items: [
|
|
297
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
298
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
299
|
+
],
|
|
300
|
+
} as TestCollector);
|
|
301
|
+
const deleteItemSpy = spyOn(handler as any, 'deleteItem').and.returnValue(Promise.resolve());
|
|
302
|
+
|
|
303
|
+
await handler.removeItem('1', 'collectorId');
|
|
304
|
+
|
|
305
|
+
expect(deleteItemSpy).toHaveBeenCalledWith('1', 'collectorId');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('| should removeItem with dontSendUpdate', async (): Promise<void> => {
|
|
309
|
+
// Test case for lines 203-226: removeItem with dontSendUpdate
|
|
310
|
+
await handler.updateData({
|
|
311
|
+
_id: 'test',
|
|
312
|
+
items: [
|
|
313
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
314
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
315
|
+
],
|
|
316
|
+
} as TestCollector);
|
|
317
|
+
settings.deleteItem = undefined;
|
|
318
|
+
handler = new DyFM_ListCollectorDataHandler<TestCollector, TestItem>(settings);
|
|
319
|
+
await handler.updateData({
|
|
320
|
+
_id: 'test',
|
|
321
|
+
items: [
|
|
322
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
323
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
324
|
+
],
|
|
325
|
+
} as TestCollector);
|
|
326
|
+
|
|
327
|
+
await handler.removeItem('1', undefined, true);
|
|
328
|
+
|
|
329
|
+
expect(handler.dataList.find(i => i._id === '1')).toBeUndefined();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('| should updateItem with collectorId parameter', async (): Promise<void> => {
|
|
333
|
+
// Test case for lines 237-269: updateItem with collectorId
|
|
334
|
+
await handler.updateData({
|
|
335
|
+
_id: 'test',
|
|
336
|
+
items: [
|
|
337
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
338
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
339
|
+
],
|
|
340
|
+
} as TestCollector);
|
|
341
|
+
const setItemSpy = spyOn(handler as any, 'setItem').and.returnValue(Promise.resolve(handler.dataList[0]));
|
|
342
|
+
|
|
343
|
+
const updatedItem = { _id: '1', name: 'updated' } as TestItem;
|
|
344
|
+
await handler.updateItem(updatedItem, 'collectorId');
|
|
345
|
+
|
|
346
|
+
expect(setItemSpy).toHaveBeenCalledWith(updatedItem, 'collectorId');
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('| should updateItem with dontSendUpdate', async (): Promise<void> => {
|
|
350
|
+
// Test case for lines 237-269: updateItem with dontSendUpdate
|
|
351
|
+
await handler.updateData({
|
|
352
|
+
_id: 'test',
|
|
353
|
+
items: [
|
|
354
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
355
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
356
|
+
],
|
|
357
|
+
} as TestCollector);
|
|
358
|
+
settings.setItem = undefined;
|
|
359
|
+
handler = new DyFM_ListCollectorDataHandler<TestCollector, TestItem>(settings);
|
|
360
|
+
await handler.updateData({
|
|
361
|
+
_id: 'test',
|
|
362
|
+
items: [
|
|
363
|
+
{ _id: '1', name: 'item1' } as TestItem,
|
|
364
|
+
{ _id: '2', name: 'item2' } as TestItem,
|
|
365
|
+
],
|
|
366
|
+
} as TestCollector);
|
|
367
|
+
|
|
368
|
+
const updatedItem = { _id: '1', name: 'updated' } as TestItem;
|
|
369
|
+
await handler.updateItem(updatedItem, undefined, true);
|
|
370
|
+
|
|
371
|
+
expect(handler.dataList.find(i => i._id === '1')?.name).toBe('updated');
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DyFM_Msg_Conversation } from './msg-conversation.data-model';
|
|
2
|
+
import { DyFM_Msg_ConversationType } from '../_enums/msg-conversation-type.enum';
|
|
3
|
+
import { DyFM_Msg_Participant } from './msg-participant.interface';
|
|
4
|
+
import { DyFM_Msg_ParticipantRole } from '../_enums/msg-participant-role.enum';
|
|
5
|
+
|
|
6
|
+
describe('| DyFM_Msg_Conversation', (): void => {
|
|
7
|
+
it('| should create an instance without initial data', (): void => {
|
|
8
|
+
const conversation = new DyFM_Msg_Conversation();
|
|
9
|
+
|
|
10
|
+
expect(conversation).toBeTruthy();
|
|
11
|
+
expect(conversation.__created).toBeInstanceOf(Date);
|
|
12
|
+
expect(conversation.__lastModified).toBeInstanceOf(Date);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('| should create an instance with initial data', (): void => {
|
|
16
|
+
const participants: DyFM_Msg_Participant[] = [
|
|
17
|
+
{ userId: 'user1', role: DyFM_Msg_ParticipantRole.owner, joinedAt: new Date() },
|
|
18
|
+
{ userId: 'user2', role: DyFM_Msg_ParticipantRole.member, joinedAt: new Date() },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const initialData: DyFM_Msg_Conversation = {
|
|
22
|
+
title: 'Test Conversation',
|
|
23
|
+
type: DyFM_Msg_ConversationType.direct,
|
|
24
|
+
participants: participants,
|
|
25
|
+
lastMessageId: 'msg1',
|
|
26
|
+
lastMessageAt: new Date('2023-01-01'),
|
|
27
|
+
lastMessagePreview: 'Hello world',
|
|
28
|
+
isArchived: false,
|
|
29
|
+
isMuted: false,
|
|
30
|
+
isPinned: true,
|
|
31
|
+
platformSource: 'test',
|
|
32
|
+
platformChannelId: 'channel1',
|
|
33
|
+
platformChannelName: 'Test Channel',
|
|
34
|
+
aiProvider: 'openai',
|
|
35
|
+
aiModel: 'gpt-4',
|
|
36
|
+
systemPrompt: 'You are a helpful assistant',
|
|
37
|
+
messageCount: 10,
|
|
38
|
+
unreadCount: 2,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const conversation = new DyFM_Msg_Conversation(initialData);
|
|
42
|
+
|
|
43
|
+
expect(conversation.title).toBe('Test Conversation');
|
|
44
|
+
expect(conversation.type).toBe(DyFM_Msg_ConversationType.direct);
|
|
45
|
+
expect(conversation.participants).toEqual(participants);
|
|
46
|
+
expect(conversation.lastMessageId).toBe('msg1');
|
|
47
|
+
expect(conversation.lastMessageAt).toEqual(new Date('2023-01-01'));
|
|
48
|
+
expect(conversation.lastMessagePreview).toBe('Hello world');
|
|
49
|
+
expect(conversation.isArchived).toBe(false);
|
|
50
|
+
expect(conversation.isMuted).toBe(false);
|
|
51
|
+
expect(conversation.isPinned).toBe(true);
|
|
52
|
+
expect(conversation.platformSource).toBe('test');
|
|
53
|
+
expect(conversation.platformChannelId).toBe('channel1');
|
|
54
|
+
expect(conversation.platformChannelName).toBe('Test Channel');
|
|
55
|
+
expect(conversation.aiProvider).toBe('openai');
|
|
56
|
+
expect(conversation.aiModel).toBe('gpt-4');
|
|
57
|
+
expect(conversation.systemPrompt).toBe('You are a helpful assistant');
|
|
58
|
+
expect(conversation.messageCount).toBe(10);
|
|
59
|
+
expect(conversation.unreadCount).toBe(2);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('| should have dataParams defined', (): void => {
|
|
63
|
+
const { DyFM_msgConversation_dataParams } = require('./msg-conversation.data-model');
|
|
64
|
+
|
|
65
|
+
expect(DyFM_msgConversation_dataParams).toBeTruthy();
|
|
66
|
+
expect(DyFM_msgConversation_dataParams.dataName).toBe('msg_conversation');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { DyFM_Msg_Message } from './msg-message.data-model';
|
|
2
|
+
import { DyFM_Msg_Type } from '../_enums/msg-type.enum';
|
|
3
|
+
import { DyFM_Msg_Status } from '../_enums/msg-status.enum';
|
|
4
|
+
|
|
5
|
+
describe('| DyFM_Msg_Message', (): void => {
|
|
6
|
+
it('| should create an instance without initial data', (): void => {
|
|
7
|
+
const message = new DyFM_Msg_Message();
|
|
8
|
+
|
|
9
|
+
expect(message).toBeTruthy();
|
|
10
|
+
expect(message.__created).toBeInstanceOf(Date);
|
|
11
|
+
expect(message.__lastModified).toBeInstanceOf(Date);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('| should create an instance with initial data', (): void => {
|
|
15
|
+
const initialData: DyFM_Msg_Message = {
|
|
16
|
+
conversationId: 'conv1',
|
|
17
|
+
content: 'Hello world',
|
|
18
|
+
type: DyFM_Msg_Type.text,
|
|
19
|
+
status: DyFM_Msg_Status.sent,
|
|
20
|
+
senderId: 'user1',
|
|
21
|
+
senderName: 'John Doe',
|
|
22
|
+
senderDisplayName: 'John',
|
|
23
|
+
recipientIds: ['user2'],
|
|
24
|
+
parentMessageId: 'parent1',
|
|
25
|
+
threadId: 'thread1',
|
|
26
|
+
attachments: [],
|
|
27
|
+
mentions: [],
|
|
28
|
+
reactions: [],
|
|
29
|
+
aiProvider: 'openai',
|
|
30
|
+
aiModel: 'gpt-4',
|
|
31
|
+
isAIGenerated: false,
|
|
32
|
+
systemPrompt: 'You are helpful',
|
|
33
|
+
agentProcessSteps: [],
|
|
34
|
+
platformSource: 'test',
|
|
35
|
+
platformMessageId: 'platform1',
|
|
36
|
+
platformChannelId: 'channel1',
|
|
37
|
+
sentAt: new Date('2023-01-01'),
|
|
38
|
+
deliveredAt: new Date('2023-01-01'),
|
|
39
|
+
readAt: new Date('2023-01-01'),
|
|
40
|
+
editedAt: new Date('2023-01-01'),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const message = new DyFM_Msg_Message(initialData);
|
|
44
|
+
|
|
45
|
+
expect(message.conversationId).toBe('conv1');
|
|
46
|
+
expect(message.content).toBe('Hello world');
|
|
47
|
+
expect(message.type).toBe(DyFM_Msg_Type.text);
|
|
48
|
+
expect(message.status).toBe(DyFM_Msg_Status.sent);
|
|
49
|
+
expect(message.senderId).toBe('user1');
|
|
50
|
+
expect(message.senderName).toBe('John Doe');
|
|
51
|
+
expect(message.senderDisplayName).toBe('John');
|
|
52
|
+
expect(message.recipientIds).toEqual(['user2']);
|
|
53
|
+
expect(message.parentMessageId).toBe('parent1');
|
|
54
|
+
expect(message.threadId).toBe('thread1');
|
|
55
|
+
expect(message.attachments).toEqual([]);
|
|
56
|
+
expect(message.mentions).toEqual([]);
|
|
57
|
+
expect(message.reactions).toEqual([]);
|
|
58
|
+
expect(message.aiProvider).toBe('openai');
|
|
59
|
+
expect(message.aiModel).toBe('gpt-4');
|
|
60
|
+
expect(message.isAIGenerated).toBe(false);
|
|
61
|
+
expect(message.systemPrompt).toBe('You are helpful');
|
|
62
|
+
expect(message.agentProcessSteps).toEqual([]);
|
|
63
|
+
expect(message.platformSource).toBe('test');
|
|
64
|
+
expect(message.platformMessageId).toBe('platform1');
|
|
65
|
+
expect(message.platformChannelId).toBe('channel1');
|
|
66
|
+
expect(message.sentAt).toEqual(new Date('2023-01-01'));
|
|
67
|
+
expect(message.deliveredAt).toEqual(new Date('2023-01-01'));
|
|
68
|
+
expect(message.readAt).toEqual(new Date('2023-01-01'));
|
|
69
|
+
expect(message.editedAt).toEqual(new Date('2023-01-01'));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('| should have dataParams defined', (): void => {
|
|
73
|
+
const { DyFM_msgMessage_dataParams } = require('./msg-message.data-model');
|
|
74
|
+
|
|
75
|
+
expect(DyFM_msgMessage_dataParams).toBeTruthy();
|
|
76
|
+
expect(DyFM_msgMessage_dataParams.dataName).toBe('msg_message');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DyFM_json_pipeTransform } from './pip-json-pipe.util';
|
|
2
|
+
|
|
3
|
+
describe('| DyFM_json_pipeTransform', (): void => {
|
|
4
|
+
it('| should stringify an object with default depth', (): void => {
|
|
5
|
+
const obj = { a: 1, b: 2, c: 3 };
|
|
6
|
+
const result = DyFM_json_pipeTransform(obj);
|
|
7
|
+
|
|
8
|
+
expect(result).toBe(JSON.stringify(obj, null, 2));
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('| should stringify an object with custom depth', (): void => {
|
|
12
|
+
const obj = { a: 1, b: 2, c: 3 };
|
|
13
|
+
const result = DyFM_json_pipeTransform(obj, 4);
|
|
14
|
+
|
|
15
|
+
expect(result).toBe(JSON.stringify(obj, null, 4));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('| should handle arrays', (): void => {
|
|
19
|
+
const arr = [1, 2, 3];
|
|
20
|
+
const result = DyFM_json_pipeTransform(arr);
|
|
21
|
+
|
|
22
|
+
expect(result).toBe(JSON.stringify(arr, null, 2));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('| should handle nested objects', (): void => {
|
|
26
|
+
const obj = { a: { b: { c: 1 } } };
|
|
27
|
+
const result = DyFM_json_pipeTransform(obj);
|
|
28
|
+
|
|
29
|
+
expect(result).toBe(JSON.stringify(obj, null, 2));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('| should handle null', (): void => {
|
|
33
|
+
const result = DyFM_json_pipeTransform(null);
|
|
34
|
+
|
|
35
|
+
expect(result).toBe(JSON.stringify(null, null, 2));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('| should handle undefined', (): void => {
|
|
39
|
+
const result = DyFM_json_pipeTransform(undefined);
|
|
40
|
+
|
|
41
|
+
expect(result).toBe(JSON.stringify(undefined, null, 2));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('| should handle strings', (): void => {
|
|
45
|
+
const result = DyFM_json_pipeTransform('test');
|
|
46
|
+
|
|
47
|
+
expect(result).toBe(JSON.stringify('test', null, 2));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('| should handle numbers', (): void => {
|
|
51
|
+
const result = DyFM_json_pipeTransform(123);
|
|
52
|
+
|
|
53
|
+
expect(result).toBe(JSON.stringify(123, null, 2));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('| should handle boolean values', (): void => {
|
|
57
|
+
const result = DyFM_json_pipeTransform(true);
|
|
58
|
+
|
|
59
|
+
expect(result).toBe(JSON.stringify(true, null, 2));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
@@ -38,17 +38,24 @@ describe('| DyFM_multiPipe_pipeTransform', () => {
|
|
|
38
38
|
expect(DyFM_multiPipe_pipeTransform(value, pipes)).toBe('transformed with arg1');
|
|
39
39
|
}); */
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
it('| should return the original value if Angular pipe is not defined', () => {
|
|
42
42
|
const value = 'test';
|
|
43
43
|
const pipes: DyFM_MultiPipe_Setting[] = [{ [DyFM_AngularMultiPipeAvailable.currency]: [] }];
|
|
44
|
-
|
|
44
|
+
const originalPipe = DyFM_multiPipeAngularPipes[DyFM_AngularMultiPipeAvailable.currency];
|
|
45
|
+
DyFM_multiPipeAngularPipes[DyFM_AngularMultiPipeAvailable.currency] = null;
|
|
46
|
+
const result = DyFM_multiPipe_pipeTransform(value, pipes);
|
|
47
|
+
DyFM_multiPipeAngularPipes[DyFM_AngularMultiPipeAvailable.currency] = originalPipe;
|
|
48
|
+
expect(result).toBe(value);
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
it('| should transform value using a defined Angular pipe', () => {
|
|
48
52
|
const value = 'test';
|
|
49
53
|
const pipes: DyFM_MultiPipe_Setting[] = [{ [DyFM_AngularMultiPipeAvailable.currency]: ['arg1'] }];
|
|
54
|
+
const originalPipe = DyFM_multiPipeAngularPipes[DyFM_AngularMultiPipeAvailable.currency];
|
|
50
55
|
DyFM_multiPipeAngularPipes[DyFM_AngularMultiPipeAvailable.currency] = (val: string, arg: string) => `angular transformed with ${arg}`;
|
|
51
|
-
|
|
56
|
+
const result = DyFM_multiPipe_pipeTransform(value, pipes);
|
|
57
|
+
DyFM_multiPipeAngularPipes[DyFM_AngularMultiPipeAvailable.currency] = originalPipe;
|
|
58
|
+
expect(result).toBe('angular transformed with arg1');
|
|
52
59
|
});
|
|
53
60
|
|
|
54
61
|
/* it('| should handle errors gracefully and return the original value', () => {
|
|
Binary file
|