feat: complete testing, security, dynamic content, and devops overhaul
This commit is contained in:
1 parent
467532713c
commit
40ff169dc2
52 files changed
+3918
-104
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { useSettingsStore } from '../settingsStore';
|
||||
import api from '../../services/api';
|
||||
|
||||
vi.mock('../../services/api', () => ({
|
||||
default: {
|
||||
get: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('settingsStore', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
useSettingsStore.setState({
|
||||
texts: {},
|
||||
scientificTerms: {},
|
||||
isLoading: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('should return fallback if key is not found', () => {
|
||||
const text = useSettingsStore.getState().getText('non-existent', 'Fallback Text');
|
||||
expect(text).toBe('Fallback Text');
|
||||
});
|
||||
|
||||
it('should return value if key is found', () => {
|
||||
useSettingsStore.setState({
|
||||
texts: { 'test-key': 'Real Value' },
|
||||
});
|
||||
const text = useSettingsStore.getState().getText('test-key', 'Fallback Text');
|
||||
expect(text).toBe('Real Value');
|
||||
});
|
||||
|
||||
it('should fetch settings successfully and map array to object', async () => {
|
||||
const mockUiTexts = [
|
||||
{ key: 'hero_title', value: 'Welcome to Canina' },
|
||||
{ key: 'hero_desc', value: 'Best supplements' },
|
||||
];
|
||||
const mockTerms = [
|
||||
{ key: 'mussel', term: 'Mussel', definition: 'NZ Green Mussel', wikiId: 'general' },
|
||||
];
|
||||
|
||||
vi.mocked(api.get).mockImplementation((url: string) => {
|
||||
if (url === '/settings/ui-texts') {
|
||||
return Promise.resolve({ data: mockUiTexts });
|
||||
}
|
||||
if (url === '/settings/scientific-terms') {
|
||||
return Promise.resolve({ data: mockTerms });
|
||||
}
|
||||
return Promise.reject(new Error('Unknown URL'));
|
||||
});
|
||||
|
||||
const store = useSettingsStore.getState();
|
||||
await store.fetchSettings();
|
||||
|
||||
const state = useSettingsStore.getState();
|
||||
expect(state.texts['hero_title']).toBe('Welcome to Canina');
|
||||
expect(state.texts['hero_desc']).toBe('Best supplements');
|
||||
expect(state.scientificTerms['mussel']).toEqual(mockTerms[0]);
|
||||
expect(state.isLoading).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user