Skip to content

Commit

Permalink
refact: extract setPolicy into utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaiWithJai committed Jan 26, 2022
1 parent 6c65966 commit 8d8fe0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
11 changes: 1 addition & 10 deletions ui/tests/acceptance/job-clients-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
11 changes: 1 addition & 10 deletions ui/tests/helpers/module-for-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 });
Expand Down
9 changes: 9 additions & 0 deletions ui/tests/utils/set-policy.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 8d8fe0b

Please sign in to comment.