/
kreyndelHam
/
Konstructorium
Обзор
Документация
Войти
/
kreyndelHam
/
Konstructorium
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
dev
frontend/src/store/adminStore.test.js
53 строки
2 KB
MihahamYT
tests added
25 май 2026, 13:06
25 май 2026, 13:06
728a833
Код
Авторство
О чём код?
import { beforeEach, describe, expect, it } from 'vitest' import { adminUser } from '../test/fixtures/user.js' import { useAdminStore } from './adminStore' describe('adminStore', () => { beforeEach(() => { localStorage.clear() useAdminStore.setState({ adminUser: null, isAdminAuthenticated: false, initialized: false, }) }) it('setAdminUser persists staff user and sets authenticated', () => { useAdminStore.getState().setAdminUser(adminUser) const state = useAdminStore.getState() expect(state.isAdminAuthenticated).toBe(true) expect(state.adminUser?.username).toBe('admin-user') expect(JSON.parse(localStorage.getItem('admin-storage'))).toMatchObject({ adminUser: expect.objectContaining({ is_staff: true }), }) }) it('setAdminUser with null clears admin session', () => { useAdminStore.getState().setAdminUser(adminUser) useAdminStore.getState().setAdminUser(null) expect(useAdminStore.getState().isAdminAuthenticated).toBe(false) expect(localStorage.getItem('admin-storage')).toBeNull() }) it('logout clears admin storage', () => { useAdminStore.getState().setAdminUser(adminUser) useAdminStore.getState().logout() expect(useAdminStore.getState().adminUser).toBeNull() expect(localStorage.getItem('admin-storage')).toBeNull() }) it('non-staff user is not treated as admin authenticated', () => { useAdminStore.getState().setAdminUser({ id: 2, username: 'buyer', email: 'b@test.com', is_staff: false, is_superuser: false, }) expect(useAdminStore.getState().isAdminAuthenticated).toBe(false) }) })