mirror of
https://github.com/ansible/awx.git
synced 2026-02-14 17:50:02 -03:30
Address PR review comments.
This commit is contained in:
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import App from '../src/App';
|
||||
import api from '../src/api';
|
||||
import * as constant from '../src/endpoints';
|
||||
import { API_LOGOUT } from '../src/endpoints';
|
||||
|
||||
import Dashboard from '../src/pages/Dashboard';
|
||||
import Login from '../src/pages/Login';
|
||||
@@ -66,13 +66,13 @@ describe('<App />', () => {
|
||||
});
|
||||
|
||||
test('api.logout called from logout button', async () => {
|
||||
api.BaseGet = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||
api.get = jest.fn().mockImplementation(() => Promise.resolve({}));
|
||||
const appWrapper = mount(<App />);
|
||||
const logoutButton = appWrapper.find('LogoutButton');
|
||||
logoutButton.props().onDevLogout();
|
||||
appWrapper.setState({ activeGroup: 'foo', activeItem: 'bar' });
|
||||
expect(api.BaseGet).toHaveBeenCalledTimes(1);
|
||||
expect(api.BaseGet).toHaveBeenCalledWith(constant.API_LOGOUT);
|
||||
expect(api.get).toHaveBeenCalledTimes(1);
|
||||
expect(api.get).toHaveBeenCalledWith(API_LOGOUT);
|
||||
await asyncFlush();
|
||||
expect(appWrapper.state().activeItem).toBe(DEFAULT_ACTIVE_ITEM);
|
||||
expect(appWrapper.state().activeGroup).toBe(DEFAULT_ACTIVE_GROUP);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import mockAxios from 'axios';
|
||||
import APIClient from '../src/api';
|
||||
import * as constant from '../src/endpoints';
|
||||
import * as endpoints from '../src/endpoints';
|
||||
|
||||
const CSRF_COOKIE_NAME = 'csrftoken';
|
||||
const CSRF_HEADER_NAME = 'X-CSRFToken';
|
||||
@@ -45,9 +45,9 @@ describe('APIClient (api.js)', () => {
|
||||
APIClient.setCookie = jest.fn();
|
||||
APIClient.login(un, pw, next).then(() => {
|
||||
expect(mockAxios.get).toHaveBeenCalledTimes(1);
|
||||
expect(mockAxios.get).toHaveBeenCalledWith(constant.API_LOGIN, { headers });
|
||||
expect(mockAxios.get).toHaveBeenCalledWith(endpoints.API_LOGIN, { headers });
|
||||
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
||||
expect(mockAxios.post).toHaveBeenCalledWith(constant.API_LOGIN, data, { headers });
|
||||
expect(mockAxios.post).toHaveBeenCalledWith(endpoints.API_LOGIN, data, { headers });
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -60,7 +60,7 @@ describe('APIClient (api.js)', () => {
|
||||
const data = `username=${encodeURIComponent(un)}&password=${encodeURIComponent(pw)}&next=${encodeURIComponent(next)}`;
|
||||
APIClient.login(un, pw, next).then(() => {
|
||||
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
||||
expect(mockAxios.post).toHaveBeenCalledWith(constant.API_LOGIN, data, { headers });
|
||||
expect(mockAxios.post).toHaveBeenCalledWith(endpoints.API_LOGIN, data, { headers });
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -69,11 +69,11 @@ describe('APIClient (api.js)', () => {
|
||||
const un = 'foo';
|
||||
const pw = 'bar';
|
||||
const headers = { 'Content-Type': LOGIN_CONTENT_TYPE };
|
||||
const data = `username=${un}&password=${pw}&next=${encodeURIComponent(constant.API_CONFIG)}`;
|
||||
const data = `username=${un}&password=${pw}&next=${encodeURIComponent(endpoints.API_CONFIG)}`;
|
||||
APIClient.setCookie = jest.fn();
|
||||
APIClient.login(un, pw).then(() => {
|
||||
expect(mockAxios.post).toHaveBeenCalledTimes(1);
|
||||
expect(mockAxios.post).toHaveBeenCalledWith(constant.API_LOGIN, data, { headers });
|
||||
expect(mockAxios.post).toHaveBeenCalledWith(endpoints.API_LOGIN, data, { headers });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user