Merge branch 'pr-264' into #264-show-expiry

# Conflicts:
#	docs/configuration.md
This commit is contained in:
Alan Grainger
2026-07-17 14:38:58 +12:00
6 changed files with 92 additions and 1 deletions
+61
View File
@@ -0,0 +1,61 @@
import { describe, it, expect, beforeEach } from 'vitest'
import dayjs from 'dayjs'
import { expiryDate } from '../src/share'
import { loadConfig } from '../src/config/loader'
import { KeyType, SharedLink } from '../src/types'
// expiryDate formats the share's Immich expiry for the gallery subtitle. It is
// gated behind ipp.gallery.showExpiryDate (default off) and formatted with
// ipp.gallery.expiryDateFormat (a dayjs format string, default ISO 8601 date).
function setConfig (config: unknown) {
process.env.CONFIG = JSON.stringify(config)
loadConfig()
}
const share = (expiresAt: string | null): SharedLink => ({
key: 'k',
keyType: KeyType.key,
type: 'ALBUM',
assets: [],
expiresAt
})
const EXPIRES = '2026-07-10T12:00:00.000Z'
describe('expiryDate', () => {
beforeEach(() => {
delete process.env.CONFIG
loadConfig()
})
it('returns undefined when the feature is off (default)', () => {
setConfig({})
expect(expiryDate(share(EXPIRES))).toBeUndefined()
})
it('returns undefined when the share never expires, even if enabled', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true } } })
expect(expiryDate(share(null))).toBeUndefined()
})
it('formats as an ISO 8601 date by default when enabled', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true } } })
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).format('YYYY-MM-DD'))
})
it('honours a custom dayjs format string', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true, expiryDateFormat: 'D MMMM YYYY' } } })
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).format('D MMMM YYYY'))
})
it('falls back to the default format when the config value is not a usable string', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true, expiryDateFormat: '' } } })
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).format('YYYY-MM-DD'))
})
it('returns undefined for an unparseable expiry date', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true } } })
expect(expiryDate(share('not-a-date'))).toBeUndefined()
})
})