test(axios): refactor axios functional tests for improved clarity

Refactored the axios functional tests by removing unnecessary asynchronous imports and simplifying the setup in the `beforeEach` hook. This change enhances the readability and maintainability of the test code, ensuring it aligns with the project's coding standards.
This commit is contained in:
alisaza 2026-09-13 13:31:19 +03:30
parent c0428bb65d
commit 3f072976fe

View File

@ -1,6 +1,8 @@
import axios, { AxiosError, type InternalAxiosRequestConfig } from 'axios'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import axiosInstance, { getOrRefreshAccessToken, resetAxiosAuthModuleState } from '@/config/axios'
const mocks = vi.hoisted(() => ({
expireRefreshSession: vi.fn().mockResolvedValue(undefined),
}))
@ -23,18 +25,15 @@ const writeStoredToken = (accessToken: string): void => {
}
describe('admin access-token refresh races', () => {
beforeEach(async () => {
beforeEach(() => {
vi.clearAllMocks()
vi.restoreAllMocks()
window.localStorage.clear()
const { resetAxiosAuthModuleState } = await import('@/config/axios')
resetAxiosAuthModuleState()
})
it('replays a late 401 with the newer stored token without rotating refresh again', async () => {
writeStoredToken('access-a')
const { default: axiosInstance } = await import('@/config/axios')
const refreshRequest = vi.spyOn(axios, 'post')
const authorizationHeaders: string[] = []
let requestCount = 0
@ -85,7 +84,6 @@ describe('admin access-token refresh races', () => {
})
try {
const { getOrRefreshAccessToken } = await import('@/config/axios')
const refreshRequest = vi.spyOn(axios, 'post')
await expect(getOrRefreshAccessToken()).resolves.toBe('access-b')