Fixes bug where users could not delete a single inventory source

This commit is contained in:
mabashian
2021-04-21 14:42:38 -04:00
parent ddcbef8545
commit c48fbec30c
4 changed files with 13 additions and 34 deletions

View File

@@ -98,8 +98,7 @@ function InventorySourceDetail({ inventorySource, i18n }) {
}; };
const deleteDetailsRequests = relatedResourceDeleteRequests.inventorySource( const deleteDetailsRequests = relatedResourceDeleteRequests.inventorySource(
inventorySource.inventory, inventorySource.id
inventorySource
); );
const VERBOSITY = { const VERBOSITY = {

View File

@@ -145,8 +145,7 @@ function InventorySourceList({ i18n }) {
const listUrl = `/inventories/${inventoryType}/${id}/sources/`; const listUrl = `/inventories/${inventoryType}/${id}/sources/`;
const deleteDetailsRequests = relatedResourceDeleteRequests.inventorySource( const deleteDetailsRequests = relatedResourceDeleteRequests.inventorySource(
id, selected[0]?.id
selected[0]
); );
return ( return (
<> <>

View File

@@ -91,9 +91,8 @@ describe('delete details', () => {
await getRelatedResourceDeleteCounts( await getRelatedResourceDeleteCounts(
relatedResourceDeleteRequests.inventorySource(1) relatedResourceDeleteRequests.inventorySource(1)
); );
expect(InventoriesAPI.updateSources).toBeCalledWith(1);
expect(WorkflowJobTemplateNodesAPI.read).toBeCalledWith({ expect(WorkflowJobTemplateNodesAPI.read).toBeCalledWith({
unified_job_template: 2, unified_job_template: 1,
}); });
}); });
@@ -105,11 +104,11 @@ describe('delete details', () => {
}); });
test('should call return error for inventory source list', async () => { test('should call return error for inventory source list', async () => {
InventoriesAPI.updateSources.mockRejectedValue({ WorkflowJobTemplateNodesAPI.read.mockRejectedValue({
response: { response: {
config: { config: {
method: 'post', method: 'get',
url: '/api/v2/inventories/1/ad_hoc_commands', url: '/api/v2/workflow_job_template_nodesP',
}, },
data: 'An error occurred', data: 'An error occurred',
status: 403, status: 403,
@@ -119,7 +118,6 @@ describe('delete details', () => {
relatedResourceDeleteRequests.inventorySource(1) relatedResourceDeleteRequests.inventorySource(1)
); );
expect(InventoriesAPI.updateSources).toBeCalledWith(1);
expect(error).toBeDefined(); expect(error).toBeDefined();
}); });

View File

@@ -113,37 +113,20 @@ export const relatedResourceDeleteRequests = {
}, },
], ],
inventorySource: (inventoryId, inventorySource) => [ inventorySource: inventorySourceId => [
{ {
request: async () => { request: async () =>
try { WorkflowJobTemplateNodesAPI.read({
const { data } = await InventoriesAPI.updateSources(inventoryId); unified_job_template: inventorySourceId,
}),
const results = await Promise.all(
data.map(async datum =>
WorkflowJobTemplateNodesAPI.read({
unified_job_template: datum.inventory_source,
})
)
);
const total = results.reduce(
({ data: { count: acc } }, { data: { count: cur } }) => acc + cur,
{ data: { count: 0 } }
);
return { data: { count: total } };
} catch (err) {
throw new Error(err);
}
},
label: i18n._(t`Workflow Job Template Nodes`), label: i18n._(t`Workflow Job Template Nodes`),
}, },
{ {
request: async () => InventorySourcesAPI.readGroups(inventorySource.id), request: async () => InventorySourcesAPI.readGroups(inventorySourceId),
label: i18n._(t`Groups`), label: i18n._(t`Groups`),
}, },
{ {
request: async () => InventorySourcesAPI.readHosts(inventorySource.id), request: async () => InventorySourcesAPI.readHosts(inventorySourceId),
label: i18n._(t`Hosts`), label: i18n._(t`Hosts`),
}, },
], ],