39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
/** @jest-environment node */
|
|
|
|
import { rewriteStorageUrlForClient } from '@/lib/url-rewrite'
|
|
|
|
describe('url rewrite', () => {
|
|
const originalEnv = { ...process.env }
|
|
|
|
beforeEach(() => {
|
|
process.env.S3_PUBLIC_DOMAIN = 'https://s3.jiansun.vip/gongxiangpan'
|
|
process.env.SERVER_IP = '192.168.58.20'
|
|
process.env.MINIO_API_PORT = '9000'
|
|
process.env.S3_ENDPOINT = 'http://192.168.58.20:9000'
|
|
})
|
|
|
|
afterEach(() => {
|
|
process.env = { ...originalEnv }
|
|
})
|
|
|
|
test('应将历史旧公网域名重写为当前配置的新公网域名', () => {
|
|
const result = rewriteStorageUrlForClient(
|
|
'https://s3.yydd.ai/gongxiangpan/由壹点AI/product-package/test-image.webp',
|
|
)
|
|
|
|
expect(result).toBe(
|
|
'https://s3.jiansun.vip/gongxiangpan/由壹点AI/product-package/test-image.webp',
|
|
)
|
|
})
|
|
|
|
test('旧 MinIO 旧 bucket 链接应保持原样', () => {
|
|
const result = rewriteStorageUrlForClient(
|
|
'https://s3.1080p.hk/jsxiangche/legacy-folder/test-image.webp',
|
|
)
|
|
|
|
expect(result).toBe(
|
|
'https://s3.1080p.hk/jsxiangche/legacy-folder/test-image.webp',
|
|
)
|
|
})
|
|
})
|