1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/test/backend/unit/model/sql/GalleryManager.ts

61 lines
2.1 KiB
TypeScript
Raw Normal View History

import {expect} from 'chai';
import {TestHelper} from './TestHelper';
import {SQLTestHelper} from '../../../SQLTestHelper';
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';
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';
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();
ObjectManagers.getInstance().PersonManager = new PersonManager();
ObjectManagers.getInstance().VersionManager = new VersionManager();
});
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));
});
});