Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions cloud/tests/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import { Payments } from "@/payments";
import { AuthenticatedUser, Authentication } from "@/auth";
import type { AuthResult } from "@/auth/context";
import type { PublicUser, PublicOrganization, ApiKeyInfo } from "@/db/schema";
import { users } from "@/db/schema";
import { TEST_DATABASE_URL } from "@/tests/db";
import { DefaultMockPayments } from "@/tests/payments";
import type { StreamMeteringContext } from "@/api/router/streaming";
import type { ProviderName } from "@/api/router/providers";
import { eq } from "drizzle-orm";

// Re-export expect from vitest
export { expect };
Expand Down Expand Up @@ -309,7 +311,10 @@ function createSequentialDescribe(

// Clean up database - delete org first (cascades), then user
if (ownerRef?.id) {
const dbLayer = createTestDatabaseLayer(databaseUrl);
const dbLayer = Layer.merge(
createTestDatabaseLayer(databaseUrl),
DrizzleORM.layer({ connectionString: databaseUrl }).pipe(Layer.orDie),
);

await Effect.runPromise(
Effect.gen(function* () {
Expand All @@ -323,8 +328,9 @@ function createSequentialDescribe(
});
}

// Delete user
yield* db.users.delete({ userId: ownerRef.id });
// Hard-delete user to avoid polluting other tests with soft-deleted rows
const client = yield* DrizzleORM;
yield* client.delete(users).where(eq(users.id, ownerRef.id));
}).pipe(Effect.provide(dbLayer)),
);
}
Expand Down