From 7f0570401e1f49c2424803a9db34b279ae2c6103 Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Mon, 18 Sep 2023 15:44:55 +0300 Subject: [PATCH] InfluxDB: Fix adhoc filter call (#74961) * Handle nullable parameters properly * run prettier --- .../plugins/datasource/influxdb/datasource.ts | 10 +++++----- .../influxdb/specs/datasource.test.ts | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index 59da1fdcdb0..000018cb133 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -335,7 +335,7 @@ export default class InfluxDatasource extends DataSourceWithBackend { @@ -345,12 +345,12 @@ export default class InfluxDatasource extends DataSourceWithBackend { // Some functions are required by the parent datasource class to provide functionality // such as ad-hoc filters, which requires the definition of the getTagKeys, and getTagValues describe('Datasource contract', () => { + const metricFindQueryMock = jest.fn(); + beforeEach(() => { + ctx.ds.metricFindQuery = metricFindQueryMock; + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + it('has function called getTagKeys', () => { expect(Object.getOwnPropertyNames(Object.getPrototypeOf(ctx.ds))).toContain('getTagKeys'); }); + it('has function called getTagValues', () => { expect(Object.getOwnPropertyNames(Object.getPrototypeOf(ctx.ds))).toContain('getTagValues'); }); + + it('should be able to call getTagKeys without specifying any parameter', () => { + ctx.ds.getTagKeys(); + expect(metricFindQueryMock).toHaveBeenCalled(); + }); + + it('should be able to call getTagValues without specifying anything but key', () => { + ctx.ds.getTagValues({ key: 'test' }); + expect(metricFindQueryMock).toHaveBeenCalled(); + }); }); describe('Variables should be interpolated correctly', () => {