Reformat project into workspaces
This commit is contained in:
1 parent
20bb10114b
commit
c3e2cf5ed3
38 files changed
+4863
-4186
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { CategoryRepository } from './category.repository';
|
||||
|
||||
describe('CategoryRepository - ltree SQL Generator', () => {
|
||||
const repository = new CategoryRepository();
|
||||
|
||||
describe('generateDescendantsQuery()', () => {
|
||||
it('should generate valid SQL using the ltree descenant operator (<@)', () => {
|
||||
const parentPath = 'Top.Science';
|
||||
const result = repository.generateDescendantsQuery(parentPath);
|
||||
|
||||
// veriy the generated SQL syntax as correct ltree
|
||||
assert.match(result.sql, /<@/);
|
||||
assert.match(result.sql, /::ltree/);
|
||||
assert.deepEqual(result.values, ['Top.Science']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateWildcardQuery()', () => {
|
||||
it('should generate valid SQL utilizing an lquery matching operator (~)', () => {
|
||||
const result = repository.generateWildcardQuery('Top.*.Astronomy');
|
||||
|
||||
assert.match(result.sql, /~/);
|
||||
assert.match(result.sql, /::lquery/);
|
||||
assert.equal(result.values[0], 'Top.*.Astronomy');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValidLtreePath() validation utility', () => {
|
||||
it('should pass for correctly formatted dot-separated ltree structures', () => {
|
||||
assert.equal(repository.isValidLtreePath('Top.Hobbies.Amateurs_Astronomy'), true);
|
||||
});
|
||||
|
||||
it('should fail if special characters or spaces are introduced into the path', () => {
|
||||
assert.equal(repository.isValidLtreePath('Top.Hobbies.Bad Path!'), false);
|
||||
assert.equal(repository.isValidLtreePath('Top..InvalidDoubleDot'), false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
// structural interface to the test table
|
||||
export interface CatetoryNode {
|
||||
id: number;
|
||||
name: string;
|
||||
path: string; // ltree field
|
||||
}
|
||||
|
||||
export class CategoryRepository {
|
||||
// simulate generating a SQL query targeting child paths
|
||||
generateDescendantsQuery(parentPath: string): { sql: string; values: string[] } {
|
||||
return {
|
||||
sql: 'SELECT id, name, path FROM categories WHERE path <@ $1::ltree',
|
||||
values: [parentPath]
|
||||
};
|
||||
}
|
||||
|
||||
generateWildcardQuery(pattern: string): { sql: string, values: string[] } {
|
||||
// Simulate genrating a SQL query using ltree wildcards
|
||||
return {
|
||||
sql: 'SELECT id, name, path FROM categories WHERE path ~ $1::lquery',
|
||||
values: [pattern]
|
||||
};
|
||||
}
|
||||
|
||||
// helper utility to validate a string as an ltree value
|
||||
isValidLtreePath(path: string): boolean {
|
||||
const ltreeRegex = /^[A-Za-z0-9_]+(\.[A-Za-z0-9_]+)*$/;
|
||||
return ltreeRegex.test(path);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user