1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-08 04:03:48 +02:00

Fixing date boundary issue. fixes #660

This commit is contained in:
Patrik J. Braun 2023-10-11 00:04:53 +02:00
parent e1ffeb0173
commit 41796e8d72
4 changed files with 771 additions and 497 deletions

File diff suppressed because it is too large Load Diff

View File

@ -46,6 +46,34 @@ export class TestHelper {
return dir;
}
public static getBasePhotoEntry(dir: DirectoryPathDTO, name = 'base media.jpg'): PhotoEntity {
const sd = new MediaDimensionEntity();
sd.height = 400;
sd.width = 200;
const m = new PhotoMetadataEntity();
m.caption = null;
m.size = sd;
m.creationDate = 1656069387772;
m.fileSize = 123456789;
// m.rating = 0; no rating by default
// TODO: remove when typeorm is fixed
m.duration = null;
m.bitRate = null;
const d = new PhotoEntity();
d.name = name;
d.directory = (dir as any);
if ((dir as DirectoryBaseDTO).media) {
(dir as DirectoryBaseDTO).media.push(d);
(dir as DirectoryBaseDTO).mediaCount++;
}
d.metadata = m;
return d;
}
public static getPhotoEntry(dir: DirectoryPathDTO): PhotoEntity {
const sd = new MediaDimensionEntity();
sd.height = 400;

View File

@ -2,7 +2,7 @@ import {Config} from '../../src/common/config/private/Config';
import * as path from 'path';
import * as fs from 'fs';
import {SQLConnection} from '../../src/backend/model/database/SQLConnection';
import {DatabaseType} from '../../src/common/config/private/PrivateConfig';
import {DatabaseType, LogLevel} from '../../src/common/config/private/PrivateConfig';
import {ProjectPath} from '../../src/backend/ProjectPath';
import {DirectoryBaseDTO, ParentDirectoryDTO, SubDirectoryDTO} from '../../src/common/entities/DirectoryDTO';
import {ObjectManagers} from '../../src/backend/model/ObjectManagers';
@ -129,7 +129,7 @@ export class DBTestHelper {
const gm = new GalleryManagerTest();
const dir = await gm.getParentDirFromId(connection,
(await gm.getDirIdAndTime(connection, directory.name, path.join(path.dirname('.'), path.sep))).id);
(await gm.getDirIdAndTime(connection, directory.name, path.join(directory.path, path.sep))).id);
const populateDir = async (d: DirectoryBaseDTO) => {
for (let i = 0; i < d.directories.length; i++) {

View File

@ -38,6 +38,7 @@ import {Config} from '../../../../../src/common/config/private/Config';
import {SearchQueryParser} from '../../../../../src/common/SearchQueryParser';
import {FileDTO} from '../../../../../src/common/entities/FileDTO';
import {SortByTypes} from '../../../../../src/common/entities/SortingMethods';
import {LogLevel} from '../../../../../src/common/config/private/PrivateConfig';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
@ -103,6 +104,8 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
let p2: PhotoDTO;
let pFaceLess: PhotoDTO;
let p4: PhotoDTO;
// let p5: PhotoDTO;
// let p6: PhotoDTO;
let gpx: FileDTO;
@ -124,7 +127,6 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
pFaceLessTmp.metadata.creationDate = Date.now() - 60 * 60 * 24 * 32 * 1000;
dir = await DBTestHelper.persistTestDir(directory);
subDir = dir.directories[0];
subDir2 = dir.directories[1];
p = (dir.media.filter(m => m.name === p.name)[0] as any);
@ -429,7 +431,6 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
});
it('should minimum of', async () => {
const sm = new SearchManager();
@ -925,122 +926,340 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
} as SearchResultDTO));
});
describe('search date pattern', async () => {
let p5: PhotoDTO;
let p6: PhotoDTO;
let p7: PhotoDTO;
let sm: SearchManager;
it('should search date pattern', async () => {
const sm = new SearchManager();
before(async () => {
await sqlHelper.clearDB();
await setUpSqlDB();
p5 = TestHelper.getBasePhotoEntry(subDir2, 'p5-23h-ago.jpg');
p5.metadata.creationDate = Date.now() - 60 * 60 * 23 * 1000;
p6 = TestHelper.getBasePhotoEntry(subDir2, 'p6-300d-ago.jpg');
p6.metadata.creationDate = Date.now() - 60 * 60 * 24 * 300 * 1000;
p7 = TestHelper.getBasePhotoEntry(subDir2, 'p7-1y-1min-ago.jpg');
const d = new Date();
d.setUTCFullYear(d.getUTCFullYear() - 1);
d.setUTCMinutes(d.getUTCMinutes() - 1);
p7.metadata.creationDate = d.getTime();
let query: DatePatternSearch = {
daysLength: 0,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
};
subDir2 = await DBTestHelper.persistTestDir(subDir2) as any;
p4 = subDir2.media[0];
p4.directory = subDir2;
p5 = subDir2.media[1];
p5.directory = subDir2;
p6 = subDir2.media[2];
p6.directory = subDir2;
p7 = subDir2.media[3];
p7.directory = subDir2;
Config.Search.listDirectories = false;
Config.Search.listMetafiles = false;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
sm = new SearchManager();
});
//TODO: this is flaky test for mysql
it('last-0-days:every-year', async () => {
query = {
daysLength: 1,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
let query: DatePatternSearch = {
daysLength: 0,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
};
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 2,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
query = {
daysLength: 0,
negate: true,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
};
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p2, p4, pFaceLess, v, p5, p6],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
});
//TODO: this is flaky test for mysql
it('last-1-days:every-year', async () => {
let query: DatePatternSearch = {
daysLength: 1,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 1,
agoNumber: 10,
frequency: DatePatternFrequency.days_ago,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
query = {
daysLength: 1,
negate: true,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p2, p4, pFaceLess, v, p5, p6],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 3,
agoNumber: 1,
frequency: DatePatternFrequency.months_ago,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
});
it('last-2-days:every-year', async () => {
let query = {
daysLength: 2,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [pFaceLess],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4, p5, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 366,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
query = {
daysLength: 2,
negate: true,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4, pFaceLess, v],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [v, pFaceLess, p6],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 32,
frequency: DatePatternFrequency.every_month,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
});
it('last-1-days:10-days-ago', async () => {
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4, pFaceLess, v],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
let query = {
daysLength: 1,
agoNumber: 10,
frequency: DatePatternFrequency.days_ago,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 1,
agoNumber: 10,
negate: true,
frequency: DatePatternFrequency.days_ago,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4, pFaceLess, v, p5, p6, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
});
it('last-3-days:1-month-ago', async () => {
let query = {
daysLength: 3,
agoNumber: 1,
frequency: DatePatternFrequency.months_ago,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [pFaceLess],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 3,
agoNumber: 1,
negate: true,
frequency: DatePatternFrequency.months_ago,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4, v, p5, p6, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
});
it('last-3-days:12-month-ago', async () => {
let query = {
daysLength: 3,
agoNumber: 12,
frequency: DatePatternFrequency.months_ago,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p4, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 3,
agoNumber: 12,
negate: true,
frequency: DatePatternFrequency.months_ago,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, v, p5, p6, pFaceLess],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
});
it('last-366-days:every-year', async () => {
let query = {
daysLength: 366,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4, pFaceLess, v, p5, p6, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 366,
negate: true,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
});
it('last-32-days:every-month', async () => {
const query = {
daysLength: 32,
frequency: DatePatternFrequency.every_month,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4, pFaceLess, v, p5, p6, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
});
it('last-364-days:every-year', async () => {
let query = {
daysLength: 364,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [p, p2, p4, pFaceLess, v, p5, p6, p7],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
query = {
daysLength: 364,
negate: true,
frequency: DatePatternFrequency.every_year,
type: SearchQueryTypes.date_pattern
} as DatePatternSearch;
expect(Utils.clone(await sm.search(query)))
.to.deep.equalInAnyOrder(removeDir({
searchQuery: query,
directories: [],
media: [],
metaFile: [],
resultOverflow: false
} as SearchResultDTO));
});
});
it('should search rating', async () => {
const sm = new SearchManager();