Files

53 lines
2.1 KiB
TypeScript

import { describe, it, expect, afterEach } from 'vitest'
import { askName, byteBudget, fieldSeparator, 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)
expect(fieldSeparator()).toBe(',')
})
it('takes a usable field separator, and falls back for one that could be part of a field', () => {
setConfig({ ipp: { upload: { fieldSeparator: '^' } } })
expect(fieldSeparator()).toBe('^')
for (const bad of ['', '-', 'a', '.', ' ', '/', '^^', '_', 7, null]) {
setConfig({ ipp: { upload: { fieldSeparator: bad } } })
expect(fieldSeparator()).toBe(',')
}
})
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 })
})
})