-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JSONPath syntactic validation (#561)
- Loading branch information
Showing
7 changed files
with
95 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
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,44 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { jsonPathSchema } from '../../../src/conditions/base/json-api'; | ||
|
||
describe('JSONPath Validation', () => { | ||
it('Invalid JSONPath: Incomplete filter expression', () => { | ||
const invalidPath = '$.store.book[?(@.price < ]'; | ||
const result = jsonPathSchema.safeParse(invalidPath); | ||
expect(result.success).toBe(false); | ||
expect(result.error!.errors[0].message).toBe('Invalid JSONPath expression'); | ||
}); | ||
|
||
it('Invalid JSONPath: Incorrect use of brackets', () => { | ||
const invalidPath = '$[store][book]'; | ||
const result = jsonPathSchema.safeParse(invalidPath); | ||
expect(result.success).toBe(false); | ||
expect(result.error!.errors[0].message).toBe('Invalid JSONPath expression'); | ||
}); | ||
|
||
it('Invalid JSONPath: Unclosed wildcard asterisk', () => { | ||
const invalidPath = '$.store.book[*'; | ||
const result = jsonPathSchema.safeParse(invalidPath); | ||
expect(result.success).toBe(false); | ||
expect(result.error!.errors[0].message).toBe('Invalid JSONPath expression'); | ||
}); | ||
|
||
it('Valid JSONPath expression', () => { | ||
const validPath = '$.store.book[?(@.price < 10)]'; | ||
const result = jsonPathSchema.safeParse(validPath); | ||
expect(result.success).toBe(true); | ||
}); | ||
|
||
it('Valid JSONPath with correct quotes', () => { | ||
const validPath = "$.store['book[?(@.price < ]']"; | ||
const result = jsonPathSchema.safeParse(validPath); | ||
expect(result.success).toBe(true); | ||
}); | ||
|
||
it('Valid JSONPath with correct wildcard', () => { | ||
const validPath = '$.store.book[*]'; | ||
const result = jsonPathSchema.safeParse(validPath); | ||
expect(result.success).toBe(true); | ||
}); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.