Skip to content

Commit 1f5b254

Browse files
committed
Move FumaDB policy test into FumaDB package
1 parent e471db5 commit 1f5b254

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

bun.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/fumadb/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@
8686
},
8787
"devDependencies": {
8888
"@effect/vitest": "catalog:",
89+
"@types/better-sqlite3": "^7.6.13",
8990
"@types/node": "catalog:",
9091
"@types/pg": "^8.20.0",
9192
"@types/semver": "^7.7.1",
93+
"better-sqlite3": "^12.9.0",
9294
"tsup": "catalog:",
9395
"typescript": "catalog:",
9496
"vitest": "catalog:"

packages/core/sdk/src/fumadb-policy-blackbox.test.ts renamed to packages/core/fumadb/src/query/table-policy.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ const v1 = schema({
118118
},
119119
});
120120

121-
const policyDB = fumadb({
122-
namespace: "policy_black_box",
121+
const tablePolicyDB = fumadb({
122+
namespace: "table_policy_test",
123123
schemas: [v1],
124124
});
125125

126-
type PolicyQuery = AbstractQuery<typeof v1>;
126+
type TablePolicyQuery = AbstractQuery<typeof v1>;
127127

128128
const makeContext = (allowedTenantIds: readonly string[], marker: string): TenantPolicyContext => ({
129129
allowedTenantIds: new Set(allowedTenantIds),
@@ -136,22 +136,22 @@ const makeHarness = async () => {
136136
sqlite.pragma("foreign_keys = ON");
137137
const runtimeSchema = createDrizzleRuntimeSchemaFromTables({
138138
tables: v1.tables,
139-
namespace: "policy_black_box",
139+
namespace: "table_policy_test",
140140
version: "1.0.0",
141141
provider: "sqlite",
142142
});
143143
const drizzleDb = drizzle(sqlite, { schema: runtimeSchema });
144144

145145
for (const statement of createDrizzleRuntimeSchemaSqlFromTables({
146146
tables: v1.tables,
147-
namespace: "policy_black_box",
147+
namespace: "table_policy_test",
148148
version: "1.0.0",
149149
provider: "sqlite",
150150
})) {
151151
sqlite.exec(statement);
152152
}
153153

154-
const client = policyDB.client(
154+
const client = tablePolicyDB.client(
155155
drizzleAdapter({
156156
db: drizzleDb,
157157
provider: "sqlite",
@@ -166,14 +166,14 @@ const makeHarness = async () => {
166166
};
167167
};
168168

169-
const useHarness = <A>(run: (orm: PolicyQuery) => Promise<A>) =>
169+
const useHarness = <A>(run: (orm: TablePolicyQuery) => Promise<A>) =>
170170
Effect.acquireUseRelease(
171171
Effect.promise(makeHarness),
172172
({ orm }) => Effect.promise(() => run(orm)),
173173
({ close }) => Effect.promise(close),
174174
);
175175

176-
const seedTenants = async (orm: PolicyQuery) => {
176+
const seedTenants = async (orm: TablePolicyQuery) => {
177177
const seed = withQueryContext(orm, makeContext(["tenant-a", "tenant-b"], "seed"));
178178

179179
await seed.createMany("authors", [

packages/core/fumadb/test/setup.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import * as fs from "node:fs";
2+
import * as path from "node:path";
13
import { afterAll } from "vitest";
2-
import { cleanupFiles } from "./shared";
4+
5+
const sqlitePath = path.join(
6+
import.meta.dirname,
7+
"../node_modules/sqlite.sqlite",
8+
);
9+
const prismaDir = path.join(import.meta.dirname, "./prisma");
10+
11+
const cleanupFiles = () => {
12+
fs.rmSync(sqlitePath, { force: true });
13+
fs.rmSync(prismaDir, { recursive: true, force: true });
14+
};
315

416
afterAll(() => {
517
cleanupFiles();

0 commit comments

Comments
 (0)