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
2019-02-04 17:46:27 -05:00

49 lines
1.4 KiB
TypeScript

import {expect} from 'chai';
import {PersonManager} from '../../../../../backend/model/sql/PersonManager';
import {FaceRegion, PhotoDTO} from '../../../../../common/entities/PhotoDTO';
// to help WebStorm to handle the test cases
declare let describe: any;
declare const after: any;
declare const it: any;
describe('PersonManager', () => {
it('should upgrade keywords to person', async () => {
const pm = new PersonManager();
pm.loadAll = () => Promise.resolve();
pm.persons = [{name: 'Han Solo', id: 0, faces: []},
{name: 'Anakin', id: 2, faces: []}];
const p_noFaces = <PhotoDTO>{
metadata: {
keywords: ['Han Solo', 'just a keyword']
}
};
const p_wFace = <PhotoDTO>{
metadata: {
keywords: ['Han Solo', 'Anakin'],
faces: [{name: 'Obivan'}]
}
};
const cmp = (a: FaceRegion, b: FaceRegion) => {
return a.name.localeCompare(b.name);
};
await pm.keywordsToPerson([p_noFaces]);
expect(p_noFaces.metadata.keywords).to.be.deep.equal(['just a keyword']);
expect(p_noFaces.metadata.faces.sort(cmp)).to.eql([{name: 'Han Solo'}].sort(cmp));
await pm.keywordsToPerson([p_wFace]);
expect(p_wFace.metadata.keywords).to.be.deep.equal([]);
expect(p_wFace.metadata.faces.sort(cmp)).to.be
.eql([{name: 'Han Solo'}, {name: 'Obivan'}, {name: 'Anakin'}].sort(cmp));
});
});