Files
grafana/public/app/plugins/datasource/influxdb/datasource_sql.test.ts
ismail simsek 3cb92e3460 InfluxDB: Template variable support for SQL language (#77799)
* Only run through with classicQuery if the language is influxql and backend migration is disabled

* Add variable editor

* Simple template variable support

* Show template variables in the drowdowns

* better imports

* unit tests

* it is now 11 just because we add rawSql interpolation in datasource.ts applyVariables method

* fix
2023-11-08 15:00:13 +01:00

45 lines
1.3 KiB
TypeScript

import { lastValueFrom } from 'rxjs';
import config from 'app/core/config';
import { SQLQuery } from '../../../features/plugins/sql';
import InfluxDatasource from './datasource';
import {
getMockDSInstanceSettings,
mockBackendService,
mockInfluxQueryRequest,
mockInfluxSQLFetchResponse,
mockTemplateSrv,
} from './mocks';
import { InfluxVersion } from './types';
config.featureToggles.influxdbBackendMigration = true;
mockBackendService(mockInfluxSQLFetchResponse);
describe('InfluxDB SQL Support', () => {
const replaceMock = jest.fn();
const templateSrv = mockTemplateSrv(jest.fn(), replaceMock);
let sqlQuery: SQLQuery;
beforeEach(() => {
sqlQuery = {
refId: 'x',
rawSql:
'SELECT "$interpolationVar2", time FROM iox.$interpolationVar WHERE time >= $__timeFrom AND time <= $__timeTo',
};
});
describe('interpolate variables', () => {
const ds = new InfluxDatasource(getMockDSInstanceSettings({ version: InfluxVersion.SQL }), templateSrv);
it('should call replace template variables for rawSql', async () => {
await lastValueFrom(ds.query(mockInfluxQueryRequest([sqlQuery])));
expect(replaceMock.mock.calls[1][0]).toBe(
`SELECT "$interpolationVar2", time FROM iox.$interpolationVar WHERE time >= $__timeFrom AND time <= $__timeTo`
);
});
});
});