46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { FeedbackClient, type SubmitFeedbackParams } from './index.js';
|
|
import type { ApiClient } from '@bytelyst/api-client';
|
|
|
|
describe('FeedbackClient', () => {
|
|
const mockApi: Partial<ApiClient> = {
|
|
fetch: vi.fn(),
|
|
};
|
|
|
|
const createClient = () => new FeedbackClient(mockApi as ApiClient);
|
|
|
|
it('should submit feedback without screenshot', async () => {
|
|
const client = createClient();
|
|
const mockResponse = {
|
|
id: 'fb_123',
|
|
productId: 'test',
|
|
userId: 'user_123',
|
|
type: 'bug',
|
|
title: 'Test bug',
|
|
status: 'new',
|
|
createdAt: new Date().toISOString(),
|
|
};
|
|
|
|
mockApi.fetch = vi.fn().mockResolvedValue(mockResponse);
|
|
|
|
const result = await client.submitWithScreenshot({
|
|
type: 'bug',
|
|
title: 'Test bug',
|
|
body: 'Description',
|
|
});
|
|
|
|
expect(result).toEqual(mockResponse);
|
|
expect(mockApi.fetch).toHaveBeenCalledWith('/api/feedback', expect.objectContaining({
|
|
method: 'POST',
|
|
}));
|
|
});
|
|
|
|
it('should throw if captureAndSubmit called without screenshot', async () => {
|
|
const client = createClient();
|
|
|
|
await expect(
|
|
client.captureAndSubmit({ type: 'bug', title: 'Test' })
|
|
).rejects.toThrow('TODO-1');
|
|
});
|
|
});
|