0
0
Fork 0

fix: refs #6598 fix unit tests

This commit is contained in:
Jorge Penadés 2024-05-16 14:05:39 +02:00
parent b63735a709
commit 74e330e523
2 changed files with 11 additions and 11 deletions

View File

@ -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;

View File

@ -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');