Skip to content

Commit

Permalink
test: json query and json path exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mirek authored Aug 22, 2024
1 parent 7478e35 commit d08325b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
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

0 comments on commit d08325b

Please sign in to comment.