@woltz/rich-domain 1.2.4 → 1.3.0
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/dist/aggregate-changes.d.ts +56 -14
- package/dist/aggregate-changes.d.ts.map +1 -1
- package/dist/aggregate-changes.js +102 -22
- package/dist/aggregate-changes.js.map +1 -1
- package/dist/base-entity.d.ts +1 -1
- package/dist/base-entity.d.ts.map +1 -1
- package/dist/base-entity.js +11 -8
- package/dist/base-entity.js.map +1 -1
- package/dist/change-tracker.d.ts +1 -0
- package/dist/change-tracker.d.ts.map +1 -1
- package/dist/change-tracker.js +41 -27
- package/dist/change-tracker.js.map +1 -1
- package/dist/criteria.d.ts +7 -15
- package/dist/criteria.d.ts.map +1 -1
- package/dist/criteria.js +99 -76
- package/dist/criteria.js.map +1 -1
- package/dist/entity-schema-registry.d.ts +133 -3
- package/dist/entity-schema-registry.d.ts.map +1 -1
- package/dist/entity-schema-registry.js +155 -4
- package/dist/entity-schema-registry.js.map +1 -1
- package/dist/paginated-result.d.ts +4 -4
- package/dist/paginated-result.d.ts.map +1 -1
- package/dist/paginated-result.js +6 -20
- package/dist/paginated-result.js.map +1 -1
- package/dist/types/change-tracker.d.ts +30 -0
- package/dist/types/change-tracker.d.ts.map +1 -1
- package/dist/types/criteria.d.ts +1 -4
- package/dist/types/criteria.d.ts.map +1 -1
- package/dist/types/domain.d.ts +2 -0
- package/dist/types/domain.d.ts.map +1 -1
- package/dist/types/utils.d.ts +2 -2
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +23 -0
- package/dist/utils/helpers.js.map +1 -1
- package/dist/value-object.d.ts +1 -1
- package/dist/value-object.js +1 -1
- package/package.json +17 -3
- package/src/aggregate-changes.ts +133 -24
- package/src/base-entity.ts +13 -8
- package/src/change-tracker.ts +107 -38
- package/src/criteria.ts +151 -109
- package/src/entity-schema-registry.ts +253 -6
- package/src/paginated-result.ts +10 -30
- package/src/types/change-tracker.ts +31 -0
- package/src/types/criteria.ts +1 -4
- package/src/types/domain.ts +2 -0
- package/src/types/utils.ts +2 -2
- package/src/utils/helpers.ts +28 -0
- package/src/value-object.ts +1 -1
- package/.versionrc.json +0 -21
- package/CHANGELOG.md +0 -163
- package/tests/aggregate-changes.test.ts +0 -284
- package/tests/criteria.test.ts +0 -716
- package/tests/depth/deep-tracking.test.ts +0 -554
- package/tests/domain-events.test.ts +0 -431
- package/tests/entity-equality.test.ts +0 -464
- package/tests/entity-schema-registry.test.ts +0 -382
- package/tests/entity-validation.test.ts +0 -252
- package/tests/history-tracker.spec.ts +0 -439
- package/tests/id.test.ts +0 -338
- package/tests/load-test/data.json +0 -347211
- package/tests/load-test/entities.ts +0 -97
- package/tests/load-test/generate-data.ts +0 -81
- package/tests/load-test/lead-to-domain.mapper.ts +0 -24
- package/tests/load-test/load.test.ts +0 -38
- package/tests/repository.test.ts +0 -635
- package/tests/to-json.test.ts +0 -99
- package/tests/utils.ts +0 -290
- package/tests/value-object-validation.test.ts +0 -219
- package/tests/value-objects.test.ts +0 -80
- package/tsconfig.json +0 -9
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
import { Id } from "../src/id";
|
|
2
|
-
import { Post, TagReference, User, Like, Address, Comment } from "./utils";
|
|
3
|
-
|
|
4
|
-
function createUser(
|
|
5
|
-
overrides: Partial<{
|
|
6
|
-
name: string;
|
|
7
|
-
email: string;
|
|
8
|
-
address: Address | null;
|
|
9
|
-
posts: Post[];
|
|
10
|
-
tags: TagReference[];
|
|
11
|
-
}> = {}
|
|
12
|
-
) {
|
|
13
|
-
const user = new User({
|
|
14
|
-
id: new Id("user-1"),
|
|
15
|
-
name: overrides.name ?? "Test User",
|
|
16
|
-
email: overrides.email ?? "test@test.com",
|
|
17
|
-
address: overrides.address ?? null,
|
|
18
|
-
posts: overrides.posts ?? [],
|
|
19
|
-
tags: overrides.tags ?? [],
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return user;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function createPost(
|
|
26
|
-
overrides: Partial<{
|
|
27
|
-
title: string;
|
|
28
|
-
content: string;
|
|
29
|
-
published: boolean;
|
|
30
|
-
comments: Comment[];
|
|
31
|
-
}> = {}
|
|
32
|
-
): Post {
|
|
33
|
-
return new Post({
|
|
34
|
-
id: new Id(),
|
|
35
|
-
title: overrides.title ?? "Test Post",
|
|
36
|
-
content: overrides.content ?? "Test content",
|
|
37
|
-
published: overrides.published ?? false,
|
|
38
|
-
comments: overrides.comments ?? [],
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function createComment(
|
|
43
|
-
overrides: Partial<{
|
|
44
|
-
text: string;
|
|
45
|
-
authorId: string;
|
|
46
|
-
likes: Like[];
|
|
47
|
-
}> = {}
|
|
48
|
-
): Comment {
|
|
49
|
-
return new Comment({
|
|
50
|
-
id: new Id(),
|
|
51
|
-
text: overrides.text ?? "Test comment",
|
|
52
|
-
authorId: overrides.authorId ?? "author-1",
|
|
53
|
-
likes: overrides.likes ?? [],
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function createAddress(street = "123 Main St", city = "Test City"): Address {
|
|
58
|
-
return new Address({
|
|
59
|
-
id: new Id(),
|
|
60
|
-
street,
|
|
61
|
-
city,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
describe("ChangeTracker.getChanges()", () => {
|
|
66
|
-
describe("no changes", () => {
|
|
67
|
-
it("should return empty changes when nothing modified", () => {
|
|
68
|
-
const user = createUser();
|
|
69
|
-
|
|
70
|
-
const changes = user.getChanges();
|
|
71
|
-
|
|
72
|
-
expect(changes.isEmpty()).toBe(true);
|
|
73
|
-
expect(changes.hasCreates()).toBe(false);
|
|
74
|
-
expect(changes.hasUpdates()).toBe(false);
|
|
75
|
-
expect(changes.hasDeletes()).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("root property changes", () => {
|
|
80
|
-
it("should detect primitive property changes", () => {
|
|
81
|
-
const user = createUser();
|
|
82
|
-
|
|
83
|
-
user.changeName("New Name");
|
|
84
|
-
user.changeEmail("new@email.com");
|
|
85
|
-
|
|
86
|
-
const changes = user.getTypedChanges();
|
|
87
|
-
|
|
88
|
-
expect(changes.hasUpdates()).toBe(true);
|
|
89
|
-
|
|
90
|
-
const userUpdates = changes.for("User");
|
|
91
|
-
expect(userUpdates.hasUpdates()).toBe(true);
|
|
92
|
-
expect(userUpdates.updates[0].changed).toMatchObject({
|
|
93
|
-
name: "New Name",
|
|
94
|
-
email: "new@email.com",
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("collection changes (1:N)", () => {
|
|
100
|
-
it("should detect added items", () => {
|
|
101
|
-
const user = createUser();
|
|
102
|
-
const newPost = createPost({ title: "New Post" });
|
|
103
|
-
|
|
104
|
-
user.addPost(newPost);
|
|
105
|
-
|
|
106
|
-
const changes = user.getTypedChanges();
|
|
107
|
-
|
|
108
|
-
expect(changes.hasCreates()).toBe(true);
|
|
109
|
-
|
|
110
|
-
const postChanges = changes.for("Post");
|
|
111
|
-
|
|
112
|
-
expect(postChanges.hasCreates()).toBe(true);
|
|
113
|
-
expect(postChanges.creates).toHaveLength(1);
|
|
114
|
-
expect(postChanges.creates[0].title).toBe("New Post");
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("should detect removed items", () => {
|
|
118
|
-
const existingPost = new Post({
|
|
119
|
-
id: new Id(),
|
|
120
|
-
title: "Existing Post",
|
|
121
|
-
content: "Existing content",
|
|
122
|
-
published: false,
|
|
123
|
-
comments: [],
|
|
124
|
-
});
|
|
125
|
-
const user = new User({
|
|
126
|
-
id: new Id(),
|
|
127
|
-
name: "Test User",
|
|
128
|
-
email: "test@test.com",
|
|
129
|
-
address: null,
|
|
130
|
-
posts: [existingPost],
|
|
131
|
-
tags: [],
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
user.removePost(existingPost.id);
|
|
135
|
-
|
|
136
|
-
const changes = user.getChanges();
|
|
137
|
-
|
|
138
|
-
expect(changes.hasDeletes()).toBe(true);
|
|
139
|
-
|
|
140
|
-
const postChanges = changes.for("Post");
|
|
141
|
-
expect(postChanges.hasDeletes()).toBe(true);
|
|
142
|
-
expect(postChanges.deletes.length).toBe(1);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("should detect updated items", () => {
|
|
146
|
-
const existingPost = createPost({ title: "Original Title" });
|
|
147
|
-
const user = createUser({ posts: [existingPost] });
|
|
148
|
-
|
|
149
|
-
user.posts[0].changeTitle("Updated Title");
|
|
150
|
-
|
|
151
|
-
const changes = user.getTypedChanges();
|
|
152
|
-
|
|
153
|
-
const postChanges = changes.for("Post");
|
|
154
|
-
expect(postChanges.hasUpdates()).toBe(true);
|
|
155
|
-
expect(postChanges.updates[0].changed).toMatchObject({
|
|
156
|
-
title: "Updated Title",
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("should detect multiple operations", () => {
|
|
161
|
-
const post1 = createPost({ title: "Post 1" });
|
|
162
|
-
const post2 = createPost({ title: "Post 2" });
|
|
163
|
-
const user = createUser({ posts: [post1, post2] });
|
|
164
|
-
|
|
165
|
-
// Remove post1
|
|
166
|
-
user.removePost(post1.id);
|
|
167
|
-
|
|
168
|
-
// Add new post
|
|
169
|
-
const post3 = createPost({ title: "Post 3" });
|
|
170
|
-
user.addPost(post3);
|
|
171
|
-
|
|
172
|
-
// Update post2
|
|
173
|
-
user.posts[0].changeTitle("Post 2 Updated");
|
|
174
|
-
|
|
175
|
-
const changes = user.getTypedChanges();
|
|
176
|
-
const postChanges = changes.for("Post");
|
|
177
|
-
|
|
178
|
-
expect(postChanges.hasCreates()).toBe(true);
|
|
179
|
-
expect(postChanges.hasUpdates()).toBe(true);
|
|
180
|
-
expect(postChanges.hasDeletes()).toBe(true);
|
|
181
|
-
expect(postChanges.creates).toHaveLength(1);
|
|
182
|
-
expect(postChanges.updates).toHaveLength(1);
|
|
183
|
-
expect(postChanges.deletes).toHaveLength(1);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
describe("nested collections", () => {
|
|
188
|
-
it("should detect changes in deeply nested collections", () => {
|
|
189
|
-
const comment = createComment({ text: "Original comment" });
|
|
190
|
-
const post = createPost({ comments: [comment] });
|
|
191
|
-
const user = createUser({ posts: [post] });
|
|
192
|
-
|
|
193
|
-
// Add new comment
|
|
194
|
-
const newComment = createComment({ text: "New comment" });
|
|
195
|
-
user.posts[0].addComment(newComment);
|
|
196
|
-
|
|
197
|
-
const changes = user.getTypedChanges();
|
|
198
|
-
const commentChanges = changes.for("Comment");
|
|
199
|
-
|
|
200
|
-
expect(commentChanges.hasCreates()).toBe(true);
|
|
201
|
-
expect(commentChanges.creates[0].text).toBe("New comment");
|
|
202
|
-
expect(commentChanges.updates).toHaveLength(0);
|
|
203
|
-
expect(commentChanges.deletes).toHaveLength(0);
|
|
204
|
-
expect(commentChanges.creates).toHaveLength(1);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("should handle 3+ levels of nesting (User > Post > Comment > Like)", () => {
|
|
208
|
-
const comment = createComment({ likes: [] });
|
|
209
|
-
const post = createPost({ comments: [comment] });
|
|
210
|
-
const user = createUser({ posts: [post] });
|
|
211
|
-
|
|
212
|
-
const newLike = new Like({
|
|
213
|
-
postId: "post-1",
|
|
214
|
-
userId: "user-2",
|
|
215
|
-
createdAt: new Date(),
|
|
216
|
-
});
|
|
217
|
-
user.posts[0].comments[0].addLike(newLike);
|
|
218
|
-
|
|
219
|
-
const changes = user.getTypedChanges();
|
|
220
|
-
const likeChanges = changes.for("Like");
|
|
221
|
-
|
|
222
|
-
expect(likeChanges.hasCreates()).toBe(true);
|
|
223
|
-
expect(likeChanges.creates).toHaveLength(1);
|
|
224
|
-
expect(likeChanges.updates).toHaveLength(0);
|
|
225
|
-
expect(likeChanges.deletes).toHaveLength(0);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe("entity relations (1:1)", () => {
|
|
230
|
-
it("should detect created entity (null → Entity)", () => {
|
|
231
|
-
const user = createUser({ address: null });
|
|
232
|
-
|
|
233
|
-
user.setAddress(createAddress("New Street", "New City"));
|
|
234
|
-
|
|
235
|
-
const changes = user.getTypedChanges();
|
|
236
|
-
const addressChanges = changes.for("Address");
|
|
237
|
-
|
|
238
|
-
expect(addressChanges.hasCreates()).toBe(true);
|
|
239
|
-
expect(addressChanges.creates[0].street).toBe("New Street");
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it("should detect deleted entity (Entity → null)", () => {
|
|
243
|
-
const address = createAddress();
|
|
244
|
-
const user = createUser({ address });
|
|
245
|
-
|
|
246
|
-
user.removeAddress();
|
|
247
|
-
|
|
248
|
-
const changes = user.getTypedChanges();
|
|
249
|
-
const addressChanges = changes.for("Address");
|
|
250
|
-
|
|
251
|
-
expect(addressChanges.hasDeletes()).toBe(true);
|
|
252
|
-
expect(addressChanges.deletes).toHaveLength(1);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("should detect updated entity (same ID with changes)", () => {
|
|
256
|
-
const address = createAddress("Old Street", "Old City");
|
|
257
|
-
const user = createUser({ address });
|
|
258
|
-
|
|
259
|
-
user.address?.changeStreet("New Street");
|
|
260
|
-
|
|
261
|
-
const changes = user.getTypedChanges();
|
|
262
|
-
const addressChanges = changes.for("Address");
|
|
263
|
-
|
|
264
|
-
expect(addressChanges.hasUpdates()).toBe(true);
|
|
265
|
-
expect(addressChanges.updates[0].changed).toMatchObject({
|
|
266
|
-
street: "New Street",
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it("should detect replaced entity (different ID)", () => {
|
|
271
|
-
const oldAddress = createAddress("Old Street", "Old City");
|
|
272
|
-
const user = createUser({ address: oldAddress });
|
|
273
|
-
|
|
274
|
-
const newAddress = createAddress("New Street", "New City");
|
|
275
|
-
user.setAddress(newAddress);
|
|
276
|
-
|
|
277
|
-
const changes = user.getTypedChanges();
|
|
278
|
-
const addressChanges = changes.for("Address");
|
|
279
|
-
|
|
280
|
-
expect(addressChanges.hasDeletes()).toBe(true);
|
|
281
|
-
expect(addressChanges.hasCreates()).toBe(true);
|
|
282
|
-
expect(addressChanges.deletes).toHaveLength(1);
|
|
283
|
-
expect(addressChanges.deletes[0].id.value).toBe(oldAddress.id.value);
|
|
284
|
-
expect(addressChanges.creates).toHaveLength(1);
|
|
285
|
-
expect(addressChanges.creates[0].id.value).toBe(newAddress.id.value);
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
describe("Value Objects with identityKey", () => {
|
|
290
|
-
it("should detect added VOs using identityKey", () => {
|
|
291
|
-
const user = createUser({ tags: [] });
|
|
292
|
-
|
|
293
|
-
const tag = new TagReference({ tagId: "tag-1", name: "JavaScript" });
|
|
294
|
-
user.addTag(tag);
|
|
295
|
-
|
|
296
|
-
const changes = user.getTypedChanges();
|
|
297
|
-
const tagChanges = changes.for("TagReference");
|
|
298
|
-
|
|
299
|
-
expect(tagChanges.hasCreates()).toBe(true);
|
|
300
|
-
expect(tagChanges.creates).toHaveLength(1);
|
|
301
|
-
expect(tagChanges.creates[0].tagId).toBe("tag-1");
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
it("should detect removed VOs using identityKey", () => {
|
|
305
|
-
const tag = new TagReference({ tagId: "tag-1", name: "JavaScript" });
|
|
306
|
-
const user = createUser({ tags: [tag] });
|
|
307
|
-
|
|
308
|
-
user.removeTag(tag.tagId);
|
|
309
|
-
|
|
310
|
-
const changes = user.getTypedChanges();
|
|
311
|
-
const tagChanges = changes.for("TagReference");
|
|
312
|
-
|
|
313
|
-
expect(tagChanges.hasDeletes()).toBe(true);
|
|
314
|
-
expect(tagChanges.deletes).toHaveLength(1);
|
|
315
|
-
expect(tagChanges.deletes[0].tagId).toBe("tag-1");
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it("should use composite identityKey for Likes", () => {
|
|
319
|
-
const like = new Like({
|
|
320
|
-
postId: "post-1",
|
|
321
|
-
userId: "user-1",
|
|
322
|
-
createdAt: new Date(),
|
|
323
|
-
});
|
|
324
|
-
const comment = createComment({ likes: [like] });
|
|
325
|
-
const post = createPost({ comments: [comment] });
|
|
326
|
-
const user = createUser({ posts: [post] });
|
|
327
|
-
|
|
328
|
-
user.posts[0].comments[0].removeLike(like.postId, like.userId);
|
|
329
|
-
|
|
330
|
-
const changes = user.getTypedChanges();
|
|
331
|
-
const likeChanges = changes.for("Like");
|
|
332
|
-
|
|
333
|
-
expect(likeChanges.hasDeletes()).toBe(true);
|
|
334
|
-
expect(likeChanges.deletes).toHaveLength(1);
|
|
335
|
-
expect(likeChanges.deletes[0].postId).toBe("post-1");
|
|
336
|
-
expect(likeChanges.deletes[0].userId).toBe("user-1");
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
describe("toBatchOperations", () => {
|
|
341
|
-
it("should group and order operations correctly", () => {
|
|
342
|
-
const comment = createComment();
|
|
343
|
-
const post = createPost({ comments: [comment] });
|
|
344
|
-
const address = createAddress();
|
|
345
|
-
const user = createUser({ posts: [post], address });
|
|
346
|
-
|
|
347
|
-
user.changeName("New Name"); // depth 0
|
|
348
|
-
user.address?.changeStreet("New Street"); // depth 1
|
|
349
|
-
user.posts[0].changeTitle("New Title"); // depth 1
|
|
350
|
-
user.posts[0].comments[0].changeText("New Comment"); // depth 2
|
|
351
|
-
|
|
352
|
-
const newPost = createPost({ title: "Brand New Post" });
|
|
353
|
-
user.addPost(newPost);
|
|
354
|
-
|
|
355
|
-
const changes = user.getTypedChanges();
|
|
356
|
-
const batch = changes.toBatchOperations();
|
|
357
|
-
|
|
358
|
-
expect(batch.deletes).toHaveLength(0);
|
|
359
|
-
|
|
360
|
-
expect(batch.creates.length).toBe(1);
|
|
361
|
-
expect(batch.creates[0].entity).toBe("Post");
|
|
362
|
-
expect(batch.creates[0].depth).toBe(1);
|
|
363
|
-
|
|
364
|
-
expect(batch.updates.length).toBe(4);
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
it("should order deletes by depth DESC (leaf → root)", () => {
|
|
368
|
-
const like = new Like({
|
|
369
|
-
postId: "post-1",
|
|
370
|
-
userId: "user-1",
|
|
371
|
-
createdAt: new Date(),
|
|
372
|
-
});
|
|
373
|
-
const comment = createComment({ likes: [like] });
|
|
374
|
-
const post = createPost({ comments: [comment] });
|
|
375
|
-
const user = createUser({ posts: [post] });
|
|
376
|
-
|
|
377
|
-
user.posts[0].comments[0].removeLike(like.postId, like.userId);
|
|
378
|
-
user.posts[0].comments = [];
|
|
379
|
-
user.posts = [];
|
|
380
|
-
|
|
381
|
-
const changes = user.getChanges();
|
|
382
|
-
const batch = changes.toBatchOperations();
|
|
383
|
-
|
|
384
|
-
// Like (depth 3) → Comment (depth 2) → Post (depth 1)
|
|
385
|
-
const likeIdx = batch.deletes.findIndex((d) => d.entity === "Like");
|
|
386
|
-
const commentIdx = batch.deletes.findIndex((d) => d.entity === "Comment");
|
|
387
|
-
const postIdx = batch.deletes.findIndex((d) => d.entity === "Post");
|
|
388
|
-
|
|
389
|
-
expect(batch.deletes).toHaveLength(3);
|
|
390
|
-
expect(likeIdx).toBeLessThan(commentIdx);
|
|
391
|
-
expect(commentIdx).toBeLessThan(postIdx);
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
it("should order creates by depth ASC (root → leaf)", () => {
|
|
395
|
-
const user = createUser();
|
|
396
|
-
|
|
397
|
-
const newComment = createComment({ text: "New Comment" });
|
|
398
|
-
const newPost = createPost({ title: "New Post" });
|
|
399
|
-
user.addPost(newPost);
|
|
400
|
-
user.posts[0].addComment(newComment);
|
|
401
|
-
|
|
402
|
-
const changes = user.getTypedChanges();
|
|
403
|
-
const batch = changes.toBatchOperations();
|
|
404
|
-
|
|
405
|
-
const postIdx = batch.creates.findIndex((c) => c.entity === "Post");
|
|
406
|
-
const commentIdx = batch.creates.findIndex((c) => c.entity === "Comment");
|
|
407
|
-
|
|
408
|
-
expect(batch.creates.length).toBe(2);
|
|
409
|
-
expect(batch.creates[0].entity).toBe("Post");
|
|
410
|
-
expect(batch.creates[0].depth).toBe(1);
|
|
411
|
-
expect(batch.creates[1].entity).toBe("Comment");
|
|
412
|
-
expect(batch.creates[1].depth).toBe(2);
|
|
413
|
-
expect(postIdx).toBeLessThan(commentIdx);
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
describe("markAsClean", () => {
|
|
418
|
-
it("should reset changes after clearHistory", () => {
|
|
419
|
-
const user = createUser();
|
|
420
|
-
|
|
421
|
-
user.changeName("Changed Name");
|
|
422
|
-
|
|
423
|
-
expect(user.getChanges().hasChanges()).toBe(true);
|
|
424
|
-
|
|
425
|
-
user.markAsClean();
|
|
426
|
-
|
|
427
|
-
expect(user.getChanges().isEmpty()).toBe(true);
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it("should reset changes after markAsClean", () => {
|
|
431
|
-
const user = createUser();
|
|
432
|
-
|
|
433
|
-
user.changeName("Changed Name");
|
|
434
|
-
user.markAsClean();
|
|
435
|
-
|
|
436
|
-
expect(user.getChanges().isEmpty()).toBe(true);
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
});
|