You've already forked pigallery2
mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-11-25 22:32:52 +02:00
Fixing tests #1015
This commit is contained in:
@@ -358,15 +358,12 @@ export class SearchManager {
|
||||
])
|
||||
.getMany();
|
||||
|
||||
console.log(result.directories.map(d=>d.cache));
|
||||
console.log(result.directories.map(d=>d.cache.cover));
|
||||
// setting covers
|
||||
if (result.directories) {
|
||||
for (const item of result.directories) {
|
||||
await ObjectManagers.getInstance().GalleryManager.fillCacheForSubDir(connection, session, item as DirectoryEntity);
|
||||
}
|
||||
}
|
||||
console.log(result.directories.map(d=>d.cache.cover));
|
||||
if (
|
||||
result.directories.length > Config.Search.maxDirectoryResult
|
||||
) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export class TestHelper {
|
||||
|
||||
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();
|
||||
dir.name = name;
|
||||
@@ -175,7 +175,7 @@ export class TestHelper {
|
||||
const p = TestHelper.getPhotoEntry(dir);
|
||||
|
||||
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.country = 'Tatooine';
|
||||
p.name = 'sw1.jpg';
|
||||
|
||||
@@ -82,7 +82,9 @@ export class DBTestHelper {
|
||||
p3: 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) {
|
||||
}
|
||||
|
||||
@@ -218,9 +218,9 @@ describe('IndexingManager', (sqlHelper: DBTestHelper) => {
|
||||
|
||||
const parent = TestHelper.getRandomizedDirectoryEntry(null, 'parent');
|
||||
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 p2 = TestHelper.getRandomizedPhotoEntry(subDir2, 'subPhoto2', 0);
|
||||
const p2 = TestHelper.getRandomizedPhotoEntry(subDir2, 'subPhoto2', 0,3);
|
||||
|
||||
|
||||
DirectoryDTOUtils.removeReferences(parent);
|
||||
|
||||
@@ -65,7 +65,7 @@ class SearchManagerTest extends SearchManager {
|
||||
describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
describe = tmpDescribe;
|
||||
/**
|
||||
* dir
|
||||
* dir <-- root: '.'
|
||||
* |- v
|
||||
* |- p
|
||||
* |- p2
|
||||
@@ -171,8 +171,11 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
new AutoCompleteItem('death star', SearchQueryTypes.keyword)]);
|
||||
|
||||
expect((await sm.autocomplete(DBTestHelper.defaultSession, 'wars', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
||||
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
||||
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]);
|
||||
new AutoCompleteItem('star wars', SearchQueryTypes.keyword)]);
|
||||
|
||||
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([
|
||||
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([
|
||||
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
||||
new AutoCompleteItem('Anakin Skywalker', SearchQueryTypes.person),
|
||||
new AutoCompleteItem('Luke Skywalker', SearchQueryTypes.person),
|
||||
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]);
|
||||
new AutoCompleteItem('Luke Skywalker', SearchQueryTypes.person)]);
|
||||
|
||||
Config.Search.AutoComplete.ItemsPerCategory.maxItems = 1;
|
||||
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('Research City', SearchQueryTypes.position),
|
||||
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.fileName = 5;
|
||||
Config.Search.AutoComplete.ItemsPerCategory.fileName = 5;
|
||||
@@ -261,6 +263,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
|
||||
describe('advanced search', async () => {
|
||||
afterEach(async () => {
|
||||
Config.loadSync();
|
||||
Config.Search.listDirectories = false;
|
||||
Config.Search.listMetafiles = false;
|
||||
});
|
||||
@@ -631,7 +634,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
} as SearchResultDTO));
|
||||
|
||||
query = ({
|
||||
text: 'han',
|
||||
text: 'han s',
|
||||
type: SearchQueryTypes.keyword
|
||||
} as TextSearch);
|
||||
|
||||
@@ -744,7 +747,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
} as SearchResultDTO), JSON.stringify(query));
|
||||
|
||||
query = ({
|
||||
text: 'wars dir',
|
||||
text: '.',
|
||||
type: SearchQueryTypes.directory
|
||||
} as TextSearch);
|
||||
|
||||
@@ -757,17 +760,13 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
} as SearchResultDTO), JSON.stringify(query));
|
||||
|
||||
query = ({
|
||||
text: '/wars dir',
|
||||
text: '.',
|
||||
matchType: TextSearchQueryMatchTypes.exact_match,
|
||||
type: SearchQueryTypes.directory
|
||||
} as TextSearch);
|
||||
|
||||
|
||||
expect(removeDir(await sm.search(DBTestHelper.defaultSession, {
|
||||
text: '/wars dir',
|
||||
matchType: TextSearchQueryMatchTypes.exact_match,
|
||||
type: SearchQueryTypes.directory
|
||||
} as TextSearch))).to.deep.equalInAnyOrder(removeDir({
|
||||
expect(removeDir(await sm.search(DBTestHelper.defaultSession, query))).to.deep.equalInAnyOrder(removeDir({
|
||||
searchQuery: query,
|
||||
directories: [],
|
||||
media: [p, p2, v],
|
||||
@@ -777,7 +776,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
|
||||
|
||||
query = ({
|
||||
text: '/wars dir/Return of the Jedi',
|
||||
text: '/Return of the Jedi',
|
||||
// matchType: TextSearchQueryMatchTypes.like,
|
||||
type: SearchQueryTypes.directory
|
||||
} as TextSearch);
|
||||
@@ -791,7 +790,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
} as SearchResultDTO), JSON.stringify(query));
|
||||
|
||||
query = ({
|
||||
text: '/wars dir/Return of the Jedi',
|
||||
text: '/Return of the Jedi',
|
||||
matchType: TextSearchQueryMatchTypes.exact_match,
|
||||
type: SearchQueryTypes.directory
|
||||
} as TextSearch);
|
||||
@@ -924,6 +923,7 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
let sm: SearchManager;
|
||||
|
||||
before(async () => {
|
||||
Config.loadSync();
|
||||
await sqlHelper.clearDB();
|
||||
await setUpSqlDB();
|
||||
p5 = TestHelper.getBasePhotoEntry(subDir2, 'p5-23h-ago.jpg');
|
||||
@@ -1719,13 +1719,13 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
||||
describe('projectionQuery (session scoped filter)', () => {
|
||||
it('getCount should respect projectionQuery', async () => {
|
||||
const sm = new SearchManager();
|
||||
const session = DBTestHelper.defaultSession;
|
||||
|
||||
const projQ = ({
|
||||
text: 'wookiees',
|
||||
matchType: TextSearchQueryMatchTypes.exact_match,
|
||||
type: SearchQueryTypes.keyword
|
||||
} as TextSearch);
|
||||
const session = Utils.clone(DBTestHelper.defaultSession);
|
||||
session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ);
|
||||
|
||||
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 () => {
|
||||
const sm = new SearchManager();
|
||||
const session = DBTestHelper.defaultSession;
|
||||
|
||||
const projQ = ({
|
||||
text: 'wookiees',
|
||||
matchType: TextSearchQueryMatchTypes.exact_match,
|
||||
type: SearchQueryTypes.keyword
|
||||
} as TextSearch);
|
||||
const session = Utils.clone(DBTestHelper.defaultSession);
|
||||
session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ);
|
||||
|
||||
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 () => {
|
||||
const sm = new SearchManager();
|
||||
const session = DBTestHelper.defaultSession;
|
||||
|
||||
const projQ = ({
|
||||
text: 'wookiees',
|
||||
matchType: TextSearchQueryMatchTypes.exact_match,
|
||||
type: SearchQueryTypes.keyword
|
||||
} as TextSearch);
|
||||
const session = Utils.clone(DBTestHelper.defaultSession);
|
||||
session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ);
|
||||
|
||||
// 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
|
||||
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 () => {
|
||||
const sm = new SearchManager();
|
||||
const session = DBTestHelper.defaultSession;
|
||||
|
||||
const projQ = ({
|
||||
text: 'wookiees',
|
||||
matchType: TextSearchQueryMatchTypes.exact_match,
|
||||
type: SearchQueryTypes.keyword
|
||||
} as TextSearch);
|
||||
const session = Utils.clone(DBTestHelper.defaultSession);
|
||||
session.projectionQuery = await sm.prepareAndBuildWhereQuery(projQ);
|
||||
|
||||
const searchQ = {text: 'star wars', matchType: TextSearchQueryMatchTypes.exact_match, type: SearchQueryTypes.keyword} as TextSearch;
|
||||
|
||||
Reference in New Issue
Block a user