Skip to content
Snippets Groups Projects
Commit 044faf06 authored by Marcos Pieras's avatar Marcos Pieras
Browse files

test: adds test with vite

parent 4906aa55
No related branches found
No related tags found
5 merge requests!42test: adds return message to handle e2e tests,!40test: adds test on populate template,!37chore: adds precommit and commitlint,!35test: adds tests on statcheck and diffcheck,!34test: adds tests for query service
No preview for this file type
......@@ -20,7 +20,8 @@
"@typescript-eslint/eslint-plugin": "^8.19.1",
"@typescript-eslint/parser": "^8.19.1",
"eslint": "^9.17.0",
"typescript-eslint": "^8.19.1"
"typescript-eslint": "^8.19.1",
"vitest": "^3.0.8"
},
"peerDependencies": {
"typescript": "^5.0.0"
......
import { query2Cypher } from './queryConverter';
import { query2Cypher } from '../../utils/cypher/converter/queryConverter';
import { StringFilterTypes, type BackendQueryFormat } from 'ts-common';
import { expect, test, describe, it } from 'bun:test';
import { expect, describe, it } from 'vitest';
function fixCypherSpaces(cypher?: string | null): string {
if (!cypher) {
......
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';
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' },
],
},
];
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 },
],
limit: 500,
return: ['*'],
cached: false,
logic: undefined,
};
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 },
];
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', () => {});
*/
});
import type { QueryMultiGraph, QueryGraphNodes, QueryGraphEdges } from 'ts-common/src/model/graphology';
import type { SerializedNode, SerializedEdge } from 'graphology-types';
import { Handles, QueryElementTypes } from 'ts-common/src/model/reactflow';
import { type BackendQueryFormat } from 'ts-common';
import { MLTypesEnum } from 'ts-common/src/model/query/machineLearningModel';
import { type QueryBuilderSettings } from 'ts-common/src/model/query/queryBuilderModel';
export function createQueryMultiGraphFromData(nodesData: any[], edgesData: any[]): QueryMultiGraph {
const nodes: SerializedNode<QueryGraphNodes>[] = nodesData.map(node => ({
key: node.id,
attributes: {
id: node.id,
name: node.name,
schemaKey: node.schemaKey,
type: node.type,
width: node.width,
height: node.height,
x: node.x,
y: node.y,
attributes: node.attributes.map((attribute: any) => ({
handleData: {
nodeId: node.id,
nodeName: node.name,
nodeType: node.type,
handleType: 'entityAttributeHandle' as Handles, // check if different reactflow Handles
attributeName: attribute.name,
attributeType: attribute.type,
},
})),
leftRelationHandleId: {
nodeId: node.id,
nodeName: node.name,
nodeType: node.type,
handleType: 'entityLeftHandle' as Handles,
},
rightRelationHandleId: {
nodeId: node.id,
nodeName: node.name,
nodeType: node.type,
handleType: 'entityRightHandle' as Handles,
},
selected: node.selected || false,
},
}));
const edges: SerializedEdge<QueryGraphEdges>[] = edgesData.map(edge => ({
source: edge.sourceNodeId,
target: edge.targetNodeId,
type: edge.type,
sourceHandleData: {
nodeId: edge.sourceNodeId,
nodeName: edge.sourceNodeName,
nodeType: edge.sourceNodeType,
handleType: edge.sourceHandleType,
attributeName: edge.sourceAttributeName,
attributeType: edge.sourceAttributeType,
},
targetHandleData: {
nodeId: edge.targetNodeId,
nodeName: edge.targetNodeName,
nodeType: edge.targetNodeType,
handleType: edge.targetHandleType,
attributeName: edge.targetAttributeName,
attributeType: edge.targetAttributeType,
},
}));
return {
nodes: nodes,
edges: edges,
options: {
type: 'mixed',
multi: true,
allowSelfLoops: false,
},
attributes: {},
};
}
export const ss_id: string = 'test';
export const settingsBase: QueryBuilderSettings = {
depth: {
max: 1,
min: 1,
},
limit: 500,
layout: 'manual',
unionTypes: {},
autocompleteRelation: true,
};
export const visualQuery_1: QueryMultiGraph = {
edges: [
{
key: 'geid_183_0',
source: 'id_1741246511422',
target: 'id_1741246512287',
attributes: {
type: 'connection',
sourceHandleData: {
nodeId: 'id_1741246511422',
nodeName: 'Person',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityRight,
attributeName: '',
},
targetHandleData: {
nodeId: 'id_1741246512287',
nodeName: 'WROTE',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationLeft,
attributeName: '',
},
},
},
{
key: 'geid_183_1',
source: 'id_1741246512287',
target: 'id_1741246511585',
attributes: {
type: 'connection',
sourceHandleData: {
nodeId: 'id_1741246512287',
nodeName: 'WROTE',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationRight,
attributeName: '',
},
targetHandleData: {
nodeId: 'id_1741246511585',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityLeft,
attributeName: '',
},
},
},
{
key: 'geid_262_0',
source: 'id_1741246511422',
target: 'id_1741246625352',
attributes: {
type: 'connection',
sourceHandleData: {
nodeId: 'id_1741246511422',
nodeName: 'Person',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityRight,
attributeName: '',
},
targetHandleData: {
nodeId: 'id_1741246625352',
nodeName: 'PRODUCED',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationLeft,
attributeName: '',
},
},
},
{
key: 'geid_319_0',
source: 'id_1741246625352',
target: 'id_1741246630119',
attributes: {
type: 'connection',
sourceHandleData: {
nodeId: 'id_1741246625352',
nodeName: 'PRODUCED',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationRight,
attributeName: '',
},
targetHandleData: {
nodeId: 'id_1741246630119',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityLeft,
attributeName: '',
},
},
},
],
nodes: [
{
key: 'id_1741246512287',
attributes: {
x: 180,
y: 90,
id: 'id_1741246512287',
name: 'WROTE',
type: QueryElementTypes.Relation,
depth: {
max: 1,
min: 1,
},
width: 86.15010000000001,
height: 20,
schemaKey: 'WROTE_PersonMovie',
attributes: [
{
handleData: {
nodeId: 'id_1741246512287',
nodeName: 'WROTE',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationAttribute,
attributeName: '(# Connection)',
attributeType: 'float',
},
},
],
collection: 'WROTE',
leftEntityHandleId: {
nodeId: 'id_1741246512287',
nodeName: 'WROTE',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationLeft,
},
rightEntityHandleId: {
nodeId: 'id_1741246512287',
nodeName: 'WROTE',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationRight,
},
},
},
{
key: 'id_1741246511422',
attributes: {
x: 0,
y: 90,
id: 'id_1741246511422',
name: 'Person',
type: QueryElementTypes.Entity,
width: 78.2166,
height: 20,
schemaKey: 'Person',
attributes: [
{
handleData: {
nodeId: 'id_1741246511422',
nodeName: 'Person',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: '(# Connection)',
attributeType: 'float',
},
},
{
handleData: {
nodeId: 'id_1741246511422',
nodeName: 'Person',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: 'name',
attributeType: 'string',
},
},
{
handleData: {
nodeId: 'id_1741246511422',
nodeName: 'Person',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: 'born',
attributeType: 'int',
},
},
],
leftRelationHandleId: {
nodeId: 'id_1741246511422',
nodeName: 'Person',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityLeft,
},
rightRelationHandleId: {
nodeId: 'id_1741246511422',
nodeName: 'Person',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityRight,
},
},
},
{
key: 'id_1741246511585',
attributes: {
x: 430,
y: 90,
id: 'id_1741246511585',
name: 'Movie',
type: QueryElementTypes.Entity,
width: 72.1999,
height: 20,
schemaKey: 'Movie',
attributes: [
{
handleData: {
nodeId: 'id_1741246511585',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: '(# Connection)',
attributeType: 'float',
},
},
{
handleData: {
nodeId: 'id_1741246511585',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.RelationAttribute,
attributeName: 'tagline',
attributeType: 'string',
},
},
{
handleData: {
nodeId: 'id_1741246511585',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: 'votes',
attributeType: 'int',
},
},
{
handleData: {
nodeId: 'id_1741246511585',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: 'title',
attributeType: 'string',
},
},
{
handleData: {
nodeId: 'id_1741246511585',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: 'released',
attributeType: 'int',
},
},
],
leftRelationHandleId: {
nodeId: 'id_1741246511585',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityLeft,
},
rightRelationHandleId: {
nodeId: 'id_1741246511585',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityRight,
},
},
},
{
key: 'id_1741246625352',
attributes: {
x: 180,
y: 170,
id: 'id_1741246625352',
name: 'PRODUCED',
type: QueryElementTypes.Relation,
depth: {
max: 1,
min: 1,
},
width: 104.2002,
height: 20,
schemaKey: 'PRODUCED_PersonMovie',
attributes: [
{
handleData: {
nodeId: 'id_1741246625352',
nodeName: 'PRODUCED',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationAttribute,
attributeName: '(# Connection)',
attributeType: 'float',
},
},
],
collection: 'PRODUCED',
leftEntityHandleId: {
nodeId: 'id_1741246625352',
nodeName: 'PRODUCED',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationLeft,
},
rightEntityHandleId: {
nodeId: 'id_1741246625352',
nodeName: 'PRODUCED',
nodeType: QueryElementTypes.Relation,
handleType: Handles.RelationRight,
},
},
},
{
key: 'id_1741246630119',
attributes: {
x: 390,
y: 200,
id: 'id_1741246630119',
name: 'Movie',
type: QueryElementTypes.Entity,
width: 72.1999,
height: 20,
schemaKey: 'Movie',
attributes: [
{
handleData: {
nodeId: 'id_1741246630119',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: '(# Connection)',
attributeType: 'float',
},
},
{
handleData: {
nodeId: 'id_1741246630119',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.RelationAttribute,
attributeName: 'tagline',
attributeType: 'string',
},
},
{
handleData: {
nodeId: 'id_1741246630119',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.RelationAttribute,
attributeName: 'votes',
attributeType: 'int',
},
},
{
handleData: {
nodeId: 'id_1741246630119',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityAttribute,
attributeName: 'title',
attributeType: 'string',
},
},
{
handleData: {
nodeId: 'id_1741246630119',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.RelationAttribute,
attributeName: 'released',
attributeType: 'int',
},
},
],
leftRelationHandleId: {
nodeId: 'id_1741246630119',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityLeft,
},
rightRelationHandleId: {
nodeId: 'id_1741246630119',
nodeName: 'Movie',
nodeType: QueryElementTypes.Entity,
handleType: Handles.EntityRight,
},
},
},
],
options: {
type: 'mixed',
multi: true,
allowSelfLoops: true,
},
attributes: {},
};
export const expectedResult_1: BackendQueryFormat = {
saveStateID: 'test',
return: ['*'],
query: [
{
id: 'path_0',
node: {
id: 'id_1741246511422',
label: 'Person',
relation: {
id: 'id_1741246512287',
label: 'WROTE',
depth: {
max: 1,
min: 1,
},
direction: 'BOTH',
node: {
id: 'id_1741246511585',
label: 'Movie',
},
},
},
},
{
id: 'path_1',
node: {
id: 'id_1741246511422',
label: 'Person',
relation: {
id: 'id_1741246625352',
label: 'PRODUCED',
depth: {
max: 1,
min: 1,
},
direction: 'BOTH',
node: {
id: 'id_1741246630119',
label: 'Movie',
},
},
},
},
],
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 },
],
limit: 500,
cached: false,
logic: undefined,
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment