Skip to content

Commit

Permalink
update hosts groups api GET to all_groups
Browse files Browse the repository at this point in the history
  • Loading branch information
John Mitchell authored and John Mitchell committed Apr 3, 2020
1 parent c32d95c commit bf4de87
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions awx/ui_next/src/api/models/Hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Hosts extends Base {
this.baseUrl = '/api/v2/hosts/';

this.readFacts = this.readFacts.bind(this);
this.readGroups = this.readGroups.bind(this);
this.readAllGroups = this.readAllGroups.bind(this);
this.readGroupsOptions = this.readGroupsOptions.bind(this);
this.associateGroup = this.associateGroup.bind(this);
this.disassociateGroup = this.disassociateGroup.bind(this);
Expand All @@ -17,8 +17,8 @@ class Hosts extends Base {
return this.http.get(`${this.baseUrl}${id}/ansible_facts/`);
}

readGroups(id, params) {
return this.http.get(`${this.baseUrl}${id}/groups/`, { params });
readAllGroups(id, params) {
return this.http.get(`${this.baseUrl}${id}/all_groups/`, { params });
}

readGroupsOptions(id) {
Expand Down
2 changes: 1 addition & 1 deletion awx/ui_next/src/screens/Host/HostGroups/HostGroupsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function HostGroupsList({ i18n, location, match, host }) {
},
actionsResponse,
] = await Promise.all([
HostsAPI.readGroups(hostId, params),
HostsAPI.readAllGroups(hostId, params),
HostsAPI.readGroupsOptions(hostId),
]);

Expand Down
12 changes: 7 additions & 5 deletions awx/ui_next/src/screens/Host/HostGroups/HostGroupsList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('<HostGroupsList />', () => {
let wrapper;

beforeEach(async () => {
HostsAPI.readGroups.mockResolvedValue({
HostsAPI.readAllGroups.mockResolvedValue({
data: {
count: mockGroups.length,
results: mockGroups,
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('<HostGroupsList />', () => {
});

test('should fetch groups from api and render them in the list', async () => {
expect(HostsAPI.readGroups).toHaveBeenCalled();
expect(HostsAPI.readAllGroups).toHaveBeenCalled();
expect(wrapper.find('HostGroupItem').length).toBe(3);
});

Expand Down Expand Up @@ -165,7 +165,9 @@ describe('<HostGroupsList />', () => {
});

test('should show content error when api throws error on initial render', async () => {
HostsAPI.readGroups.mockImplementation(() => Promise.reject(new Error()));
HostsAPI.readAllGroups.mockImplementation(() =>
Promise.reject(new Error())
);
await act(async () => {
wrapper = mountWithContexts(<HostGroupsList host={host} />);
});
Expand Down Expand Up @@ -224,7 +226,7 @@ describe('<HostGroupsList />', () => {

test('expected api calls are made for multi-disassociation', async () => {
expect(HostsAPI.disassociateGroup).toHaveBeenCalledTimes(0);
expect(HostsAPI.readGroups).toHaveBeenCalledTimes(1);
expect(HostsAPI.readAllGroups).toHaveBeenCalledTimes(1);
expect(wrapper.find('DataListCheck').length).toBe(3);
wrapper.find('DataListCheck').forEach(el => {
expect(el.props().checked).toBe(false);
Expand All @@ -246,7 +248,7 @@ describe('<HostGroupsList />', () => {
.simulate('click');
});
expect(HostsAPI.disassociateGroup).toHaveBeenCalledTimes(3);
expect(HostsAPI.readGroups).toHaveBeenCalledTimes(2);
expect(HostsAPI.readAllGroups).toHaveBeenCalledTimes(2);
});

test('should show error modal for failed disassociation', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function InventoryHostGroupsList({ i18n, location, match }) {
},
actionsResponse,
] = await Promise.all([
HostsAPI.readGroups(hostId, params),
HostsAPI.readAllGroups(hostId, params),
HostsAPI.readGroupsOptions(hostId),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('<InventoryHostGroupsList />', () => {
let wrapper;

beforeEach(async () => {
HostsAPI.readGroups.mockResolvedValue({
HostsAPI.readAllGroups.mockResolvedValue({
data: {
count: mockGroups.length,
results: mockGroups,
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('<InventoryHostGroupsList />', () => {
});

test('should fetch groups from api and render them in the list', async () => {
expect(HostsAPI.readGroups).toHaveBeenCalled();
expect(HostsAPI.readAllGroups).toHaveBeenCalled();
expect(wrapper.find('InventoryHostGroupItem').length).toBe(3);
});

Expand Down Expand Up @@ -157,7 +157,9 @@ describe('<InventoryHostGroupsList />', () => {
});

test('should show content error when api throws error on initial render', async () => {
HostsAPI.readGroups.mockImplementation(() => Promise.reject(new Error()));
HostsAPI.readAllGroups.mockImplementation(() =>
Promise.reject(new Error())
);
await act(async () => {
wrapper = mountWithContexts(<InventoryHostGroupsList />);
});
Expand Down Expand Up @@ -216,7 +218,7 @@ describe('<InventoryHostGroupsList />', () => {

test('expected api calls are made for multi-disassociation', async () => {
expect(HostsAPI.disassociateGroup).toHaveBeenCalledTimes(0);
expect(HostsAPI.readGroups).toHaveBeenCalledTimes(1);
expect(HostsAPI.readAllGroups).toHaveBeenCalledTimes(1);
expect(wrapper.find('DataListCheck').length).toBe(3);
wrapper.find('DataListCheck').forEach(el => {
expect(el.props().checked).toBe(false);
Expand All @@ -238,7 +240,7 @@ describe('<InventoryHostGroupsList />', () => {
.simulate('click');
});
expect(HostsAPI.disassociateGroup).toHaveBeenCalledTimes(3);
expect(HostsAPI.readGroups).toHaveBeenCalledTimes(2);
expect(HostsAPI.readAllGroups).toHaveBeenCalledTimes(2);
});

test('should show error modal for failed disassociation', async () => {
Expand Down

0 comments on commit bf4de87

Please sign in to comment.