Skip to content

Commit d9b095d

Browse files
committed
test(QueryEditor): use modern explain query schema
1 parent 78acc45 commit d9b095d

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

Diff for: src/utils/query.test.ts

+59-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import {parseQueryAPIExecuteResponse} from './query';
1+
import {
2+
parseQueryAPIExecuteResponse,
3+
parseQueryAPIExplainResponse,
4+
} from './query';
25

36
describe('API utils', () => {
47
describe('json/viewer/query', () => {
@@ -185,5 +188,60 @@ describe('API utils', () => {
185188
});
186189
});
187190
});
191+
192+
describe('parseQueryAPIExplainResponse', () => {
193+
it('should handle empty response', () => {
194+
expect(parseQueryAPIExplainResponse(null)).toEqual({});
195+
});
196+
197+
it('should accept stats without a plan', () => {
198+
const stats = {metric: 'good'};
199+
expect(parseQueryAPIExplainResponse({stats}).stats).toEqual(stats);
200+
});
201+
202+
describe('old format', () => {
203+
describe('explain', () => {
204+
it('should parse plan data in the root', () => {
205+
const plan = {foo: 'bar'};
206+
expect(parseQueryAPIExplainResponse(plan).plan).toEqual(plan);
207+
});
208+
209+
it('should parse plan in the result field with stats', () => {
210+
const plan = {foo: 'bar'};
211+
const stats = {metric: 'good'};
212+
const actual = parseQueryAPIExplainResponse({result: plan, stats});
213+
expect(actual.plan).toEqual(plan);
214+
expect(actual.stats).toEqual(stats);
215+
});
216+
});
217+
218+
describe('explain-ast', () => {
219+
it('should parse ast field in the root', () => {
220+
const ast = 'ast';
221+
expect(parseQueryAPIExplainResponse({ast}).ast).toBe(ast);
222+
});
223+
224+
it('should parse ast in the result field with stats', () => {
225+
const ast = 'ast';
226+
const stats = {metric: 'good'};
227+
const actual = parseQueryAPIExplainResponse({result: {ast}, stats});
228+
expect(actual.ast).toBe(ast);
229+
expect(actual.stats).toEqual(stats);
230+
});
231+
});
232+
});
233+
234+
describe('new format', () => {
235+
it('should parse explain response with stats', () => {
236+
const plan = {foo: 'bar'};
237+
const ast = 'ast';
238+
const stats = {metric: 'good'};
239+
const actual = parseQueryAPIExplainResponse({plan, ast, stats});
240+
expect(actual.plan).toEqual(plan);
241+
expect(actual.ast).toBe(ast);
242+
expect(actual.stats).toEqual(stats);
243+
});
244+
});
245+
});
188246
});
189247
});

0 commit comments

Comments
 (0)