-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: typescript runtime test and tuples (#1980)
- Loading branch information
1 parent
a217537
commit f5bf72d
Showing
10 changed files
with
242 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"$id": "TestObject", | ||
"description": "This object contains all types of MetaModel generations", | ||
"type": "object", | ||
"properties": { | ||
"string_type": { | ||
"type": "string" | ||
}, | ||
"number_type": { | ||
"type": "number" | ||
}, | ||
"boolean_type": { | ||
"type": "boolean", | ||
"description": "Status if marriage live in given house" | ||
}, | ||
"union_type": { | ||
"oneOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "number" | ||
}, | ||
{ | ||
"type": "boolean" | ||
} | ||
] | ||
}, | ||
"array_type": { | ||
"type": "array", | ||
"items": { | ||
"oneOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "number" | ||
} | ||
] | ||
} | ||
}, | ||
"tuple_type": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "number" | ||
} | ||
], | ||
"additionalItems": false | ||
}, | ||
"object_type": { | ||
"type": "object", | ||
"properties": { | ||
"test": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"dictionary_type": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"type": "string" | ||
} | ||
}, | ||
"enum_type": { | ||
"enum": ["test", 1, true, {"test": 2}] | ||
} | ||
}, | ||
"patternProperties": { | ||
"^S(.?*)test&": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["string_type", "boolean_type"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"$id": "TestObject", | ||
"description": "This object contains simple types of MetaModel generations. Object, enum, number, boolean array, tuple.", | ||
"type": "object", | ||
"properties": { | ||
"string_type": { | ||
"type": "string" | ||
}, | ||
"number_type": { | ||
"type": "number" | ||
}, | ||
"boolean_type": { | ||
"type": "boolean", | ||
"description": "Status if marriage live in given house" | ||
}, | ||
"array_type": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"tuple_type": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "number" | ||
} | ||
], | ||
"additionalItems": false | ||
}, | ||
"object_type": { | ||
"type": "object", | ||
"properties": { | ||
"test": { | ||
"type": "string" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"enum_type": { | ||
"enum": ["test", 1, true, {"test": 2}] | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": ["string_type", "boolean_type"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 25 additions & 16 deletions
41
test/runtime/runtime-typescript/test/DefaultAddressTest.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
import Address from '../src/defaultExport/Address'; | ||
import NestedObject from '../src/defaultExport/NestedObject'; | ||
import TestObject from '../src/defaultExport/TestObject'; | ||
import ObjectType from '../src/defaultExport/ObjectType'; | ||
import EnumType from '../src/defaultExport/EnumType'; | ||
|
||
describe('Address', () => { | ||
describe('Default exports', () => { | ||
test('should be able to instantiate default export model', () => { | ||
const nestedObj = new NestedObject({ | ||
const objectType = new ObjectType({ | ||
test: 'test' | ||
}); | ||
const address = new Address({ | ||
streetName: 'test', | ||
houseNumber: 1, | ||
marriage: true, | ||
members: 2, | ||
const testObject = new TestObject({ | ||
stringType: 'test', | ||
numberType: 1, | ||
booleanType: true, | ||
arrayType: [1, 'test'], | ||
nestedObject: nestedObj | ||
objectType: objectType, | ||
dictionaryType: new Map(Object.entries({"test": "test"})), | ||
additionalProperties: new Map(Object.entries({"test": "test"})), | ||
enumType: EnumType.CURLYLEFT_QUOTATION_TEST_QUOTATION_COLON_2_CURLYRIGHT, | ||
tupleType: ['test', 1], | ||
unionType: 'test' | ||
}); | ||
expect(address.streetName).toEqual('test'); | ||
expect(address.houseNumber).toEqual(1); | ||
expect(address.marriage).toEqual(true); | ||
expect(address.members).toEqual(2); | ||
expect(address.arrayType).toEqual([1, 'test']); | ||
expect(address.nestedObject?.test).toEqual('test'); | ||
expect(testObject.stringType).toEqual('test'); | ||
expect(testObject.numberType).toEqual(1); | ||
expect(testObject.booleanType).toEqual(true); | ||
expect(testObject.arrayType).toEqual([1, 'test']); | ||
expect(testObject.objectType).toEqual(objectType); | ||
expect(Object.fromEntries(testObject.dictionaryType!)).toEqual({"test": "test"}); | ||
expect(Object.fromEntries(testObject.additionalProperties!)).toEqual({"test": "test"}); | ||
expect(testObject.enumType).toEqual(EnumType.CURLYLEFT_QUOTATION_TEST_QUOTATION_COLON_2_CURLYRIGHT); | ||
expect(testObject.tupleType).toEqual(['test', 1]); | ||
expect(testObject.unionType).toEqual('test'); | ||
}); | ||
}); |
29 changes: 19 additions & 10 deletions
29
test/runtime/runtime-typescript/test/JsonBinPackPreset.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
import { Address } from '../src/jsonbinpack/Address'; | ||
import { ObjectType } from '../src/jsonbinpack/ObjectType'; | ||
import { TestObject } from '../src/jsonbinpack/TestObject'; | ||
import { EnumType } from '../src/jsonbinpack/EnumType'; | ||
|
||
describe('Address', () => { | ||
const address = new Address({ | ||
streetName: 'test', | ||
houseNumber: 1, | ||
marriage: true | ||
describe('JSON binpack', () => { | ||
const objectType = new ObjectType({ | ||
test: 'test' | ||
}); | ||
test('be able to serialize model and turning it back to a model with the same values', async () => { | ||
const serialized = await address.jsonbinSerialize(); | ||
const newAddress = await Address.jsonbinDeserialize(serialized); | ||
expect(address.marshal()).toEqual(newAddress.marshal()); | ||
const testObject = new TestObject({ | ||
stringType: 'test', | ||
numberType: 1, | ||
booleanType: true, | ||
arrayType: ['test'], | ||
objectType: objectType, | ||
enumType: EnumType.CURLYLEFT_QUOTATION_TEST_QUOTATION_COLON_2_CURLYRIGHT, | ||
tupleType: ['test', 1] | ||
}); | ||
test.skip('should be able to serialize model and turning it back to a model with the same values', async () => { | ||
const serialized = await testObject.jsonbinSerialize(); | ||
const newTestObject = await TestObject.jsonbinDeserialize(serialized); | ||
expect(testObject.marshal()).toEqual(newTestObject.marshal()); | ||
}); | ||
}); |
Oops, something went wrong.