Skip to content

Commit

Permalink
chore: added tests for non-object roots (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: Maciej Urbańczyk <[email protected]>
  • Loading branch information
jonaslagoni and magicmatatjahu authored Feb 22, 2021
1 parent 8aa660a commit 92855d8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/simplification/simplify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,22 @@ describe('Simplification', function() {
expect(actualModels[1]).toEqual(expectedModels[1]);
expect(schema.$id).toBeUndefined();
});
});

test('should support array roots', function() {
const actualModels = simplify({ "type": "array", "items": [{ "type": "string" }, { "type": "number" }] });
const expectedSchemaString = fs.readFileSync(path.resolve(__dirname, './simplify/expected/array_root.json'), 'utf8');
const expectedModel = JSON.parse(expectedSchemaString);
expect(actualModels).not.toBeUndefined();
expect(actualModels[0]).toEqual(expectedModel);
});
test('should support primitive roots', function() {
const actualModels = simplify({ "type": "string" });
expect(actualModels).not.toBeUndefined();
expect(actualModels[0]).toEqual({
"originalSchema":{
"type":"string"
},
"type":"string"
});
});
});
31 changes: 31 additions & 0 deletions test/simplification/simplify/expected/array_root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"originalSchema": {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "number"
}
]
},
"type": "array",
"items": {
"type": [
"string",
"number"
],
"originalSchema": {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "number"
}
]
}
}
}

0 comments on commit 92855d8

Please sign in to comment.