refact: extract setPolicy into utils

This commit is contained in:
Jai Bhagat
2022-01-26 12:06:18 -05:00
parent 6c65966c16
commit 8d8fe0bd2d
3 changed files with 11 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import Clients from 'nomad-ui/tests/pages/jobs/job/clients';
import setPolicy from 'nomad-ui/tests/utils/set-policy';
let job;
let clients;
@@ -227,13 +228,3 @@ module('Acceptance | job clients', function (hooks) {
// TODO: add facet tests for actual list filtering
}
});
function setPolicy(policy) {
const { id: policyId } = server.create('policy', policy);
const clientToken = server.create('token', { type: 'client' });
clientToken.policyIds = [policyId];
clientToken.save();
window.localStorage.clear();
window.localStorage.nomadTokenSecret = clientToken.secretId;
}

View File

@@ -10,6 +10,7 @@ import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import JobDetail from 'nomad-ui/tests/pages/jobs/detail';
import setPolicy from 'nomad-ui/tests/utils/set-policy';
// moduleFor is an old Ember-QUnit API that is deprected https://guides.emberjs.com/v1.10.0/testing/unit-test-helpers/
// this is a misnomer in our context, because we're not using this API, however, the linter does not understand this
@@ -363,16 +364,6 @@ function urlWithNamespace(url, namespace) {
return `${parts[0]}?${params.toString()}`;
}
function setPolicy(policy) {
const { id: policyId } = server.create('policy', policy);
const clientToken = server.create('token', { type: 'client' });
clientToken.policyIds = [policyId];
clientToken.save();
window.localStorage.clear();
window.localStorage.nomadTokenSecret = clientToken.secretId;
}
async function visitJobDetailPage({ id, namespace }) {
if (!namespace || namespace === 'default') {
await JobDetail.visit({ id });

View File

@@ -0,0 +1,9 @@
export default function setPolicy(policy) {
const { id: policyId } = server.create('policy', policy);
const clientToken = server.create('token', { type: 'client' });
clientToken.policyIds = [policyId];
clientToken.save();
window.localStorage.clear();
window.localStorage.nomadTokenSecret = clientToken.secretId;
}