From 74e330e523e0aa9a82c79f2e817b613e8e44aeff Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 16 May 2024 14:05:39 +0200 Subject: [PATCH] fix: refs #6598 fix unit tests --- .../__tests__/composables/useSession.spec.js | 17 ++++++++--------- test/vitest/__tests__/pages/Login/Login.spec.js | 5 +++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/vitest/__tests__/composables/useSession.spec.js b/test/vitest/__tests__/composables/useSession.spec.js index 2292859a9..6e08807cf 100644 --- a/test/vitest/__tests__/composables/useSession.spec.js +++ b/test/vitest/__tests__/composables/useSession.spec.js @@ -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; diff --git a/test/vitest/__tests__/pages/Login/Login.spec.js b/test/vitest/__tests__/pages/Login/Login.spec.js index 6e2de9870..9b9968736 100644 --- a/test/vitest/__tests__/pages/Login/Login.spec.js +++ b/test/vitest/__tests__/pages/Login/Login.spec.js @@ -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');