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 committed Aug 22, 2024
1 parent 7478e35 commit 591fc24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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 591fc24

Please sign in to comment.