diff --git a/cypress/fixtures/groups/Ba8B79ab5adC8E41e255D5f8aDb8f1F3.json b/cypress/fixtures/groups/Ba8B79ab5adC8E41e255D5f8aDb8f1F3.json deleted file mode 100644 index c499d9599..000000000 --- a/cypress/fixtures/groups/Ba8B79ab5adC8E41e255D5f8aDb8f1F3.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "count": 1, - "page": 1, - "per_page": 50, - "results": [ - { - "name": "ea velit incididunt", - "updated_at": "1998-04-17T22:00:00.0Z", - "id": "620f9ae75A8F6b83d78F3B55Af1c4b2C", - "account": "irure ea exercitation adipisicing velit", - "org_id": "non", - "created_at": "1994-07-28T22:00:00.0Z", - "host_ids": [ - "00fcC027-F4e3-aB4D-3eB9-392B09E4E9eC", - "82c882beA274db74bA79Dad9695CDdcD", - "374ECeB4-4aA6-637a-A5d8-eBD40A51EED8", - "12f6cdf2-fBcA-EF8A-3cC1-739627825F5B", - "37F4D8D9-A1Bd-cEE7-1Bcc-A03A20589B1B", - "ab29a822dA3259bf4a80A586Bd2e16E0", - "0ed9cfebEb3bfdB9A6F51757008dFB2F", - "4ddCF8Ee4a5DF968CBCaaaed16F5c55f", - "3cfF3e49-35Af-fD3E-62eb-c4eBDa0Ac3fF", - "8ce37289-4B8f-cECF-a3db-94f9F9ACB45a", - "Fd60B4f79D74507bDE8be6913caFDa8e", - "BbEAB14B-9A1f-eDFB-9c3B-eF0C6b6CB4dF", - "14FA22F08BBFf6f9738cBED71aFf66eE", - "fcF870cc-8C3C-8ba9-FcdA-dff79Ba0e2dE", - "38B60BDf17c9E6C9Cdd11840aCb4e804", - "C306bEc5EAF6BfD025fa6f48b3BeAF43", - "83CE42Eadccd8b2e5E5Aca1eaBAB55aa", - "4da9f2C5d6C1Ce6EE2f3D7BBC974E7c3", - "CaaE8C2e-C67c-41b3-5EB8-5Fd233eC9FdC" - ] - } - ], - "total": 1 -} diff --git a/cypress/support/interceptors.js b/cypress/support/interceptors.js index 173d54c45..11cb35b14 100644 --- a/cypress/support/interceptors.js +++ b/cypress/support/interceptors.js @@ -18,7 +18,7 @@ export const groupsInterceptors = { .as('getGroups'), 'successful with some items second page': () => cy - .intercept('GET', '/api/inventory/v1/groups?*page=2&perPage=50*', { + .intercept('GET', '/api/inventory/v1/groups?*page=2&per_page=50*', { statusCode: 200, body: groupsSecondPage }) diff --git a/src/Utilities/hooks/useFetchBatched.js b/src/Utilities/hooks/useFetchBatched.js index 2260a06ae..b286416e9 100644 --- a/src/Utilities/hooks/useFetchBatched.js +++ b/src/Utilities/hooks/useFetchBatched.js @@ -10,7 +10,8 @@ const useFetchBatched = () => { const results = resolve( [...new Array(pages)].map( - (_, pageIdx) => () => fetchFunction(filter, { page: pageIdx + 1, perPage: batchSize }) + // eslint-disable-next-line camelcase + (_, pageIdx) => () => fetchFunction(filter, { page: pageIdx + 1, per_page: batchSize }) ) ); diff --git a/src/components/GroupsTable/GroupsTable.cy.js b/src/components/GroupsTable/GroupsTable.cy.js index 701461d35..5f2864247 100644 --- a/src/components/GroupsTable/GroupsTable.cy.js +++ b/src/components/GroupsTable/GroupsTable.cy.js @@ -121,7 +121,7 @@ describe('pagination', () => { changePagination(el).then(() => { cy.wait('@getGroups') .its('request.url') - .should('include', `perPage=${el}`); + .should('include', `per_page=${el}`); }); }); }); @@ -186,12 +186,12 @@ describe('filtering', () => { it('sends correct request', () => { applyNameFilter(); - cy.wait('@getGroups').its('request.url').should('include', 'hostname_or_id=lorem'); + cy.wait('@getGroups').its('request.url').should('include', 'name=lorem'); }); it('can remove the chip or reset filters', () => { applyNameFilter(); - cy.wait('@getGroups').its('request.url').should('contain', 'hostname_or_id=lorem'); + cy.wait('@getGroups').its('request.url').should('contain', 'name=lorem'); cy.get(CHIP_GROUP) .find(CHIP) .ouiaId('close', 'button') @@ -199,7 +199,7 @@ describe('filtering', () => { cy.get(CHIP_GROUP).find(CHIP).ouiaId('close', 'button'); }); cy.get('button').contains('Reset filters').click(); - cy.wait('@getGroups').its('request.url').should('not.contain', 'hostname_or_id'); + cy.wait('@getGroups').its('request.url').should('not.contain', 'name'); cy.get(CHIP_GROUP).should('not.exist'); }); diff --git a/src/components/GroupsTable/GroupsTable.js b/src/components/GroupsTable/GroupsTable.js index 63ba30d2f..2d490ecc9 100644 --- a/src/components/GroupsTable/GroupsTable.js +++ b/src/components/GroupsTable/GroupsTable.js @@ -88,10 +88,10 @@ const GroupsTable = () => { const order_by = GROUPS_TABLE_COLUMNS_TO_URL[sortIndex]; const order_how = upperCase(sortDirection); return dispatch( - fetchGroups({ ...search, order_by, order_how }, { page, perPage }) + fetchGroups({ ...search, order_by, order_how }, { page, per_page: perPage }) ); } else { - return dispatch(fetchGroups(search, { page, perPage })); + return dispatch(fetchGroups(search, { page, per_page: perPage })); } }, REQUEST_DEBOUNCE_TIMEOUT), // wait the timeout before making the final fetch [] @@ -140,16 +140,16 @@ const GroupsTable = () => { data-ouia-component-type="PF4/TextInput" data-ouia-component-id="name-filter" placeholder="Filter by name" - value={filters.hostname_or_id || ''} + value={filters.name || ''} onChange={(value) => { - const { hostname_or_id, ...fs } = filters; + const { name, ...fs } = filters; return setFilters({ ...fs, - ...(value.length > 0 ? { hostname_or_id: value } : {}) + ...(value.length > 0 ? { name: value } : {}) }); }} onClear={() => { - const { hostname_or_id, ...fs } = filters; + const { name, ...fs } = filters; return setFilters(fs); }} isDisabled={rejected} @@ -158,20 +158,20 @@ const GroupsTable = () => { } } ], - [filters.hostname_or_id, rejected] + [filters.name, rejected] ); const onResetFilters = () => setFilters(GROUPS_TABLE_INITIAL_STATE); const activeFiltersConfig = { - showDeleteButton: !!filters.hostname_or_id, + showDeleteButton: !!filters.name, deleteTitle: 'Reset filters', - filters: filters.hostname_or_id + filters: filters.name ? [ { category: 'Name', chips: [ - { name: filters.hostname_or_id, value: filters.hostname_or_id } + { name: filters.name, value: filters.name } ] } ] diff --git a/src/components/InventoryGroups/utils/api.js b/src/components/InventoryGroups/utils/api.js index 2ae0ac650..a6e99302e 100644 --- a/src/components/InventoryGroups/utils/api.js +++ b/src/components/InventoryGroups/utils/api.js @@ -4,22 +4,14 @@ import { INVENTORY_API_BASE } from '../../../api'; import { TABLE_DEFAULT_PAGINATION } from '../../../constants'; import PropTypes from 'prop-types'; import union from 'lodash/union'; -import fixtureGroups from '../../../../cypress/fixtures/groups.json'; -import fixtureGroupsDetails from '../../../../cypress/fixtures/groups/Ba8B79ab5adC8E41e255D5f8aDb8f1F3.json'; -// eslint-disable-next-line camelcase export const getGroups = (search = {}, pagination = { page: 1, per_page: TABLE_DEFAULT_PAGINATION }) => { - if (window.Cypress) { - const parameters = new URLSearchParams({ - ...search, - ...pagination - }).toString(); + const parameters = new URLSearchParams({ + ...search, + ...pagination + }).toString(); - return instance.get(`${INVENTORY_API_BASE}/groups?${parameters}`); - } - - // FIXME: remove mock data when API is implemented - return Promise.resolve(fixtureGroups); + return instance.get(`${INVENTORY_API_BASE}/groups?${parameters}` /* , { headers: { Prefer: 'code=404' } } */); }; export const createGroup = (payload) => { @@ -31,22 +23,12 @@ export const createGroup = (payload) => { }; export const validateGroupName = (name) => { - if (window.Cypress) { - return instance.get(`${INVENTORY_API_BASE}/groups`) - .then((resp) => resp?.results.some((group) => group.name === name)); - } - - // FIXME: remove mock data when API is implemented - return Promise.resolve(fixtureGroups).then((resp) => resp?.results.some((group) => group.name === name)); + return instance.get(`${INVENTORY_API_BASE}/groups`) + .then((resp) => resp?.results.some((group) => group.name === name)); }; export const getGroupDetail = (groupId) => { - if (window.Cypress) { - return instance.get(`${INVENTORY_API_BASE}/groups/${groupId}`); - } - - // FIXME: remove mock data when API is implemented - return Promise.resolve(fixtureGroupsDetails); + return instance.get(`${INVENTORY_API_BASE}/groups/${groupId}`); }; export const updateGroupById = (id, payload) => { @@ -75,11 +57,10 @@ export const addHostToGroup = (groupId, newHostId) => { getGroups.propTypes = { search: PropTypes.shape({ - // eslint-disable-next-line camelcase - hostname_or_id: PropTypes.string + name: PropTypes.string }), pagination: PropTypes.shape({ - perPage: PropTypes.number, + per_page: PropTypes.number, page: PropTypes.number }) }; diff --git a/src/store/actions.test.js b/src/store/actions.test.js index ff71dc4a0..e3bf3a6d0 100644 --- a/src/store/actions.test.js +++ b/src/store/actions.test.js @@ -2,7 +2,7 @@ import { editAnsibleHost, editDisplayName, fetchGroups, systemProfile } from './actions'; import { hosts } from '../api'; import mockedData from '../__mocks__/mockedData.json'; -import fixturesGroups from '../../cypress/fixtures/groups.json'; +import mockedGroups from '../__mocks__/mockedGroups.json'; import MockAdapter from 'axios-mock-adapter'; const mocked = new MockAdapter(hosts.axios); @@ -65,10 +65,10 @@ describe('editAnsibleHost', () => { describe('fetchGroups', () => { it('should call correct endpoint', async () => { mocked.onGet(new RegExp('/api/inventory/v1/groups*')).reply(() => { - return [200, fixturesGroups]; + return [200, mockedGroups]; }); const { type, payload } = await fetchGroups(); expect(type).toBe('GROUPS'); - expect(await payload).toEqual(fixturesGroups); + expect(await payload).toEqual(mockedGroups); }); });