mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
33 lines
1021 B
TypeScript
33 lines
1021 B
TypeScript
import { AxiosCacheInstance } from '../../src';
|
|
import { StatusCodes } from '../../src/';
|
|
import { axiosMock, mockAxios } from '../mocks/axios';
|
|
|
|
const KEY = 'cacheKey';
|
|
|
|
describe('Tests cached status code', () => {
|
|
let axios: AxiosCacheInstance;
|
|
|
|
beforeEach(() => {
|
|
axios = mockAxios({});
|
|
|
|
axios.storage.set(KEY, {
|
|
data: { body: true },
|
|
expiration: Infinity,
|
|
state: 'cached'
|
|
});
|
|
});
|
|
|
|
it('test response status code', async () => {
|
|
const firstResponse = await axios.get(axiosMock.url);
|
|
expect(firstResponse.status).toBe(axiosMock.statusCode);
|
|
expect(firstResponse.statusText).toBe(axiosMock.statusText);
|
|
|
|
const secondResponse = await axios.get(axiosMock.url);
|
|
expect(secondResponse.status).not.toBe(axiosMock.statusCode);
|
|
expect(secondResponse.statusText).not.toBe(axiosMock.statusText);
|
|
|
|
expect(secondResponse.status).toBe(StatusCodes.CACHED_RESPONSE_STATUS);
|
|
expect(secondResponse.statusText).toBe(StatusCodes.CACHED_RESPONSE_STATUS_TEXT);
|
|
});
|
|
});
|