Files
immich-magic-proxy/upload-app/tests/config.test.ts
T
2026-10-19 15:43:29 +13:00

43 lines
1.7 KiB
TypeScript

import { describe, it, expect, afterEach } from 'vitest'
import { askName, byteBudget, filenamePrefix, maxFileSize, notifyConfig, uploadNotice } from '../src/config'
import { resetConfig, setConfig } from './helpers'
afterEach(resetConfig)
const MB = 1024 * 1024
describe('upload options', () => {
it('has the documented defaults', () => {
expect(maxFileSize()).toBe(500 * MB)
expect(byteBudget()).toBe(10240 * MB)
expect(filenamePrefix()).toBe('ipp_upload_')
expect(notifyConfig()).toBeUndefined()
expect(uploadNotice()).toBe('Uploaded photos may not appear in the gallery immediately.')
expect(askName()).toBe(true)
})
it('turns the name field off only on an explicit false', () => {
setConfig({ ipp: { upload: { askName: false } } })
expect(askName()).toBe(false)
setConfig({ ipp: { upload: { askName: 0 } } })
expect(askName()).toBe(true)
})
it('shows the owner\'s notice, and hides one that is not a string', () => {
setConfig({ ipp: { upload: { notice: 'Les photos apparaissent plus tard.' } } })
expect(uploadNotice()).toBe('Les photos apparaissent plus tard.')
setConfig({ ipp: { upload: { notice: false } } })
expect(uploadNotice()).toBe('')
})
it('never lets maxFileSize reach zero, which would refuse every file', () => {
setConfig({ ipp: { upload: { maxFileSize: 0 } } })
expect(maxFileSize()).toBe(MB)
})
it('keeps only string notification headers', () => {
setConfig({ ipp: { upload: { notifyUrl: 'https://ntfy.example.com/topic', notifyHeaders: { Authorization: 'Bearer x', Bad: 1 } } } })
expect(notifyConfig()).toEqual({ url: 'https://ntfy.example.com/topic', headers: { Authorization: 'Bearer x' }, timeoutMs: 10_000 })
})
})