feat: exif medium tests (#23561)

This commit is contained in:
Jason Rasmussen
2025-11-04 16:03:02 -05:00
committed by GitHub
parent c34be73d81
commit 0df70365d7
11 changed files with 234 additions and 682 deletions

View File

@@ -1,4 +1,5 @@
import { BinaryField, ExifDateTime } from 'exiftool-vendored';
import { DateTime } from 'luxon';
import { randomBytes } from 'node:crypto';
import { Stats } from 'node:fs';
import { defaults } from 'src/config';
@@ -231,7 +232,7 @@ describe(MetadataService.name, () => {
});
});
it('should account for the server being in a non-UTC timezone', async () => {
it('should determine dateTimeOriginal regardless of the server time zone', async () => {
process.env.TZ = 'America/Los_Angeles';
mocks.assetJob.getForMetadataExtraction.mockResolvedValue(assetStub.sidecar);
mockReadTags({ DateTimeOriginal: '2022:01:01 00:00:00' });
@@ -239,7 +240,7 @@ describe(MetadataService.name, () => {
await sut.handleMetadataExtraction({ id: assetStub.image.id });
expect(mocks.asset.upsertExif).toHaveBeenCalledWith(
expect.objectContaining({
dateTimeOriginal: new Date('2022-01-01T08:00:00.000Z'),
dateTimeOriginal: new Date('2022-01-01T00:00:00.000Z'),
}),
);
@@ -856,6 +857,7 @@ describe(MetadataService.name, () => {
tz: 'UTC-11:30',
Rating: 3,
};
mocks.assetJob.getForMetadataExtraction.mockResolvedValue(assetStub.image);
mockReadTags(tags);
@@ -897,7 +899,7 @@ describe(MetadataService.name, () => {
id: assetStub.image.id,
duration: null,
fileCreatedAt: dateForTest,
localDateTime: dateForTest,
localDateTime: DateTime.fromISO('1970-01-01T00:00:00.000Z').toJSDate(),
}),
);
});
@@ -1595,7 +1597,7 @@ describe(MetadataService.name, () => {
const result = firstDateTime(tags);
expect(result?.tag).toBe('SonyDateTime2');
expect(result?.dateTime?.toDate()?.toISOString()).toBe('2023-07-07T07:00:00.000Z');
expect(result?.dateTime?.toISOString()).toBe('2023-07-07T07:00:00');
});
it('should respect full priority order with all date tags present', () => {
@@ -1624,7 +1626,7 @@ describe(MetadataService.name, () => {
const result = firstDateTime(tags);
// Should use SubSecDateTimeOriginal as it has highest priority
expect(result?.tag).toBe('SubSecDateTimeOriginal');
expect(result?.dateTime?.toDate()?.toISOString()).toBe('2023-01-01T01:00:00.000Z');
expect(result?.dateTime?.toISOString()).toBe('2023-01-01T01:00:00');
});
it('should handle missing SubSec tags and use available date tags', () => {
@@ -1644,7 +1646,7 @@ describe(MetadataService.name, () => {
const result = firstDateTime(tags);
// Should use CreationDate when available
expect(result?.tag).toBe('CreationDate');
expect(result?.dateTime?.toDate()?.toISOString()).toBe('2023-07-07T07:00:00.000Z');
expect(result?.dateTime?.toISOString()).toBe('2023-07-07T07:00:00');
});
it('should handle invalid date formats gracefully', () => {
@@ -1658,7 +1660,7 @@ describe(MetadataService.name, () => {
const result = firstDateTime(tags);
// Should skip invalid dates and use the first valid one
expect(result?.tag).toBe('GPSDateTime');
expect(result?.dateTime?.toDate()?.toISOString()).toBe('2023-10-10T10:00:00.000Z');
expect(result?.dateTime?.toISOString()).toBe('2023-10-10T10:00:00');
});
it('should prefer CreationDate over CreateDate', () => {