generated from finos-labs/project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from willosborne/generate-ref-lookup
Follow refs when generating definitions
- Loading branch information
Showing
17 changed files
with
984 additions
and
434 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,259 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import { SchemaDirectory } from '../schema-directory'; | ||
import { instantiateNodeInterfaces, instantiateNodes } from './node'; | ||
|
||
jest.mock('../../helper', () => { | ||
return { | ||
initLogger: () => { | ||
return { | ||
info: () => { }, | ||
debug: () => { } | ||
}; | ||
} | ||
}; | ||
}); | ||
|
||
jest.mock('../schema-directory'); | ||
|
||
let mockSchemaDir; | ||
|
||
beforeEach(() => { | ||
mockSchemaDir = new SchemaDirectory('directory'); | ||
}); | ||
|
||
function getSamplePatternNode(properties: any): any { | ||
return { | ||
properties: { | ||
nodes: { | ||
type: 'array', | ||
prefixItems: [ | ||
{ | ||
properties: properties | ||
} | ||
] | ||
} | ||
} | ||
}; | ||
} | ||
|
||
|
||
describe('instantiateNodes', () => { | ||
it('return instantiated node with array property', () => { | ||
const pattern = getSamplePatternNode({ | ||
'property-name': { | ||
type: 'array' | ||
} | ||
}); | ||
expect(instantiateNodes(pattern, mockSchemaDir)) | ||
.toEqual( | ||
[{ | ||
'property-name': [ | ||
'{{ PROPERTY_NAME }}' | ||
] | ||
}] | ||
); | ||
}); | ||
|
||
it('return instantiated node with string property', () => { | ||
const pattern = getSamplePatternNode({ | ||
'property-name': { | ||
type: 'string' | ||
} | ||
}); | ||
|
||
expect(instantiateNodes(pattern, mockSchemaDir)) | ||
.toEqual([ | ||
{ | ||
'property-name': '{{ PROPERTY_NAME }}' | ||
} | ||
]); | ||
}); | ||
|
||
it('return instantiated node with const property', () => { | ||
const pattern = getSamplePatternNode({ | ||
'property-name': { | ||
const: 'value here' | ||
} | ||
}); | ||
|
||
expect(instantiateNodes(pattern, mockSchemaDir)) | ||
.toEqual([ | ||
{ | ||
'property-name': 'value here' | ||
} | ||
]); | ||
}); | ||
|
||
it('call schema directory to resolve $ref nodes`', () => { | ||
const reference = 'https://calm.com/core.json#/node'; | ||
const pattern = { | ||
properties: { | ||
nodes: { | ||
type: 'array', | ||
prefixItems: [ | ||
{ | ||
'$ref': reference | ||
} | ||
] | ||
} | ||
} | ||
}; | ||
|
||
const spy = jest.spyOn(mockSchemaDir, 'getDefinition'); | ||
spy.mockReturnValue({ | ||
properties: { | ||
'property-name': { | ||
const: 'value here' | ||
} | ||
} | ||
}); | ||
|
||
expect(instantiateNodes(pattern, mockSchemaDir)) | ||
.toEqual([ | ||
{ | ||
'property-name': 'value here' | ||
} | ||
]); | ||
expect(spy).toHaveBeenCalledWith(reference); | ||
}); | ||
|
||
it('return instantiated node with interface', () => { | ||
const pattern = { | ||
properties: { | ||
nodes: { | ||
type: 'array', | ||
prefixItems: [ | ||
{ | ||
properties: { | ||
'unique-id': { | ||
'const': 'unique-id' | ||
}, | ||
// interfaces should be inserted | ||
'interfaces': { | ||
'prefixItems': [ | ||
{ | ||
properties: { | ||
// should insert placeholder {{ INTERFACE_PROPERTY }} | ||
'interface-property': { | ||
'type': 'string' | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
||
} | ||
|
||
}; | ||
|
||
const expected = [ | ||
{ | ||
'unique-id': 'unique-id', | ||
'interfaces': [ | ||
{ | ||
'interface-property': '{{ INTERFACE_PROPERTY }}' | ||
} | ||
] | ||
} | ||
]; | ||
|
||
expect(instantiateNodes(pattern, mockSchemaDir)) | ||
.toEqual(expected); | ||
|
||
}); | ||
}); | ||
|
||
|
||
function getSampleNodeInterfaces(properties: any): any { | ||
return { | ||
prefixItems: [ | ||
{ | ||
properties: properties | ||
} | ||
] | ||
}; | ||
} | ||
|
||
|
||
describe('instantiateNodeInterfaces', () => { | ||
|
||
it('return instantiated node with array property', () => { | ||
const pattern = getSampleNodeInterfaces({ | ||
'property-name': { | ||
type: 'array' | ||
} | ||
}); | ||
expect(instantiateNodeInterfaces(pattern, mockSchemaDir)) | ||
.toEqual( | ||
[{ | ||
'property-name': [ | ||
'{{ PROPERTY_NAME }}' | ||
] | ||
}] | ||
); | ||
}); | ||
|
||
it('return instantiated node with string property', () => { | ||
const pattern = getSampleNodeInterfaces({ | ||
'property-name': { | ||
type: 'string' | ||
} | ||
}); | ||
|
||
expect(instantiateNodeInterfaces(pattern, mockSchemaDir)) | ||
.toEqual([ | ||
{ | ||
'property-name': '{{ PROPERTY_NAME }}' | ||
} | ||
]); | ||
}); | ||
|
||
it('return instantiated node with const property', () => { | ||
const pattern = getSampleNodeInterfaces({ | ||
'property-name': { | ||
const: 'value here' | ||
} | ||
}); | ||
|
||
expect(instantiateNodeInterfaces(pattern, mockSchemaDir)) | ||
.toEqual([ | ||
{ | ||
'property-name': 'value here' | ||
} | ||
]); | ||
}); | ||
|
||
it('call schema directory to resolve $ref interfaces`', () => { | ||
const reference = 'https://calm.com/core.json#/interface'; | ||
|
||
const pattern = { | ||
prefixItems: [ | ||
{ | ||
'$ref': reference | ||
} | ||
] | ||
}; | ||
|
||
const spy = jest.spyOn(mockSchemaDir, 'getDefinition'); | ||
spy.mockReturnValue({ | ||
properties: { | ||
'property-name': { | ||
const: 'value here' | ||
} | ||
} | ||
}); | ||
|
||
expect(instantiateNodeInterfaces(pattern, mockSchemaDir)) | ||
.toEqual([ | ||
{ | ||
'property-name': 'value here' | ||
} | ||
]); | ||
expect(spy).toHaveBeenCalledWith(reference); | ||
}); | ||
}); |
Oops, something went wrong.