Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: json query and json path exists #78

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:
- 1433:1433
strategy:
matrix:
node-version: [18.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: pnpm/action-setup@v2.2.2
- uses: pnpm/action-setup@v4
with:
version: 7.12.2
version: 9
- run: pnpm i
- run: pnpm t
12 changes: 8 additions & 4 deletions src/identifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ test('json value', () => {
expect(Tsql.id('fooJson->bar').toString()).toEqual('json_value(fooJson, N\'bar\')')
})

test('json query', () => {
expect(Tsql.id('fooJson~>bar').toString()).toEqual('json_query(fooJson, N\'bar\')')
})

test('json path exists', () => {
expect(Tsql.id('fooJson?>bar').toString()).toEqual('json_path_exists(fooJson, N\'bar\')')
})

test('quote', () => {
expect(Tsql.id('Target').toString()).toEqual('[Target]')
expect(Tsql.id('foo[bar').toString()).toEqual('[foo[bar]')
Expand All @@ -23,7 +31,3 @@ test('quote', () => {
expect(Tsql.id('_foo').toString()).toEqual('_foo')
expect(Tsql.id('1foo').toString()).toEqual('[1foo]')
})

test('json path exists', () => {
expect(Tsql.id('fooJson?>bar').toString()).toEqual('json_path_exists(fooJson, N\'bar\')')
})
8 changes: 6 additions & 2 deletions src/where.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ test('different ops', () => {
}, '((a in (1, 2, 3)) and (b like N\'foo%\') and (c >= 5) and (d <= 1) and (e < 0) and (f not in (3, 5, 7)) and (g = 3) and (h <> 0) and (i !> 1) and (j !< -1) and (not ((k = 0)) or (l = 1)) and (m between 0 and 1) and (n not between 0 and 1))')
})

test('json', () => {
expect(Tsql.where({ 'payloadJson->status': 'COMPLETED' }).toString()).toEqual('(json_value(payloadJson, N\'status\') = N\'COMPLETED\')')
test('json value', () => {
expect(Tsql.where({ 'payloadJson->$.status': 'COMPLETED' }).toString()).toEqual('(json_value(payloadJson, N\'$.status\') = N\'COMPLETED\')')
})

test('json exists', () => {
expect(Tsql.where({ 'payloadJson?>$.status': true }).toString()).toEqual('(json_path_exists(payloadJson, N\'$.status\') = cast(1 as bit))')
})

test('unique', () => {
Expand Down
Loading