Skip to content

Commit

Permalink
Revert "chore: Mock GET groups related requests (RedHatInsights#1793)"
Browse files Browse the repository at this point in the history
This reverts commit a82ed4f.
  • Loading branch information
gkarat committed Apr 26, 2023
1 parent b3e8fa5 commit fb6d33f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 67 deletions.
37 changes: 0 additions & 37 deletions cypress/fixtures/groups/Ba8B79ab5adC8E41e255D5f8aDb8f1F3.json

This file was deleted.

36 changes: 9 additions & 27 deletions src/components/InventoryGroups/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
export const getGroups = (search = {}, pagination = { page: 1, perPage: TABLE_DEFAULT_PAGINATION }) => {
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) => {
Expand All @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/store/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});

0 comments on commit fb6d33f

Please sign in to comment.