|
1 |
| -import {parseQueryAPIExecuteResponse} from './query'; |
| 1 | +import { |
| 2 | + parseQueryAPIExecuteResponse, |
| 3 | + parseQueryAPIExplainResponse, |
| 4 | +} from './query'; |
2 | 5 |
|
3 | 6 | describe('API utils', () => {
|
4 | 7 | describe('json/viewer/query', () => {
|
@@ -185,5 +188,60 @@ describe('API utils', () => {
|
185 | 188 | });
|
186 | 189 | });
|
187 | 190 | });
|
| 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 | + }); |
188 | 246 | });
|
189 | 247 | });
|
0 commit comments