(getConfig: () => Promise<TagsTestConfig>)
| 28 | type SyncMode = 'eager' | 'on-demand' | 'progressive' |
| 29 | |
| 30 | export function createMovesTestSuite(getConfig: () => Promise<TagsTestConfig>) { |
| 31 | describe(`Moves Suite`, () => { |
| 32 | let usersTable: string |
| 33 | let postsTable: string |
| 34 | let dbClient: Client |
| 35 | let baseUrl: string |
| 36 | let testSchema: string |
| 37 | let config: TagsTestConfig |
| 38 | |
| 39 | beforeAll(async () => { |
| 40 | config = await getConfig() |
| 41 | const setup = config.tagsTestSetup |
| 42 | dbClient = setup.dbClient |
| 43 | baseUrl = setup.baseUrl |
| 44 | testSchema = setup.testSchema |
| 45 | usersTable = setup.usersTable |
| 46 | postsTable = setup.postsTable |
| 47 | }) |
| 48 | |
| 49 | // Helper to create a collection on posts table with WHERE clause that has nested subquery |
| 50 | // This creates a shape: posts WHERE userId IN (SELECT id FROM users WHERE isActive = true) |
| 51 | // When a user's isActive changes, posts will move in/out of this shape |
| 52 | function createPostsByActiveUsersCollection( |
| 53 | syncMode: SyncMode, |
| 54 | id?: string, |
| 55 | ): Collection<any, string, ElectricCollectionUtils, any, any> { |
| 56 | // Remove quotes from table names for the WHERE clause SQL |
| 57 | const usersTableUnquoted = usersTable.replace(/"/g, ``) |
| 58 | const collectionId = |
| 59 | id || `tags-posts-active-users-${syncMode}-${Date.now()}` |
| 60 | |
| 61 | return createCollection( |
| 62 | electricCollectionOptions({ |
| 63 | id: collectionId, |
| 64 | shapeOptions: { |
| 65 | url: `${baseUrl}/v1/shape`, |
| 66 | params: { |
| 67 | table: `${testSchema}.${postsTable}`, |
| 68 | // WHERE clause with nested subquery |
| 69 | // Posts will move in/out when users' isActive changes |
| 70 | // Column reference should be just the column name, not the full table path |
| 71 | where: `"userId" IN (SELECT id FROM ${testSchema}.${usersTableUnquoted} WHERE "isActive" = true)`, |
| 72 | }, |
| 73 | }, |
| 74 | syncMode, |
| 75 | getKey: (item: any) => item.id, |
| 76 | startSync: syncMode !== 'progressive', |
| 77 | }), |
| 78 | ) as any |
| 79 | } |
| 80 | |
| 81 | // Helper to wait for collection to be ready |
| 82 | async function waitForReady( |
| 83 | collection: Collection<any, any, any, any, any>, |
| 84 | syncMode: SyncMode, |
| 85 | ) { |
| 86 | if (syncMode === 'progressive') { |
| 87 | // For progressive mode, start sync explicitly |
no test coverage detected