refactor: 💡 change default target type to tcp

This commit is contained in:
Priya Patel authored and Dharini committed 2025-09-03 17:01:27 -07:00
1 parent b359d9f525
commit 9077a747d6
2 files changed
+8 -23

No files matched your search

@@ -5,11 +5,7 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import {
TYPE_TARGET_TCP,
TYPE_TARGET_SSH,
TYPE_TARGET_RDP,
} from 'api/models/target';
import { TYPE_TARGET_TCP } from 'api/models/target';
export default class ScopesScopeTargetsNewRoute extends Route {
// =services
@@ -47,21 +43,10 @@ export default class ScopesScopeTargetsNewRoute extends Route {
* @return {TargetModel}
*/
model({ type }) {
model({ type = TYPE_TARGET_TCP }) {
let name, description;
const scopeModel = this.modelFor('scopes.scope');
// default type is RDP if the feature is enabled, or is SSH if feature enabled otherwise TCP
if (!type) {
if (this.features.isEnabled('rdp-target')) {
type = TYPE_TARGET_RDP;
} else if (this.features.isEnabled('ssh-target')) {
type = TYPE_TARGET_SSH;
} else {
type = TYPE_TARGET_TCP;
}
}
if (this.currentModel?.isNew) {
({ name, description } = this.currentModel);
this.currentModel.rollbackAttributes();
@@ -91,7 +91,7 @@ module('Acceptance | targets | create', function (hooks) {
await authenticateSession({});
});
test('defaults to type `ssh` when no query param provided', async function (assert) {
test('defaults to type `tcp` when no query param provided', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
@@ -100,13 +100,12 @@ module('Acceptance | targets | create', function (hooks) {
},
},
});
featuresService.enable('ssh-target');
await visit(urls.targets);
await click(commonSelectors.HREF(urls.newTarget));
assert.dom(selectors.FIELD_TYPE_CHECKED).hasValue(TYPE_TARGET_SSH);
assert.dom(selectors.FIELD_TYPE_CHECKED).hasValue(TYPE_TARGET_TCP);
});
test('can create a type `ssh` target', async function (assert) {
@@ -181,6 +180,7 @@ module('Acceptance | targets | create', function (hooks) {
await visit(urls.targets);
await click(commonSelectors.HREF(urls.newTarget));
await click(selectors.FIELD_TYPE_VALUE('ssh'));
assert.dom(selectors.FIELD_DEFAULT_PORT_LABEL).includesText('Optional');
});
@@ -199,7 +199,6 @@ module('Acceptance | targets | create', function (hooks) {
await visit(urls.targets);
await click(commonSelectors.HREF(urls.newTarget));
await click(selectors.FIELD_TYPE_VALUE('tcp'));
assert.dom(selectors.FIELD_DEFAULT_PORT_LABEL).includesText('Required');
});
@@ -516,13 +515,13 @@ module('Acceptance | targets | create', function (hooks) {
assert.strictEqual(currentURL(), urls.targets);
});
test('defaults to type `rdp` when no query param provided and rdp feature is enabled', async function (assert) {
test('defaults to type `tcp` when no query param provided and rdp feature is enabled', async function (assert) {
featuresService.enable('rdp-target');
await visit(urls.targets);
await click(commonSelectors.HREF(urls.newTarget));
assert.dom(selectors.FIELD_TYPE_CHECKED).hasValue(TYPE_TARGET_RDP);
assert.dom(selectors.FIELD_TYPE_CHECKED).hasValue(TYPE_TARGET_TCP);
});
test('cannot navigate to new RDP targets route when rdp feature is disabled', async function (assert) {
@@ -545,6 +544,7 @@ module('Acceptance | targets | create', function (hooks) {
await visit(urls.targets);
await click(commonSelectors.HREF(urls.newTarget));
await click(selectors.FIELD_TYPE_VALUE('rdp'));
assert.dom(selectors.FIELD_DEFAULT_PORT_LABEL).includesText('Optional');
});