@rebasepro/server-postgresql 0.0.1-canary.4d4fb3e → 0.0.1-canary.ca2cb6e
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/common/src/collections/CollectionRegistry.d.ts +8 -0
- package/dist/common/src/util/entities.d.ts +22 -0
- package/dist/common/src/util/relations.d.ts +14 -4
- package/dist/common/src/util/resolutions.d.ts +1 -1
- package/dist/index.es.js +1254 -591
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1254 -591
- package/dist/index.umd.js.map +1 -1
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +17 -29
- package/dist/server-postgresql/src/auth/services.d.ts +7 -3
- package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +1 -1
- package/dist/server-postgresql/src/connection.d.ts +34 -1
- package/dist/server-postgresql/src/data-transformer.d.ts +26 -4
- package/dist/server-postgresql/src/databasePoolManager.d.ts +2 -2
- package/dist/server-postgresql/src/schema/auth-schema.d.ts +139 -38
- package/dist/server-postgresql/src/schema/doctor-cli.d.ts +2 -0
- package/dist/server-postgresql/src/schema/doctor.d.ts +43 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema-logic.d.ts +1 -1
- package/dist/server-postgresql/src/schema/test-schema.d.ts +24 -0
- package/dist/server-postgresql/src/services/EntityFetchService.d.ts +22 -8
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +1 -1
- package/dist/server-postgresql/src/services/RelationService.d.ts +11 -5
- package/dist/server-postgresql/src/services/entity-helpers.d.ts +16 -2
- package/dist/server-postgresql/src/services/entityService.d.ts +8 -6
- package/dist/server-postgresql/src/services/realtimeService.d.ts +2 -0
- package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +2 -2
- package/dist/types/src/controllers/auth.d.ts +2 -0
- package/dist/types/src/controllers/client.d.ts +119 -7
- package/dist/types/src/controllers/collection_registry.d.ts +4 -3
- package/dist/types/src/controllers/customization_controller.d.ts +7 -1
- package/dist/types/src/controllers/data.d.ts +34 -7
- package/dist/types/src/controllers/data_driver.d.ts +20 -28
- package/dist/types/src/controllers/database_admin.d.ts +2 -2
- package/dist/types/src/controllers/email.d.ts +34 -0
- package/dist/types/src/controllers/index.d.ts +1 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +4 -4
- package/dist/types/src/controllers/navigation.d.ts +5 -5
- package/dist/types/src/controllers/registry.d.ts +6 -3
- package/dist/types/src/controllers/side_entity_controller.d.ts +7 -6
- package/dist/types/src/controllers/storage.d.ts +24 -26
- package/dist/types/src/rebase_context.d.ts +8 -4
- package/dist/types/src/types/backend.d.ts +4 -1
- package/dist/types/src/types/builders.d.ts +5 -4
- package/dist/types/src/types/chips.d.ts +1 -1
- package/dist/types/src/types/collections.d.ts +169 -125
- package/dist/types/src/types/cron.d.ts +102 -0
- package/dist/types/src/types/data_source.d.ts +1 -1
- package/dist/types/src/types/entity_actions.d.ts +8 -8
- package/dist/types/src/types/entity_callbacks.d.ts +15 -15
- package/dist/types/src/types/entity_link_builder.d.ts +1 -1
- package/dist/types/src/types/entity_overrides.d.ts +2 -1
- package/dist/types/src/types/entity_views.d.ts +8 -8
- package/dist/types/src/types/export_import.d.ts +3 -3
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/plugins.d.ts +72 -18
- package/dist/types/src/types/properties.d.ts +118 -33
- package/dist/types/src/types/relations.d.ts +1 -1
- package/dist/types/src/types/slots.d.ts +30 -6
- package/dist/types/src/types/translations.d.ts +44 -0
- package/dist/types/src/types/user_management_delegate.d.ts +1 -0
- package/drizzle-test/0000_woozy_junta.sql +6 -0
- package/drizzle-test/0001_youthful_arachne.sql +1 -0
- package/drizzle-test/0002_lively_dragon_lord.sql +2 -0
- package/drizzle-test/0003_mean_king_cobra.sql +2 -0
- package/drizzle-test/meta/0000_snapshot.json +47 -0
- package/drizzle-test/meta/0001_snapshot.json +48 -0
- package/drizzle-test/meta/0002_snapshot.json +38 -0
- package/drizzle-test/meta/0003_snapshot.json +48 -0
- package/drizzle-test/meta/_journal.json +34 -0
- package/drizzle-test-out/0000_tan_trauma.sql +6 -0
- package/drizzle-test-out/0001_rapid_drax.sql +1 -0
- package/drizzle-test-out/meta/0000_snapshot.json +44 -0
- package/drizzle-test-out/meta/0001_snapshot.json +54 -0
- package/drizzle-test-out/meta/_journal.json +20 -0
- package/drizzle.test.config.ts +10 -0
- package/package.json +88 -89
- package/scratch.ts +41 -0
- package/src/PostgresBackendDriver.ts +63 -79
- package/src/PostgresBootstrapper.ts +7 -8
- package/src/auth/ensure-tables.ts +158 -86
- package/src/auth/services.ts +109 -50
- package/src/cli.ts +259 -16
- package/src/collections/PostgresCollectionRegistry.ts +6 -6
- package/src/connection.ts +70 -48
- package/src/data-transformer.ts +155 -116
- package/src/databasePoolManager.ts +6 -5
- package/src/history/HistoryService.ts +3 -12
- package/src/interfaces.ts +3 -3
- package/src/schema/auth-schema.ts +26 -3
- package/src/schema/doctor-cli.ts +47 -0
- package/src/schema/doctor.ts +595 -0
- package/src/schema/generate-drizzle-schema-logic.ts +204 -57
- package/src/schema/generate-drizzle-schema.ts +6 -6
- package/src/schema/test-schema.ts +11 -0
- package/src/services/BranchService.ts +5 -5
- package/src/services/EntityFetchService.ts +317 -188
- package/src/services/EntityPersistService.ts +15 -17
- package/src/services/RelationService.ts +299 -37
- package/src/services/entity-helpers.ts +39 -13
- package/src/services/entityService.ts +11 -9
- package/src/services/realtimeService.ts +58 -29
- package/src/utils/drizzle-conditions.ts +25 -24
- package/src/websocket.ts +52 -21
- package/test/auth-services.test.ts +131 -39
- package/test/batch-many-to-many-regression.test.ts +573 -0
- package/test/branchService.test.ts +22 -12
- package/test/data-transformer-hardening.test.ts +417 -0
- package/test/data-transformer.test.ts +175 -0
- package/test/doctor.test.ts +182 -0
- package/test/entityService.errors.test.ts +31 -16
- package/test/entityService.relations.test.ts +155 -59
- package/test/entityService.subcollection-search.test.ts +107 -57
- package/test/entityService.test.ts +105 -47
- package/test/generate-drizzle-schema.test.ts +262 -69
- package/test/historyService.test.ts +31 -16
- package/test/n-plus-one-regression.test.ts +314 -0
- package/test/postgresDataDriver.test.ts +260 -168
- package/test/realtimeService.test.ts +70 -39
- package/test/relation-pipeline-gaps.test.ts +637 -0
- package/test/relations.test.ts +492 -39
- package/test-drizzle-bug.ts +18 -0
- package/test-drizzle-out/0000_cultured_freak.sql +7 -0
- package/test-drizzle-out/0001_tiresome_professor_monster.sql +1 -0
- package/test-drizzle-out/meta/0000_snapshot.json +55 -0
- package/test-drizzle-out/meta/0001_snapshot.json +63 -0
- package/test-drizzle-out/meta/_journal.json +20 -0
- package/test-drizzle-prompt.sh +2 -0
- package/test-policy-prompt.sh +3 -0
- package/test-programmatic.ts +30 -0
- package/test-programmatic2.ts +59 -0
- package/test-schema-no-policies.ts +12 -0
- package/test_drizzle_mock.js +2 -2
- package/test_find_changed.mjs +3 -1
- package/test_hash.js +14 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +5 -5
|
@@ -11,19 +11,24 @@ const mockAuthorsTable = {
|
|
|
11
11
|
_def: { tableName: "authors" }
|
|
12
12
|
};
|
|
13
13
|
const mockPostsTable = {
|
|
14
|
-
id: { name: "id",
|
|
14
|
+
id: { name: "id",
|
|
15
|
+
dataType: "number" },
|
|
15
16
|
title: { name: "title" },
|
|
16
|
-
author_id: { name: "author_id",
|
|
17
|
+
author_id: { name: "author_id",
|
|
18
|
+
dataType: "number" },
|
|
17
19
|
_def: { tableName: "posts" }
|
|
18
20
|
};
|
|
19
21
|
const mockTagsTable = {
|
|
20
|
-
id: { name: "id",
|
|
22
|
+
id: { name: "id",
|
|
23
|
+
dataType: "number" },
|
|
21
24
|
name: { name: "name" },
|
|
22
25
|
_def: { tableName: "tags" }
|
|
23
26
|
};
|
|
24
27
|
const mockPostsTagsTable = {
|
|
25
|
-
post_id: { name: "post_id",
|
|
26
|
-
|
|
28
|
+
post_id: { name: "post_id",
|
|
29
|
+
dataType: "number" },
|
|
30
|
+
tag_id: { name: "tag_id",
|
|
31
|
+
dataType: "number" },
|
|
27
32
|
_def: { tableName: "posts_tags" }
|
|
28
33
|
};
|
|
29
34
|
const mockProjectUsersTable = {
|
|
@@ -43,7 +48,7 @@ const tagsCollection: EntityCollection = {
|
|
|
43
48
|
id: { type: "number" },
|
|
44
49
|
name: { type: "string" }
|
|
45
50
|
},
|
|
46
|
-
idField: "id"
|
|
51
|
+
idField: "id"
|
|
47
52
|
};
|
|
48
53
|
|
|
49
54
|
const projectUsersCollection: EntityCollection = {
|
|
@@ -94,7 +99,7 @@ const postsCollection: EntityCollection = {
|
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
],
|
|
97
|
-
idField: "id"
|
|
102
|
+
idField: "id"
|
|
98
103
|
};
|
|
99
104
|
|
|
100
105
|
authorsCollection = {
|
|
@@ -118,7 +123,7 @@ authorsCollection = {
|
|
|
118
123
|
foreignKeyOnTarget: "author_id"
|
|
119
124
|
}
|
|
120
125
|
],
|
|
121
|
-
idField: "id"
|
|
126
|
+
idField: "id"
|
|
122
127
|
};
|
|
123
128
|
|
|
124
129
|
describe("EntityService", () => {
|
|
@@ -157,7 +162,7 @@ describe("EntityService", () => {
|
|
|
157
162
|
update: jest.fn().mockReturnThis(),
|
|
158
163
|
set: jest.fn().mockReturnThis(),
|
|
159
164
|
delete: jest.fn().mockReturnThis(),
|
|
160
|
-
transaction: jest.fn((callback) => callback(db))
|
|
165
|
+
transaction: jest.fn((callback) => callback(db))
|
|
161
166
|
} as unknown as jest.Mocked<NodePgDatabase>;
|
|
162
167
|
|
|
163
168
|
entityService = new EntityService(db, collectionRegistry);
|
|
@@ -220,7 +225,7 @@ describe("EntityService", () => {
|
|
|
220
225
|
db.limit.mockResolvedValue([{
|
|
221
226
|
id: 4,
|
|
222
227
|
title: "Post by Jane",
|
|
223
|
-
author_id: "3"
|
|
228
|
+
author_id: "3" // Database stores the foreign key
|
|
224
229
|
}]);
|
|
225
230
|
|
|
226
231
|
const entity = await entityService.saveEntity("posts", newPost);
|
|
@@ -228,7 +233,7 @@ describe("EntityService", () => {
|
|
|
228
233
|
// 1. Check that the relation was serialized to a foreign key for the database insert
|
|
229
234
|
expect(db.values).toHaveBeenCalledWith(expect.objectContaining({
|
|
230
235
|
title: "Post by Jane",
|
|
231
|
-
author_id: "3"
|
|
236
|
+
author_id: "3" // Should be serialized to FK for database storage
|
|
232
237
|
}));
|
|
233
238
|
|
|
234
239
|
// 2. Check that the returned entity has the relation deserialized correctly
|
|
@@ -303,8 +308,12 @@ describe("EntityService", () => {
|
|
|
303
308
|
describe("fetchCollectionFromPath", () => {
|
|
304
309
|
it("should fetch related entities from a nested path", async () => {
|
|
305
310
|
const mockRelatedPosts = [
|
|
306
|
-
{ id: 1,
|
|
307
|
-
|
|
311
|
+
{ id: 1,
|
|
312
|
+
title: "Post by John",
|
|
313
|
+
author_id: 1 },
|
|
314
|
+
{ id: 2,
|
|
315
|
+
title: "Another Post by John",
|
|
316
|
+
author_id: 1 }
|
|
308
317
|
];
|
|
309
318
|
// RelationService.fetchEntitiesUsingJoins ends query chain with where(), not orderBy()
|
|
310
319
|
// Make where() awaitable by returning a promise-like object
|
|
@@ -333,7 +342,8 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
333
342
|
|
|
334
343
|
// Extended mock tables for more complex scenarios
|
|
335
344
|
const mockUsersTable = {
|
|
336
|
-
id: { name: "id",
|
|
345
|
+
id: { name: "id",
|
|
346
|
+
dataType: "number" },
|
|
337
347
|
email: { name: "email" },
|
|
338
348
|
name: { name: "name" },
|
|
339
349
|
created_at: { name: "created_at" },
|
|
@@ -384,7 +394,8 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
384
394
|
};
|
|
385
395
|
|
|
386
396
|
const mockTagsTable = {
|
|
387
|
-
id: { name: "id",
|
|
397
|
+
id: { name: "id",
|
|
398
|
+
dataType: "number" },
|
|
388
399
|
name: { name: "name" },
|
|
389
400
|
_def: { tableName: "tags" }
|
|
390
401
|
};
|
|
@@ -399,7 +410,8 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
399
410
|
email: { type: "string" },
|
|
400
411
|
name: { type: "string" },
|
|
401
412
|
created_at: { type: "date" },
|
|
402
|
-
companies: { type: "relation",
|
|
413
|
+
companies: { type: "relation",
|
|
414
|
+
relationName: "companies" }
|
|
403
415
|
},
|
|
404
416
|
relations: [{
|
|
405
417
|
relationName: "companies",
|
|
@@ -418,8 +430,10 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
418
430
|
properties: {
|
|
419
431
|
id: { type: "number" },
|
|
420
432
|
name: { type: "string" },
|
|
421
|
-
owner: { type: "relation",
|
|
422
|
-
|
|
433
|
+
owner: { type: "relation",
|
|
434
|
+
relationName: "owner" },
|
|
435
|
+
projects: { type: "relation",
|
|
436
|
+
relationName: "projects" }
|
|
423
437
|
},
|
|
424
438
|
relations: [
|
|
425
439
|
{
|
|
@@ -450,9 +464,12 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
450
464
|
description: { type: "string" },
|
|
451
465
|
status: { type: "string" },
|
|
452
466
|
priority: { type: "number" },
|
|
453
|
-
company: { type: "relation",
|
|
454
|
-
|
|
455
|
-
|
|
467
|
+
company: { type: "relation",
|
|
468
|
+
relationName: "company" },
|
|
469
|
+
tasks: { type: "relation",
|
|
470
|
+
relationName: "tasks" },
|
|
471
|
+
tags: { type: "relation",
|
|
472
|
+
relationName: "tags" }
|
|
456
473
|
},
|
|
457
474
|
relations: [
|
|
458
475
|
{
|
|
@@ -491,8 +508,10 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
491
508
|
properties: {
|
|
492
509
|
id: { type: "number" },
|
|
493
510
|
title: { type: "string" },
|
|
494
|
-
project: { type: "relation",
|
|
495
|
-
|
|
511
|
+
project: { type: "relation",
|
|
512
|
+
relationName: "project" },
|
|
513
|
+
assignee: { type: "relation",
|
|
514
|
+
relationName: "assignee" }
|
|
496
515
|
},
|
|
497
516
|
relations: [
|
|
498
517
|
{
|
|
@@ -531,8 +550,10 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
531
550
|
properties: {
|
|
532
551
|
id: { type: "number" },
|
|
533
552
|
name: { type: "string" },
|
|
534
|
-
parent: { type: "relation",
|
|
535
|
-
|
|
553
|
+
parent: { type: "relation",
|
|
554
|
+
relationName: "parent" },
|
|
555
|
+
children: { type: "relation",
|
|
556
|
+
relationName: "children" }
|
|
536
557
|
},
|
|
537
558
|
relations: [
|
|
538
559
|
{
|
|
@@ -591,7 +612,7 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
591
612
|
update: jest.fn().mockReturnThis(),
|
|
592
613
|
set: jest.fn().mockReturnThis(),
|
|
593
614
|
delete: jest.fn().mockReturnThis(),
|
|
594
|
-
transaction: jest.fn((callback) => callback(db))
|
|
615
|
+
transaction: jest.fn((callback) => callback(db))
|
|
595
616
|
} as unknown as jest.Mocked<NodePgDatabase>;
|
|
596
617
|
|
|
597
618
|
// Add a then method to make the db object awaitable when the query chain ends
|
|
@@ -602,7 +623,9 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
602
623
|
|
|
603
624
|
describe("fetchEntity - Edge Cases", () => {
|
|
604
625
|
it("should handle numeric IDs correctly", async () => {
|
|
605
|
-
const mockUser = { id: 123,
|
|
626
|
+
const mockUser = { id: 123,
|
|
627
|
+
email: "test@example.com",
|
|
628
|
+
name: "Test User" };
|
|
606
629
|
db.limit.mockResolvedValue([mockUser]);
|
|
607
630
|
|
|
608
631
|
const entity = await entityService.fetchEntity("users", 123);
|
|
@@ -623,7 +646,8 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
623
646
|
jest.spyOn(collectionRegistry, "getCollectionByPath").mockReturnValue(stringIdCollection);
|
|
624
647
|
jest.spyOn(collectionRegistry, "getTable").mockImplementation(tableName => {
|
|
625
648
|
if (tableName === "users") return {
|
|
626
|
-
id: { name: "id",
|
|
649
|
+
id: { name: "id",
|
|
650
|
+
dataType: "string" },
|
|
627
651
|
email: { name: "email" },
|
|
628
652
|
name: { name: "name" },
|
|
629
653
|
_def: { tableName: "users" }
|
|
@@ -637,7 +661,9 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
637
661
|
return undefined;
|
|
638
662
|
});
|
|
639
663
|
|
|
640
|
-
const mockUser = { id: "uuid-123",
|
|
664
|
+
const mockUser = { id: "uuid-123",
|
|
665
|
+
email: "test@example.com",
|
|
666
|
+
name: "Test User" };
|
|
641
667
|
db.limit.mockResolvedValue([mockUser]);
|
|
642
668
|
|
|
643
669
|
const entity = await entityService.fetchEntity("users", "uuid-123");
|
|
@@ -655,7 +681,10 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
655
681
|
});
|
|
656
682
|
|
|
657
683
|
it("should handle entities with null relation fields", async () => {
|
|
658
|
-
const mockTask = { id: 1,
|
|
684
|
+
const mockTask = { id: 1,
|
|
685
|
+
title: "Task 1",
|
|
686
|
+
project_id: null,
|
|
687
|
+
assignee_id: null };
|
|
659
688
|
db.limit.mockResolvedValue([mockTask]);
|
|
660
689
|
|
|
661
690
|
const entity = await entityService.fetchEntity("tasks", 1);
|
|
@@ -665,10 +694,10 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
665
694
|
// on the relation resolution logic, so we should check if they are either
|
|
666
695
|
// undefined or have the expected structure
|
|
667
696
|
if (entity?.values.project) {
|
|
668
|
-
expect(entity.values.project).toHaveProperty(
|
|
697
|
+
expect(entity.values.project).toHaveProperty("__type", "relation");
|
|
669
698
|
}
|
|
670
699
|
if (entity?.values.assignee) {
|
|
671
|
-
expect(entity.values.assignee).toHaveProperty(
|
|
700
|
+
expect(entity.values.assignee).toHaveProperty("__type", "relation");
|
|
672
701
|
}
|
|
673
702
|
|
|
674
703
|
// The main test is that the entity was successfully fetched despite null relations
|
|
@@ -680,13 +709,20 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
680
709
|
describe("fetchCollection - Filtering and Pagination", () => {
|
|
681
710
|
it("should apply filters correctly", async () => {
|
|
682
711
|
const mockProjects = [
|
|
683
|
-
{ id: 1,
|
|
684
|
-
|
|
712
|
+
{ id: 1,
|
|
713
|
+
title: "Project 1",
|
|
714
|
+
status: "active",
|
|
715
|
+
priority: 1 },
|
|
716
|
+
{ id: 2,
|
|
717
|
+
title: "Project 2",
|
|
718
|
+
status: "active",
|
|
719
|
+
priority: 2 }
|
|
685
720
|
];
|
|
686
721
|
db.orderBy.mockResolvedValue(mockProjects);
|
|
687
722
|
|
|
688
723
|
await entityService.fetchCollection("projects", {
|
|
689
|
-
filter: { status: ["==", "active"],
|
|
724
|
+
filter: { status: ["==", "active"],
|
|
725
|
+
priority: [">=", 1] }
|
|
690
726
|
});
|
|
691
727
|
|
|
692
728
|
expect(db.where).toHaveBeenCalled();
|
|
@@ -694,8 +730,12 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
694
730
|
|
|
695
731
|
it("should apply ordering correctly", async () => {
|
|
696
732
|
const mockProjects = [
|
|
697
|
-
{ id: 2,
|
|
698
|
-
|
|
733
|
+
{ id: 2,
|
|
734
|
+
title: "Project 2",
|
|
735
|
+
priority: 2 },
|
|
736
|
+
{ id: 1,
|
|
737
|
+
title: "Project 1",
|
|
738
|
+
priority: 1 }
|
|
699
739
|
];
|
|
700
740
|
db.orderBy.mockResolvedValue(mockProjects);
|
|
701
741
|
|
|
@@ -709,8 +749,10 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
709
749
|
|
|
710
750
|
it("should apply limit correctly", async () => {
|
|
711
751
|
const mockProjects = [
|
|
712
|
-
{ id: 1,
|
|
713
|
-
|
|
752
|
+
{ id: 1,
|
|
753
|
+
title: "Project 1" },
|
|
754
|
+
{ id: 2,
|
|
755
|
+
title: "Project 2" }
|
|
714
756
|
];
|
|
715
757
|
// Override the then method to return our mock data for this specific test
|
|
716
758
|
(db as unknown as Record<string, jest.Mock>).then = jest.fn((resolve) => resolve(mockProjects));
|
|
@@ -726,8 +768,12 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
726
768
|
describe("Nested Path Relations", () => {
|
|
727
769
|
it("should handle deep nested paths", async () => {
|
|
728
770
|
const mockTasks = [
|
|
729
|
-
{ id: 1,
|
|
730
|
-
|
|
771
|
+
{ id: 1,
|
|
772
|
+
title: "Task 1",
|
|
773
|
+
project_id: 1 },
|
|
774
|
+
{ id: 2,
|
|
775
|
+
title: "Task 2",
|
|
776
|
+
project_id: 1 }
|
|
731
777
|
];
|
|
732
778
|
// RelationService.fetchEntitiesUsingJoins ends query chain with where(), not orderBy()
|
|
733
779
|
// Make where() awaitable by returning a promise-like object
|
|
@@ -746,8 +792,12 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
746
792
|
|
|
747
793
|
it("should handle self-referencing relations", async () => {
|
|
748
794
|
const mockCategories = [
|
|
749
|
-
{ id: 2,
|
|
750
|
-
|
|
795
|
+
{ id: 2,
|
|
796
|
+
name: "Subcategory 1",
|
|
797
|
+
parent_id: 1 },
|
|
798
|
+
{ id: 3,
|
|
799
|
+
name: "Subcategory 2",
|
|
800
|
+
parent_id: 1 }
|
|
751
801
|
];
|
|
752
802
|
// RelationService.fetchEntitiesUsingJoins ends query chain with where(), not orderBy()
|
|
753
803
|
db.where.mockReturnValue({
|
|
@@ -780,7 +830,9 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
780
830
|
const newProject = {
|
|
781
831
|
title: "New Project",
|
|
782
832
|
description: "A new project",
|
|
783
|
-
company: { id: "1",
|
|
833
|
+
company: { id: "1",
|
|
834
|
+
path: "companies",
|
|
835
|
+
__type: "relation" }
|
|
784
836
|
};
|
|
785
837
|
|
|
786
838
|
db.returning.mockResolvedValue([{ id: 5 }]);
|
|
@@ -803,7 +855,9 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
803
855
|
it("should handle updating entity with relation changes", async () => {
|
|
804
856
|
const updatedTask = {
|
|
805
857
|
title: "Updated Task",
|
|
806
|
-
assignee: { id: "2",
|
|
858
|
+
assignee: { id: "2",
|
|
859
|
+
path: "users",
|
|
860
|
+
__type: "relation" }
|
|
807
861
|
};
|
|
808
862
|
|
|
809
863
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
@@ -864,7 +918,9 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
864
918
|
describe("searchEntities", () => {
|
|
865
919
|
it("should perform search across specified fields", async () => {
|
|
866
920
|
const mockResults = [
|
|
867
|
-
{ id: 1,
|
|
921
|
+
{ id: 1,
|
|
922
|
+
title: "Searchable Project",
|
|
923
|
+
description: "Test description" }
|
|
868
924
|
];
|
|
869
925
|
// Override the then method to return our mock data for this specific test
|
|
870
926
|
(db as unknown as Record<string, jest.Mock>).then = jest.fn((resolve) => resolve(mockResults));
|
|
@@ -877,7 +933,9 @@ describe("EntityService - Comprehensive Tests", () => {
|
|
|
877
933
|
|
|
878
934
|
it("should combine search with filters", async () => {
|
|
879
935
|
const mockResults = [
|
|
880
|
-
{ id: 1,
|
|
936
|
+
{ id: 1,
|
|
937
|
+
title: "Active Project",
|
|
938
|
+
status: "active" }
|
|
881
939
|
];
|
|
882
940
|
// Override the then method to return our mock data for this specific test
|
|
883
941
|
(db as unknown as Record<string, jest.Mock>).then = jest.fn((resolve) => resolve(mockResults));
|