Files
PicHost/server/utils/storage-capacity.test.ts
T
O96u 6fc054328d feat: activity logs, gallery storage filter, and upload rate limits
Add per-user activity logs with storage backend tracking, gallery
storage filter, and IP/token upload rate limiting. Fix storage delete
modal flash, pin local backend in filter order, and link settings
version to GitHub releases.
2026-08-26 17:09:38 +08:00

36 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { buildBackendCapacity } from './storage-capacity'
describe('buildBackendCapacity', () => {
it('calculates quota-based capacity for s3 backends', async () => {
const quotaBytes = 10 * 1024 ** 3
const capacity = await buildBackendCapacity('s3-test', 's3', 72_390, quotaBytes)
expect(capacity.source).toBe('quota')
expect(capacity.totalBytes).toBe(quotaBytes)
expect(capacity.usedBytes).toBe(72_390)
expect(capacity.freeBytes).toBe(quotaBytes - 72_390)
expect(capacity.percent).toBeGreaterThanOrEqual(0)
})
it('allows usage percent to exceed 100 when over quota', async () => {
const quotaBytes = 1024
const capacity = await buildBackendCapacity('s3-test', 's3', 2048, quotaBytes)
expect(capacity.percent).toBe(200)
expect(capacity.freeBytes).toBe(0)
})
it('reads disk stats for local backend when available', async () => {
const capacity = await buildBackendCapacity('local', 'local', 1024, null)
expect(capacity.source).toBe('disk')
if (capacity.totalBytes != null) {
expect(capacity.totalBytes).toBeGreaterThan(0)
expect(capacity.freeBytes).not.toBeNull()
expect(capacity.percent).not.toBeNull()
} else {
expect(capacity.usedBytes).toBe(1024)
expect(capacity.freeBytes).toBeNull()
expect(capacity.percent).toBeNull()
}
})
})