Skip to content
Snippets Groups Projects

test: adds tests for query service

Open Marcos Pieras requested to merge test/queryTests into main
4 unresolved threads
Files
3
import { expect, describe, it } from 'vitest';
import type { QueryMultiGraph } from 'ts-common/src/model/graphology';
import { MLTypesEnum } from 'ts-common/src/model/query/machineLearningModel';
import { type QueryBuilderSettings } from 'ts-common/src/model/query/queryBuilderModel';
import { Query2BackendQuery } from './../../../utils/reactflow/query2backend';
import type { MachineLearning } from 'ts-common/src/model/query/queryRequestModel';
import { type BackendQueryFormat } from 'ts-common';
import { createQueryMultiGraphFromData, settingsBase, ss_id } from './testData';
import { visualQuery_1 } from './testData';
import { expectedResult_1 } from './testData';
import { Logger } from 'ts-common';
Logger.excludedOwners.push('ts-common');
Logger.excludedOwners.push('query-service');
describe('query2backend', () => {
it('should return correctly a node - 0', () => {
const nodesData = [
{
id: 'Movie',
schemaKey: 'Movie',
type: 'entity',
width: 100,
height: 100,
x: 50,
y: 50,
name: 'Movie',
attributes: [
{ name: '(# Connection)', type: 'float' },
{ name: 'tagline', type: 'string' },
{ name: 'votes', type: 'int' },
{ name: 'title', type: 'string' },
{ name: 'released', type: 'int' },
],
    • Comment on lines +20 to +34
      Suggested change
      20 id: 'Movie',
      21 schemaKey: 'Movie',
      22 type: 'entity',
      23 width: 100,
      24 height: 100,
      25 x: 50,
      26 y: 50,
      27 name: 'Movie',
      28 attributes: [
      29 { name: '(# Connection)', type: 'float' },
      30 { name: 'tagline', type: 'string' },
      31 { name: 'votes', type: 'int' },
      32 { name: 'title', type: 'string' },
      33 { name: 'released', type: 'int' },
      34 ],
      20 id: 'Movie',
      21 type: 'entity',
      22 name: 'Movie',
      23 attributes: [],

      Lets keep this as minimal as possible. For what its testing at the moment, only these keys are necessary. The rest does not appear in the result, and would not need to be provided

Please register or sign in to reply
},
];
const visualQuery: QueryMultiGraph = createQueryMultiGraphFromData(nodesData, []);
const ml: MachineLearning[] = [
{ type: MLTypesEnum.linkPrediction, parameters: [], id: 1 },
{ type: MLTypesEnum.centrality, parameters: [], id: 2 },
{ type: MLTypesEnum.communityDetection, parameters: [], id: 3 },
{ type: MLTypesEnum.shortestPath, parameters: [], id: 4 },
];
const result = Query2BackendQuery(ss_id, visualQuery, settingsBase, ml);
const expectedResult: BackendQueryFormat = {
saveStateID: 'test',
query: [
{
id: 'path_0',
node: {
label: 'Movie',
id: 'Movie',
relation: undefined,
},
},
],
machineLearning: [
{ type: MLTypesEnum.linkPrediction, parameters: [], id: 1 },
{ type: MLTypesEnum.centrality, parameters: [], id: 2 },
{ type: MLTypesEnum.communityDetection, parameters: [], id: 3 },
{ type: MLTypesEnum.shortestPath, parameters: [], id: 4 },
],
    • Comment on lines +60 to +65
      Suggested change
      60 machineLearning: [
      61 { type: MLTypesEnum.linkPrediction, parameters: [], id: 1 },
      62 { type: MLTypesEnum.centrality, parameters: [], id: 2 },
      63 { type: MLTypesEnum.communityDetection, parameters: [], id: 3 },
      64 { type: MLTypesEnum.shortestPath, parameters: [], id: 4 },
      65 ],
      60 machineLearning: ml

      I think this would also work

Please register or sign in to reply
limit: 500,
return: ['*'],
cached: false,
logic: undefined,
Please register or sign in to reply
};
expect(result).toEqual(expectedResult);
});
it('should return correctly on a simple query with multiple paths - 1', () => {
const ml: MachineLearning[] = [
{ type: MLTypesEnum.linkPrediction, parameters: [], id: 1 },
{ type: MLTypesEnum.centrality, parameters: [], id: 2 },
{ type: MLTypesEnum.communityDetection, parameters: [], id: 3 },
{ type: MLTypesEnum.shortestPath, parameters: [], id: 4 },
];
Please register or sign in to reply
const result = Query2BackendQuery(ss_id, visualQuery_1, settingsBase, ml);
expect(result).toEqual(expectedResult_1);
});
/*
it('should return correctly on a complex query with logic', () => {});
it('should return correctly on a query with group by logic', () => {});
it('should return correctly on a query with no label', () => {});
it('should return correctly on a query with no depth', () => {});
it('should return correctly on a query with average calculation', () => {});
it('should return correctly on a query with average calculation and multiple paths', () => {});
it('should return correctly on a single entity query with lower like logic', () => {});
it('should return correctly on a query with like logic', () => {});
it('should return correctly on a query with both direction relation', () => {});
*/
});
Loading