1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-11-27 22:38:10 +02:00

Fixing tests #1015

This commit is contained in:
Patrik J. Braun
2025-09-01 21:38:12 +02:00
parent 90869cbd1f
commit 04263d97f8
5 changed files with 28 additions and 29 deletions

View File

@@ -358,15 +358,12 @@ export class SearchManager {
]) ])
.getMany(); .getMany();
console.log(result.directories.map(d=>d.cache));
console.log(result.directories.map(d=>d.cache.cover));
// setting covers // setting covers
if (result.directories) { if (result.directories) {
for (const item of result.directories) { for (const item of result.directories) {
await ObjectManagers.getInstance().GalleryManager.fillCacheForSubDir(connection, session, item as DirectoryEntity); await ObjectManagers.getInstance().GalleryManager.fillCacheForSubDir(connection, session, item as DirectoryEntity);
} }
} }
console.log(result.directories.map(d=>d.cache.cover));
if ( if (
result.directories.length > Config.Search.maxDirectoryResult result.directories.length > Config.Search.maxDirectoryResult
) { ) {

View File

@@ -30,7 +30,7 @@ export class TestHelper {
public static readonly TMP_DIR = path.join(__dirname, './tmp'); public static readonly TMP_DIR = path.join(__dirname, './tmp');
public static getDirectoryEntry(parent: DirectoryBaseDTO = null, name = 'wars dir'): DirectoryEntity { public static getDirectoryEntry(parent: DirectoryBaseDTO = null, name = '.'): DirectoryEntity {
const dir = new DirectoryEntity(); const dir = new DirectoryEntity();
dir.name = name; dir.name = name;
@@ -175,7 +175,7 @@ export class TestHelper {
const p = TestHelper.getPhotoEntry(dir); const p = TestHelper.getPhotoEntry(dir);
p.metadata.caption = 'Han Solo\'s dice'; p.metadata.caption = 'Han Solo\'s dice';
p.metadata.keywords = ['Boba Fett', 'star wars', 'Anakin', 'death star']; p.metadata.keywords = ['Boba Fett', 'star wars', 'Anakin', 'death star', 'phantom menace'];
p.metadata.positionData.city = 'Mos Eisley'; p.metadata.positionData.city = 'Mos Eisley';
p.metadata.positionData.country = 'Tatooine'; p.metadata.positionData.country = 'Tatooine';
p.name = 'sw1.jpg'; p.name = 'sw1.jpg';

View File

@@ -82,7 +82,9 @@ export class DBTestHelper {
p3: null, p3: null,
p4: null p4: null
}; };
public static readonly defaultSession: SessionContext = {user: {projectionKey: SessionManager.NO_PROJECTION_KEY}} as any; public static get defaultSession(): SessionContext {
return {user: {projectionKey: SessionManager.NO_PROJECTION_KEY}} as any;
}
constructor(public dbType: DatabaseType) { constructor(public dbType: DatabaseType) {
} }

View File

@@ -218,9 +218,9 @@ describe('IndexingManager', (sqlHelper: DBTestHelper) => {
const parent = TestHelper.getRandomizedDirectoryEntry(null, 'parent'); const parent = TestHelper.getRandomizedDirectoryEntry(null, 'parent');
const subDir1 = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir'); const subDir1 = TestHelper.getRandomizedDirectoryEntry(parent, 'subDir');
const p1 = TestHelper.getRandomizedPhotoEntry(subDir1, 'subPhoto1', 0); const p1 = TestHelper.getRandomizedPhotoEntry(subDir1, 'subPhoto1', 0, 5);
const subDir2 = TestHelper.getRandomizedDirectoryEntry(parent, 'SUBDIR'); const subDir2 = TestHelper.getRandomizedDirectoryEntry(parent, 'SUBDIR');
const p2 = TestHelper.getRandomizedPhotoEntry(subDir2, 'subPhoto2', 0); const p2 = TestHelper.getRandomizedPhotoEntry(subDir2, 'subPhoto2', 0,3);
DirectoryDTOUtils.removeReferences(parent); DirectoryDTOUtils.removeReferences(parent);

View File

@@ -65,7 +65,7 @@ class SearchManagerTest extends SearchManager {
describe('SearchManager', (sqlHelper: DBTestHelper) => { describe('SearchManager', (sqlHelper: DBTestHelper) => {
describe = tmpDescribe; describe = tmpDescribe;
/** /**
* dir * dir <-- root: '.'
* |- v * |- v
* |- p * |- p
* |- p2 * |- p2
@@ -171,8 +171,11 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
new AutoCompleteItem('death star', SearchQueryTypes.keyword)]); new AutoCompleteItem('death star', SearchQueryTypes.keyword)]);
expect((await sm.autocomplete(DBTestHelper.defaultSession, 'wars', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([ expect((await sm.autocomplete(DBTestHelper.defaultSession, 'wars', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
new AutoCompleteItem('star wars', SearchQueryTypes.keyword), new AutoCompleteItem('star wars', SearchQueryTypes.keyword)]);
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]);
expect((await sm.autocomplete(DBTestHelper.defaultSession, 'phantom', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
new AutoCompleteItem('phantom menace', SearchQueryTypes.keyword),
new AutoCompleteItem('The Phantom Menace', SearchQueryTypes.directory)]);
expect((await sm.autocomplete(DBTestHelper.defaultSession, 'arch', SearchQueryTypes.any_text))).eql([ expect((await sm.autocomplete(DBTestHelper.defaultSession, 'arch', SearchQueryTypes.any_text))).eql([
new AutoCompleteItem('Research City', SearchQueryTypes.position)]); new AutoCompleteItem('Research City', SearchQueryTypes.position)]);
@@ -181,8 +184,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
expect((await sm.autocomplete(DBTestHelper.defaultSession, 'wa', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([ expect((await sm.autocomplete(DBTestHelper.defaultSession, 'wa', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
new AutoCompleteItem('star wars', SearchQueryTypes.keyword), new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
new AutoCompleteItem('Anakin Skywalker', SearchQueryTypes.person), new AutoCompleteItem('Anakin Skywalker', SearchQueryTypes.person),
new AutoCompleteItem('Luke Skywalker', SearchQueryTypes.person), new AutoCompleteItem('Luke Skywalker', SearchQueryTypes.person)]);
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]);
Config.Search.AutoComplete.ItemsPerCategory.maxItems = 1; Config.Search.AutoComplete.ItemsPerCategory.maxItems = 1;
expect((await sm.autocomplete(DBTestHelper.defaultSession, 'a', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([ expect((await sm.autocomplete(DBTestHelper.defaultSession, 'a', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
@@ -190,7 +192,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
new AutoCompleteItem('Han Solo\'s dice', SearchQueryTypes.caption), new AutoCompleteItem('Han Solo\'s dice', SearchQueryTypes.caption),
new AutoCompleteItem('Research City', SearchQueryTypes.position), new AutoCompleteItem('Research City', SearchQueryTypes.position),
new AutoCompleteItem('death star', SearchQueryTypes.keyword), new AutoCompleteItem('death star', SearchQueryTypes.keyword),
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]); new AutoCompleteItem('The Phantom Menace', SearchQueryTypes.directory)]);
Config.Search.AutoComplete.ItemsPerCategory.maxItems = 5; Config.Search.AutoComplete.ItemsPerCategory.maxItems = 5;
Config.Search.AutoComplete.ItemsPerCategory.fileName = 5; Config.Search.AutoComplete.ItemsPerCategory.fileName = 5;
Config.Search.AutoComplete.ItemsPerCategory.fileName = 5; Config.Search.AutoComplete.ItemsPerCategory.fileName = 5;
@@ -261,6 +263,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
describe('advanced search', async () => { describe('advanced search', async () => {
afterEach(async () => { afterEach(async () => {
Config.loadSync();
Config.Search.listDirectories = false; Config.Search.listDirectories = false;
Config.Search.listMetafiles = false; Config.Search.listMetafiles = false;
}); });
@@ -631,7 +634,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
} as SearchResultDTO)); } as SearchResultDTO));
query = ({ query = ({
text: 'han', text: 'han s',
type: SearchQueryTypes.keyword type: SearchQueryTypes.keyword
} as TextSearch); } as TextSearch);
@@ -744,7 +747,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
} as SearchResultDTO), JSON.stringify(query)); } as SearchResultDTO), JSON.stringify(query));
query = ({ query = ({
text: 'wars dir', text: '.',
type: SearchQueryTypes.directory type: SearchQueryTypes.directory
} as TextSearch); } as TextSearch);
@@ -757,17 +760,13 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
} as SearchResultDTO), JSON.stringify(query)); } as SearchResultDTO), JSON.stringify(query));
query = ({ query = ({
text: '/wars dir', text: '.',
matchType: TextSearchQueryMatchTypes.exact_match, matchType: TextSearchQueryMatchTypes.exact_match,
type: SearchQueryTypes.directory type: SearchQueryTypes.directory
} as TextSearch); } as TextSearch);
expect(removeDir(await sm.search(DBTestHelper.defaultSession, { expect(removeDir(await sm.search(DBTestHelper.defaultSession, query))).to.deep.equalInAnyOrder(removeDir({
text: '/wars dir',
matchType: TextSearchQueryMatchTypes.exact_match,
type: SearchQueryTypes.directory
} as TextSearch))).to.deep.equalInAnyOrder(removeDir({
searchQuery: query, searchQuery: query,
directories: [], directories: [],
media: [p, p2, v], media: [p, p2, v],
@@ -777,7 +776,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
query = ({ query = ({
text: '/wars dir/Return of the Jedi', text: '/Return of the Jedi',
// matchType: TextSearchQueryMatchTypes.like, // matchType: TextSearchQueryMatchTypes.like,
type: SearchQueryTypes.directory type: SearchQueryTypes.directory
} as TextSearch); } as TextSearch);
@@ -791,7 +790,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
} as SearchResultDTO), JSON.stringify(query)); } as SearchResultDTO), JSON.stringify(query));
query = ({ query = ({
text: '/wars dir/Return of the Jedi', text: '/Return of the Jedi',
matchType: TextSearchQueryMatchTypes.exact_match, matchType: TextSearchQueryMatchTypes.exact_match,
type: SearchQueryTypes.directory type: SearchQueryTypes.directory
} as TextSearch); } as TextSearch);
@@ -924,6 +923,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
let sm: SearchManager; let sm: SearchManager;
before(async () => { before(async () => {
Config.loadSync();
await sqlHelper.clearDB(); await sqlHelper.clearDB();
await setUpSqlDB(); await setUpSqlDB();
p5 = TestHelper.getBasePhotoEntry(subDir2, 'p5-23h-ago.jpg'); p5 = TestHelper.getBasePhotoEntry(subDir2, 'p5-23h-ago.jpg');
@@ -1719,13 +1719,13 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
describe('projectionQuery (session scoped filter)', () => { describe('projectionQuery (session scoped filter)', () => {
it('getCount should respect projectionQuery', async () => { it('getCount should respect projectionQuery', async () => {
const sm = new SearchManager(); const sm = new SearchManager();
const session = DBTestHelper.defaultSession;
const projQ = ({ const projQ = ({
text: 'wookiees', text: 'wookiees',
matchType: TextSearchQueryMatchTypes.exact_match, matchType: TextSearchQueryMatchTypes.exact_match,
type: SearchQueryTypes.keyword type: SearchQueryTypes.keyword
} as TextSearch); } as TextSearch);
const session = Utils.clone(DBTestHelper.defaultSession);
session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ); session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ);
const searchQ = {text: 'star wars', matchType: TextSearchQueryMatchTypes.exact_match, type: SearchQueryTypes.keyword} as TextSearch; const searchQ = {text: 'star wars', matchType: TextSearchQueryMatchTypes.exact_match, type: SearchQueryTypes.keyword} as TextSearch;
@@ -1741,13 +1741,13 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
it('getNMedia should respect projectionQuery', async () => { it('getNMedia should respect projectionQuery', async () => {
const sm = new SearchManager(); const sm = new SearchManager();
const session = DBTestHelper.defaultSession;
const projQ = ({ const projQ = ({
text: 'wookiees', text: 'wookiees',
matchType: TextSearchQueryMatchTypes.exact_match, matchType: TextSearchQueryMatchTypes.exact_match,
type: SearchQueryTypes.keyword type: SearchQueryTypes.keyword
} as TextSearch); } as TextSearch);
const session = Utils.clone(DBTestHelper.defaultSession);
session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ); session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ);
const searchQ = {text: 'star wars', matchType: TextSearchQueryMatchTypes.exact_match, type: SearchQueryTypes.keyword} as TextSearch; const searchQ = {text: 'star wars', matchType: TextSearchQueryMatchTypes.exact_match, type: SearchQueryTypes.keyword} as TextSearch;
@@ -1763,17 +1763,17 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
it('autocomplete should respect projectionQuery', async () => { it('autocomplete should respect projectionQuery', async () => {
const sm = new SearchManager(); const sm = new SearchManager();
const session = DBTestHelper.defaultSession;
const projQ = ({ const projQ = ({
text: 'wookiees', text: 'wookiees',
matchType: TextSearchQueryMatchTypes.exact_match, matchType: TextSearchQueryMatchTypes.exact_match,
type: SearchQueryTypes.keyword type: SearchQueryTypes.keyword
} as TextSearch); } as TextSearch);
const session = Utils.clone(DBTestHelper.defaultSession);
session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ); session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ);
// validate projection less count // validate projection less count
expect((await sm.autocomplete(DBTestHelper.defaultSession, 'star', SearchQueryTypes.any_text)).length).to.equal(2); expect((await sm.autocomplete(DBTestHelper.defaultSession, 'phantom', SearchQueryTypes.any_text)).length).to.equal(2);
// test // test
expect((await sm.autocomplete(session, 'star', SearchQueryTypes.any_text)).length).to.equal(1); expect((await sm.autocomplete(session, 'star', SearchQueryTypes.any_text)).length).to.equal(1);
@@ -1785,13 +1785,13 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
it('search should respect projectionQuery', async () => { it('search should respect projectionQuery', async () => {
const sm = new SearchManager(); const sm = new SearchManager();
const session = DBTestHelper.defaultSession;
const projQ = ({ const projQ = ({
text: 'wookiees', text: 'wookiees',
matchType: TextSearchQueryMatchTypes.exact_match, matchType: TextSearchQueryMatchTypes.exact_match,
type: SearchQueryTypes.keyword type: SearchQueryTypes.keyword
} as TextSearch); } as TextSearch);
const session = Utils.clone(DBTestHelper.defaultSession);
session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ); session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ);
const searchQ = {text: 'star wars', matchType: TextSearchQueryMatchTypes.exact_match, type: SearchQueryTypes.keyword} as TextSearch; const searchQ = {text: 'star wars', matchType: TextSearchQueryMatchTypes.exact_match, type: SearchQueryTypes.keyword} as TextSearch;