From 3d304bf7feaea0206cac56720b3bdf2f9c28c0da Mon Sep 17 00:00:00 2001 From: Michael Krotscheck Date: Wed, 22 Jan 2014 11:25:59 -0800 Subject: [PATCH] Remove mock API interfaces from storyboard. This patch will remove the existing mock abstraction from storyboard, so that we can finally pair it with a real api. Change-Id: Ica72e8b71236033e1a7d34ed0e3c8177aad42917 --- src/app/services/mock/auth_provider_mock.js | 86 ----------- src/app/services/mock/mock_service.js | 163 -------------------- src/app/services/mock/project_mock.js | 58 ------- src/app/services/mock/task_mock.js | 34 ---- src/app/services/mock/team.js | 34 ---- src/app/services/mock/user_mock.js | 34 ---- src/app/services/module.js | 3 +- src/app/services/resource/project_group.js | 22 +-- 8 files changed, 2 insertions(+), 432 deletions(-) delete mode 100644 src/app/services/mock/auth_provider_mock.js delete mode 100644 src/app/services/mock/mock_service.js delete mode 100644 src/app/services/mock/project_mock.js delete mode 100644 src/app/services/mock/task_mock.js delete mode 100644 src/app/services/mock/team.js delete mode 100644 src/app/services/mock/user_mock.js diff --git a/src/app/services/mock/auth_provider_mock.js b/src/app/services/mock/auth_provider_mock.js deleted file mode 100644 index b96c609a..00000000 --- a/src/app/services/mock/auth_provider_mock.js +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the 'License'); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * Mock resource responses for the AuthProvider resource. - */ - -angular.module('sb.services') - .run(function (mock) { - 'use strict'; - - var authProviders = [ - { - 'id': 0, - 'type': 'openid', - 'title': 'OpenID', - 'url': 'https://login.launchpad.net/+openid', - 'params': { - 'openid.ns': 'http://specs.openid.net/auth/2.0', - 'openid.claimed_id': 'http://specs.openid.net/auth' + - '/2.0/identifier_select', - 'openid.identity': 'http://specs.openid.net/auth' + - '/2.0/identifier_select', -// 'openid.return_to': 'https://review.openstack.org/ -// openid?gerrit.mode=SIGN_IN&gerrit.token=%2Fq%2Fstatus%3Aopen%2Cn%2Cz', -// 'openid.realm': 'https://review.openstack.org/', - 'openid.assoc_handle': '{HMAC-SHA256}{52c79079}{z+v4vA==}', - 'openid.mode': 'checkid_setup', - 'openid.ns.sreg': 'http://openid.net/sreg/1.0', - 'openid.sreg.required': 'fullname,email', - 'openid.ns.ext2': 'http://openid.net/srv/ax/1.0', - 'openid.ext2.mode': 'fetch_request', - 'openid.ext2.type.FirstName': 'http://schema.openid.net/' + - 'namePerson/first', - 'openid.ext2.type.LastName': 'http://schema.openid.net/' + - 'namePerson/last', - 'openid.ext2.type.Email': 'http://schema.openid.net/' + - 'contact/email', - 'openid.ext2.required': 'FirstName,LastName,Email' - } - }, - { - 'id': 1, - 'type': 'openid_connect', - 'title': 'OpenID Connect', - 'url': 'https://www.google.com/prediscovered' + - '/redirection/url', - 'params': { - 'list': 'of', - 'additional': 'parameters', - 'required': 'for.this.provider' - } - }, - { - 'id': 2, - 'type': 'ldap', - 'title': 'LDAP', - 'url': 'https://www.google.com/prediscovered' + - '/redirection/url', - 'params': { - 'list': 'of', - 'additional': 'parameters', - 'required': 'for.this.provider' - } - } - ]; - - mock.api('/api/v1/auth/provider', - '/api/v1/auth/provider/:id', - 'id', - authProviders); - - }); \ No newline at end of file diff --git a/src/app/services/mock/mock_service.js b/src/app/services/mock/mock_service.js deleted file mode 100644 index cc534ff2..00000000 --- a/src/app/services/mock/mock_service.js +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * This service creates an automatic CRUD mock based on provided - * urls and data sets. - * - * TODO(krotscheck): Once we have a real API, we can remove this. - */ - -angular.module('sb.services') - .factory('mock', function ($log, $urlMatcherFactory, $httpBackend) { - 'use strict'; - - /** - * URL matcher factory generator, used for testing API urls for - * mocking. - * - * @param testUrl - */ - function matchUrl(testUrl) { - var urlMatcher = $urlMatcherFactory.compile(testUrl); - - return { - test: function (url) { - return urlMatcher.exec(url); - } - }; - } - - /** - * Utility method that extracts the array index from the default data - * passed. Necessary because to simulate our mock list, we're splicing - * all the time, so the actual indexes of the array may not match the - * ID's of the items therein. - */ - function getIndexById(defaultData, idParamName, id) { - for (var i = 0; i < defaultData.length; i++) { - var item = defaultData[i]; - if (item[idParamName] === id) { - return i; - } - } - - return false; - } - - return { - /** - * This method mocks an entire RESTful api endpoint. - */ - api: function (searchUrl, crudUrl, crudIdParamName, defaultData) { - this.search(searchUrl, defaultData); - this.crud(searchUrl, crudUrl, crudIdParamName, defaultData); - }, - - /** - * This method creates a mock search service for the passed URL and - * the provided data hash. - */ - search: function (searchUrl, defaultData) { - $httpBackend.when('GET', matchUrl(searchUrl)) - .respond(function (method, url) { - $log.info('[mock] ' + method + ' ' + url); - return [200, { - total: defaultData.length, - offset: 0, - limit: defaultData.length, - results: defaultData - }]; - } - ); - }, - /** - * This method creates a mock CRUD service for the passed URL, - * ID parameter name, and data hash - */ - crud: function (createUrl, crudUrl, idParamName, defaultData) { - var crudMatcher = matchUrl(crudUrl); - var createMatcher = matchUrl(createUrl); - - /** - * Mock responder for a POST action. Extracts the ID from the - * last item in our default data array and increments it, then - * adds another item with that same ID. - */ - var createResolver = function (method, url, body) { - $log.info('[mock] ' + method + ' ' + url); - - body = JSON.parse(body); - var now = Math.round(new Date().getTime() / 1000); - body.id = defaultData[defaultData.length - 1].id + 1; - // jshint -W106 - body.created_at = now; - body.updated_at = now; - // jshint +W106 - defaultData[body.id] = body; - console.warn(defaultData); - return [201, body]; - }; - - /** - * Mock responder for Get/Update/Delete. Given an existing ID, - * extracts the data from that location and either just sends - * it back, or manipulates it as requested. - */ - var rudResolver = function (method, url, body) { - $log.info('[mock] ' + method + ' ' + url); - - if (!!body) { - body = JSON.parse(body); - } - - var id = parseInt(crudMatcher.test(url).id); - var idx = getIndexById(defaultData, idParamName, id); - var now = Math.round(new Date().getTime() / 1000); - - if (idx === false) { - return [404]; - } - - // Temporarily disable the camelcase JSHint rule. - // jshint -W106 - switch (method) { - case 'GET': - return [200, defaultData[idx]]; - case 'PUT': - body.id = id; - body.updated_at = now; - defaultData[idx] = body; - return [200, defaultData[idx]]; - case 'DELETE': - defaultData.splice(idx, 1); - return [200]; - } - // Re-enable camelcase check. - // jshint +W106 - }; - - $httpBackend.when('POST', createMatcher) - .respond(createResolver); - $httpBackend.when('GET', crudMatcher) - .respond(rudResolver); - $httpBackend.when('PUT', crudMatcher) - .respond(rudResolver); - $httpBackend.when('DELETE', crudMatcher) - .respond(rudResolver); - } - }; - }); \ No newline at end of file diff --git a/src/app/services/mock/project_mock.js b/src/app/services/mock/project_mock.js deleted file mode 100644 index 1d411349..00000000 --- a/src/app/services/mock/project_mock.js +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * Mock resource responses for the Project resource. - */ - -angular.module('sb.services') - .run(function (mock) { - 'use strict'; - - var projects = [ - { - 'id': 0, - 'created_at': 12000000, - 'updated_at': 12000000, - 'name': 'Test Project 1', - 'description': 'Let\'s make orange juice', - 'team_id': null - }, - { - 'id': 1, - 'created_at': 12000000, - 'updated_at': 12000000, - 'name': 'Test Project 2', - 'description': 'Let\'s make apple juice', - 'team_id': null - }, - { - 'id': 2, - 'created_at': 12000000, - 'updated_at': 12000000, - 'name': 'Test Project 3', - 'description': 'Let\'s make lemonade', - 'team_id': null - } - ]; - - mock.api('/api/v1/projects', - '/api/v1/projects/:id', - 'id', - projects); - } -) -; \ No newline at end of file diff --git a/src/app/services/mock/task_mock.js b/src/app/services/mock/task_mock.js deleted file mode 100644 index 71b34474..00000000 --- a/src/app/services/mock/task_mock.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * Mock resource responses for the Task resource. - */ - -angular.module('sb.services') - .run(function (mock) { - 'use strict'; - - var tasks = [ - ]; - - mock.api('/api/v1/tasks', - '/api/v1/tasks/:id', - 'id', - tasks); - } -) -; \ No newline at end of file diff --git a/src/app/services/mock/team.js b/src/app/services/mock/team.js deleted file mode 100644 index 1cfc2e26..00000000 --- a/src/app/services/mock/team.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * Mock resource responses for the Team resource. - */ - -angular.module('sb.services') - .run(function (mock) { - 'use strict'; - - var team = [ - ]; - - mock.api('/api/v1/teams', - '/api/v1/teams/:id', - 'id', - team); - } -) -; \ No newline at end of file diff --git a/src/app/services/mock/user_mock.js b/src/app/services/mock/user_mock.js deleted file mode 100644 index 0d1f8369..00000000 --- a/src/app/services/mock/user_mock.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * Mock resource responses for the User resource. - */ - -angular.module('sb.services') - .run(function (mock) { - 'use strict'; - - var users = [ - ]; - - mock.api('/api/v1/users', - '/api/v1/users/:id', - 'id', - users); - } -) -; \ No newline at end of file diff --git a/src/app/services/module.js b/src/app/services/module.js index 135ea440..ffaa62f8 100644 --- a/src/app/services/module.js +++ b/src/app/services/module.js @@ -21,5 +21,4 @@ * * @author Michael Krotscheck */ -angular.module('sb.services', ['ngResource', 'ngCookies', 'ngMock', - 'ui.router']); \ No newline at end of file +angular.module('sb.services', ['ngResource', 'ngCookies']); \ No newline at end of file diff --git a/src/app/services/resource/project_group.js b/src/app/services/resource/project_group.js index 652056f7..2675b7bd 100644 --- a/src/app/services/resource/project_group.js +++ b/src/app/services/resource/project_group.js @@ -27,24 +27,4 @@ angular.module('sb.services').factory('ProjectGroup', return $resource(storyboardApiBase + '/project_groups/:id', {id: '@id'}, storyboardApiSignature); - }); - - -/* - This is initial commit adding pecan/wsme framework. - Example operations are: - * GET /v1/project_groups - * GET /v1/project_groups/ - - * GET /v1/projects - * GET /v1/projects/ - - * GET /v1/teams - * GET /v1/teams/ - * POST /v1/teams - - * GET /v1/users - * GET /v1/users/ - * POST /v1/users - * PUT /v1/users/ - */ \ No newline at end of file + }); \ No newline at end of file