33 lines
1018 B
JavaScript
33 lines
1018 B
JavaScript
import { vi, describe, expect, it } from 'vitest';
|
|
import axios from 'axios';
|
|
import { flushPromises } from '@vue/test-utils';
|
|
import { useTokenConfig } from 'composables/useTokenConfig';
|
|
const tokenConfig = useTokenConfig();
|
|
|
|
describe('useTokenConfig', () => {
|
|
describe('fetch', () => {
|
|
it('should call setTokenConfig of the state with the expected data', async () => {
|
|
const data = {
|
|
id: 1,
|
|
renewPeriod: 21600,
|
|
courtesyTime: 60,
|
|
renewInterval: 300,
|
|
};
|
|
vi.spyOn(axios, 'get').mockResolvedValueOnce({
|
|
data,
|
|
});
|
|
|
|
vi.spyOn(tokenConfig.state, 'setTokenConfig');
|
|
|
|
tokenConfig.fetch();
|
|
|
|
await flushPromises();
|
|
|
|
expect(tokenConfig.state.setTokenConfig).toHaveBeenCalledWith(data);
|
|
|
|
const renewPeriod = sessionStorage.getItem('renewPeriod');
|
|
expect(renewPeriod).toEqual(data.renewPeriod);
|
|
});
|
|
});
|
|
});
|