import { vi, describe, expect, it, beforeAll } from 'vitest'; import { createWrapper } from 'app/test/vitest/helper'; import App from 'src/App.vue'; import { useSession } from 'src/composables/useSession'; const mockLoggedIn = vi.fn(); const mockDestroy = vi.fn(); const session = useSession(); vi.mock('src/composables/useSession', () => ({ useSession: () => ({ isLoggedIn: mockLoggedIn, destroy: mockDestroy, }), })); describe('App', () => { let vm; beforeAll(() => { const options = { global: { stubs: ['router-view'], }, }; vm = createWrapper(App, options).vm; }); it('should return a login error message', async () => { vi.spyOn(vm.quasar, 'notify'); session.isLoggedIn.mockReturnValue(false); const response = { response: { status: 401, }, }; expect(vm.responseError(response)).rejects.toEqual(expect.objectContaining(response)); expect(vm.quasar.notify).toHaveBeenCalledWith( expect.objectContaining({ message: 'Invalid username or password', type: 'negative', }) ); }); it('should return an unauthorized error message', async () => { vi.spyOn(vm.quasar, 'notify'); session.isLoggedIn.mockReturnValue(true); const response = { response: { status: 401, }, }; expect(vm.responseError(response)).rejects.toEqual(expect.objectContaining(response)); expect(vm.quasar.notify).toHaveBeenCalledWith( expect.objectContaining({ message: 'Access denied', type: 'negative', }) ); expect(session.destroy).toHaveBeenCalled(); }); });