forked from verdnatura/salix-front
fix: refs #6598 fix unit tests
This commit is contained in:
parent
b63735a709
commit
74e330e523
|
@ -1,5 +1,5 @@
|
|||
import { vi, describe, expect, it, beforeAll, beforeEach } from 'vitest';
|
||||
import { axios, flushPromises } from 'app/test/vitest/helper';
|
||||
import { axios } from 'app/test/vitest/helper';
|
||||
import { useSession } from 'composables/useSession';
|
||||
import { useState } from 'composables/useState';
|
||||
|
||||
|
@ -7,6 +7,7 @@ const session = useSession();
|
|||
const state = useState();
|
||||
|
||||
describe('session', () => {
|
||||
|
||||
describe('getToken / setToken', () => {
|
||||
it('should return an empty string if no token is found in local or session storage', async () => {
|
||||
const expectedToken = '';
|
||||
|
@ -87,13 +88,15 @@ describe('session', () => {
|
|||
},
|
||||
},
|
||||
];
|
||||
beforeEach(() => {
|
||||
vi.spyOn(axios, 'get').mockImplementation((url) => {
|
||||
if(url === 'VnUsers/acls') return Promise.resolve({data: []});
|
||||
return Promise.resolve({data: { roles: rolesData, user: expectedUser }});
|
||||
});
|
||||
})
|
||||
|
||||
it('should fetch the user roles and then set token in the sessionStorage', async () => {
|
||||
const expectedRoles = ['salesPerson', 'admin'];
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
data: { roles: rolesData, user: expectedUser },
|
||||
});
|
||||
|
||||
const expectedToken = 'mySessionToken';
|
||||
const expectedTokenMultimedia = 'mySessionTokenMultimedia';
|
||||
const keepLogin = false;
|
||||
|
@ -117,10 +120,6 @@ describe('session', () => {
|
|||
|
||||
it('should fetch the user roles and then set token in the localStorage', async () => {
|
||||
const expectedRoles = ['salesPerson', 'admin'];
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
data: { roles: rolesData, user: expectedUser },
|
||||
});
|
||||
|
||||
const expectedToken = 'myLocalToken';
|
||||
const expectedTokenMultimedia = 'myLocalTokenMultimedia';
|
||||
const keepLogin = true;
|
||||
|
|
|
@ -23,8 +23,9 @@ describe('Login', () => {
|
|||
},
|
||||
};
|
||||
vi.spyOn(axios, 'post').mockResolvedValueOnce({ data: { token: 'token' } });
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
data: { roles: [], user: expectedUser , multimediaToken: {id:'multimediaToken' }},
|
||||
vi.spyOn(axios, 'get').mockImplementation((url) => {
|
||||
if (url === 'VnUsers/acls') return Promise.resolve({ data: [] });
|
||||
return Promise.resolve({data: { roles: [], user: expectedUser , multimediaToken: {id:'multimediaToken' }}});
|
||||
});
|
||||
vi.spyOn(vm.quasar, 'notify');
|
||||
|
||||
|
|
Loading…
Reference in New Issue