Skip to content

Commit b6e16ff

Browse files
authored
chore: reenable post-update test cases (#277)
1 parent f531ad6 commit b6e16ff

File tree

12 files changed

+30
-30
lines changed

12 files changed

+30
-30
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
- [ ] Short-circuit pre-create check for scalar-field only policies
102102
- [x] Inject "on conflict do update"
103103
- [x] `check` function
104+
- [ ] Custom functions
104105
- [ ] Accessing tables not in the schema
105106
- [x] Migration
106107
- [ ] Databases

packages/runtime/src/plugins/policy/expression-transformer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ export class ExpressionTransformer<Schema extends SchemaDef> {
523523
});
524524

525525
if (currNode) {
526-
invariant(SelectQueryNode.is(currNode), 'expected select query node');
527526
currNode = {
528527
...relation,
529528
selections: [

packages/runtime/test/policy/migrated/multi-id-fields.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ describe('Policy tests multiple id fields', () => {
5757
).toResolveTruthy();
5858
});
5959

60-
// TODO: `future()` support
61-
it.skip('multi-id fields id update', async () => {
60+
it('multi-id fields id update', async () => {
6261
const db = await createPolicyTestClient(
6362
`
6463
model A {
@@ -70,7 +69,8 @@ describe('Policy tests multiple id fields', () => {
7069
7170
@@allow('read', true)
7271
@@allow('create', value > 0)
73-
@@allow('update', value > 0 && future().value > 1)
72+
@@allow('update', value > 0)
73+
@@allow('post-update', value > 1)
7474
}
7575
7676
model B {
@@ -319,8 +319,7 @@ describe('Policy tests multiple id fields', () => {
319319
expect(await db.c.findUnique({ where: { id: 1 } })).toEqual(expect.objectContaining({ v: 6 }));
320320
});
321321

322-
// TODO: `future()` support
323-
it.skip('multi-id fields nested id update', async () => {
322+
it('multi-id fields nested id update', async () => {
324323
const db = await createPolicyTestClient(
325324
`
326325
model A {
@@ -333,7 +332,8 @@ describe('Policy tests multiple id fields', () => {
333332
334333
@@allow('read', true)
335334
@@allow('create', value > 0)
336-
@@allow('update', value > 0 && future().value > 1)
335+
@@allow('update', value > 0)
336+
@@allow('post-update', value > 1)
337337
}
338338
339339
model B {
@@ -369,7 +369,7 @@ describe('Policy tests multiple id fields', () => {
369369
upsert: {
370370
where: { x_y: { x: '2', y: 2 } },
371371
update: { x: '3', y: 3, value: 0 },
372-
create: { x: '4', y: '4', value: 4 },
372+
create: { x: '4', y: 4, value: 4 },
373373
},
374374
},
375375
},
@@ -384,7 +384,7 @@ describe('Policy tests multiple id fields', () => {
384384
upsert: {
385385
where: { x_y: { x: '2', y: 2 } },
386386
update: { x: '3', y: 3, value: 3 },
387-
create: { x: '4', y: '4', value: 4 },
387+
create: { x: '4', y: 4, value: 4 },
388388
},
389389
},
390390
},

packages/runtime/test/policy/migrated/nested-to-one.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ describe('With Policy:nested to-one', () => {
197197
).toBeRejectedNotFound();
198198
});
199199

200-
// TODO: `future()` support
201-
it.skip('nested update id tests', async () => {
200+
it('nested update id tests', async () => {
202201
const db = await createPolicyTestClient(
203202
`
204203
model M1 {
@@ -216,7 +215,8 @@ describe('With Policy:nested to-one', () => {
216215
217216
@@allow('read', true)
218217
@@allow('create', value > 0)
219-
@@allow('update', value > 1 && future().value > 2)
218+
@@allow('update', value > 1)
219+
@@allow('post-update', value > 2)
220220
}
221221
`,
222222
);

packages/runtime/test/policy/migrated/petstore-sample.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { describe, expect, it } from 'vitest';
22
import { createPolicyTestClient } from '../utils';
33
import { schema } from '../../schemas/petstore/schema';
44

5-
// TODO: `future()` support
6-
describe.skip('Pet Store Policy Tests', () => {
5+
describe('Pet Store Policy Tests', () => {
76
it('crud', async () => {
87
const petData = [
98
{

packages/runtime/test/policy/migrated/todo-sample.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ describe('Todo Policy Tests', () => {
370370
expect(r1.lists).toHaveLength(1);
371371
});
372372

373-
// TODO: `future()` support
374-
it.skip('post-update checks', async () => {
373+
it('post-update checks', async () => {
375374
await createSpaceAndUsers(db.$unuseAll());
376375

377376
const user1Db = db.$setAuth({ id: user1.id });

packages/runtime/test/policy/migrated/toplevel-operations.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ describe('Policy toplevel operations tests', () => {
133133
).toBeTruthy();
134134
});
135135

136-
// TODO: `future()` support
137-
it.skip('update id tests', async () => {
136+
it('update id tests', async () => {
138137
const db = await createPolicyTestClient(
139138
`
140139
model Model {
@@ -143,7 +142,8 @@ describe('Policy toplevel operations tests', () => {
143142
144143
@@allow('read', value > 1)
145144
@@allow('create', value > 0)
146-
@@allow('update', value > 1 && future().value > 2)
145+
@@allow('update', value > 1)
146+
@@allow('post-update', value > 2)
147147
}
148148
`,
149149
);
@@ -164,7 +164,7 @@ describe('Policy toplevel operations tests', () => {
164164
value: 1,
165165
},
166166
}),
167-
).toBeRejectedNotFound();
167+
).toBeRejectedByPolicy();
168168

169169
// update success
170170
await expect(

packages/runtime/test/policy/todo-sample.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ describe('todo sample tests', () => {
383383
expect(r1?.lists).toHaveLength(1);
384384
});
385385

386-
// TODO: `future()` support
387-
it.skip('works with post-update checks', async () => {
386+
it('works with post-update checks', async () => {
388387
const anonDb = await createPolicyTestClient(schema);
389388
await createSpaceAndUsers(anonDb.$unuseAll());
390389

packages/runtime/test/schemas/petstore/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export const schema = {
9292
},
9393
attributes: [
9494
{ name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.field("orderId"), "==", ExpressionUtils._null()), "||", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("order"), ["user"]), "==", ExpressionUtils.call("auth"))) }] },
95+
{ name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("update") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "!=", ExpressionUtils._null()) }] },
9596
{ name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("post-update") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("before"), ["name"]), "==", ExpressionUtils.field("name")), "&&", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("before"), ["category"]), "==", ExpressionUtils.field("category"))), "&&", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("before"), ["orderId"]), "==", ExpressionUtils._null())) }] }
9697
],
9798
idFields: ["id"],

packages/runtime/test/schemas/petstore/schema.zmodel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ model Pet {
3535
// unsold pets are readable to all; sold ones are readable to buyers only
3636
@@allow('read', orderId == null || order.user == auth())
3737

38+
@@allow('update', auth() != null)
39+
3840
// only allow update to 'orderId' field if it's not set yet (unsold)
3941
@@allow('post-update', before().name == name && before().category == category && before().orderId == null)
4042
}

0 commit comments

Comments
 (0)