feat: Add 'deleteHostSet' method to a target

'deleteHostSet' wraps a host set id in an array and uses
'deleteHostSets' method
This commit is contained in:
Susmitha Girumala committed 2020-08-27 12:59:26 -04:00
1 parent 54008c8977
commit f97eebe1b8
3 files changed
+44 -1

No files matched your search

+10
View File
@@ -79,4 +79,14 @@ export default class TargetModel extends GeneratedTargetModel {
});
}
/**
* Delete a single host set via the `delete-host-sets` method.
* @param {object} hostSet
* @param {object} options
* @return {Promise}
*/
deleteHostSet(hostSet, options) {
return this.deleteHostSets([hostSet.id], options);
}
}
@@ -122,4 +122,37 @@ module('Unit | Model | target', function (hooks) {
const model = store.peekRecord('target', '123abc');
await model.deleteHostSets(['1', '3']);
});
test('it has a `deleteHostSet` method that deletes a single host set using `deleteHostSets` method', async function (assert) {
assert.expect(1);
this.server.post('/v1/scopes/o_1/targets/123abc:delete-host-sets', (schema, request) => {
const body = JSON.parse(request.requestBody);
assert.deepEqual(body, {
host_set_ids: ['3'],
version: 1
});
});
const store = this.owner.lookup('service:store');
store.push({
data: {
id: '123abc',
type: 'target',
attributes: {
name: 'Target',
description: 'Description',
host_sets: [
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' }
],
version: 1,
scope: {
scope_id: 'o_1',
type: 'scope'
}
}
}
});
const model = store.peekRecord('target', '123abc');
await model.deleteHostSet({id: '3'});
});
});
@@ -59,7 +59,7 @@ export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extend
@action
async delete(target, hostSet) {
try {
await target.deleteHostSets([hostSet.id]);
await target.deleteHostSet(hostSet);
this.refresh();
this.notify.success(this.intl.t('notify.delete-success'));
this.transitionTo('scopes.scope.projects.project.targets.target.host-sets');