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';
|
2021-04-02 03:48:38 +08:00
|
|
|
import {DBTestHelper} from '../../../DBTestHelper';
|
2022-06-25 00:05:45 +08:00
|
|
|
import {TestHelper} from '../../../../TestHelper';
|
2021-03-28 18:43:13 +08:00
|
|
|
import {PhotoDTO} from '../../../../../src/common/entities/PhotoDTO';
|
2021-01-02 00:58:41 +08:00
|
|
|
import {Utils} from '../../../../../src/common/Utils';
|
2021-06-28 01:33:37 +08:00
|
|
|
import {ParentDirectoryDTO} from '../../../../../src/common/entities/DirectoryDTO';
|
2021-01-17 17:56:33 +08:00
|
|
|
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';
|
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;
|
|
|
|
|
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
// eslint-disable-next-line prefer-const
|
2021-04-02 03:48:38 +08:00
|
|
|
describe = DBTestHelper.describe();
|
2019-02-05 06:46:27 +08:00
|
|
|
|
2021-04-02 03:48:38 +08:00
|
|
|
describe('PersonManager', (sqlHelper: DBTestHelper) => {
|
2020-01-01 22:57:16 +08:00
|
|
|
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
let dir: ParentDirectoryDTO;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
let v: VideoDTO;
|
|
|
|
let p: PhotoDTO;
|
|
|
|
let p2: PhotoDTO;
|
2021-04-18 21:48:35 +08:00
|
|
|
let pFaceLess: PhotoDTO;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
let savedPerson: PersonEntry[] = [];
|
2020-01-01 22:57:16 +08:00
|
|
|
|
|
|
|
const setUpSqlDB = async () => {
|
|
|
|
await sqlHelper.initDB();
|
2021-06-28 01:33:37 +08:00
|
|
|
const directory: ParentDirectoryDTO = TestHelper.getDirectoryEntry();
|
2021-03-28 18:43:13 +08:00
|
|
|
p = TestHelper.getPhotoEntry1(directory);
|
|
|
|
p2 = TestHelper.getPhotoEntry2(directory);
|
2021-04-18 21:48:35 +08:00
|
|
|
const pFaceLessTmp = TestHelper.getPhotoEntry3(directory);
|
|
|
|
delete pFaceLessTmp.metadata.faces;
|
2021-03-28 18:43:13 +08:00
|
|
|
v = TestHelper.getVideoEntry1(directory);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-02 03:48:38 +08:00
|
|
|
dir = await DBTestHelper.persistTestDir(directory);
|
2021-04-18 21:48:35 +08:00
|
|
|
p = (dir.media.filter(m => m.name === p.name)[0] as any);
|
|
|
|
p2 = (dir.media.filter(m => m.name === p2.name)[0] as any);
|
|
|
|
pFaceLess = (dir.media[2] as any);
|
|
|
|
v = (dir.media.filter(m => m.name === v.name)[0] as any);
|
2021-01-17 17:56:33 +08:00
|
|
|
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-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
|
|
|
|
2021-08-28 17:42:06 +08:00
|
|
|
const selected = Utils.clone(await pm.get('Boba Fett'));
|
|
|
|
delete selected.sampleRegion;
|
|
|
|
delete person.sampleRegion;
|
|
|
|
person.count = 1;
|
|
|
|
expect(selected).to.deep.equal(person);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
expect((await pm.get('Boba Fett') as PersonEntry).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
|
|
|
});
|