mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
fixing tests
This commit is contained in:
parent
97fcc3eeea
commit
0cd5e90866
@ -8,10 +8,11 @@ import {SortingMethods} from '../../../../common/entities/SortingMethods';
|
|||||||
import {ISQLSearchManager} from './ISearchManager';
|
import {ISQLSearchManager} from './ISearchManager';
|
||||||
import {IPreviewManager, PreviewPhotoDTOWithID} from '../interfaces/IPreviewManager';
|
import {IPreviewManager, PreviewPhotoDTOWithID} from '../interfaces/IPreviewManager';
|
||||||
import {SQLConnection} from './SQLConnection';
|
import {SQLConnection} from './SQLConnection';
|
||||||
import {SearchQueryDTO} from '../../../../common/entities/SearchQueryDTO';
|
import {SearchQueryDTO, SearchQueryTypes, TextSearch} from '../../../../common/entities/SearchQueryDTO';
|
||||||
import {DirectoryEntity} from './enitites/DirectoryEntity';
|
import {DirectoryEntity} from './enitites/DirectoryEntity';
|
||||||
import {ParentDirectoryDTO} from '../../../../common/entities/DirectoryDTO';
|
import {ParentDirectoryDTO} from '../../../../common/entities/DirectoryDTO';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import {Utils} from '../../../../common/Utils';
|
||||||
|
|
||||||
const LOG_TAG = '[PreviewManager]';
|
const LOG_TAG = '[PreviewManager]';
|
||||||
|
|
||||||
@ -108,7 +109,8 @@ export class PreviewManager implements IPreviewManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let previewMedia = null;
|
let previewMedia = null;
|
||||||
if (Config.Server.Preview.SearchQuery) {
|
if (Config.Server.Preview.SearchQuery &&
|
||||||
|
!Utils.equalsFilter(Config.Server.Preview.SearchQuery, {type: SearchQueryTypes.any_text, text: ''} as TextSearch)) {
|
||||||
previewMedia = await (await previewQuery())
|
previewMedia = await (await previewQuery())
|
||||||
.andWhere(await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager)
|
.andWhere(await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager)
|
||||||
.prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery))
|
.prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery))
|
||||||
@ -169,7 +171,11 @@ export class PreviewManager implements IPreviewManager {
|
|||||||
|
|
||||||
|
|
||||||
let previewMedia: PreviewPhotoDTOWithID = null;
|
let previewMedia: PreviewPhotoDTOWithID = null;
|
||||||
if (Config.Server.Preview.SearchQuery) {
|
if (Config.Server.Preview.SearchQuery &&
|
||||||
|
!Utils.equalsFilter(Config.Server.Preview.SearchQuery, {
|
||||||
|
type: SearchQueryTypes.any_text,
|
||||||
|
text: ''
|
||||||
|
} as TextSearch)) {
|
||||||
previewMedia = await previewQuery()
|
previewMedia = await previewQuery()
|
||||||
.andWhere(await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager)
|
.andWhere(await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager)
|
||||||
.prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery))
|
.prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery))
|
||||||
|
@ -36,53 +36,4 @@ class GalleryManagerTest extends GalleryManager {
|
|||||||
describe('GalleryManager', (sqlHelper: DBTestHelper) => {
|
describe('GalleryManager', (sqlHelper: DBTestHelper) => {
|
||||||
describe = tmpDescribe;
|
describe = tmpDescribe;
|
||||||
|
|
||||||
|
|
||||||
const setUpSqlDB = async () => {
|
|
||||||
await sqlHelper.initDB();
|
|
||||||
await sqlHelper.setUpTestGallery();
|
|
||||||
await ObjectManagers.InitSQLManagers();
|
|
||||||
};
|
|
||||||
|
|
||||||
before(setUpSqlDB);
|
|
||||||
after(sqlHelper.clearDB);
|
|
||||||
|
|
||||||
it('should invalidate and update preview', async () => {
|
|
||||||
const gm = new GalleryManagerTest();
|
|
||||||
const conn = await SQLConnection.getConnection();
|
|
||||||
|
|
||||||
const selectDir = async () => {
|
|
||||||
return await conn.getRepository(DirectoryEntity).findOne({id: sqlHelper.testGalleyEntities.subDir.id}, {
|
|
||||||
join: {
|
|
||||||
alias: 'dir',
|
|
||||||
leftJoinAndSelect: {preview: 'dir.preview'}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
let subdir = await selectDir();
|
|
||||||
|
|
||||||
expect(subdir.validPreview).to.equal(true);
|
|
||||||
expect(subdir.preview.id).to.equal(1);
|
|
||||||
|
|
||||||
// new version should invalidate
|
|
||||||
await gm.onNewDataVersion(sqlHelper.testGalleyEntities.subDir as ParentDirectoryDTO);
|
|
||||||
subdir = await selectDir();
|
|
||||||
expect(subdir.validPreview).to.equal(false);
|
|
||||||
// during invalidation, we do not remove the previous preview (it's good to show at least some photo)
|
|
||||||
expect(subdir.preview.id).to.equal(1);
|
|
||||||
|
|
||||||
await conn.createQueryBuilder()
|
|
||||||
.update(DirectoryEntity)
|
|
||||||
.set({validPreview: false, preview: null}).execute();
|
|
||||||
expect((await selectDir()).preview).to.equal(null);
|
|
||||||
|
|
||||||
const res = await gm.selectParentDir(conn, sqlHelper.testGalleyEntities.dir.name, sqlHelper.testGalleyEntities.dir.path);
|
|
||||||
await gm.fillParentDir(conn, res);
|
|
||||||
subdir = await selectDir();
|
|
||||||
expect(subdir.validPreview).to.equal(true);
|
|
||||||
expect(subdir.preview.id).to.equal(1);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -221,4 +221,45 @@ describe('PreviewManager', (sqlHelper: DBTestHelper) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should invalidate and update preview', async () => {
|
||||||
|
const gm = new GalleryManagerTest();
|
||||||
|
const pm = new PreviewManager();
|
||||||
|
const conn = await SQLConnection.getConnection();
|
||||||
|
|
||||||
|
const selectDir = async () => {
|
||||||
|
return await conn.getRepository(DirectoryEntity).findOne({id: subDir.id}, {
|
||||||
|
join: {
|
||||||
|
alias: 'dir',
|
||||||
|
leftJoinAndSelect: {preview: 'dir.preview'}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let subdir = await selectDir();
|
||||||
|
|
||||||
|
expect(subdir.validPreview).to.equal(true);
|
||||||
|
expect(subdir.preview.id).to.equal(2);
|
||||||
|
|
||||||
|
// new version should invalidate
|
||||||
|
await pm.onNewDataVersion(subDir as ParentDirectoryDTO);
|
||||||
|
subdir = await selectDir();
|
||||||
|
expect(subdir.validPreview).to.equal(false);
|
||||||
|
// during invalidation, we do not remove the previous preview (it's good to show at least some photo)
|
||||||
|
expect(subdir.preview.id).to.equal(2);
|
||||||
|
|
||||||
|
await conn.createQueryBuilder()
|
||||||
|
.update(DirectoryEntity)
|
||||||
|
.set({validPreview: false, preview: null}).execute();
|
||||||
|
expect((await selectDir()).preview).to.equal(null);
|
||||||
|
|
||||||
|
const res = await gm.selectParentDir(conn, dir.name, dir.path);
|
||||||
|
await gm.fillParentDir(conn, res);
|
||||||
|
subdir = await selectDir();
|
||||||
|
expect(subdir.validPreview).to.equal(true);
|
||||||
|
expect(subdir.preview.id).to.equal(2);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user