-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
154 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { JsonTemplateEngine } from './engine'; | ||
|
||
describe('engine', () => { | ||
describe('isValidJSONPath', () => { | ||
it('should return true for valid JSON root path', () => { | ||
expect(JsonTemplateEngine.isValidJSONPath('$.user.name')).toBeTruthy(); | ||
}); | ||
|
||
it('should return true for valid JSON relative path', () => { | ||
expect(JsonTemplateEngine.isValidJSONPath('.user.name')).toBeTruthy(); | ||
|
||
expect(JsonTemplateEngine.isValidJSONPath('@.user.name')).toBeTruthy(); | ||
}); | ||
|
||
it('should return false for invalid JSON path', () => { | ||
expect(JsonTemplateEngine.isValidJSONPath('userId')).toBeFalsy(); | ||
}); | ||
|
||
it('should return false for invalid template', () => { | ||
expect(JsonTemplateEngine.isValidJSONPath('a=')).toBeFalsy(); | ||
}); | ||
|
||
it('should return false for empty path', () => { | ||
expect(JsonTemplateEngine.isValidJSONPath('')).toBeFalsy(); | ||
}); | ||
}); | ||
describe('validateMappings', () => { | ||
it('should validate mappings', () => { | ||
expect(() => | ||
JsonTemplateEngine.validateMappings([ | ||
{ | ||
input: '$.userId', | ||
output: '$.user.id', | ||
}, | ||
{ | ||
input: '$.discount', | ||
output: '$.events[0].items[*].discount', | ||
}, | ||
]), | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should throw error for mappings which are not compatible with each other', () => { | ||
expect(() => | ||
JsonTemplateEngine.validateMappings([ | ||
{ | ||
input: '$.events[0]', | ||
output: '$.events[0].name', | ||
}, | ||
{ | ||
input: '$.discount', | ||
output: '$.events[0].name[*].discount', | ||
}, | ||
]), | ||
).toThrowError('Invalid mapping'); | ||
}); | ||
|
||
it('should throw error for mappings with invalid json paths', () => { | ||
expect(() => | ||
JsonTemplateEngine.validateMappings([ | ||
{ | ||
input: 'events[0]', | ||
output: 'events[0].name', | ||
}, | ||
]), | ||
).toThrowError('Invalid mapping'); | ||
}); | ||
}); | ||
}); |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './lexer'; | ||
export * from './parser'; | ||
export * from './translator'; |
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 @@ | ||
export class JsonTemplateLexerError extends Error {} |
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,9 @@ | ||
export class JsonTemplateMappingError extends Error { | ||
inputMapping: string; | ||
outputMapping: string; | ||
constructor(message: string, inputMapping: string, outputMapping: string) { | ||
super(`${message}. Input: ${inputMapping}, Output: ${outputMapping}`); | ||
this.inputMapping = inputMapping; | ||
this.outputMapping = outputMapping; | ||
} | ||
} |
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 @@ | ||
export class JsonTemplateParserError extends Error {} |
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 @@ | ||
export class JsonTemplateTranslatorError extends Error {} |
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
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