| 159 | ] as const; |
| 160 | |
| 161 | const countTenantRows = async (db: DrizzleDb, tenant: string): Promise<number> => { |
| 162 | let total = 0; |
| 163 | for (const table of TENANT_TABLES) { |
| 164 | const rows = await db.select().from(table).where(eq(table.tenant, tenant)); |
| 165 | total += rows.length; |
| 166 | } |
| 167 | // Count by the exact namespaces `seedTenant` inserts. Matching on a `%tenant%` |
| 168 | // LIKE here would reintroduce the very wildcard hazard under test. |
| 169 | const blobs = await db |
| 170 | .select() |
| 171 | .from(blob) |
| 172 | .where(inArray(blob.namespace, [`o:${tenant}/plugin`, `u:${tenant}:subject/plugin`])); |
| 173 | return total + blobs.length; |
| 174 | }; |
| 175 | |
| 176 | describe("purgeOrganizationData", () => { |
| 177 | it("removes all of one org's data and leaves other orgs untouched", async () => { |