Files
wehub-resource-sync 3a28426bf4
Lint and Format Check / lint-and-format (push) Failing after 0s
Check Migrations / Check for duplicate migration numbers (push) Failing after 1s
CI Pre-merge Check / CI Pre-merge Check (push) Failing after 2m17s
chore: import upstream snapshot with attribution
2026-07-13 12:23:40 +08:00

57 lines
1.5 KiB
TypeScript

import { describe, it, expect, afterEach, vi } from 'vitest';
vi.mock('@/infra/config/app.config.js', () => {
const c = {
server: {
get maxFileSize() {
const val = process.env.MAX_FILE_SIZE;
if (!val) return undefined;
const parsed = parseInt(val, 10);
return isNaN(parsed) ? undefined : parsed;
},
maxFilesPerField: 10,
logsDir: 'logs',
},
app: {
logLevel: 'info',
},
};
return { config: c, appConfig: c };
});
import { getMaxFileSize } from '../../src/api/middlewares/upload';
const DEFAULT_50MB = 50 * 1024 * 1024;
describe('getMaxFileSize', () => {
const originalEnv = process.env.MAX_FILE_SIZE;
afterEach(() => {
if (originalEnv === undefined) {
delete process.env.MAX_FILE_SIZE;
} else {
process.env.MAX_FILE_SIZE = originalEnv;
}
});
it('returns 50MB default when env var is not set', () => {
delete process.env.MAX_FILE_SIZE;
expect(getMaxFileSize()).toBe(DEFAULT_50MB);
});
it('returns 50MB default when env var is empty string', () => {
process.env.MAX_FILE_SIZE = '';
expect(getMaxFileSize()).toBe(DEFAULT_50MB);
});
it('returns custom value when env var is set', () => {
process.env.MAX_FILE_SIZE = '10485760'; // 10MB
expect(getMaxFileSize()).toBe(10485760);
});
it('returns default for non-numeric env var', () => {
process.env.MAX_FILE_SIZE = 'not-a-number';
expect(getMaxFileSize()).toBe(DEFAULT_50MB);
});
});