veza/apps/web/src/services/gearService.test.ts

71 lines
1.9 KiB
TypeScript
Raw Normal View History

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { gearService } from './gearService';
describe('gearService', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('list', () => {
it('should return list of gear items', async () => {
const items = await gearService.list();
expect(items).toBeDefined();
expect(Array.isArray(items)).toBe(true);
expect(items.length).toBeGreaterThan(0);
expect(items[0]).toHaveProperty('id');
expect(items[0]).toHaveProperty('name');
expect(items[0]).toHaveProperty('category');
});
it('should filter by category', async () => {
const items = await gearService.list({ category: 'Synth' });
expect(items).toBeDefined();
expect(Array.isArray(items)).toBe(true);
});
});
describe('get', () => {
it('should return a specific gear item', async () => {
const item = await gearService.get('1');
expect(item).toBeDefined();
expect(item).toHaveProperty('id');
expect(item).toHaveProperty('name');
});
});
describe('create', () => {
it('should create a new gear item', async () => {
const newItem = await gearService.create({
name: 'Test Gear',
category: 'Synth',
});
expect(newItem).toBeDefined();
expect(newItem).toHaveProperty('id');
expect(newItem.name).toBe('Test Gear');
});
});
describe('update', () => {
it('should update a gear item', async () => {
const updated = await gearService.update('1', {
name: 'Updated Name',
});
expect(updated).toBeDefined();
expect(updated).toHaveProperty('id');
});
});
describe('delete', () => {
it('should delete a gear item', async () => {
const result = await gearService.delete('1');
expect(result).toBeUndefined(); // delete returns void
});
});
});