style: format addons/api
This commit is contained in:
62 files changed
+590
-521
No files matched your search
@@ -1,13 +1,12 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | account', function(hooks) {
|
||||
module('Unit | Model | account', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('account', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,11 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | auth method', function(hooks) {
|
||||
module('Unit | Model | auth method', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('auth-method', {});
|
||||
assert.ok(model);
|
||||
|
||||
@@ -19,8 +19,8 @@ module('Unit | Model | base', function (hooks) {
|
||||
store.push({
|
||||
data: {
|
||||
id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
});
|
||||
store.push({
|
||||
data: {
|
||||
@@ -29,10 +29,10 @@ module('Unit | Model | base', function (hooks) {
|
||||
attributes: {
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const scope = store.peekRecord('scope', 'o_1');
|
||||
const model = store.peekRecord('user', '123abc');
|
||||
@@ -42,7 +42,7 @@ module('Unit | Model | base', function (hooks) {
|
||||
test('it may accept a `scopeModel` for convenience, instead of a fragment', function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const scope = store.createRecord('scope', {id: 'o_1', type: 'org'});
|
||||
const scope = store.createRecord('scope', { id: 'o_1', type: 'org' });
|
||||
const model = store.createRecord('user', '123abc');
|
||||
assert.notEqual(model.scopeID, scope.id);
|
||||
model.scopeModel = scope;
|
||||
@@ -98,17 +98,17 @@ module('Unit | Model | base', function (hooks) {
|
||||
const store = this.owner.lookup('service:store');
|
||||
const model = store.createRecord('user', { scopeID: 'o_123' });
|
||||
this.server.post('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.');
|
||||
return {};
|
||||
});
|
||||
await model.save();
|
||||
this.server.patch('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped update record URL was requested.')
|
||||
assert.ok(true, 'Correctly scoped update record URL was requested.');
|
||||
return {};
|
||||
});
|
||||
await model.save();
|
||||
this.server.delete('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped delete record URL was requested.')
|
||||
assert.ok(true, 'Correctly scoped delete record URL was requested.');
|
||||
return {};
|
||||
});
|
||||
await model.destroyRecord();
|
||||
@@ -118,35 +118,35 @@ module('Unit | Model | base', function (hooks) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const customScopeID = 'global';
|
||||
const scope = {scope_id: 'o_123'};
|
||||
const scope = { scope_id: 'o_123' };
|
||||
const model = store.createRecord('user', { scope });
|
||||
this.server.post('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.');
|
||||
return {};
|
||||
});
|
||||
await model.save({adapterOptions: {scopeID: customScopeID}});
|
||||
await model.save({ adapterOptions: { scopeID: customScopeID } });
|
||||
this.server.patch('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped update record URL was requested.')
|
||||
assert.ok(true, 'Correctly scoped update record URL was requested.');
|
||||
return {};
|
||||
});
|
||||
await model.save({adapterOptions: {scopeID: customScopeID}});
|
||||
await model.save({ adapterOptions: { scopeID: customScopeID } });
|
||||
this.server.delete('/v1/users', () => {
|
||||
assert.ok(true, 'Correctly scoped delete record URL was requested.')
|
||||
assert.ok(true, 'Correctly scoped delete record URL was requested.');
|
||||
return {};
|
||||
});
|
||||
await model.destroyRecord({adapterOptions: {scopeID: customScopeID}});
|
||||
await model.destroyRecord({ adapterOptions: { scopeID: customScopeID } });
|
||||
});
|
||||
|
||||
test('it saves records to a URL with a custom method if requested', async function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const method = 'my-custom-method';
|
||||
const scope = {scope_id: 'o_123'};
|
||||
const scope = { scope_id: 'o_123' };
|
||||
const model = store.createRecord('user', { scope });
|
||||
this.server.post(`/v1/users:${method}`, () => {
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.')
|
||||
assert.ok(true, 'Correctly scoped create record URL was requested.');
|
||||
return {};
|
||||
});
|
||||
await model.save({adapterOptions: {method}});
|
||||
await model.save({ adapterOptions: { method } });
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | fragment host set', function(hooks) {
|
||||
module('Unit | Model | fragment host set', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('fragment-host-set', {});
|
||||
assert.ok(model);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | fragment principal', function(hooks) {
|
||||
module('Unit | Model | fragment principal', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('fragment-principal', {});
|
||||
assert.ok(model);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | fragment string', function(hooks) {
|
||||
module('Unit | Model | fragment string', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('fragment-string', {});
|
||||
assert.ok(model);
|
||||
|
||||
@@ -2,11 +2,11 @@ import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
|
||||
module('Unit | Model | group', function(hooks) {
|
||||
module('Unit | Model | group', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
test('it has a `members` array of resolved model instances (if those instances are already in the store)', function(assert) {
|
||||
test('it has a `members` array of resolved model instances (if those instances are already in the store)', function (assert) {
|
||||
assert.expect(4);
|
||||
const store = this.owner.lookup('service:store');
|
||||
store.push({
|
||||
@@ -14,30 +14,42 @@ module('Unit | Model | group', function(hooks) {
|
||||
id: 'group_123',
|
||||
type: 'group',
|
||||
attributes: {
|
||||
member_ids: [ '1', '2', ]
|
||||
}
|
||||
}
|
||||
member_ids: ['1', '2'],
|
||||
},
|
||||
},
|
||||
});
|
||||
const group = store.peekRecord('group', 'group_123');
|
||||
assert.equal(group.member_ids.length, 2, 'Group has two entires in member_ids');
|
||||
assert.equal(group.members.length, 0, 'Group has no resolved members because they are not loaded yet');
|
||||
assert.equal(
|
||||
group.member_ids.length,
|
||||
2,
|
||||
'Group has two entires in member_ids'
|
||||
);
|
||||
assert.equal(
|
||||
group.members.length,
|
||||
0,
|
||||
'Group has no resolved members because they are not loaded yet'
|
||||
);
|
||||
store.push({
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'user',
|
||||
attributes: {}
|
||||
}
|
||||
attributes: {},
|
||||
},
|
||||
});
|
||||
store.push({
|
||||
data: {
|
||||
id: '2',
|
||||
type: 'user',
|
||||
attributes: {}
|
||||
}
|
||||
attributes: {},
|
||||
},
|
||||
});
|
||||
// eslint-disable-next-line no-self-assign
|
||||
group.member_ids = [...group.member_ids];
|
||||
assert.equal(group.member_ids.length, 2, 'Group has two entires in member_ids');
|
||||
assert.equal(
|
||||
group.member_ids.length,
|
||||
2,
|
||||
'Group has two entires in member_ids'
|
||||
);
|
||||
assert.equal(group.members.length, 2, 'Group has two resolved members');
|
||||
});
|
||||
|
||||
@@ -47,7 +59,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['123_abc', 'foobar'],
|
||||
version: 1
|
||||
version: 1,
|
||||
});
|
||||
});
|
||||
const store = this.owner.lookup('service:store');
|
||||
@@ -58,14 +70,14 @@ module('Unit | Model | group', function(hooks) {
|
||||
attributes: {
|
||||
name: 'Group',
|
||||
description: 'Description',
|
||||
member_ids: [ '1', '2' ],
|
||||
member_ids: ['1', '2'],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('group', '123abc');
|
||||
await model.addMembers(['123_abc', 'foobar']);
|
||||
@@ -77,7 +89,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['1', '3'],
|
||||
version: 1
|
||||
version: 1,
|
||||
});
|
||||
});
|
||||
const store = this.owner.lookup('service:store');
|
||||
@@ -88,14 +100,14 @@ module('Unit | Model | group', function(hooks) {
|
||||
attributes: {
|
||||
name: 'group',
|
||||
description: 'Description',
|
||||
member_ids: [ '4', '5' ],
|
||||
member_ids: ['4', '5'],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('group', '123abc');
|
||||
await model.removeMembers(['1', '3']);
|
||||
@@ -107,7 +119,7 @@ module('Unit | Model | group', function(hooks) {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
member_ids: ['3'],
|
||||
version: 1
|
||||
version: 1,
|
||||
});
|
||||
});
|
||||
const store = this.owner.lookup('service:store');
|
||||
@@ -118,29 +130,33 @@ module('Unit | Model | group', function(hooks) {
|
||||
attributes: {
|
||||
name: 'group',
|
||||
description: 'Description',
|
||||
member_ids: [ '1', '3' ],
|
||||
member_ids: ['1', '3'],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('group', '123abc');
|
||||
await model.removeMember('3');
|
||||
});
|
||||
|
||||
test('it defaults `members_ids` to an empty array when model instance does not define it', function(assert) {
|
||||
test('it defaults `members_ids` to an empty array when model instance does not define it', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
store.push({
|
||||
data: {
|
||||
id: 'group_123',
|
||||
type: 'group'
|
||||
}
|
||||
type: 'group',
|
||||
},
|
||||
});
|
||||
const group = store.peekRecord('group', 'group_123');
|
||||
assert.equal(group.member_ids.length, 0, 'Group has empty member_ids by default');
|
||||
assert.equal(
|
||||
group.member_ids.length,
|
||||
0,
|
||||
'Group has empty member_ids by default'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | host catalog', function(hooks) {
|
||||
module('Unit | Model | host catalog', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('host-catalog', {});
|
||||
assert.ok(model);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | host set', function(hooks) {
|
||||
module('Unit | Model | host set', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('host-set', {});
|
||||
assert.ok(model);
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | host', function(hooks) {
|
||||
module('Unit | Model | host', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('host', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
|
||||
test('it contains attributes', function(assert) {
|
||||
test('it contains attributes', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('host', {
|
||||
type: 'static',
|
||||
attributes: {
|
||||
address: '127.0.0.1'
|
||||
}
|
||||
address: '127.0.0.1',
|
||||
},
|
||||
});
|
||||
assert.equal(model.attributes.address, '127.0.0.1');
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ module('Unit | Model | role', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('role', {});
|
||||
assert.ok(model);
|
||||
@@ -18,7 +18,7 @@ module('Unit | Model | role', function (hooks) {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
grant_strings: ['grant1', 'grant2'],
|
||||
version: 1
|
||||
version: 1,
|
||||
});
|
||||
});
|
||||
const store = this.owner.lookup('service:store');
|
||||
@@ -29,14 +29,14 @@ module('Unit | Model | role', function (hooks) {
|
||||
attributes: {
|
||||
name: 'Role',
|
||||
description: 'Description',
|
||||
grants: [{value: 'grant1'}, {value: 'grant2'}],
|
||||
grants: [{ value: 'grant1' }, { value: 'grant2' }],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('role', '123abc');
|
||||
await model.saveGrants();
|
||||
@@ -48,7 +48,7 @@ module('Unit | Model | role', function (hooks) {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
principal_ids: ['123_abc', 'foobar'],
|
||||
version: 1
|
||||
version: 1,
|
||||
});
|
||||
});
|
||||
const store = this.owner.lookup('service:store');
|
||||
@@ -61,15 +61,15 @@ module('Unit | Model | role', function (hooks) {
|
||||
description: 'Description',
|
||||
principals: [
|
||||
{ id: '1', type: 'user' },
|
||||
{ id: '3', type: 'group' }
|
||||
{ id: '3', type: 'group' },
|
||||
],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('role', '123abc');
|
||||
await model.addPrincipals(['123_abc', 'foobar']);
|
||||
@@ -77,13 +77,16 @@ module('Unit | Model | role', function (hooks) {
|
||||
|
||||
test('it has a `removePrincipals` method that targets a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/roles/123abc:remove-principals', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
principal_ids: ['1', '3'],
|
||||
version: 1
|
||||
});
|
||||
});
|
||||
this.server.post(
|
||||
'/v1/roles/123abc:remove-principals',
|
||||
(schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
principal_ids: ['1', '3'],
|
||||
version: 1,
|
||||
});
|
||||
}
|
||||
);
|
||||
const store = this.owner.lookup('service:store');
|
||||
store.push({
|
||||
data: {
|
||||
@@ -94,15 +97,15 @@ module('Unit | Model | role', function (hooks) {
|
||||
description: 'Description',
|
||||
principals: [
|
||||
{ id: '1', type: 'user' },
|
||||
{ id: '3', type: 'group' }
|
||||
{ id: '3', type: 'group' },
|
||||
],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('role', '123abc');
|
||||
await model.removePrincipals(['1', '3']);
|
||||
@@ -110,13 +113,16 @@ module('Unit | Model | role', function (hooks) {
|
||||
|
||||
test('it has a `removePrincipal` method that deletes a single principal using `removePrincipals` method', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/roles/123abc:remove-principals', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
principal_ids: ['3'],
|
||||
version: 1
|
||||
});
|
||||
});
|
||||
this.server.post(
|
||||
'/v1/roles/123abc:remove-principals',
|
||||
(schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
principal_ids: ['3'],
|
||||
version: 1,
|
||||
});
|
||||
}
|
||||
);
|
||||
const store = this.owner.lookup('service:store');
|
||||
store.push({
|
||||
data: {
|
||||
@@ -127,15 +133,15 @@ module('Unit | Model | role', function (hooks) {
|
||||
description: 'Description',
|
||||
principals: [
|
||||
{ id: '1', type: 'user' },
|
||||
{ id: '3', type: 'group' }
|
||||
{ id: '3', type: 'group' },
|
||||
],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('role', '123abc');
|
||||
await model.removePrincipal('3');
|
||||
|
||||
@@ -2,37 +2,60 @@ import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
|
||||
module('Unit | Model | scope', function(hooks) {
|
||||
module('Unit | Model | scope', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
test('it may have a scope fragment', async function(assert) {
|
||||
test('it may have a scope fragment', async function (assert) {
|
||||
assert.expect(6);
|
||||
const store = this.owner.lookup('service:store');
|
||||
this.server.get('/v1/scopes', () => ({
|
||||
items: [
|
||||
{id: 'global', type: 'global'},
|
||||
{id: 'o_1', type: 'org', scope: {scope_id: 'global'}},
|
||||
{id: 'o_2', type: 'org', scope: {scope_id: 'global'}},
|
||||
{id: 'p_1', type: 'project', scope: {scope_id: 'o_1'}},
|
||||
{id: 'p_2', type: 'project', scope: {scope_id: 'o_1'}},
|
||||
{id: 'p_3', type: 'project', scope: {scope_id: 'o_2'}},
|
||||
]
|
||||
{ id: 'global', type: 'global' },
|
||||
{ id: 'o_1', type: 'org', scope: { scope_id: 'global' } },
|
||||
{ id: 'o_2', type: 'org', scope: { scope_id: 'global' } },
|
||||
{ id: 'p_1', type: 'project', scope: { scope_id: 'o_1' } },
|
||||
{ id: 'p_2', type: 'project', scope: { scope_id: 'o_1' } },
|
||||
{ id: 'p_3', type: 'project', scope: { scope_id: 'o_2' } },
|
||||
],
|
||||
}));
|
||||
const scopes = await store.findAll('scope');
|
||||
// check integrity of scope relationships
|
||||
assert.notOk(await scopes.firstObject.get('scope'), 'Global scope has no parent');
|
||||
assert.equal(await scopes.objectAt(1).get('scope.scope_id'), 'global', 'Org 1 parent scope is global');
|
||||
assert.equal(await scopes.objectAt(2).get('scope.scope_id'), 'global', 'Org 2 parent scope is global');
|
||||
assert.equal(await scopes.objectAt(3).get('scope.scope_id'), 'o_1', 'Project 1 parent scope is org 1');
|
||||
assert.equal(await scopes.objectAt(4).get('scope.scope_id'), 'o_1', 'Project 2 parent scope is org 1');
|
||||
assert.equal(await scopes.objectAt(5).get('scope.scope_id'), 'o_2', 'Project 3 parent scope is org 2');
|
||||
assert.notOk(
|
||||
await scopes.firstObject.get('scope'),
|
||||
'Global scope has no parent'
|
||||
);
|
||||
assert.equal(
|
||||
await scopes.objectAt(1).get('scope.scope_id'),
|
||||
'global',
|
||||
'Org 1 parent scope is global'
|
||||
);
|
||||
assert.equal(
|
||||
await scopes.objectAt(2).get('scope.scope_id'),
|
||||
'global',
|
||||
'Org 2 parent scope is global'
|
||||
);
|
||||
assert.equal(
|
||||
await scopes.objectAt(3).get('scope.scope_id'),
|
||||
'o_1',
|
||||
'Project 1 parent scope is org 1'
|
||||
);
|
||||
assert.equal(
|
||||
await scopes.objectAt(4).get('scope.scope_id'),
|
||||
'o_1',
|
||||
'Project 2 parent scope is org 1'
|
||||
);
|
||||
assert.equal(
|
||||
await scopes.objectAt(5).get('scope.scope_id'),
|
||||
'o_2',
|
||||
'Project 3 parent scope is org 2'
|
||||
);
|
||||
});
|
||||
|
||||
test('it has isType boolean getters and setters', async function(assert) {
|
||||
test('it has isType boolean getters and setters', async function (assert) {
|
||||
assert.expect(9);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const model = store.createRecord('scope', {type: 'global'});
|
||||
const model = store.createRecord('scope', { type: 'global' });
|
||||
assert.ok(model.isGlobal);
|
||||
assert.notOk(model.isOrg);
|
||||
assert.notOk(model.isProject);
|
||||
@@ -45,5 +68,4 @@ module('Unit | Model | scope', function(hooks) {
|
||||
assert.notOk(model.isOrg);
|
||||
assert.ok(model.isProject);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -6,7 +6,7 @@ module('Unit | Model | target', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
|
||||
test('it has a `hostSets` array of resolved model instances (if those instances are already in the store)', function(assert) {
|
||||
test('it has a `hostSets` array of resolved model instances (if those instances are already in the store)', function (assert) {
|
||||
assert.expect(6);
|
||||
const store = this.owner.lookup('service:store');
|
||||
store.push({
|
||||
@@ -16,41 +16,56 @@ module('Unit | Model | target', function (hooks) {
|
||||
attributes: {
|
||||
host_sets: [
|
||||
{ host_set_id: '1', host_catalog_id: '2' },
|
||||
{ host_set_id: '3', host_catalog_id: '2' }
|
||||
]
|
||||
}
|
||||
}
|
||||
{ host_set_id: '3', host_catalog_id: '2' },
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const target = store.peekRecord('target', '123abc');
|
||||
assert.equal(target.host_sets.length, 2, 'Target has two entires in host_sets');
|
||||
assert.equal(target.hostSets.length, 0, 'Target has no resolved hostSets because they are not loaded yet');
|
||||
assert.equal(
|
||||
target.host_sets.length,
|
||||
2,
|
||||
'Target has two entires in host_sets'
|
||||
);
|
||||
assert.equal(
|
||||
target.hostSets.length,
|
||||
0,
|
||||
'Target has no resolved hostSets because they are not loaded yet'
|
||||
);
|
||||
store.push({
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'host-set',
|
||||
attributes: {}
|
||||
}
|
||||
attributes: {},
|
||||
},
|
||||
});
|
||||
store.push({
|
||||
data: {
|
||||
id: '3',
|
||||
type: 'host-set',
|
||||
attributes: {}
|
||||
}
|
||||
attributes: {},
|
||||
},
|
||||
});
|
||||
// Since `hostSets` is computed on `host_sets`, not the store itself,
|
||||
// it's necessary to do this assignment to kick-off the computed update.
|
||||
// eslint-disable-next-line no-self-assign
|
||||
target.host_sets = target.host_sets;
|
||||
assert.equal(target.host_sets.length, 2, 'Target has two entires in host_sets');
|
||||
assert.equal(
|
||||
target.host_sets.length,
|
||||
2,
|
||||
'Target has two entires in host_sets'
|
||||
);
|
||||
assert.equal(target.hostSets.length, 2, 'Target has two resolved hostSets');
|
||||
assert.notOk(target.hostSets[0].hostCatalog, 'Host catalog was not resolved because it is not loaded yet');
|
||||
assert.notOk(
|
||||
target.hostSets[0].hostCatalog,
|
||||
'Host catalog was not resolved because it is not loaded yet'
|
||||
);
|
||||
store.push({
|
||||
data: {
|
||||
id: '2',
|
||||
type: 'host-catalog',
|
||||
attributes: {}
|
||||
}
|
||||
attributes: {},
|
||||
},
|
||||
});
|
||||
// eslint-disable-next-line no-self-assign
|
||||
target.host_sets = target.host_sets;
|
||||
@@ -63,7 +78,7 @@ module('Unit | Model | target', function (hooks) {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
host_set_ids: ['123_abc', 'foobar'],
|
||||
version: 1
|
||||
version: 1,
|
||||
});
|
||||
});
|
||||
const store = this.owner.lookup('service:store');
|
||||
@@ -76,15 +91,15 @@ module('Unit | Model | target', function (hooks) {
|
||||
description: 'Description',
|
||||
host_sets: [
|
||||
{ host_set_id: '1', host_catalog_id: '2' },
|
||||
{ host_set_id: '3', host_catalog_id: '4' }
|
||||
{ host_set_id: '3', host_catalog_id: '4' },
|
||||
],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('target', '123abc');
|
||||
await model.addHostSets(['123_abc', 'foobar']);
|
||||
@@ -92,13 +107,16 @@ module('Unit | Model | target', function (hooks) {
|
||||
|
||||
test('it has a `removeHostSets` method that targets a specific POST API endpoint and serialization', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/targets/123abc:remove-host-sets', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
host_set_ids: ['1', '3'],
|
||||
version: 1
|
||||
});
|
||||
});
|
||||
this.server.post(
|
||||
'/v1/targets/123abc:remove-host-sets',
|
||||
(schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
host_set_ids: ['1', '3'],
|
||||
version: 1,
|
||||
});
|
||||
}
|
||||
);
|
||||
const store = this.owner.lookup('service:store');
|
||||
store.push({
|
||||
data: {
|
||||
@@ -109,15 +127,15 @@ module('Unit | Model | target', function (hooks) {
|
||||
description: 'Description',
|
||||
host_sets: [
|
||||
{ host_set_id: '1', host_catalog_id: '2' },
|
||||
{ host_set_id: '3', host_catalog_id: '4' }
|
||||
{ host_set_id: '3', host_catalog_id: '4' },
|
||||
],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('target', '123abc');
|
||||
await model.removeHostSets(['1', '3']);
|
||||
@@ -125,13 +143,16 @@ module('Unit | Model | target', function (hooks) {
|
||||
|
||||
test('it has a `removeHostSet` method that deletes a single host set using `removeHostSets` method', async function (assert) {
|
||||
assert.expect(1);
|
||||
this.server.post('/v1/targets/123abc:remove-host-sets', (schema, request) => {
|
||||
const body = JSON.parse(request.requestBody);
|
||||
assert.deepEqual(body, {
|
||||
host_set_ids: ['3'],
|
||||
version: 1
|
||||
});
|
||||
});
|
||||
this.server.post(
|
||||
'/v1/targets/123abc:remove-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: {
|
||||
@@ -142,15 +163,15 @@ module('Unit | Model | target', function (hooks) {
|
||||
description: 'Description',
|
||||
host_sets: [
|
||||
{ host_set_id: '1', host_catalog_id: '2' },
|
||||
{ host_set_id: '3', host_catalog_id: '4' }
|
||||
{ host_set_id: '3', host_catalog_id: '4' },
|
||||
],
|
||||
version: 1,
|
||||
scope: {
|
||||
scope_id: 'o_1',
|
||||
type: 'scope'
|
||||
}
|
||||
}
|
||||
}
|
||||
type: 'scope',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const model = store.peekRecord('target', '123abc');
|
||||
await model.removeHostSet('3');
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Model | user', function(hooks) {
|
||||
module('Unit | Model | user', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let model = store.createRecord('user', {});
|
||||
assert.ok(model);
|
||||
|
||||
Reference in new issue
Block a user