mirror of
https://github.com/strapi/strapi.git
synced 2025-08-02 13:58:18 +00:00
fix tests review comments
This commit is contained in:
parent
0a68d2d9b6
commit
5d50cfb19f
@ -12,7 +12,6 @@ import {
|
|||||||
const token = 'coolToken';
|
const token = 'coolToken';
|
||||||
auth.getToken = jest.fn().mockReturnValue(token);
|
auth.getToken = jest.fn().mockReturnValue(token);
|
||||||
auth.clearAppStorage = jest.fn().mockReturnValue(token);
|
auth.clearAppStorage = jest.fn().mockReturnValue(token);
|
||||||
process.env.STRAPI_ADMIN_BACKEND_URL = 'http://localhost:1337';
|
|
||||||
|
|
||||||
describe('ADMIN | utils | fetchClient', () => {
|
describe('ADMIN | utils | fetchClient', () => {
|
||||||
describe('Test the interceptors', () => {
|
describe('Test the interceptors', () => {
|
||||||
@ -25,12 +24,12 @@ describe('ADMIN | utils | fetchClient', () => {
|
|||||||
expect(result.headers.Accept).toBe('application/json');
|
expect(result.headers.Accept).toBe('application/json');
|
||||||
expect(apiInstance.interceptors.response.handlers[0].fulfilled('foo')).toBe('foo');
|
expect(apiInstance.interceptors.response.handlers[0].fulfilled('foo')).toBe('foo');
|
||||||
});
|
});
|
||||||
describe('Test the addInterceptor funcion', () => {
|
describe('Test the addInterceptor function', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// restore the spy created with spyOn
|
// restore the spy created with spyOn
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
});
|
});
|
||||||
it('should add a response interceptor to the axios instance', () => {
|
it('should add a response interceptor to the fetchClient instance', () => {
|
||||||
const apiInstance = fetchClient({
|
const apiInstance = fetchClient({
|
||||||
baseUrl: 'http://strapi-test',
|
baseUrl: 'http://strapi-test',
|
||||||
});
|
});
|
||||||
@ -67,7 +66,7 @@ describe('ADMIN | utils | fetchClient', () => {
|
|||||||
url: '/test',
|
url: '/test',
|
||||||
};
|
};
|
||||||
const configResponse = await reqInterceptor(configMock);
|
const configResponse = await reqInterceptor(configMock);
|
||||||
expect(configResponse.headers.Authorization).toBe('Bearer coolToken');
|
expect(configResponse.headers.Authorization).toBe(`Bearer ${token}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should throw an error when the request interceptor error callback is called', () => {
|
it('should throw an error when the request interceptor error callback is called', () => {
|
||||||
|
@ -3,8 +3,6 @@ import { getFetchClient } from '../getFetchClient';
|
|||||||
|
|
||||||
const token = 'coolToken';
|
const token = 'coolToken';
|
||||||
auth.getToken = jest.fn().mockReturnValue(token);
|
auth.getToken = jest.fn().mockReturnValue(token);
|
||||||
auth.clearAppStorage = jest.fn().mockReturnValue(token);
|
|
||||||
process.env.STRAPI_ADMIN_BACKEND_URL = 'http://localhost:1337';
|
|
||||||
|
|
||||||
describe('ADMIN | utils | getFetchClient', () => {
|
describe('ADMIN | utils | getFetchClient', () => {
|
||||||
it('should return the 4 HTTP methods to call GET, POST, PUT and DELETE apis', () => {
|
it('should return the 4 HTTP methods to call GET, POST, PUT and DELETE apis', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user