(autoIndex: `off` | `eager`)
| 801 | } |
| 802 | |
| 803 | function createJoinTests(autoIndex: `off` | `eager`): void { |
| 804 | describe(`with autoIndex ${autoIndex}`, () => { |
| 805 | // Generate tests for each join type |
| 806 | joinTypes.forEach((joinType) => { |
| 807 | testJoinType(joinType, autoIndex) |
| 808 | }) |
| 809 | |
| 810 | describe(`Complex Join Scenarios`, () => { |
| 811 | let usersCollection: ReturnType<typeof createUsersCollection> |
| 812 | let departmentsCollection: ReturnType<typeof createDepartmentsCollection> |
| 813 | |
| 814 | beforeEach(() => { |
| 815 | usersCollection = createUsersCollection(autoIndex) |
| 816 | departmentsCollection = createDepartmentsCollection(autoIndex) |
| 817 | }) |
| 818 | |
| 819 | test(`should handle multiple simultaneous updates`, () => { |
| 820 | const innerJoinQuery = createLiveQueryCollection({ |
| 821 | startSync: true, |
| 822 | query: (q) => |
| 823 | q |
| 824 | .from({ user: usersCollection }) |
| 825 | .join( |
| 826 | { dept: departmentsCollection }, |
| 827 | ({ user, dept }) => eq(user.department_id, dept.id), |
| 828 | `inner`, |
| 829 | ) |
| 830 | .select(({ user, dept }) => ({ |
| 831 | user_name: user.name, |
| 832 | department_name: dept.name, |
| 833 | })), |
| 834 | }) |
| 835 | |
| 836 | expect(innerJoinQuery.size).toBe(3) |
| 837 | |
| 838 | // Perform multiple operations in a single transaction |
| 839 | usersCollection.utils.begin() |
| 840 | departmentsCollection.utils.begin() |
| 841 | |
| 842 | // Delete Alice |
| 843 | const alice = sampleUsers.find((u) => u.id === 1)! |
| 844 | usersCollection.utils.write({ type: `delete`, value: alice }) |
| 845 | |
| 846 | // Add new user Eve to Engineering |
| 847 | const eve: User = { |
| 848 | id: 5, |
| 849 | name: `Eve`, |
| 850 | email: `eve@example.com`, |
| 851 | department_id: 1, |
| 852 | } |
| 853 | usersCollection.utils.write({ type: `insert`, value: eve }) |
| 854 | |
| 855 | // Add new department IT |
| 856 | const itDept: Department = { id: 4, name: `IT`, budget: 120000 } |
| 857 | departmentsCollection.utils.write({ type: `insert`, value: itDept }) |
| 858 | |
| 859 | // Update Dave to join IT |
| 860 | const updatedDave: User = { |
no test coverage detected
searching dependent graphs…