2026-01-07 09:33:52 +00:00
|
|
|
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();
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
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' });
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
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');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
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',
|
|
|
|
|
});
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
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',
|
|
|
|
|
});
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(updated).toBeDefined();
|
|
|
|
|
expect(updated).toHaveProperty('id');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('delete', () => {
|
|
|
|
|
it('should delete a gear item', async () => {
|
|
|
|
|
const result = await gearService.delete('1');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:33:52 +00:00
|
|
|
expect(result).toBeUndefined(); // delete returns void
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|