From 20361ef00cd41ae02184db2cf735f00ac770457e Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 15 Jul 2020 11:52:39 -0400 Subject: [PATCH] chore: rip out scope adapter mixin --- addons/api/addon/mixins/scope-adapter.js | 53 --------------- .../tests/unit/mixins/scope-adapter-test.js | 68 ------------------- 2 files changed, 121 deletions(-) delete mode 100644 addons/api/addon/mixins/scope-adapter.js delete mode 100644 addons/api/tests/unit/mixins/scope-adapter-test.js diff --git a/addons/api/addon/mixins/scope-adapter.js b/addons/api/addon/mixins/scope-adapter.js deleted file mode 100644 index 705e5f1c0..000000000 --- a/addons/api/addon/mixins/scope-adapter.js +++ /dev/null @@ -1,53 +0,0 @@ -import Mixin from '@ember/object/mixin'; -import { inject as service } from '@ember/service'; - -/** - * Add this mixin to resource adapters which should be accessed via an - * org/project-scoped URL. This mixin appends a scope path based on the scope - * reported by `ScopeService`. - */ -export default Mixin.create({ - // =services - - scope: service(), - - // =properties - - /** - * If true and the current scope has a project, will include the project in - * the resource path. Set to false for resources that are scoped exclusively - * to org. - * @type {boolean} - */ - includeProject: true, - - // =methods - - /** - * Appends a scope path to the URL prefix, if a scope is set. - * @override - * @return {string} - */ - urlPrefix() { - const prefix = this._super(...arguments); - let scopePath = this.scopePath; - // Ensure a slash is added between prefix + scope path if needed. - if (scopePath && prefix.charAt(prefix.length - 1) !== '/') { - scopePath = `/${scopePath}`; - } - return `${prefix}${scopePath}`; - }, - - /** - * Generates a scope path for the current scope as reported by `ScopeService`. - * If no scope is set, returns empty string. - * @return {string} - */ - get scopePath() { - const { org, project } = this.scope; - const scopePath = []; - if (org) scopePath.push('orgs', org.id); - if (project && this.includeProject) scopePath.push('projects', project.id); - return scopePath.join('/'); - }, -}); diff --git a/addons/api/tests/unit/mixins/scope-adapter-test.js b/addons/api/tests/unit/mixins/scope-adapter-test.js deleted file mode 100644 index 9b6f8a455..000000000 --- a/addons/api/tests/unit/mixins/scope-adapter-test.js +++ /dev/null @@ -1,68 +0,0 @@ -// 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 ScopeAdapter = RESTAdapter.extend(ScopeAdapterMixin); - this.owner.register('adapter:scope', ScopeAdapter); - const adapter = this.owner.lookup('adapter:scope'); - const url = adapter._buildURL('model', 1); - assert.equal(url, '/models/1'); - }); - - test('it does not interfere with namespaced URLs', function (assert) { - assert.expect(1); - const ScopeAdapter = RESTAdapter.extend(ScopeAdapterMixin, { - namespace: 'api/v1', - }); - this.owner.register('adapter:scope', ScopeAdapter); - const adapter = this.owner.lookup('adapter:scope'); - const url = adapter._buildURL('model', 1); - assert.equal(url, '/api/v1/models/1'); - }); - - test('it adds a scope to basic URLs when scope is set', function (assert) { - assert.expect(4); - const service = this.owner.lookup('service:scope'); - service.org = { id: 1 }; - const ScopeAdapter = RESTAdapter.extend(ScopeAdapterMixin, { - namespace: 'api/v1', - }); - this.owner.register('adapter:scope', ScopeAdapter); - const adapter = this.owner.lookup('adapter:scope'); - let url = adapter._buildURL('model', 1); - assert.equal(url, '/api/v1/orgs/1/models/1'); - service.project = { id: 2 }; - url = adapter._buildURL('model', 1); - assert.equal(url, '/api/v1/orgs/1/projects/2/models/1'); - service.org = { id: 'foobar' }; - url = adapter._buildURL('model', 1); - assert.equal(url, '/api/v1/orgs/foobar/projects/2/models/1'); - // can't have a project without an org - service.org = null; - url = adapter._buildURL('model', 1); - assert.equal(url, '/api/v1/models/1'); - }); - - test('it does not add a project scope to basic URLs when includeProject is false', function (assert) { - assert.expect(1); - const service = this.owner.lookup('service:scope'); - service.org = { id: 1 }; - service.project = { id: 2 }; - const ScopeAdapter = RESTAdapter.extend(ScopeAdapterMixin, { - namespace: 'api/v1', - includeProject: false, - }); - this.owner.register('adapter:scope', ScopeAdapter); - const adapter = this.owner.lookup('adapter:scope'); - let url = adapter._buildURL('model', 1); - assert.equal(url, '/api/v1/orgs/1/models/1'); - }); - */ -});