chore: rip out scope service

This commit is contained in:
Randall Morey committed 2020-07-15 11:08:59 -04:00
1 parent a43efaddfa
commit 9261941c1b
24 files changed
+6 -384

No files matched your search

-16
View File
@@ -1,16 +0,0 @@
import ApplicationAdapter from './application';
import ScopeAdapterMixin from '../mixins/scope-adapter';
export default class AuthMethodAdapter extends ApplicationAdapter.extend(
ScopeAdapterMixin
) {
// =attributes
/**
* Auth method is scoped to org only.
* @type {boolean}
*/
includeProject = false;
}
-14
View File
@@ -1,14 +0,0 @@
import ApplicationAdapter from './application';
import ScopeAdapterMixin from '../mixins/scope-adapter';
export default class GroupAdapter extends ApplicationAdapter.extend(
ScopeAdapterMixin
) {
// =attributes
/**
* Group is scoped to org only, for now.
* @type {boolean}
*/
includeProject = false;
}
@@ -1,6 +0,0 @@
import ApplicationAdapter from './application';
import ScopeAdapterMixin from '../mixins/scope-adapter';
export default class HostCatalogAdapter extends ApplicationAdapter.extend(
ScopeAdapterMixin
) { }
-14
View File
@@ -1,14 +0,0 @@
import ApplicationAdapter from './application';
import ScopeAdapterMixin from '../mixins/scope-adapter';
export default class ProjectAdapter extends ApplicationAdapter.extend(
ScopeAdapterMixin
) {
// =attributes
/**
* Project is scoped to org only, technically.
* @type {boolean}
*/
includeProject = false;
}
-14
View File
@@ -1,14 +0,0 @@
import ApplicationAdapter from './application';
import ScopeAdapterMixin from '../mixins/scope-adapter';
export default class RoleAdapter extends ApplicationAdapter.extend(
ScopeAdapterMixin
) {
// =attributes
/**
* Role is scoped to org only, for now.
* @type {boolean}
*/
includeProject = false;
}
-14
View File
@@ -1,14 +0,0 @@
import ApplicationAdapter from './application';
import ScopeAdapterMixin from '../mixins/scope-adapter';
export default class UserAdapter extends ApplicationAdapter.extend(
ScopeAdapterMixin
) {
// =attributes
/**
* Project is scoped to org only, technically.
* @type {boolean}
*/
includeProject = false;
}
-123
View File
@@ -1,123 +0,0 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { computed } from '@ember/object';
/**
* This module includes two parts:
*
* - `Scope` class: a data structure representing an org/project tuple
* - `ScopeService`: manages the scope and exposes it to the application
*/
/**
* Represents a _scope_, which is defined as an organization/project tuple.
* This class is intended as a simple data structure and is used by the
* scope service (see below).
* Immutable.
*/
class Scope {
/**
* @type {?object}
* @private
*/
#org = null;
/**
* @type {?object}
* @private
*/
#project = null;
/**
* Initializes an instance of `Scope` with optional org and project.
* A scope with only project is invalid and in thi scenario, project will
* be null.
* @param {?object} org
* @param {?object} project
*/
constructor(org = null, project = null) {
if (org) this.#org = org;
if (org && project) this.#project = project;
}
/**
* Org for this scope. Immutable.
* @type {?object}
*/
get org() {
return this.#org;
}
/**
* Project for this scope.
* @type {?object}
*/
get project() {
return this.#project;
}
/**
* Returns the JSON representation of this scope.
* @return {?object}
*/
toJSON() {
const { org, project } = this;
return { org, project };
}
}
export { Scope };
/**
* The scope service manages the current scope, making it available throughout
* the Ember application. Use `service.org` and `service.project` directly,
* rather than interacting with the internal `scope` member.
*
* @example
* // inject the scope service
* import { inject as service } from '@ember/service';
* class MyClass {
* @service scope;
* }
*
* // set an org, project, or both
* this.scope.org = {id: 1};
* this.scope.project = {id: 2};
*
* // retrieve the org and/or project
* const org = this.scope.org;
* const project = this.scope.project;
*/
export default class ScopeService extends Service {
/**
* The currently selected scope. This is an internal member only.
* @type {?Scope}
*/
@tracked scope = new Scope();
/**
* When setting org, `service.org = {...}`, a new scope is instantiated,
* since scopes are immutable.
* @type {?object}
*/
@computed('scope.org')
get org() {
return this.scope ? this.scope.org : null;
}
set org(org) {
this.scope = new Scope(org, this.project);
}
/**
* When setting project, `service.project = {...}`, a new scope is
* instantiated, since scopes are immutable.
* @type {?object}
*/
@computed('scope.project')
get project() {
return this.scope ? this.scope.project : null;
}
set project(project) {
this.scope = new Scope(this.org, project);
}
}
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/adapters/auth-method';
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/adapters/group';
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/adapters/host-catalog';
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/adapters/project';
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/adapters/role';
-1
View File
@@ -1 +0,0 @@
export { default } from 'api/adapters/user';
-1
View File
@@ -1 +0,0 @@
export { default, Scope } from 'api/services/scope';
@@ -1,9 +1,6 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ApplicationRoute extends Route {
@service scope;
model() {
this.store.findAll('project');
}
@@ -37,7 +37,7 @@ module('Unit | Adapter | application', function (hooks) {
test('it prenormalizes "empty" responses into a form that the fetch-manager will not reject', async function (assert) {
assert.expect(1);
const adapter = this.owner.lookup('adapter:project');
const adapter = this.owner.lookup('adapter:application');
const store = this.owner.lookup('service:store');
this.server.get('/v1/projects', () => new Response({}));
const prenormalized = await adapter.findAll(store, {modelName: 'project'}, null, []);
@@ -1,16 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import config from 'ember-get-config';
module('Unit | Adapter | auth method', function (hooks) {
setupTest(hooks);
test('it generates URL prefixes without project scope', function (assert) {
assert.expect(1);
const service = this.owner.lookup('service:scope');
service.org = { id: 1 };
service.project = { id: 2 };
const adapter = this.owner.lookup('adapter:auth-method');
assert.equal(adapter.urlPrefix(), `${config.api.namespace}/orgs/1`);
});
});
@@ -1,21 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import config from 'ember-get-config';
module('Unit | Adapter | group', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let adapter = this.owner.lookup('adapter:group');
assert.ok(adapter);
});
test('it generates URL prefixes without project scope', function (assert) {
assert.expect(1);
const service = this.owner.lookup('service:scope');
service.org = { id: 1 };
service.project = { id: 2 };
const adapter = this.owner.lookup('adapter:group');
assert.equal(adapter.urlPrefix(), `${config.api.namespace}/orgs/1`);
});
});
@@ -1,11 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Adapter | host catalog', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let adapter = this.owner.lookup('adapter:host-catalog');
assert.ok(adapter);
});
});
@@ -1,16 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import config from 'ember-get-config';
module('Unit | Adapter | project', function (hooks) {
setupTest(hooks);
test('it generates URL prefixes without project scope', function (assert) {
assert.expect(1);
const service = this.owner.lookup('service:scope');
service.org = { id: 1 };
service.project = { id: 2 };
const adapter = this.owner.lookup('adapter:project');
assert.equal(adapter.urlPrefix(), `${config.api.namespace}/orgs/1`);
});
});
@@ -1,16 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import config from 'ember-get-config';
module('Unit | Adapter | role', function(hooks) {
setupTest(hooks);
test('it generates URL prefixes without project scope', function (assert) {
assert.expect(1);
const service = this.owner.lookup('service:scope');
service.org = { id: 1 };
service.project = { id: 2 };
const adapter = this.owner.lookup('adapter:role');
assert.equal(adapter.urlPrefix(), `${config.api.namespace}/orgs/1`);
});
});
@@ -1,21 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import config from 'ember-get-config';
module('Unit | Adapter | user', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let adapter = this.owner.lookup('adapter:user');
assert.ok(adapter);
});
test('it generates URL prefixes without project scope', function (assert) {
assert.expect(1);
const service = this.owner.lookup('service:scope');
service.org = { id: 1 };
service.project = { id: 2 };
const adapter = this.owner.lookup('adapter:user');
assert.equal(adapter.urlPrefix(), `${config.api.namespace}/orgs/1`);
});
});
@@ -1,14 +1,14 @@
import RESTAdapter from '@ember-data/adapter/rest';
import ScopeAdapterMixin from 'api/mixins/scope-adapter';
import { module, test } from 'qunit';
// import RESTAdapter from '@ember-data/adapter/rest';
// import ScopeAdapterMixin from 'api/mixins/scope-adapter';
import { module/*, test */} from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Mixin | scope-adapter', function (hooks) {
setupTest(hooks);
/*
test('it does not interfere with basic URLs', function (assert) {
assert.expect(1);
//const service = this.owner.lookup('service:scope');
const ScopeAdapter = RESTAdapter.extend(ScopeAdapterMixin);
this.owner.register('adapter:scope', ScopeAdapter);
const adapter = this.owner.lookup('adapter:scope');
@@ -18,7 +18,6 @@ module('Unit | Mixin | scope-adapter', function (hooks) {
test('it does not interfere with namespaced URLs', function (assert) {
assert.expect(1);
//const service = this.owner.lookup('service:scope');
const ScopeAdapter = RESTAdapter.extend(ScopeAdapterMixin, {
namespace: 'api/v1',
});
@@ -65,4 +64,5 @@ module('Unit | Mixin | scope-adapter', function (hooks) {
let url = adapter._buildURL('model', 1);
assert.equal(url, '/api/v1/orgs/1/models/1');
});
*/
});
@@ -1,66 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { Scope } from '../../../services/scope';
module('Unit | Service | scope class', function (hooks) {
setupTest(hooks);
test('it provides a scope class', function (assert) {
assert.expect(1);
assert.ok(Scope);
});
test('it has initializable org and project members', function (assert) {
assert.expect(2);
const org = { id: 1 };
const project = { id: 2 };
const scope = new Scope(org, project);
assert.equal(scope.org.id, 1);
assert.equal(scope.project.id, 2);
});
test('it has a null project if org is null, even if project was initialized to non-null', function (assert) {
assert.expect(2);
const org = null;
const project = { id: 2 };
const scope = new Scope(org, project);
assert.notOk(scope.org);
assert.notOk(scope.project);
});
test('it serializes to JSON', function (assert) {
assert.expect(2);
let scope = new Scope({ id: 1 });
assert.deepEqual(scope.toJSON(), {
org: { id: 1 },
project: null,
});
scope = new Scope({ id: 1 }, { id: 2 });
assert.deepEqual(scope.toJSON(), {
org: { id: 1 },
project: { id: 2 },
});
});
});
module('Unit | Service | scope', function (hooks) {
setupTest(hooks);
test('it returns nulls when scope is not set', function (assert) {
assert.expect(2);
const service = this.owner.lookup('service:scope');
assert.equal(service.org, null);
assert.equal(service.project, null);
});
test('it aliases org and project to a scope instance', function (assert) {
assert.expect(2);
const service = this.owner.lookup('service:scope');
const org = { id: 1 };
const project = { id: 2 };
service.org = org;
service.project = project;
assert.equal(service.org, service.scope.org);
assert.equal(service.project, service.scope.project);
});
});