|
| 1 | +import { ProfileQueryType, SEARCH_COMMANDS, GRAPH_COMMANDS } from './constants' |
| 2 | + |
| 3 | +import { |
| 4 | + generateGraphProfileQuery, |
| 5 | + generateSearchProfileQuery, |
| 6 | + generateProfileQueryForCommand, |
| 7 | +} from './utils' |
| 8 | + |
| 9 | + |
| 10 | +const generateGraphProfileQueryTests: Record<string, any>[] = [ |
| 11 | + { input: 'GRAPH.QUERY key "MATCH (n) RETURN n"', output: 'graph.profile key "MATCH (n) RETURN n"', type: ProfileQueryType.Profile }, |
| 12 | + { input: 'GRAPH.QUERY key "MATCH (n) RETURN n"', output: 'graph.explain key "MATCH (n) RETURN n"', type: ProfileQueryType.Explain }, |
| 13 | + { input: 'graph.query key "MATCH (n) RETURN n"', output: 'graph.profile key "MATCH (n) RETURN n"', type: ProfileQueryType.Profile }, |
| 14 | + { input: 'graph.query key "MATCH (n) RETURN n"', output: 'graph.explain key "MATCH (n) RETURN n"', type: ProfileQueryType.Explain }, |
| 15 | +] |
| 16 | + |
| 17 | +describe('generateGraphProfileQuery', () => { |
| 18 | + |
| 19 | + generateGraphProfileQueryTests.forEach(test => { |
| 20 | + it(`should be output: ${test.output} for input: ${test.input} and type: ${test.type}`, () => { |
| 21 | + const result = generateGraphProfileQuery(test.input, test.type); |
| 22 | + |
| 23 | + expect(result).toEqual(test.output); |
| 24 | + }); |
| 25 | + }) |
| 26 | +}); |
| 27 | + |
| 28 | + |
| 29 | +const generateSearchProfileQueryTests: Record<string, any>[] = [ |
| 30 | + { input: 'FT.SEARCH index tomatoes', output: 'ft.profile index SEARCH QUERY tomatoes', type: ProfileQueryType.Profile }, |
| 31 | + { input: 'FT.AGGREGATE index tomatoes', output: 'ft.profile index AGGREGATE QUERY tomatoes', type: ProfileQueryType.Profile }, |
| 32 | +{ input: 'FT.SEARCH index tomatoes', output: 'ft.explain index tomatoes', type: ProfileQueryType.Explain }, |
| 33 | + { input: 'FT.AGGREGATE index tomatoes', output: 'ft.explain index tomatoes', type: ProfileQueryType.Explain }, |
| 34 | +{ input: 'ft.search index tomatoes', output: 'ft.profile index search QUERY tomatoes', type: ProfileQueryType.Profile }, |
| 35 | + { input: 'ft.aggregate index tomatoes', output: 'ft.profile index aggregate QUERY tomatoes', type: ProfileQueryType.Profile }, |
| 36 | +{ input: 'ft.search index tomatoes', output: 'ft.explain index tomatoes', type: ProfileQueryType.Explain }, |
| 37 | + { input: 'ft.aggregate index tomatoes', output: 'ft.explain index tomatoes', type: ProfileQueryType.Explain }, |
| 38 | +{ input: 'ft.SEARCH index tomatoes', output: 'ft.profile index SEARCH QUERY tomatoes', type: ProfileQueryType.Profile }, |
| 39 | + { input: 'ft.AGGREGATE index tomatoes', output: 'ft.profile index AGGREGATE QUERY tomatoes', type: ProfileQueryType.Profile }, |
| 40 | +{ input: 'ft.SEARCH index tomatoes', output: 'ft.explain index tomatoes', type: ProfileQueryType.Explain }, |
| 41 | + { input: 'ft.AGGREGATE index tomatoes', output: 'ft.explain index tomatoes', type: ProfileQueryType.Explain }, |
| 42 | +] |
| 43 | + |
| 44 | +describe('generateSearchProfileQuery', () => { |
| 45 | + |
| 46 | + generateSearchProfileQueryTests.forEach(test => { |
| 47 | + it(`should be output: ${test.output} for input: ${test.input} and type: ${test.type}`, () => { |
| 48 | + const result = generateSearchProfileQuery(test.input, test.type); |
| 49 | + |
| 50 | + expect(result).toEqual(test.output); |
| 51 | + }); |
| 52 | + }) |
| 53 | +}); |
| 54 | + |
| 55 | +const generateProfileQueryForCommandTests: Record<string, any>[] = [ |
| 56 | + ...generateGraphProfileQueryTests, |
| 57 | + ...generateSearchProfileQueryTests, |
| 58 | + { input: 'GRAPH.LIST', output: null, type: ProfileQueryType.Profile }, |
| 59 | + { input: 'GRAPH.LIST', output: null, type: ProfileQueryType.Explain }, |
| 60 | + { input: 'GRAPH.PROFILE key "MATCH (n) RETURN n"', output: null, type: ProfileQueryType.Profile }, |
| 61 | + { input: 'GRAPH.PROFILE key "MATCH (n) RETURN n"', output: null, type: ProfileQueryType.Explain }, |
| 62 | + { input: 'GRAPH.EXPLAIN key "MATCH (n) RETURN n"', output: null, type: ProfileQueryType.Profile }, |
| 63 | + { input: 'GRAPH.EXPLAIN key "MATCH (n) RETURN n"', output: null, type: ProfileQueryType.Explain }, |
| 64 | + { input: 'ft._LIST', output: null, type: ProfileQueryType.Profile }, |
| 65 | + { input: 'ft._LIST', output: null, type: ProfileQueryType.Explain }, |
| 66 | +{ input: 'ft.profile index SEARCH QUERY tomatoes', output: null, type: ProfileQueryType.Profile }, |
| 67 | + { input: 'ft.profile index AGGREGATE QUERY tomatoes', output: null, type: ProfileQueryType.Explain }, |
| 68 | +{ input: 'ft.explain index tomatoes', output: null, type: ProfileQueryType.Profile }, |
| 69 | + { input: 'ft.explain index tomatoes', output: null, type: ProfileQueryType.Explain }, |
| 70 | +] |
| 71 | +describe('generateProfileQueryForCommand', () => { |
| 72 | + generateProfileQueryForCommandTests.forEach(test => { |
| 73 | + it(`should be output: ${test.output} for input: ${test.input} and type: ${test.type}`, () => { |
| 74 | + const result = generateProfileQueryForCommand(test.input, test.type); |
| 75 | + |
| 76 | + expect(result).toEqual(test.output); |
| 77 | + }); |
| 78 | + }) |
| 79 | +}); |
0 commit comments