2020-01-01 22:57:16 +08:00
|
|
|
import {expect} from 'chai';
|
2019-12-15 00:27:01 +08:00
|
|
|
import {PersonManager} from '../../../../../src/backend/model/database/sql/PersonManager';
|
2020-01-01 22:57:16 +08:00
|
|
|
import {SQLTestHelper} from '../../../SQLTestHelper';
|
|
|
|
import {TestHelper} from './TestHelper';
|
2021-01-17 17:56:33 +08:00
|
|
|
import {PhotoDTO, PhotoMetadata} from '../../../../../src/common/entities/PhotoDTO';
|
2021-01-02 00:58:41 +08:00
|
|
|
import {Utils} from '../../../../../src/common/Utils';
|
|
|
|
import {PersonWithSampleRegion} from '../../../../../src/common/entities/PersonDTO';
|
2021-01-17 17:56:33 +08:00
|
|
|
import {DirectoryDTO} from '../../../../../src/common/entities/DirectoryDTO';
|
|
|
|
import {VideoDTO} from '../../../../../src/common/entities/VideoDTO';
|
|
|
|
import {SQLConnection} from '../../../../../src/backend/model/database/sql/SQLConnection';
|
|
|
|
import {PersonEntry} from '../../../../../src/backend/model/database/sql/enitites/PersonEntry';
|
|
|
|
import {MediaDTO} from '../../../../../src/common/entities/MediaDTO';
|
2019-02-05 06:46:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
// to help WebStorm to handle the test cases
|
|
|
|
declare let describe: any;
|
|
|
|
declare const after: any;
|
2021-03-15 01:23:30 +08:00
|
|
|
declare const before: any;
|
2019-02-05 06:46:27 +08:00
|
|
|
declare const it: any;
|
|
|
|
|
|
|
|
|
2020-01-01 22:57:16 +08:00
|
|
|
describe = SQLTestHelper.describe;
|
2019-02-05 06:46:27 +08:00
|
|
|
|
2020-01-01 22:57:16 +08:00
|
|
|
describe('PersonManager', (sqlHelper: SQLTestHelper) => {
|
|
|
|
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
let dir: DirectoryDTO;
|
|
|
|
|
|
|
|
let v: VideoDTO;
|
|
|
|
let p: PhotoDTO;
|
|
|
|
let p2: PhotoDTO;
|
|
|
|
let p_faceLess: PhotoDTO;
|
|
|
|
|
|
|
|
let savedPerson: PersonWithSampleRegion[] = [];
|
2020-01-01 22:57:16 +08:00
|
|
|
|
|
|
|
const setUpSqlDB = async () => {
|
|
|
|
await sqlHelper.initDB();
|
2021-01-17 17:56:33 +08:00
|
|
|
const directory: DirectoryDTO = TestHelper.getDirectoryEntry();
|
|
|
|
TestHelper.getPhotoEntry1(directory);
|
|
|
|
TestHelper.getPhotoEntry2(directory);
|
|
|
|
const pFaceLess = TestHelper.getPhotoEntry3(directory);
|
|
|
|
delete pFaceLess.metadata.faces;
|
|
|
|
TestHelper.getVideoEntry1(directory);
|
|
|
|
|
|
|
|
dir = await SQLTestHelper.persistTestDir(directory);
|
|
|
|
p = <any>dir.media[0];
|
|
|
|
p2 = <any>dir.media[1];
|
|
|
|
p_faceLess = <any>dir.media[2];
|
|
|
|
v = <any>dir.media[3];
|
|
|
|
savedPerson = await (await SQLConnection.getConnection()).getRepository(PersonEntry).find({
|
|
|
|
relations: ['sampleRegion',
|
|
|
|
'sampleRegion.media',
|
|
|
|
'sampleRegion.media.directory']
|
|
|
|
});
|
2020-01-01 22:57:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-03-15 01:23:30 +08:00
|
|
|
before(async () => {
|
2020-01-01 22:57:16 +08:00
|
|
|
await setUpSqlDB();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
|
|
|
await sqlHelper.clearDB();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-01-02 00:58:41 +08:00
|
|
|
it('should get person', async () => {
|
2020-01-02 03:26:59 +08:00
|
|
|
const pm = new PersonManager();
|
2021-01-02 00:58:41 +08:00
|
|
|
const person = Utils.clone(savedPerson[0]);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(await pm.get('Boba Fett')).to.deep.equal(person);
|
|
|
|
|
|
|
|
expect((await pm.get('Boba Fett') as PersonWithSampleRegion).sampleRegion.media.name).to.deep.equal(p.name);
|
2020-01-01 22:57:16 +08:00
|
|
|
});
|
2019-02-05 06:46:27 +08:00
|
|
|
|
2020-01-02 03:26:59 +08:00
|
|
|
|
2019-02-05 06:46:27 +08:00
|
|
|
});
|