@gencow/core 0.1.24 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/crud.d.ts +2 -2
- package/dist/crud.js +225 -208
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/reactive.js +10 -3
- package/dist/retry.js +1 -1
- package/dist/rls-db.d.ts +2 -2
- package/dist/rls-db.js +1 -5
- package/dist/scheduler.d.ts +2 -0
- package/dist/scheduler.js +16 -6
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -1
- package/dist/storage.js +29 -22
- package/dist/v.d.ts +2 -2
- package/dist/workflow.js +4 -11
- package/dist/workflows-api.js +5 -12
- package/package.json +45 -42
- package/src/__tests__/auth.test.ts +90 -86
- package/src/__tests__/crons.test.ts +69 -67
- package/src/__tests__/crud-codegen-integration.test.ts +164 -170
- package/src/__tests__/crud-owner-rls.test.ts +308 -301
- package/src/__tests__/crud.test.ts +694 -711
- package/src/__tests__/dist-exports.test.ts +120 -120
- package/src/__tests__/fixtures/basic/auth.ts +16 -16
- package/src/__tests__/fixtures/basic/drizzle.config.ts +1 -4
- package/src/__tests__/fixtures/basic/index.ts +1 -1
- package/src/__tests__/fixtures/basic/schema.ts +1 -1
- package/src/__tests__/fixtures/basic/tasks.ts +4 -4
- package/src/__tests__/fixtures/common/auth-schema.ts +38 -34
- package/src/__tests__/helpers/basic-rls-fixture.ts +80 -78
- package/src/__tests__/helpers/pglite-migrations.ts +2 -5
- package/src/__tests__/helpers/pglite-rls-session.ts +13 -16
- package/src/__tests__/helpers/seed-like-fill.ts +47 -41
- package/src/__tests__/helpers/test-gencow-ctx-rls.ts +4 -7
- package/src/__tests__/httpaction.test.ts +91 -91
- package/src/__tests__/image-optimization.test.ts +570 -574
- package/src/__tests__/load.test.ts +321 -308
- package/src/__tests__/network-sim.test.ts +238 -215
- package/src/__tests__/reactive.test.ts +380 -358
- package/src/__tests__/retry.test.ts +99 -84
- package/src/__tests__/rls-crud-basic.test.ts +172 -245
- package/src/__tests__/rls-crud-no-owner-rls-pglite.test.ts +81 -81
- package/src/__tests__/rls-custom-mutation-handlers.test.ts +47 -94
- package/src/__tests__/rls-custom-query-handlers.test.ts +92 -92
- package/src/__tests__/rls-db-leased-connection.test.ts +2 -6
- package/src/__tests__/rls-session-and-policies.test.ts +181 -199
- package/src/__tests__/scheduler-durable-v2.test.ts +199 -181
- package/src/__tests__/scheduler-durable.test.ts +117 -117
- package/src/__tests__/scheduler-exec.test.ts +258 -246
- package/src/__tests__/scheduler.test.ts +129 -111
- package/src/__tests__/storage.test.ts +282 -269
- package/src/__tests__/tsconfig.json +6 -6
- package/src/__tests__/validator.test.ts +236 -232
- package/src/__tests__/workflow.test.ts +309 -286
- package/src/__tests__/ws-integration.test.ts +223 -218
- package/src/__tests__/ws-scale.test.ts +168 -159
- package/src/auth-config.ts +18 -18
- package/src/auth.ts +106 -106
- package/src/crons.ts +77 -77
- package/src/crud.ts +523 -479
- package/src/index.ts +69 -5
- package/src/reactive.ts +357 -331
- package/src/retry.ts +51 -54
- package/src/rls-db.ts +195 -205
- package/src/rls.ts +33 -36
- package/src/scheduler.ts +237 -211
- package/src/server.ts +0 -1
- package/src/storage.ts +632 -593
- package/src/v.ts +119 -114
- package/src/workflow-types.ts +67 -70
- package/src/workflow.ts +99 -116
- package/src/workflows-api.ts +231 -241
- package/dist/db.d.ts +0 -13
- package/dist/db.js +0 -16
- package/src/db.ts +0 -18
|
@@ -65,25 +65,13 @@ describe("fixtures/basic + PGlite + CRUD + RLS", () => {
|
|
|
65
65
|
db = env.db;
|
|
66
66
|
seededTaskRows = env.taskRows;
|
|
67
67
|
listDef = env.defs.list;
|
|
68
|
-
listHandler = env.defs.list!.handler as (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
) => Promise<
|
|
72
|
-
getHandler = env.defs.get!.handler as (
|
|
73
|
-
ctx: unknown,
|
|
74
|
-
args: unknown
|
|
75
|
-
) => Promise<TaskRow | null>;
|
|
76
|
-
createHandler = env.defs.create!.handler as (
|
|
77
|
-
ctx: unknown,
|
|
78
|
-
args: unknown
|
|
79
|
-
) => Promise<TaskRow>;
|
|
80
|
-
updateHandler = env.defs.update!.handler as (
|
|
81
|
-
ctx: unknown,
|
|
82
|
-
args: unknown
|
|
83
|
-
) => Promise<TaskRow | undefined>;
|
|
68
|
+
listHandler = env.defs.list!.handler as (ctx: unknown, args: unknown) => Promise<TaskListResult>;
|
|
69
|
+
getHandler = env.defs.get!.handler as (ctx: unknown, args: unknown) => Promise<TaskRow | null>;
|
|
70
|
+
createHandler = env.defs.create!.handler as (ctx: unknown, args: unknown) => Promise<TaskRow>;
|
|
71
|
+
updateHandler = env.defs.update!.handler as (ctx: unknown, args: unknown) => Promise<TaskRow | undefined>;
|
|
84
72
|
removeHandler = env.defs.remove!.handler as (
|
|
85
73
|
ctx: unknown,
|
|
86
|
-
args: unknown
|
|
74
|
+
args: unknown,
|
|
87
75
|
) => Promise<{ success: boolean }>;
|
|
88
76
|
});
|
|
89
77
|
|
|
@@ -102,109 +90,81 @@ describe("fixtures/basic + PGlite + CRUD + RLS", () => {
|
|
|
102
90
|
tenantId: "tenant_fixture",
|
|
103
91
|
vars: { "app.note": "ok" },
|
|
104
92
|
});
|
|
105
|
-
const otherUserRows = await scoped
|
|
106
|
-
.select()
|
|
107
|
-
.from(tasks)
|
|
108
|
-
.where(eq(tasks.userId, fixtureUsers[1].id));
|
|
93
|
+
const otherUserRows = await scoped.select().from(tasks).where(eq(tasks.userId, fixtureUsers[1].id));
|
|
109
94
|
expect(otherUserRows.length).toBe(0);
|
|
110
95
|
|
|
111
|
-
const ownRows = await scoped
|
|
112
|
-
|
|
113
|
-
.from(tasks)
|
|
114
|
-
.where(eq(tasks.userId, user0Identity.id));
|
|
115
|
-
expect(ownRows.length).toBe(
|
|
116
|
-
seededTaskRows.filter((r) => r.userId === user0Identity.id).length
|
|
117
|
-
);
|
|
96
|
+
const ownRows = await scoped.select().from(tasks).where(eq(tasks.userId, user0Identity.id));
|
|
97
|
+
expect(ownRows.length).toBe(seededTaskRows.filter((r) => r.userId === user0Identity.id).length);
|
|
118
98
|
});
|
|
119
99
|
|
|
120
100
|
it("tasks.list returns only the current user (us_000) rows per RLS and total matches", async () => {
|
|
121
101
|
expect(listDef).toBeDefined();
|
|
122
102
|
|
|
123
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
expect(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
expect(row).toBeDefined();
|
|
145
|
-
expect(row!.id).toBe(seeded.id);
|
|
146
|
-
expect(row!.userId).toBe(seeded.userId);
|
|
147
|
-
expect(row!.done).toBe(seeded.done);
|
|
148
|
-
expect(row!.title).toBe(seeded.title);
|
|
149
|
-
}
|
|
103
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (ctx) => {
|
|
104
|
+
const listResult = await listHandler(ctx, {});
|
|
105
|
+
|
|
106
|
+
const expected = seededTaskRows.filter((r) => r.userId === fixtureUsers[0].id);
|
|
107
|
+
|
|
108
|
+
expect(listResult).toHaveProperty("data");
|
|
109
|
+
expect(listResult).toHaveProperty("total");
|
|
110
|
+
expect(listResult.total).toBe(expected.length);
|
|
111
|
+
|
|
112
|
+
const rows = listResult.data;
|
|
113
|
+
|
|
114
|
+
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
115
|
+
expect(byId.size).toBe(expected.length);
|
|
116
|
+
|
|
117
|
+
for (const seeded of expected) {
|
|
118
|
+
const row = byId.get(seeded.id);
|
|
119
|
+
expect(row).toBeDefined();
|
|
120
|
+
expect(row!.id).toBe(seeded.id);
|
|
121
|
+
expect(row!.userId).toBe(seeded.userId);
|
|
122
|
+
expect(row!.done).toBe(seeded.done);
|
|
123
|
+
expect(row!.title).toBe(seeded.title);
|
|
150
124
|
}
|
|
151
|
-
);
|
|
125
|
+
});
|
|
152
126
|
});
|
|
153
127
|
|
|
154
128
|
it("search parameter applies to title/description ilike search", async () => {
|
|
155
129
|
expect(listDef).toBeDefined();
|
|
156
130
|
|
|
157
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
expect(rows.length).toBe(expectedForUser0.length);
|
|
172
|
-
|
|
173
|
-
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
174
|
-
for (const seeded of expectedForUser0) {
|
|
175
|
-
expect(byId.get(seeded.id)?.title).toBe(seeded.title);
|
|
176
|
-
}
|
|
131
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (ctx) => {
|
|
132
|
+
const sharedSubstring = "Project Alpha";
|
|
133
|
+
const expectedForUser0 = seededTaskRows.filter(
|
|
134
|
+
(r) => r.userId === user0Identity.id && r.title.toLowerCase().includes(sharedSubstring.toLowerCase()),
|
|
135
|
+
);
|
|
136
|
+
expect(expectedForUser0.length).toBe(2);
|
|
137
|
+
|
|
138
|
+
const result = await listHandler(ctx, { search: sharedSubstring });
|
|
139
|
+
const rows = result.data;
|
|
140
|
+
expect(rows.length).toBe(expectedForUser0.length);
|
|
141
|
+
|
|
142
|
+
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
143
|
+
for (const seeded of expectedForUser0) {
|
|
144
|
+
expect(byId.get(seeded.id)?.title).toBe(seeded.title);
|
|
177
145
|
}
|
|
178
|
-
);
|
|
146
|
+
});
|
|
179
147
|
});
|
|
180
148
|
|
|
181
149
|
it("tasks.get succeeds when current user reads own task", async () => {
|
|
182
150
|
const ownTaskId = "tk-003";
|
|
183
151
|
|
|
184
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
185
|
-
|
|
186
|
-
user0Identity,
|
|
187
|
-
async (ctx) => {
|
|
188
|
-
const task = await getHandler(ctx, { id: ownTaskId });
|
|
152
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (ctx) => {
|
|
153
|
+
const task = await getHandler(ctx, { id: ownTaskId });
|
|
189
154
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
);
|
|
155
|
+
expect(task).toBeDefined();
|
|
156
|
+
expect(task?.id).toBe(ownTaskId);
|
|
157
|
+
expect(task?.userId).toBe(user0Identity.id);
|
|
158
|
+
});
|
|
195
159
|
});
|
|
196
160
|
|
|
197
161
|
it("tasks.get fails when current user tries to read another user's task", async () => {
|
|
198
162
|
const user1TaskId = "tk-001";
|
|
199
163
|
|
|
200
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const task = await getHandler(ctx, { id: user1TaskId });
|
|
205
|
-
expect(task).toBeNull();
|
|
206
|
-
}
|
|
207
|
-
);
|
|
164
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (ctx) => {
|
|
165
|
+
const task = await getHandler(ctx, { id: user1TaskId });
|
|
166
|
+
expect(task).toBeNull();
|
|
167
|
+
});
|
|
208
168
|
});
|
|
209
169
|
|
|
210
170
|
it("tasks.update succeeds when updating a task owned by current user", async () => {
|
|
@@ -212,179 +172,146 @@ describe("fixtures/basic + PGlite + CRUD + RLS", () => {
|
|
|
212
172
|
const updatedTitle = "Project Alpha — updated by owner";
|
|
213
173
|
const updatedDone = true;
|
|
214
174
|
|
|
215
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
expect(fetched?.title).toBe(updatedTitle);
|
|
242
|
-
expect(fetched?.done).toBe(updatedDone);
|
|
243
|
-
}
|
|
244
|
-
);
|
|
175
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (ctx) => {
|
|
176
|
+
const before = await getHandler(ctx, {
|
|
177
|
+
id: ownTaskId,
|
|
178
|
+
});
|
|
179
|
+
expect(before?.title).not.toBe(updatedTitle);
|
|
180
|
+
expect(before?.done).not.toBe(updatedDone);
|
|
181
|
+
|
|
182
|
+
const updated = await updateHandler(ctx, {
|
|
183
|
+
id: ownTaskId,
|
|
184
|
+
title: updatedTitle,
|
|
185
|
+
done: updatedDone,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
expect(updated).toBeDefined();
|
|
189
|
+
expect(updated?.id).toBe(ownTaskId);
|
|
190
|
+
expect(updated?.userId).toBe(user0Identity.id);
|
|
191
|
+
expect(updated?.title).toBe(updatedTitle);
|
|
192
|
+
expect(updated?.done).toBe(updatedDone);
|
|
193
|
+
|
|
194
|
+
const fetched = await getHandler(ctx, {
|
|
195
|
+
id: ownTaskId,
|
|
196
|
+
});
|
|
197
|
+
expect(fetched?.id).toBe(ownTaskId);
|
|
198
|
+
expect(fetched?.title).toBe(updatedTitle);
|
|
199
|
+
expect(fetched?.done).toBe(updatedDone);
|
|
200
|
+
});
|
|
245
201
|
});
|
|
246
202
|
|
|
247
203
|
it("tasks.create succeeds when creating a task with current userId", async () => {
|
|
248
204
|
const ownTaskId = "tk-own-create";
|
|
249
205
|
const ownTaskTitle = "Project Delta — created by owner";
|
|
250
206
|
|
|
251
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
expect(fetched?.id).toBe(ownTaskId);
|
|
273
|
-
expect(fetched?.userId).toBe(user0Identity.id);
|
|
274
|
-
}
|
|
275
|
-
);
|
|
207
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (user0Ctx) => {
|
|
208
|
+
const created = await createHandler(user0Ctx, {
|
|
209
|
+
id: ownTaskId,
|
|
210
|
+
userId: user0Identity.id,
|
|
211
|
+
title: ownTaskTitle,
|
|
212
|
+
done: false,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
expect(created).toBeDefined();
|
|
216
|
+
expect(created.id).toBe(ownTaskId);
|
|
217
|
+
expect(created.userId).toBe(user0Identity.id);
|
|
218
|
+
expect(created.title).toBe(ownTaskTitle);
|
|
219
|
+
expect(created.done).toBe(false);
|
|
220
|
+
|
|
221
|
+
const fetched = await getHandler(user0Ctx, {
|
|
222
|
+
id: ownTaskId,
|
|
223
|
+
});
|
|
224
|
+
expect(fetched).toBeDefined();
|
|
225
|
+
expect(fetched?.id).toBe(ownTaskId);
|
|
226
|
+
expect(fetched?.userId).toBe(user0Identity.id);
|
|
227
|
+
});
|
|
276
228
|
});
|
|
277
229
|
|
|
278
230
|
it("tasks.create fails when current user tries to create with another userId", async () => {
|
|
279
231
|
const unauthorizedTaskId = "tk-other-user-create";
|
|
280
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
});
|
|
292
|
-
} catch (e) {
|
|
293
|
-
thrown = e;
|
|
294
|
-
}
|
|
295
|
-
expect(thrown).toBeInstanceOf(Error);
|
|
296
|
-
|
|
297
|
-
const user1Ctx = makeTestGencowCtxWithRls(
|
|
298
|
-
user0Ctx.unsafeDb as any,
|
|
299
|
-
user1Identity
|
|
300
|
-
);
|
|
301
|
-
const after = await getHandler(user1Ctx, { id: unauthorizedTaskId });
|
|
302
|
-
expect(after).toBeNull();
|
|
232
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (user0Ctx) => {
|
|
233
|
+
let thrown: unknown;
|
|
234
|
+
try {
|
|
235
|
+
await createHandler(user0Ctx, {
|
|
236
|
+
id: unauthorizedTaskId,
|
|
237
|
+
userId: user1Identity.id,
|
|
238
|
+
title: "Unauthorized create attempt",
|
|
239
|
+
done: false,
|
|
240
|
+
});
|
|
241
|
+
} catch (e) {
|
|
242
|
+
thrown = e;
|
|
303
243
|
}
|
|
304
|
-
|
|
244
|
+
expect(thrown).toBeInstanceOf(Error);
|
|
245
|
+
|
|
246
|
+
const user1Ctx = makeTestGencowCtxWithRls(user0Ctx.unsafeDb as any, user1Identity);
|
|
247
|
+
const after = await getHandler(user1Ctx, { id: unauthorizedTaskId });
|
|
248
|
+
expect(after).toBeNull();
|
|
249
|
+
});
|
|
305
250
|
});
|
|
306
251
|
|
|
307
252
|
it("tasks.update fails when current user tries to update user1 task", async () => {
|
|
308
253
|
const user1TaskId = "tk-001";
|
|
309
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
id: user1TaskId,
|
|
335
|
-
});
|
|
336
|
-
expect(after).toBeDefined();
|
|
337
|
-
expect(after?.title).toBe(beforeTitle);
|
|
338
|
-
expect(after?.done).toBe(beforeDone);
|
|
339
|
-
}
|
|
340
|
-
);
|
|
254
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (user0Ctx) => {
|
|
255
|
+
const user1Ctx = makeTestGencowCtxWithRls(user0Ctx.unsafeDb as any, user1Identity);
|
|
256
|
+
|
|
257
|
+
const before = await getHandler(user1Ctx, {
|
|
258
|
+
id: user1TaskId,
|
|
259
|
+
});
|
|
260
|
+
expect(before).toBeDefined();
|
|
261
|
+
const beforeTitle = before?.title;
|
|
262
|
+
const beforeDone = before?.done ?? false;
|
|
263
|
+
|
|
264
|
+
const unauthorizedUpdate = await updateHandler(user0Ctx, {
|
|
265
|
+
id: user1TaskId,
|
|
266
|
+
title: "Unauthorized update attempt",
|
|
267
|
+
done: !beforeDone,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
expect(unauthorizedUpdate).toBeUndefined();
|
|
271
|
+
|
|
272
|
+
const after = await getHandler(user1Ctx, {
|
|
273
|
+
id: user1TaskId,
|
|
274
|
+
});
|
|
275
|
+
expect(after).toBeDefined();
|
|
276
|
+
expect(after?.title).toBe(beforeTitle);
|
|
277
|
+
expect(after?.done).toBe(beforeDone);
|
|
278
|
+
});
|
|
341
279
|
});
|
|
342
280
|
|
|
343
281
|
it("tasks.remove succeeds when deleting a task owned by current user", async () => {
|
|
344
282
|
const ownTaskId = "tk-002";
|
|
345
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
async (user0Ctx) => {
|
|
349
|
-
const before = await getHandler(user0Ctx, { id: ownTaskId });
|
|
350
|
-
expect(before).toBeDefined();
|
|
351
|
-
|
|
352
|
-
const removeResult = await removeHandler(user0Ctx, {
|
|
353
|
-
id: ownTaskId,
|
|
354
|
-
});
|
|
355
|
-
expect(removeResult.success).toBe(true);
|
|
283
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (user0Ctx) => {
|
|
284
|
+
const before = await getHandler(user0Ctx, { id: ownTaskId });
|
|
285
|
+
expect(before).toBeDefined();
|
|
356
286
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
287
|
+
const removeResult = await removeHandler(user0Ctx, {
|
|
288
|
+
id: ownTaskId,
|
|
289
|
+
});
|
|
290
|
+
expect(removeResult.success).toBe(true);
|
|
291
|
+
|
|
292
|
+
const after = await getHandler(user0Ctx, { id: ownTaskId });
|
|
293
|
+
expect(after).toBeNull();
|
|
294
|
+
});
|
|
361
295
|
});
|
|
362
296
|
|
|
363
297
|
it("tasks.remove cannot delete a task owned by another user", async () => {
|
|
364
298
|
const user1TaskId = "tk-004";
|
|
365
|
-
await runWithRollbackTestGencowCtxWithRls(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const after = await getHandler(user1Ctx, {
|
|
383
|
-
id: user1TaskId,
|
|
384
|
-
});
|
|
385
|
-
expect(after).toBeDefined();
|
|
386
|
-
expect(after?.id).toBe(user1TaskId);
|
|
387
|
-
}
|
|
388
|
-
);
|
|
299
|
+
await runWithRollbackTestGencowCtxWithRls(db, user0Identity, async (user0Ctx) => {
|
|
300
|
+
const user1Ctx = makeTestGencowCtxWithRls(user0Ctx.unsafeDb as any, user1Identity);
|
|
301
|
+
|
|
302
|
+
const before = await getHandler(user1Ctx, { id: user1TaskId });
|
|
303
|
+
expect(before).toBeDefined();
|
|
304
|
+
|
|
305
|
+
const removeResult = await removeHandler(user0Ctx, {
|
|
306
|
+
id: user1TaskId,
|
|
307
|
+
});
|
|
308
|
+
expect(removeResult.success).toBe(true);
|
|
309
|
+
|
|
310
|
+
const after = await getHandler(user1Ctx, {
|
|
311
|
+
id: user1TaskId,
|
|
312
|
+
});
|
|
313
|
+
expect(after).toBeDefined();
|
|
314
|
+
expect(after?.id).toBe(user1TaskId);
|
|
315
|
+
});
|
|
389
316
|
});
|
|
390
317
|
});
|