2019-01-28 03:36:42 +08:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import {TestHelper} from './TestHelper';
|
|
|
|
import {SQLTestHelper} from '../../../SQLTestHelper';
|
2019-12-15 00:27:01 +08:00
|
|
|
import {GalleryManager} from '../../../../../src/backend/model/database/sql/GalleryManager';
|
|
|
|
import {IndexingManager} from '../../../../../src/backend/model/database/sql/IndexingManager';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {DirectoryDTO} from '../../../../../src/common/entities/DirectoryDTO';
|
|
|
|
import {Utils} from '../../../../../src/common/Utils';
|
|
|
|
import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
2019-12-15 00:27:01 +08:00
|
|
|
import {PersonManager} from '../../../../../src/backend/model/database/sql/PersonManager';
|
|
|
|
import {MediaEntity} from '../../../../../src/backend/model/database/sql/enitites/MediaEntity';
|
|
|
|
import {VersionManager} from '../../../../../src/backend/model/database/sql/VersionManager';
|
2019-01-28 03:36:42 +08:00
|
|
|
|
|
|
|
class IndexingManagerTest extends IndexingManager {
|
|
|
|
|
|
|
|
public async saveToDB(scannedDirectory: DirectoryDTO): Promise<void> {
|
|
|
|
return super.saveToDB(scannedDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// to help WebStorm to handle the test cases
|
|
|
|
declare let describe: any;
|
|
|
|
declare const after: any;
|
|
|
|
describe = SQLTestHelper.describe;
|
|
|
|
|
|
|
|
describe('GalleryManager', (sqlHelper: SQLTestHelper) => {
|
|
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
await sqlHelper.initDB();
|
2019-02-16 00:47:09 +08:00
|
|
|
ObjectManagers.getInstance().PersonManager = new PersonManager();
|
|
|
|
ObjectManagers.getInstance().VersionManager = new VersionManager();
|
2019-01-28 03:36:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
after(async () => {
|
|
|
|
await sqlHelper.clearDB();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get random photo', async () => {
|
|
|
|
const gm = new GalleryManager();
|
|
|
|
const im = new IndexingManagerTest();
|
|
|
|
|
|
|
|
const parent = TestHelper.getRandomizedDirectoryEntry();
|
|
|
|
const p1 = TestHelper.getRandomizedPhotoEntry(parent, 'Photo1');
|
|
|
|
expect(await gm.getRandomPhoto({})).to.not.exist;
|
|
|
|
DirectoryDTO.removeReferences(parent);
|
|
|
|
await im.saveToDB(Utils.clone(parent));
|
|
|
|
|
|
|
|
delete p1.metadata.faces;
|
|
|
|
delete p1.directory;
|
|
|
|
delete p1.id;
|
|
|
|
const found: MediaEntity = <any>await gm.getRandomPhoto({});
|
|
|
|
delete found.metadata.bitRate;
|
|
|
|
delete found.metadata.duration;
|
|
|
|
delete found.directory;
|
|
|
|
delete found.id;
|
|
|
|
expect(Utils.clone(found)).to.be.deep.equal(Utils.clone(p1));
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|