| 204 | }; |
| 205 | |
| 206 | const countTenantRows = async (db: DrizzleDb, tenant: string): Promise<number> => { |
| 207 | let total = 0; |
| 208 | for (const table of TENANT_TABLES) { |
| 209 | const rows = await db.select().from(table).where(eq(table.tenant, tenant)); |
| 210 | total += rows.length; |
| 211 | } |
| 212 | // Count by the exact namespaces `seedTenant` inserts. Matching on a `%tenant%` |
| 213 | // LIKE here would reintroduce the very wildcard hazard under test. |
| 214 | const blobs = await db |
| 215 | .select() |
| 216 | .from(blob) |
| 217 | .where(inArray(blob.namespace, [`o:${tenant}/plugin`, `u:${tenant}:subject/plugin`])); |
| 218 | return total + blobs.length; |
| 219 | }; |
| 220 | |
| 221 | describe("purgeOrganizationData", () => { |
| 222 | it("removes all of one org's data and leaves other orgs untouched", async () => { |