Skip to content

Commit c59029f

Browse files
authored
fix: instancePath using incorrect value for tests (#295)
2 parents 185709d + c7b7c1e commit c59029f

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

pkg/js/tests/validate-rules.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, expect, it } from "@jest/globals";
22
import { Validator } from "../validator/validate-rules";
33

44
// These tests are a subset of bad formats that all validation rules that should fail
5-
const validatedBadStructure = (validator: any) => {
5+
const validatedBadStructure = (validator: (value: string) => boolean) => {
66
it("should fail if '::' is the delimiter", () => {
77
expect(validator("item::1")).toBeFalsy();
88
});

pkg/js/validator/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from "./validate-dsl";
2+
export * from "./validate-rules";
3+
export * from "./validate-store";

pkg/js/validator/validate-store.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Ajv, { Schema, ValidateFunction, SchemaValidateFunction } from "ajv";
1212
import { Validator } from "./validate-rules";
1313

1414
export function isStringValue(str: unknown) {
15-
return typeof str == "string";
15+
return typeof str == "string" || String;
1616
}
1717

1818
type Store = {
@@ -34,16 +34,20 @@ type Test = {
3434

3535
type CheckTest = Omit<CheckRequestTupleKey, "relation"> & {
3636
assertions: Record<string, boolean>;
37+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3738
context: Record<string, any>;
3839
};
3940

4041
type ListObjectTest = Omit<ListObjectsRequest, "relation"> & {
42+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4143
assertions: Record<string, any>;
4244
};
4345

4446
type ListUsersTest = Omit<ListUsersRequest, "relation" | "user_filters"> & {
4547
object: string;
48+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4649
user_filter: Record<string, any>;
50+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4751
assertions: Record<string, any>;
4852
};
4953

@@ -418,6 +422,7 @@ function validateUserField(model: AuthorizationModel, types: string[], userField
418422
function validateAssertionField(
419423
model: AuthorizationModel,
420424
typeField: string,
425+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
421426
assertions: Record<string, any>,
422427
instancePath: string,
423428
) {
@@ -649,7 +654,7 @@ function validateTestTypes(store: Store, model: AuthorizationModel, instancePath
649654

650655
// Validate check
651656
if (test.check) {
652-
for (const singleCheckTest of test.check) {
657+
for (const [testNumber, singleCheckTest] of Object.entries(test.check)) {
653658
if (!singleCheckTest.user || !singleCheckTest.object) {
654659
return false;
655660
}
@@ -659,15 +664,15 @@ function validateTestTypes(store: Store, model: AuthorizationModel, instancePath
659664
singleCheckTest,
660665
tuples,
661666
params,
662-
instancePath + `/tests/${singleTest}/check/${singleCheckTest}`,
667+
instancePath + `/tests/${singleTest}/check/${testNumber}`,
663668
),
664669
);
665670
}
666671
}
667672

668673
// Validate list objects
669674
if (test.list_objects) {
670-
for (const singleListObjectTest of test.list_objects) {
675+
for (const [testNumber, singleListObjectTest] of Object.entries(test.list_objects)) {
671676
if (!singleListObjectTest.user || !singleListObjectTest.type) {
672677
return false;
673678
}
@@ -677,15 +682,15 @@ function validateTestTypes(store: Store, model: AuthorizationModel, instancePath
677682
singleListObjectTest,
678683
tuples,
679684
params,
680-
instancePath + `/tests/${singleTest}/list_objects/${singleListObjectTest}`,
685+
instancePath + `/tests/${singleTest}/list_objects/${testNumber}`,
681686
),
682687
);
683688
}
684689
}
685690

686691
// Validate list users
687692
if (test.list_users) {
688-
for (const singleListUsersTest of test.list_users) {
693+
for (const [testNumber, singleListUsersTest] of Object.entries(test.list_users)) {
689694
if (!singleListUsersTest.object || !singleListUsersTest.user_filter) {
690695
return false;
691696
}
@@ -695,7 +700,7 @@ function validateTestTypes(store: Store, model: AuthorizationModel, instancePath
695700
singleListUsersTest,
696701
tuples,
697702
params,
698-
instancePath + `/tests/${singleTest}/list_users/${singleListUsersTest}`,
703+
instancePath + `/tests/${singleTest}/list_users/${testNumber}`,
699704
),
700705
);
701706
}

0 commit comments

Comments
 (0)