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/PersonManager.ts

77 lines
2.4 KiB
TypeScript
Raw Normal View History

2020-01-01 22:57:16 +08:00
import {expect} from 'chai';
import {PersonManager} from '../../../../../src/backend/model/database/sql/PersonManager';
2021-04-02 03:48:38 +08:00
import {DBTestHelper} from '../../../DBTestHelper';
2020-01-01 22:57:16 +08:00
import {TestHelper} from './TestHelper';
import {PhotoDTO} from '../../../../../src/common/entities/PhotoDTO';
import {Utils} from '../../../../../src/common/Utils';
import {PersonWithSampleRegion} from '../../../../../src/common/entities/PersonDTO';
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';
2019-02-05 06:46:27 +08:00
// to help WebStorm to handle the test cases
declare let describe: any;
declare const after: any;
declare const before: any;
2019-02-05 06:46:27 +08:00
declare const it: any;
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
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();
const directory: DirectoryDTO = TestHelper.getDirectoryEntry();
p = TestHelper.getPhotoEntry1(directory);
p2 = TestHelper.getPhotoEntry2(directory);
const pFaceLess = TestHelper.getPhotoEntry3(directory);
delete pFaceLess.metadata.faces;
v = TestHelper.getVideoEntry1(directory);
2021-04-02 03:48:38 +08:00
dir = await DBTestHelper.persistTestDir(directory);
p = <any>dir.media.filter(m => m.name === p.name)[0];
p2 = <any>dir.media.filter(m => m.name === p2.name)[0];
p_faceLess = <any>dir.media[2];
v = <any>dir.media.filter(m => m.name === v.name)[0];
savedPerson = await (await SQLConnection.getConnection()).getRepository(PersonEntry).find({
relations: ['sampleRegion',
'sampleRegion.media',
'sampleRegion.media.directory']
});
2020-01-01 22:57:16 +08:00
};
before(async () => {
2020-01-01 22:57:16 +08:00
await setUpSqlDB();
});
after(async () => {
await sqlHelper.clearDB();
});
it('should get person', async () => {
const pm = new PersonManager();
const person = Utils.clone(savedPerson[0]);
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
2019-02-05 06:46:27 +08:00
});