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

test: first version

parent e585b3a1
Branches test/diffCheck2
No related tags found
No related merge requests found
Pipeline #146072 passed
......@@ -5,6 +5,10 @@ import type { GraphQueryResultMetaFromBackend } from 'ts-common/src/model/webSoc
import { ums } from '../variables';
import type { InsightModel } from 'ts-common';
export const compareHashedQueryResults = (previousHash: string | null, currentHash: string): boolean => {
return !previousHash || !hashIsEqual(currentHash, previousHash);
};
export const diffCheck = async (
insight: InsightModel,
ss: SaveState,
......@@ -20,7 +24,9 @@ export const diffCheck = async (
});
log.debug('Comparing hash values from current and previous query');
const changed = !previousQueryResult || !hashIsEqual(queryResultHash, previousQueryResult);
const changed = compareHashedQueryResults(previousQueryResult, queryResultHash);
insight.status ||= changed;
log.debug('Updated node and edge ids in SaveState');
......
import { expect, test, describe, it } from 'bun:test';
import type { GraphQueryResultMetaFromBackend } from 'ts-common';
import { hashDictionary, hashIsEqual } from '../../utils/hashing';
import { compareHashedQueryResults } from '../diffCheck';
describe('Hash Comparison Tests', () => {
it('should detect different hashes for different graph structures', () => {
// First query result
const query1: GraphQueryResultMetaFromBackend = {
nodes: [{ _id: 'node1' }, { _id: 'node2' }],
edges: [{ _id: 'edge1' }],
} as GraphQueryResultMetaFromBackend;
// Second query result with different structure
const query2: GraphQueryResultMetaFromBackend = {
nodes: [{ _id: 'node1' }, { _id: 'node2' }, { _id: 'node3' }],
edges: [{ _id: 'edge1' }, { _id: 'edge2' }],
} as GraphQueryResultMetaFromBackend;
const hash1 = hashDictionary({
nodes: query1.nodes.map(node => node._id),
edges: query1.edges.map(edge => edge._id),
});
const hash2 = hashDictionary({
nodes: query2.nodes.map(node => node._id),
edges: query2.edges.map(edge => edge._id),
});
// Test direct hash comparison
expect(hashIsEqual(hash1, hash2)).toBe(false);
// Test using compareHashedQueryResults
expect(compareHashedQueryResults(hash1, hash2)).toBe(true);
});
it('should detect identical hashes for same graph structures', () => {
const query1 = {
nodes: [{ _id: 'node1' }, { _id: 'node2' }],
edges: [{ _id: 'edge1' }],
} as GraphQueryResultMetaFromBackend;
const query2 = {
nodes: [{ _id: 'node1' }, { _id: 'node2' }],
edges: [{ _id: 'edge1' }],
} as GraphQueryResultMetaFromBackend;
const hash1 = hashDictionary({
nodes: query1.nodes.map(node => node._id),
edges: query1.edges.map(edge => edge._id),
});
const hash2 = hashDictionary({
nodes: query2.nodes.map(node => node._id),
edges: query2.edges.map(edge => edge._id),
});
// Test direct hash comparison
expect(hashIsEqual(hash1, hash2)).toBe(true);
// Test using compareHashedQueryResults
expect(compareHashedQueryResults(hash1, hash2)).toBe(false);
});
});
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