mirror of
https://github.com/saltbo/zpan.git
synced 2026-09-19 10:01:12 +08:00
* refactor: remove custom filePath, enforce tenant-isolated storage path Replace user-customizable filePath template with a hardcoded tenant-isolated pattern ($ORG_ID/$UID/$NOW_DATE/$RAND_16KEY$RAW_EXT). This ensures proper tenant isolation and removes unnecessary complexity. The DB column is preserved to avoid migration; code simply stops reading/writing it. Agent-Profile: https://agent-kanban.dev/agents/a6bb038c4226a87f * refactor: clean up dead tokens, locale keys, and simplify path template Remove unused template tokens ($UUID, $RAW_NAME, $NOW_YEAR, $NOW_MONTH, $NOW_DAY) and corresponding TemplateVars fields (uuid, rawName) since the hardcoded template doesn't use them. Remove orphaned i18n keys for fieldFilePath. Update DB schema default to empty string. Add storage service unit tests. Agent-Profile: https://agent-kanban.dev/agents/a6bb038c4226a87f --------- Co-authored-by: Bob <aibob@mails.agent-kanban.dev>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { buildObjectKey } from './path-template.js'
|
|
|
|
const baseVars = {
|
|
uid: 'user123',
|
|
orgId: 'org456',
|
|
rawExt: '.jpg',
|
|
}
|
|
|
|
describe('buildObjectKey', () => {
|
|
it('produces tenant-isolated key with fixed template', () => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(new Date('2026-03-15T12:00:00Z'))
|
|
|
|
const result = buildObjectKey(baseVars)
|
|
// Template: $ORG_ID/$UID/$NOW_DATE/$RAND_16KEY$RAW_EXT
|
|
expect(result).toMatch(/^org456\/user123\/20260315\/.{16}\.jpg$/)
|
|
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('includes a 16-char random key', () => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(new Date('2026-03-15T12:00:00Z'))
|
|
|
|
const result = buildObjectKey(baseVars)
|
|
const parts = result.split('/')
|
|
const filename = parts[3] // RAND_16KEY + ext
|
|
expect(filename.replace('.jpg', '')).toHaveLength(16)
|
|
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('handles empty rawExt', () => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(new Date('2026-03-15T12:00:00Z'))
|
|
|
|
const result = buildObjectKey({ ...baseVars, rawExt: '' })
|
|
expect(result).toMatch(/^org456\/user123\/20260315\/.{16}$/)
|
|
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('generates unique keys on each call', () => {
|
|
const a = buildObjectKey(baseVars)
|
|
const b = buildObjectKey(baseVars)
|
|
expect(a).not.toBe(b)
|
|
})
|
|
})
|