Skip to content

Commit

Permalink
Update unit tests for ref builder and json columns
Browse files Browse the repository at this point in the history
  • Loading branch information
ducher committed Oct 21, 2024
1 parent 1e9f988 commit d2aed69
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/unit/queryBuilder/ReferenceBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,41 @@ describe('ReferenceBuilder', () => {

it('should allow field expression + casting', () => {
let reference = ref('Table.Column:jsonAttr').castBool();
expect(toRawArgs(reference)).to.eql(["CAST(??#>>'{jsonAttr}' AS boolean)", ['Table.Column']]);
expect(toRawArgs(reference)).to.eql(["CAST(??->>'jsonAttr' AS boolean)", ['Table.Column']]);
});

it('should allow field expression + no casting', () => {
let reference = ref('Table.Column:jsonAttr');
expect(toRawArgs(reference)).to.eql(["??#>'{jsonAttr}'", ['Table.Column']]);
expect(toRawArgs(reference)).to.eql(["??->'jsonAttr'", ['Table.Column']]);
});

it('should support few different casts', () => {
expect(toRawArgs(ref('Table.Column:jsonAttr').castText())).to.eql([
"CAST(??#>>'{jsonAttr}' AS text)",
"CAST(??->>'jsonAttr' AS text)",
['Table.Column'],
]);
expect(toRawArgs(ref('Table.Column:jsonAttr').castInt())).to.eql([
"CAST(??#>>'{jsonAttr}' AS integer)",
"CAST(??->>'jsonAttr' AS integer)",
['Table.Column'],
]);
expect(toRawArgs(ref('Table.Column:jsonAttr').castBigInt())).to.eql([
"CAST(??#>>'{jsonAttr}' AS bigint)",
"CAST(??->>'jsonAttr' AS bigint)",
['Table.Column'],
]);
expect(toRawArgs(ref('Table.Column:jsonAttr').castFloat())).to.eql([
"CAST(??#>>'{jsonAttr}' AS float)",
"CAST(??->>'jsonAttr' AS float)",
['Table.Column'],
]);
expect(toRawArgs(ref('Table.Column:jsonAttr').castDecimal())).to.eql([
"CAST(??#>>'{jsonAttr}' AS decimal)",
"CAST(??->>'jsonAttr' AS decimal)",
['Table.Column'],
]);
expect(toRawArgs(ref('Table.Column:jsonAttr').castReal())).to.eql([
"CAST(??#>>'{jsonAttr}' AS real)",
"CAST(??->>'jsonAttr' AS real)",
['Table.Column'],
]);
expect(toRawArgs(ref('Table.Column:jsonAttr').castBool())).to.eql([
"CAST(??#>>'{jsonAttr}' AS boolean)",
"CAST(??->>'jsonAttr' AS boolean)",
['Table.Column'],
]);
expect(toRawArgs(ref('Table.Column').castJson())).to.eql(['to_jsonb(??)', ['Table.Column']]);
Expand Down

0 comments on commit d2aed69

Please sign in to comment.