Skip to content

Commit

Permalink
Added tests for getting fullname for each schema item type (iTwin#1359)
Browse files Browse the repository at this point in the history
* Added tests for getting fullname for each schema item type if they didn't exist before

* Ran rush change

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
IvanJK97 and mergify[bot] authored May 11, 2021
1 parent 97d75e1 commit 43d4f50
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@bentley/ecschema-metadata",
"comment": "Added get fullName tests for each schema item type if they didn't exist before",
"type": "none"
}
],
"packageName": "@bentley/ecschema-metadata",
"email": "[email protected]"
}
14 changes: 14 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/Class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ import { createEmptyXmlDocument, getElementChildren, getElementChildrenByTagName
describe("ECClass", () => {
let schema: Schema;

it("should get fullName", async () => {
const schemaJson = createSchemaJsonWithItems({
testStruct: {
schemaItemType: "StructClass",
},
});

const ecSchema = await Schema.fromJson(schemaJson, new SchemaContext());
assert.isDefined(ecSchema);
const structClass = await ecSchema.getItem<StructClass>("testStruct");
assert.isDefined(structClass);
expect(structClass!.fullName).eq("TestSchema.testStruct");
});

describe("get properties", () => {
beforeEach(() => {
schema = new Schema(new SchemaContext(), "TestSchema", "ts", 1, 0, 0);
Expand Down
17 changes: 17 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/Constant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ describe("Constant", () => {
});
}

it("should get fullName", async () => {
const fullyDefinedConstant = createSchemaJson({
label: "Test Constant",
description: "testing a constant",
phenomenon: "TestSchema.TestPhenomenon",
definition: "PI",
numerator: 5.5,
denominator: 5.1,
});

const ecSchema = await Schema.fromJson(fullyDefinedConstant, new SchemaContext());
assert.isDefined(ecSchema);
const testConst = await ecSchema.getItem<Constant>("TestConstant");
assert.isDefined(testConst);
expect(testConst!.fullName).eq("TestSchema.TestConstant");
});

describe("deserialization", () => {
// Fully defined constant
const fullyDefinedConstant = createSchemaJson({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ import { createEmptyXmlDocument, getElementChildrenByTagName } from "../TestUtil
/* eslint-disable @typescript-eslint/naming-convention */

describe("CustomAttributeClass", () => {
it("should get fullName", async () => {
const schemaJson = createSchemaJsonWithItems({
TestCAClass: {
schemaItemType: "CustomAttributeClass",
label: "Test CustomAttribute Class",
description: "Used for testing",
modifier: "Sealed",
appliesTo: "AnyClass",
},
});

const ecschema = await Schema.fromJson(schemaJson, new SchemaContext());
const testCAClass = await ecschema.getItem<CustomAttributeClass>("TestCAClass");
expect(testCAClass).to.exist;
expect(testCAClass!.fullName).eq("TestSchema.TestCAClass");
});

describe("deserialization", () => {
function createSchemaJson(caClassJson: any): any {
return createSchemaJsonWithItems({
Expand Down
5 changes: 5 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/EntityClass.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ describe("EntityClass", () => {
schema = new Schema(new SchemaContext(), "TestSchema", "ts", 1, 0, 0);
});

it("should get fullName", () => {
const entityClass = new EntityClass(schema, "TestClass");
expect(entityClass.fullName).eq("TestSchema.TestClass");
});

it("from mixins", async () => {
const baseClass = new EntityClass(schema, "TestBase");
const basePrimProp = await (baseClass as ECClass as MutableClass).createPrimitiveProperty("BasePrimProp");
Expand Down
87 changes: 51 additions & 36 deletions core/ecschema-metadata/src/test/Metadata/Enumeration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,33 @@ import { ECObjectsError } from "../../Exception";
import { Enumeration, MutableEnumeration } from "../../Metadata/Enumeration";
import { Schema } from "../../Metadata/Schema";
import { createEmptyXmlDocument, getElementChildrenByTagName } from "../TestUtils/SerializationHelper";
import { createSchemaJsonWithItems } from "../TestUtils/DeserializationHelpers";

describe("Enumeration", () => {
it("should get fullName", async () => {
const schemaJson = createSchemaJsonWithItems({
testEnum: {
schemaItemType: "Enumeration",
type: "string",
description: "Test description",
label: "Test Enumeration",
isStrict: true,
enumerators: [
{
name: "testEnumerator",
value: "test",
},
],
},
});

const schema = await Schema.fromJson(schemaJson, new SchemaContext());
assert.isDefined(schema);
const testEnum = await schema.getItem<Enumeration>("testEnum");
assert.isDefined(testEnum);
expect(testEnum!.fullName).eq("TestSchema.testEnum");
});

describe("addEnumerator tests", () => {
let testEnum: Enumeration;
let testStringEnum: Enumeration;
Expand Down Expand Up @@ -50,26 +75,21 @@ describe("Enumeration", () => {

describe("deserialization", () => {
it("minimum values", async () => {
const testSchema = {
$schema: "https://dev.bentley.com/json_schemas/ec/32/ecschema",
name: "TestSchema",
version: "1.2.3",
items: {
testEnum: {
schemaItemType: "Enumeration",
type: "string",
description: "Test description",
label: "Test Enumeration",
isStrict: true,
enumerators: [
{
name: "testEnumerator",
value: "test",
},
],
},
const testSchema = createSchemaJsonWithItems({
testEnum: {
schemaItemType: "Enumeration",
type: "string",
description: "Test description",
label: "Test Enumeration",
isStrict: true,
enumerators: [
{
name: "testEnumerator",
value: "test",
},
],
},
};
});

const ecSchema = await Schema.fromJson(testSchema, new SchemaContext());
const testEnum = await ecSchema.getItem<Enumeration>("testEnum");
Expand All @@ -84,24 +104,19 @@ describe("Enumeration", () => {
});

it("with enumerators", async () => {
const testSchema = {
$schema: "https://dev.bentley.com/json_schemas/ec/32/ecschema",
name: "TestSchema",
version: "1.2.3",
items: {
testEnum: {
schemaItemType: "Enumeration",
type: "int",
enumerators: [
{
name: "ZeroValue",
value: 0,
label: "None",
},
],
},
const testSchema = createSchemaJsonWithItems({
testEnum: {
schemaItemType: "Enumeration",
type: "int",
enumerators: [
{
name: "ZeroValue",
value: 0,
label: "None",
},
],
},
};
});

const ecSchema = await Schema.fromJson(testSchema, new SchemaContext());
const testEnum = await ecSchema.getItem<Enumeration>("testEnum");
Expand Down
15 changes: 15 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/Format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ describe("Format", () => {
let schema: Schema;
let testFormat: Format;

it("should get fullName", async () => {
const schemaJson = createSchemaJsonWithItems({
TestFormat: {
schemaItemType: "Format",
type: "Decimal",
},
});

const ecSchema = await Schema.fromJson(schemaJson, new SchemaContext());
assert.isDefined(ecSchema);
const format = await ecSchema.getItem<Format>("TestFormat");
assert.isDefined(format);
expect(format!.fullName).eq("TestSchema.TestFormat");
});

describe("type checking json", () => {
let jsonParser: JsonParser; // This is an easy way to test the logic directly in the parser without having to go through deserialization every time.

Expand Down
24 changes: 24 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/Mixin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ describe("Mixin", () => {
});
}

it("should get fullName", async () => {
const schemaJson = createSchemaJsonWithItems({
TestMixin: {
schemaItemType: "Mixin",
baseClass: "TestSchema.BaseMixin",
appliesTo: "TestSchema.TestEntity",
},
BaseMixin: {
schemaItemType: "Mixin",
appliesTo: "TestSchema.TestEntity",
},
TestEntity: {
schemaItemType: "EntityClass",
},
});

const schema = await Schema.fromJson(schemaJson, new SchemaContext());
assert.isDefined(schema);
const baseMixin = await schema.getItem<Mixin>("BaseMixin");
const mixin = await schema.getItem<Mixin>("TestMixin");
expect(baseMixin!.fullName).eq("TestSchema.BaseMixin");
expect(mixin!.fullName).eq("TestSchema.TestMixin");
});

describe("deserialization", () => {
it("should succeed with fully defined", async () => {
const testSchema = createSchemaJsonWithItems({
Expand Down
23 changes: 23 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/Phenomenon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ import { createEmptyXmlDocument } from "../TestUtils/SerializationHelper";

describe("Phenomenon tests", () => {
let testPhenomenon: Phenomenon;

it("should get fullName", async () => {
const schemaJson = {
$schema: "https://dev.bentley.com/json_schemas/ec/32/ecschema",
name: "TestSchema",
version: "1.2.3",
items: {
testPhenomenon: {
schemaItemType: "Phenomenon",
name: "AREA",
label: "Area",
definition: "Units.LENGTH(2)",
},
},
};

const schema = await Schema.fromJson(schemaJson, new SchemaContext());
assert.isDefined(schema);
const phenomenon = await schema.getItem<Phenomenon>("testPhenomenon");
assert.isDefined(phenomenon);
expect(phenomenon!.fullName).eq("TestSchema.testPhenomenon");
});

describe("Async fromJson", () => {
beforeEach(() => {
const schema = new Schema(new SchemaContext(), "ExampleSchema", "es", 1, 0, 0);
Expand Down
Loading

0 comments on commit 43d4f50

Please sign in to comment.