feat(builder): shared asset upload/list util
Extract uploadAsset/listAssets into utils/assets.ts, lifting the exact uploadToWhp body and list_assets fetch pattern already duplicated across shared.tsx/ImageBlock/Logo/Navbar/etc. shared.tsx's uploadToWhp is now a thin re-export (`export const uploadToWhp = uploadAsset`) so its ~6 existing callers are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { describe, test, expect, vi, afterEach } from 'vitest';
|
||||
import { uploadToWhp } from './shared';
|
||||
import { uploadAsset } from '../../../utils/assets';
|
||||
|
||||
describe('shared.uploadToWhp', () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
delete (window as any).WHP_CONFIG;
|
||||
});
|
||||
|
||||
test('is a thin re-export of uploadAsset (same function reference)', () => {
|
||||
expect(uploadToWhp).toBe(uploadAsset);
|
||||
});
|
||||
|
||||
test('still works standalone (no WHP_CONFIG -> blob: URL) for existing callers', async () => {
|
||||
(URL as any).createObjectURL = vi.fn(() => 'blob:mock-url');
|
||||
const file = new File(['x'], 'photo.png', { type: 'image/png' });
|
||||
const url = await uploadToWhp(file);
|
||||
expect(url).toBe('blob:mock-url');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user