Skip to content

Commit

Permalink
add a test on successful build
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Oct 11, 2021
1 parent d4cc111 commit 5ba98bc
Show file tree
Hide file tree
Showing 109 changed files with 74 additions and 9,694 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"private": true,
"scripts": {
"postinstall": "lerna bootstrap --force-local",
"prebuild": "yarn run clean:build",
"build": "lerna run build",
"publish:local": "lerna exec yalc publish # then, use 'yalc link <package-name>' in your project",
"link-yarn-legacy": "lerna exec yarn link && ./scripts/link-duplicates.sh # deprecated, symlink creates issue with React, Webpack...",
"unlink-yarn-legacy": "lerna exec yarn unlink",
"clean": "rm -Rf ./node_modules ./packages/*/dist ./packages/*/node_modules",
"clean": "rm -Rf ./node_modules ./packages/*/node_modules && yarn run clean:build",
"clean:build": "rm -Rf ./packages/*/dist",
"test": "jest",
"typecheck": "tsc --noEmit",
"coverage": "jest --coverage",
Expand Down
21 changes: 10 additions & 11 deletions packages/permissions/permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getDocumentBasedPermissionFieldNames,
getReadableFields,
restrictViewableFields,
owns
owns,
} from "../permissions/permissions";

describe("vulcan:users/permissions", () => {
Expand Down Expand Up @@ -43,9 +43,8 @@ describe("vulcan:users/permissions", () => {

describe("fields allowed for filtering", () => {
test("get fields that needs to be checked against the document to be tested", () => {
const documentBasedPermissionFields = getDocumentBasedPermissionFieldNames(
Dummies
);
const documentBasedPermissionFields =
getDocumentBasedPermissionFieldNames(Dummies);
expect(documentBasedPermissionFields).toContain("ownerField");
expect(documentBasedPermissionFields).toContain("customField");
});
Expand Down Expand Up @@ -152,27 +151,27 @@ describe("vulcan:users/permissions", () => {
});
const document = {
_id: "123",
userId: "foo"
userId: "foo",
};
const rightUser = {
_id: "foo",
groups: [],
isAdmin: false
}
isAdmin: false,
};
const wrongUser = {
_id: "bar",
groups: [],
isAdmin: false
}
isAdmin: false,
};

describe('owns', () => {
describe("owns", () => {
test("owns returns true when it's the right couple user-document", () => {
const value = owns(rightUser, document);
expect(value).toBe(true);
});
test("owns returns false when it's the a wrong couple user-document", () => {
const value = owns(wrongUser, document);
expect(value).toBe(false)
expect(value).toBe(false);
});
});
});
16 changes: 10 additions & 6 deletions packages/react-ui/components/form/modules/schema_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const getEditableFields = function (schema, user, document) {
return fields;
};

const isNestedSchema = (schema: any): schema is VulcanSchema => {
return typeof schema === "object";
};

/**
* Vulcan Schema => Form Schema
* TODO: type this better
Expand Down Expand Up @@ -87,20 +91,20 @@ export const convertSchema = (
schema
);

// call convertSchema recursively on the subSchema
const convertedSubSchema = convertSchema(subSchemaOrType, options);
// nested schema can be a field schema ({type, canRead, etc.}) (convertedSchema will be null)
// or a schema on its own with subfields (convertedSchema will return smth)
if (!convertedSubSchema) {
// subSchema is a simple field in this case (eg array of numbers)
jsonSchema[fieldName].isSimpleArrayField = true; //getFieldSchema(`${fieldName}.$`, schema);
} else {
if (isNestedSchema(subSchemaOrType)) {
// call convertSchema recursively on the subSchema
const convertedSubSchema = convertSchema(subSchemaOrType, options);
// subSchema is a full schema with multiple fields (eg array of objects)
if (flatten) {
jsonSchema = { ...jsonSchema, ...convertedSubSchema };
} else {
jsonSchema[fieldName].schema = convertedSubSchema;
}
} else {
// subSchema is a simple field in this case (eg array of numbers)
jsonSchema[fieldName].isSimpleArrayField = true; //getFieldSchema(`${fieldName}.$`, schema);
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions packages/react-ui/components/form/tests/schema_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("schema_utils", function () {
"addresses",
simpleSchema
);
if (!nestedSchema) throw new Error("Schema not found");
// nestedSchema is a complex SimpleSchema object, so we can only
// test its type instead (might not be the simplest way though)
expect(Object.keys(nestedSchema)).toEqual(Object.keys(addressSchema));
Expand All @@ -40,6 +41,7 @@ describe("schema_utils", function () {
"meetingPlace",
simpleSchema
);
if (!nestedSchema) throw new Error("nested schema not found");
expect(Object.keys(nestedSchema)).toEqual(Object.keys(addressSchema));
});
it("return null for other types", function () {
Expand Down
20 changes: 13 additions & 7 deletions packages/schema/typings/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type FieldTypeName =
| "Date";

type PermissionFunction = (
user: Object | null | undefined,
user: VulcanDocument | null | undefined,
document?: Object
) => boolean;
type PermissionDefinition = String | PermissionFunction | Function;
Expand Down Expand Up @@ -82,7 +82,7 @@ interface VulcanField<TField = any> {
// Field-level resolver
// TODO: review those fields
// Field is hidden in forms
hidden?: boolean;
hidden?: boolean | ((args: { props: any; document: any }) => boolean);
// "mustComplete", // mustComplete: true means the field is required to have a complete profile
form?: any; // extra form properties
inputProperties?: any; // extra form properties
Expand Down Expand Up @@ -146,19 +146,25 @@ export type VulcanFieldSchemaShared<TField = any> = VulcanFieldSchema<TField> &
export type VulcanFieldType = SchemaDefinition<any>["type"] | VulcanFieldSchema;

// Extendable Vulcan schema
export type VulcanSchema<TSchemaFieldExtension = any> = {
/**
* Type to be used to allow any custom field, but also keep
* autocompletion of existing fields (contrary to "any")
*/
type AnyObject = { [key: string]: any };

export type VulcanSchema<TSchemaFieldExtension = AnyObject> = {
[key: string]: VulcanFieldSchema & TSchemaFieldExtension;
};
/**
* @server-only
*/
export type VulcanSchemaServer<TSchemaFieldExtension = any> = {
export type VulcanSchemaServer<TSchemaFieldExtension = AnyObject> = {
[key: string]: VulcanFieldSchemaServer & TSchemaFieldExtension;
};
/** Safer type that adds server-only fields with "never" type and a nice error message */
export type VulcanSchemaShared<TSchemaFieldExtension = any> = {
[key: string]: VulcanFieldSchemaServer & TSchemaFieldExtension;
};
//export type VulcanSchemaShared<TSchemaFieldExtension = any> = {
// [key: string]: VulcanFieldSchemaServer & TSchemaFieldExtension;
//};

/**
* Version obtained after running new SimpleSchema({...})._schema
Expand Down
18 changes: 0 additions & 18 deletions packages/ui-react-material/accounts.css

This file was deleted.

25 changes: 0 additions & 25 deletions packages/ui-react-material/en_US.js

This file was deleted.

16 changes: 0 additions & 16 deletions packages/ui-react-material/forms.css

This file was deleted.

7 changes: 0 additions & 7 deletions packages/ui-react-material/fr_FR.js

This file was deleted.

Loading

0 comments on commit 5ba98bc

Please sign in to comment.