Skip to content

Commit

Permalink
Merge pull request #433 from influxdata/chore/flux_test_432
Browse files Browse the repository at this point in the history
chore(core): improve flux function tests
  • Loading branch information
sranka authored Apr 19, 2022
2 parents 4b7126a + 75dcc67 commit 587b959
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

1. [#431](https://github.com/influxdata/influxdb-client-js/pull/431): Regenerate APIs from swagger.

### Other

1. [#429](https://github.com/influxdata/influxdb-client-js/pull/429): Improve query examples.
1. [#430](https://github.com/influxdata/influxdb-client-js/pull/430): Upgrade dependencies.
1. [#433](https://github.com/influxdata/influxdb-client-js/pull/433): Improve flux function tests.

## 1.24.0 [2022-03-18]

### Features
Expand Down
75 changes: 75 additions & 0 deletions packages/core/test/unit/query/flux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,79 @@ describe('Flux Tagged Template', () => {
'from(bucket:"my-bucket")'
)
})
it('interpolates parameter with escaping', () => {
const pairs: Array<{value: any; flux: string}> = [
{value: flux`${null}`, flux: 'null'},
{value: flux`${false}`, flux: 'false'},
{value: flux`${1}`, flux: '1'},
{value: flux`${1.1}`, flux: '1.1'},
{value: flux`${-1.1}`, flux: '-1.1'},
{value: flux`${'a'}`, flux: '"a"'},
{
value: flux`${new Date(1589521447471)}`,
flux: '2020-05-15T05:44:07.471Z',
},
{value: flux`${/abc/}`, flux: 'regexp.compile(v: "/abc/")'},
{
value: flux`${{
toString: function(): string {
return 'whatever'
},
}}`,
flux: '"whatever"',
},
{value: flux`${fluxExpression('1ms')}`, flux: '1ms'},
{value: flux`${'abc\n\r\t\\"def'}`, flux: '"abc\\n\\r\\t\\\\\\"def"'},
{value: flux`${'abc${val}def'}`, flux: '"abc\\${val}def"'},
{value: flux`${'abc$'}`, flux: '"abc$"'},
{value: flux`${'a"$d'}`, flux: '"a\\"$d"'},
{value: flux`${[]}`, flux: '[]'},
{value: flux`${['a"$d']}`, flux: '["a\\"$d"]'},
{
value: flux`${Symbol('thisSym')}`,
flux: `"${Symbol('thisSym').toString()}"`,
},
]
pairs.forEach(pair => {
expect(pair.value.toString()).equals(pair.flux)
})
})
it('interpolates double quoted parameter with escaping', () => {
const pairs: Array<{value: any; flux: string}> = [
{value: flux`"${null}"`, flux: '""'},
{value: flux`"${undefined}"`, flux: '""'},
{value: flux`"${false}"`, flux: '"false"'},
{value: flux`"${1}"`, flux: '"1"'},
{value: flux`"${1.1}"`, flux: '"1.1"'},
{value: flux`"${-1.1}"`, flux: '"-1.1"'},
{value: flux`"${'a'}"`, flux: '"a"'},
{
value: flux`"${new Date(1589521447471)}"`,
flux: `"${new Date(1589521447471)}"`,
},
{value: flux`"${/abc/}"`, flux: `"${/abc/.toString()}"`},
{
value: flux`"${{
toString: function(): string {
return 'whatever'
},
}}"`,
flux: '"whatever"',
},
{value: flux`"${fluxExpression('1ms')}"`, flux: '"1ms"'},
{value: flux`"${'abc\n\r\t\\"def'}"`, flux: '"abc\\n\\r\\t\\\\\\"def"'},
{value: flux`"${'abc${val}def'}"`, flux: '"abc\\${val}def"'},
{value: flux`"${'abc$'}"`, flux: '"abc$"'},
{value: flux`"${'a"$d'}"`, flux: '"a\\"$d"'},
{value: flux`"${[]}"`, flux: `""`},
{value: flux`"${['a"$d']}"`, flux: `"a\\"$d"`},
{
value: flux`"${Symbol('thisSym')}"`,
flux: `"${Symbol('thisSym').toString()}"`,
},
]
pairs.forEach(pair => {
expect(pair.value.toString()).equals(pair.flux)
})
})
})

0 comments on commit 587b959

Please sign in to comment.