Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.6 KB
Raw Blame
import { mapQueryDataFromApi } from '../mapQueryDataFromApi';
import {
	compositeQueriesWithFunctions,
	compositeQueryWithoutVariables,
	compositeQueryWithVariables,
	defaultOutput,
	outputWithFunctions,
	replaceVariables,
	stepIntervalUnchanged,
} from './mapQueryDataFromApiInputs';

jest.mock('uuid', () => ({
	v4: (): string => 'test-id',
}));

describe('mapQueryDataFromApi function tests', () => {
	it('should not update the step interval when query is passed', () => {
		const output = mapQueryDataFromApi(compositeQueryWithoutVariables);

		// composite query is the response from the `v3/query_range/format` API call.
		// even if the composite query returns stepInterval updated do not modify it
		expect(output).toStrictEqual(stepIntervalUnchanged);
	});

	it('should update filter from the composite query', () => {
		const output = mapQueryDataFromApi(compositeQueryWithVariables);

		// replace the variables in the widget query and leave the rest items untouched
		expect(output).toStrictEqual(replaceVariables);
	});

	it('should not update the step intervals with multiple queries and functions', () => {
		const output = mapQueryDataFromApi(compositeQueriesWithFunctions);

		expect(output).toStrictEqual(outputWithFunctions);
	});

	it('should use the default query values and the compositeQuery object when query is not passed', () => {
		const output = mapQueryDataFromApi(compositeQueryWithoutVariables);

		// when the query object is not passed take the initial values and merge the composite query on top of it
		expect(output).toStrictEqual(defaultOutput);
	});
});