turash/bugulma/frontend/hooks/pages/useOrganizationData.test.ts
Damir Mukimov 6347f42e20
Consolidate repositories: Remove nested frontend .git and merge into main repository
- Remove nested git repository from bugulma/frontend/.git
- Add all frontend files to main repository tracking
- Convert from separate frontend/backend repos to unified monorepo
- Preserve all frontend code and development history as tracked files
- Eliminate nested repository complexity for simpler development workflow

This creates a proper monorepo structure with frontend and backend
coexisting in the same repository for easier development and deployment.
2025-11-25 06:02:57 +01:00

101 lines
3.0 KiB
TypeScript

import { renderHook } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { Organization } from '@/types.ts';
import { useOrganizationData } from '@/hooks/pages/useOrganizationData.ts';
// Use vi.hoisted to ensure mocks are applied before imports
const mockOrganizations: Organization[] = [
{
id: '1',
name: 'Org 1',
sector: 'tech',
location: { lat: 55.7887, lng: 49.1221 },
legal_form: 'LLC' as const,
description: 'A tech company',
primary_contact: {
name: 'John Doe',
email: 'john@example.com',
phone: '+71234567890',
},
company_size: 100,
founding_year: 2020,
business_focus: ['B2B'],
industries: ['software'],
tags: ['tech', 'innovation'],
verified: true,
status: 'active' as const,
needs: [],
offers: [],
},
{
id: '2',
name: 'Org 2',
sector: 'health',
location: { lat: 55.7887, lng: 49.1221 },
legal_form: 'corporation' as const,
description: 'A health company',
primary_contact: {
name: 'Jane Smith',
email: 'jane@example.com',
phone: '+79876543210',
},
company_size: 50,
founding_year: 2019,
business_focus: ['Услуги'],
industries: ['medical'],
tags: ['health', 'care'],
verified: false,
status: 'active' as const,
needs: [],
offers: [],
},
];
vi.mock('@/hooks/useOrganizations.ts', () => ({
useOrganizations: () => ({
organizations: mockOrganizations,
getOrganizationById: (id: string) => mockOrganizations.find((org) => org.id === id),
}),
}));
vi.mock('../../schemas/organization.ts', async (importOriginal) => {
const original = await importOriginal();
return {
...original,
organizationSchema: {
parse: (data: unknown) => data,
},
};
});
describe('useOrganizationData', () => {
it('should return organization data for a valid ID', () => {
const { result } = renderHook(() => useOrganizationData('1'));
expect(result.current.organization?.name).toBe('Org 1');
expect(result.current.isLoading).toBe(false);
expect(result.current.error).toBe(null);
});
it('should return undefined for an invalid ID', () => {
const { result } = renderHook(() => useOrganizationData('3'));
expect(result.current.organization).toBeUndefined();
expect(result.current.isLoading).toBe(false);
expect(result.current.error).toBe(null);
});
it('should handle parsing errors', async () => {
const { organizationSchema } = await import('../../schemas/organization.ts');
const mockParse = vi.fn().mockImplementation(() => {
throw new Error('Parsing failed');
});
vi.spyOn(organizationSchema, 'parse').mockImplementation(mockParse);
const { result } = renderHook(() => useOrganizationData('1'));
expect(result.current.organization).toBeUndefined();
expect(result.current.isLoading).toBe(false);
expect(result.current.error).toBe('Failed to parse organization data.');
vi.restoreAllMocks();
});
});