- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler - veza-common: logging, metrics, traits, validation, random - veza-stream-server: audio pipeline, codecs, cache, monitoring, routes - apps/web/dist_verification: refresh build assets (content-hashed filenames) Co-authored-by: Cursor <cursoragent@cursor.com>
109 lines
3.1 KiB
TypeScript
109 lines
3.1 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { uploadService } from './uploadService';
|
|
import { apiClient } from '@/services/api/client';
|
|
|
|
// Mock apiClient
|
|
vi.mock('@/services/api/client', () => ({
|
|
apiClient: {
|
|
post: vi.fn(),
|
|
get: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
const mockedApiClient = apiClient as {
|
|
post: ReturnType<typeof vi.fn>;
|
|
get: ReturnType<typeof vi.fn>;
|
|
};
|
|
|
|
describe('uploadService', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('uploadTrack', () => {
|
|
it('should initiate upload, send chunks, and complete', async () => {
|
|
const file = new File(['test content'], 'test.mp3', {
|
|
type: 'audio/mpeg',
|
|
});
|
|
const progressCallback = vi.fn();
|
|
|
|
// Mock initiate response
|
|
mockedApiClient.post.mockResolvedValueOnce({
|
|
data: { upload_id: 'upload-123' },
|
|
});
|
|
// Mock chunk upload response (file is small, so only 1 chunk)
|
|
mockedApiClient.post.mockResolvedValueOnce({ data: {} });
|
|
// Mock complete response
|
|
mockedApiClient.post.mockResolvedValueOnce({
|
|
data: { track_id: 'track-456' },
|
|
});
|
|
|
|
const result = await uploadService.uploadTrack(
|
|
file,
|
|
{ title: 'Test Track' },
|
|
progressCallback,
|
|
);
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result).toHaveProperty('track_id');
|
|
expect(result.track_id).toBe('track-456');
|
|
|
|
// Verify initiate was called
|
|
expect(mockedApiClient.post).toHaveBeenCalledWith(
|
|
'/tracks/initiate',
|
|
expect.objectContaining({
|
|
filename: 'test.mp3',
|
|
title: 'Test Track',
|
|
}),
|
|
);
|
|
|
|
// Verify complete was called
|
|
expect(mockedApiClient.post).toHaveBeenCalledWith('/tracks/complete', {
|
|
upload_id: 'upload-123',
|
|
});
|
|
|
|
// Verify progress was reported
|
|
expect(progressCallback).toHaveBeenCalledWith(100);
|
|
});
|
|
|
|
it('should upload without progress callback', async () => {
|
|
const file = new File(['test content'], 'test.mp3', {
|
|
type: 'audio/mpeg',
|
|
});
|
|
|
|
mockedApiClient.post.mockResolvedValueOnce({
|
|
data: { upload_id: 'upload-123' },
|
|
});
|
|
mockedApiClient.post.mockResolvedValueOnce({ data: {} });
|
|
mockedApiClient.post.mockResolvedValueOnce({
|
|
data: { track_id: 'track-456' },
|
|
});
|
|
|
|
const result = await uploadService.uploadTrack(file, {
|
|
title: 'Test Track',
|
|
});
|
|
|
|
expect(result).toBeDefined();
|
|
expect(result).toHaveProperty('track_id');
|
|
});
|
|
});
|
|
|
|
describe('getTrackStatus', () => {
|
|
it('should return track processing status', async () => {
|
|
mockedApiClient.get.mockResolvedValue({
|
|
data: { status: 'completed', progress: 100 },
|
|
});
|
|
|
|
const status = await uploadService.getTrackStatus('track-456');
|
|
|
|
expect(status).toBeDefined();
|
|
expect(status).toHaveProperty('status');
|
|
expect(status).toHaveProperty('progress');
|
|
expect(status.status).toBe('completed');
|
|
expect(status.progress).toBe(100);
|
|
expect(mockedApiClient.get).toHaveBeenCalledWith(
|
|
'/tracks/track-456/status',
|
|
);
|
|
});
|
|
});
|
|
});
|