Skip to content

Commit de4d670

Browse files
committed
fix tests
1 parent bb86a2f commit de4d670

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

packages/language/test/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import path from 'node:path';
55
import { expect } from 'vitest';
66
import { loadDocument } from '../src';
77

8+
const pluginDocs = [path.resolve(__dirname, '../../plugins/policy/plugin.zmodel')];
9+
810
export async function loadSchema(schema: string) {
911
// create a temp file
1012
const tempFile = path.join(os.tmpdir(), `zenstack-schema-${crypto.randomUUID()}.zmodel`);
1113
fs.writeFileSync(tempFile, schema);
12-
const r = await loadDocument(tempFile);
14+
const r = await loadDocument(tempFile, pluginDocs);
1315
expect(r).toSatisfy(
1416
(r) => r.success,
1517
`Failed to load schema: ${(r as any).errors?.map((e) => e.toString()).join(', ')}`,
@@ -22,7 +24,8 @@ export async function loadSchemaWithError(schema: string, error: string | RegExp
2224
// create a temp file
2325
const tempFile = path.join(os.tmpdir(), `zenstack-schema-${crypto.randomUUID()}.zmodel`);
2426
fs.writeFileSync(tempFile, schema);
25-
const r = await loadDocument(tempFile);
27+
28+
const r = await loadDocument(tempFile, pluginDocs);
2629
expect(r.success).toBe(false);
2730
invariant(!r.success);
2831
if (typeof error === 'string') {

packages/plugins/policy/plugin.zmodel

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Defines an access policy that allows a set of operations when the given condition is true.
33
*
4-
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
4+
* @param operation: comma-separated list of "create", "read", "update", "post-update", " "delete". Use "all" to denote all operations.
55
* @param condition: a boolean expression that controls if the operation should be allowed.
66
*/
77
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'post-update'","'delete'", "'all'"]), _ condition: Boolean)
@@ -10,24 +10,24 @@ attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "
1010
* Defines an access policy that allows the annotated field to be read or updated.
1111
* You can pass a third argument as `true` to make it override the model-level policies.
1212
*
13-
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
13+
* @param operation: comma-separated list of "create", "read", "update", "post-update", "delete". Use "all" to denote all operations.
1414
* @param condition: a boolean expression that controls if the operation should be allowed.
1515
* @param override: a boolean value that controls if the field-level policy should override the model-level policy.
1616
*/
17-
// attribute @allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean, _ override: Boolean?)
17+
// attribute @allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'post-update'", "'delete'", "'all'"]), _ condition: Boolean, _ override: Boolean?)
1818

1919
/**
2020
* Defines an access policy that denies a set of operations when the given condition is true.
2121
*
22-
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
22+
* @param operation: comma-separated list of "create", "read", "update", "post-update", "delete". Use "all" to denote all operations.
2323
* @param condition: a boolean expression that controls if the operation should be denied.
2424
*/
2525
attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'post-update'","'delete'", "'all'"]), _ condition: Boolean)
2626

2727
/**
2828
* Defines an access policy that denies the annotated field to be read or updated.
2929
*
30-
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
30+
* @param operation: comma-separated list of "create", "read", "update", "post-update", "delete". Use "all" to denote all operations.
3131
* @param condition: a boolean expression that controls if the operation should be denied.
3232
*/
3333
// attribute @deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
@@ -36,7 +36,7 @@ attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'
3636
* Checks if the current user can perform the given operation on the given field.
3737
*
3838
* @param field: The field to check access for
39-
* @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
39+
* @param operation: The operation to check access for. Can be "read", "create", "update", "post-update", or "delete". If the operation is not provided,
4040
* it defaults the operation of the containing policy rule.
4141
*/
4242
function check(field: Any, operation: String?): Boolean {

0 commit comments

Comments
 (0)