From 76abcd6d5193c6946470bb3ac2c942fdda5ae414 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 12 May 2016 12:20:07 +0200 Subject: [PATCH 01/49] Install ember-cli-mirage --- app/app/mirage/config.js | 82 +++++++++++++++++++++++++++++ app/app/mirage/factories/contact.js | 20 +++++++ app/app/mirage/scenarios/default.js | 7 +++ app/bower.json | 5 +- app/package.json | 3 +- 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 app/app/mirage/config.js create mode 100644 app/app/mirage/factories/contact.js create mode 100644 app/app/mirage/scenarios/default.js diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js new file mode 100644 index 00000000..d006425e --- /dev/null +++ b/app/app/mirage/config.js @@ -0,0 +1,82 @@ +export default function() { + + // These comments are here to help you get started. Feel free to delete them. + + /* + Config (with defaults). + + Note: these only affect routes defined *after* them! + */ + // this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server + // this.namespace = ''; // make this `api`, for example, if your API is namespaced + // this.timing = 400; // delay for each request, automatically set to 0 during testing + + /* + Route shorthand cheatsheet + */ + /* + GET shorthands + + // Collections + this.get('/contacts'); + this.get('/contacts', 'users'); + this.get('/contacts', ['contacts', 'addresses']); + + // Single objects + this.get('/contacts/:id'); + this.get('/contacts/:id', 'user'); + this.get('/contacts/:id', ['contact', 'addresses']); + */ + + /* + POST shorthands + + this.post('/contacts'); + this.post('/contacts', 'user'); // specify the type of resource to be created + */ + + /* + PUT shorthands + + this.put('/contacts/:id'); + this.put('/contacts/:id', 'user'); // specify the type of resource to be updated + */ + + /* + DELETE shorthands + + this.del('/contacts/:id'); + this.del('/contacts/:id', 'user'); // specify the type of resource to be deleted + + // Single object + related resources. Make sure parent resource is first. + this.del('/contacts/:id', ['contact', 'addresses']); + */ + + /* + Function fallback. Manipulate data in the db via + + - db.{collection} + - db.{collection}.find(id) + - db.{collection}.where(query) + - db.{collection}.update(target, attrs) + - db.{collection}.remove(target) + + // Example: return a single object with related models + this.get('/contacts/:id', function(db, request) { + var contactId = +request.params.id; + + return { + contact: db.contacts.find(contactId), + addresses: db.addresses.where({contact_id: contactId}) + }; + }); + + */ +} + +/* +You can optionally export a config that is only loaded during tests +export function testConfig() { + +} +*/ diff --git a/app/app/mirage/factories/contact.js b/app/app/mirage/factories/contact.js new file mode 100644 index 00000000..1b3a3eab --- /dev/null +++ b/app/app/mirage/factories/contact.js @@ -0,0 +1,20 @@ +/* + This is an example factory definition. + + Create more files in this directory to define additional factories. +*/ +import Mirage/*, {faker} */ from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({ + // name: 'Pete', // strings + // age: 20, // numbers + // tall: true, // booleans + + // email: function(i) { // and functions + // return 'person' + i + '@test.com'; + // }, + + // firstName: faker.name.firstName, // using faker + // lastName: faker.name.firstName, + // zipCode: faker.address.zipCode +}); diff --git a/app/app/mirage/scenarios/default.js b/app/app/mirage/scenarios/default.js new file mode 100644 index 00000000..e07271cc --- /dev/null +++ b/app/app/mirage/scenarios/default.js @@ -0,0 +1,7 @@ +export default function(/* server */) { + + // Seed your development database using your factories. This + // data will not be loaded in your tests. + + // server.createList('contact', 10); +} diff --git a/app/bower.json b/app/bower.json index b17f0403..ba2ada57 100644 --- a/app/bower.json +++ b/app/bower.json @@ -8,7 +8,10 @@ "jquery": "*", "loader.js": "^3.5.0", "qunit": "~1.20.0", - "install": "~1.0.4" + "install": "~1.0.4", + "pretender": "~0.10.1", + "lodash": "~3.7.0", + "Faker": "~3.0.0" }, "resolutions": { "jquery": ">=2.1.1", diff --git a/app/package.json b/app/package.json index d3c16066..155890d2 100644 --- a/app/package.json +++ b/app/package.json @@ -29,6 +29,7 @@ "ember-cli-htmlbars-inline-precompile": "^0.3.1", "ember-cli-inject-live-reload": "^1.4.0", "ember-cli-jshint": "^1.0.0", + "ember-cli-mirage": "0.1.13", "ember-cli-qunit": "^1.4.0", "ember-cli-release": "0.2.8", "ember-cli-sass": "5.3.1", @@ -40,4 +41,4 @@ "ember-resolver": "^2.0.3", "loader.js": "^4.0.1" } -} \ No newline at end of file +} From 8624d21e5348e14fc05d9af6c34dee40b75c7a7a Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 12 May 2016 16:40:40 +0200 Subject: [PATCH 02/49] Make tests load --- app/app/mirage/config.js | 10 +++++++++- app/app/router.js | 8 ++++---- app/config/environment.js | 14 +++++++++----- app/tests/index.html | 18 +++++++++++++----- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index d006425e..eee36605 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -8,7 +8,7 @@ export default function() { Note: these only affect routes defined *after* them! */ // this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server - // this.namespace = ''; // make this `api`, for example, if your API is namespaced + this.namespace = 'api/public'; // make this `api`, for example, if your API is namespaced // this.timing = 400; // delay for each request, automatically set to 0 during testing /* @@ -17,6 +17,8 @@ export default function() { /* GET shorthands + this.get() + // Collections this.get('/contacts'); this.get('/contacts', 'users'); @@ -28,6 +30,12 @@ export default function() { this.get('/contacts/:id', ['contact', 'addresses']); */ + this.get('/authenticate', function() { + return { + + }; + }); + /* POST shorthands diff --git a/app/app/router.js b/app/app/router.js index dd9b740a..11979a7f 100644 --- a/app/app/router.js +++ b/app/app/router.js @@ -94,9 +94,9 @@ export default Router.map(function() { path: 'widgets' }); - this.route('not-found', { - path: '/*wildcard' - }); + // this.route('not-found', { + // path: '/*wildcard' + // }); this.route('pods', function() {}); -}); \ No newline at end of file +}); diff --git a/app/config/environment.js b/app/config/environment.js index 77f0ac3b..5ddcd95a 100644 --- a/app/config/environment.js +++ b/app/config/environment.js @@ -24,6 +24,9 @@ module.exports = function(environment) { EmberENV: { FEATURES: {} + }, + "ember-cli-mirage": { + enabled: false }, APP: {} }; @@ -42,12 +45,13 @@ module.exports = function(environment) { ENV.APP.LOG_VIEW_LOOKUPS = false; // ENV.APP.LOG_TRANSITIONS = false; // ENV.APP.LOG_TRANSITIONS_INTERNAL = false; - ENV.APP.LOG_TRANSITIONS = true; - ENV.APP.LOG_TRANSITIONS_INTERNAL = true; - // ENV.baseURL = '/'; - // ENV.locationType = 'none'; - // ENV.APP.rootElement = '#ember-testing'; + ENV.baseURL = '/'; + ENV.locationType = 'none'; + ENV.APP.rootElement = '#ember-testing'; + ENV['ember-cli-mirage'] = { + enabled: true + }; ENV.apiHost = "https://localhost:5001"; // ENV.apiHost = "https://demo1.dev:5001"; diff --git a/app/tests/index.html b/app/tests/index.html index d8285128..8c89846b 100644 --- a/app/tests/index.html +++ b/app/tests/index.html @@ -6,15 +6,22 @@ Documize Tests - {{content-for "head"}} {{content-for "test-head"}} + + + {{content-for "head"}} + {{content-for "test-head"}} - {{content-for "head-footer"}} {{content-for "test-head-footer"}} + + + {{content-for "head-footer"}} + {{content-for "test-head-footer"}} - {{content-for "body"}} {{content-for "test-body"}} + {{content-for "body"}} + {{content-for "test-body"}} @@ -23,7 +30,8 @@ - {{content-for "body-footer"}} {{content-for "test-body-footer"}} + {{content-for "body-footer"}} + {{content-for "test-body-footer"}} - \ No newline at end of file + From 08fad01c6fed19dd8536beb153704bedbd023d2f Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 12 May 2016 16:41:09 +0200 Subject: [PATCH 03/49] Clean up tests before starting to add new once --- app/tests/acceptance/index-test.js | 19 ++++++++++ app/tests/acceptance/login-test.js | 35 ------------------- app/tests/acceptance/nologin-test.js | 12 ------- .../section/gemini/type-editor-test.js | 24 ------------- .../section/gemini/type-renderer-test.js | 24 ------------- .../unit/helpers/document/file-icon-test.js | 14 -------- app/tests/unit/helpers/formatted-date-test.js | 9 ----- app/tests/unit/helpers/time-ago-test.js | 9 ----- app/tests/unit/helpers/user-initials-test.js | 9 ----- app/tests/unit/initializers/audit-test.js | 22 ------------ app/tests/unit/mixins/notifier-test.js | 12 ------- app/tests/unit/mixins/tooltip-test.js | 12 ------- .../unit/pods/document/wizard/route-test.js | 11 ------ app/tests/unit/routes/document/wizard-test.js | 11 ------ app/tests/unit/services/section-test.js | 12 ------- app/tests/unit/utils/date-test.js | 33 ----------------- app/tests/unit/utils/encoding-test.js | 9 ----- app/tests/unit/utils/string-test.js | 14 -------- 18 files changed, 19 insertions(+), 272 deletions(-) create mode 100644 app/tests/acceptance/index-test.js delete mode 100644 app/tests/acceptance/login-test.js delete mode 100644 app/tests/acceptance/nologin-test.js delete mode 100644 app/tests/integration/components/section/gemini/type-editor-test.js delete mode 100644 app/tests/integration/components/section/gemini/type-renderer-test.js delete mode 100644 app/tests/unit/helpers/document/file-icon-test.js delete mode 100644 app/tests/unit/helpers/formatted-date-test.js delete mode 100644 app/tests/unit/helpers/time-ago-test.js delete mode 100644 app/tests/unit/helpers/user-initials-test.js delete mode 100644 app/tests/unit/initializers/audit-test.js delete mode 100644 app/tests/unit/mixins/notifier-test.js delete mode 100644 app/tests/unit/mixins/tooltip-test.js delete mode 100644 app/tests/unit/pods/document/wizard/route-test.js delete mode 100644 app/tests/unit/routes/document/wizard-test.js delete mode 100644 app/tests/unit/services/section-test.js delete mode 100644 app/tests/unit/utils/date-test.js delete mode 100644 app/tests/unit/utils/encoding-test.js delete mode 100644 app/tests/unit/utils/string-test.js diff --git a/app/tests/acceptance/index-test.js b/app/tests/acceptance/index-test.js new file mode 100644 index 00000000..b91d1d0a --- /dev/null +++ b/app/tests/acceptance/index-test.js @@ -0,0 +1,19 @@ +import { test } from 'qunit'; +import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; + +moduleForAcceptance('Acceptance | /'); + +// TODO: when accessing / with /api/public/meta -> { allowAnonymousAccess: false } then take user to login +// TODO: when accessing / with /api/public/meta -> { allowAnonymousAccess: true } then take user to folers.index +// TODO: when accessing / with /api/public/meta -> { allowAnonymousAccess: true } and user is authenticated -> show authenticated user information + +test('visiting /', function(assert) { + visit('/'); + + // setup mirage for /api/public/meta -> { allowAnonymousAccess: false} + + + andThen(function() { + assert.equal(currentURL(), '/login'); + }); +}); diff --git a/app/tests/acceptance/login-test.js b/app/tests/acceptance/login-test.js deleted file mode 100644 index 9ecbe69e..00000000 --- a/app/tests/acceptance/login-test.js +++ /dev/null @@ -1,35 +0,0 @@ -import Ember from 'ember'; -import { - module, - test -} from 'qunit'; -import startApp from 'ember-testing/tests/helpers/start-app'; -import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; - -moduleForAcceptance('Acceptance | login'); - -var application; - -module('Acceptance | login', { - beforeEach: function() { - application = startApp(); - window.localStorage.removeItem('token'); - window.localStorage.removeItem('user'); - window.localStorage.removeItem('folder'); - }, - - afterEach: function() { - Ember.run(application, 'destroy'); - } -}); - - -test('visiting /auth/login', function(assert) { - visit('/auth/login'); - // fillIn('#authEmail', 'harvey@kandola.com'); - // fillIn('#authPassword', 'demo123'); - // click('button'); - andThen(function() { - assert.equal(currentURL(), '/auth/login'); - }); -}); \ No newline at end of file diff --git a/app/tests/acceptance/nologin-test.js b/app/tests/acceptance/nologin-test.js deleted file mode 100644 index 5db6fd84..00000000 --- a/app/tests/acceptance/nologin-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { test } from 'qunit'; -import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; - -moduleForAcceptance('Acceptance | nologin'); - -test('visiting /', function(assert) { - visit('/'); - - andThen(function() { - assert.equal(currentURL().substring(0, 3), '/s/'); // NOTE because we do not know the correct uuid/space for the database being tested - }); -}); diff --git a/app/tests/integration/components/section/gemini/type-editor-test.js b/app/tests/integration/components/section/gemini/type-editor-test.js deleted file mode 100644 index 10f5704c..00000000 --- a/app/tests/integration/components/section/gemini/type-editor-test.js +++ /dev/null @@ -1,24 +0,0 @@ -import { moduleForComponent, test } from 'ember-qunit'; -import hbs from 'htmlbars-inline-precompile'; - -moduleForComponent('section/gemini/type-editor', 'Integration | Component | section/gemini/type editor', { - integration: true -}); - -test('it renders', function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.on('myAction', function(val) { ... }); - - this.render(hbs`{{section/gemini/type-editor}}`); - - assert.equal(this.$().text().trim(), ''); - - // Template block usage: - this.render(hbs` - {{#section/gemini/type-editor}} - template block text - {{/section/gemini/type-editor}} - `); - - assert.equal(this.$().text().trim(), 'template block text'); -}); diff --git a/app/tests/integration/components/section/gemini/type-renderer-test.js b/app/tests/integration/components/section/gemini/type-renderer-test.js deleted file mode 100644 index 3655012f..00000000 --- a/app/tests/integration/components/section/gemini/type-renderer-test.js +++ /dev/null @@ -1,24 +0,0 @@ -import { moduleForComponent, test } from 'ember-qunit'; -import hbs from 'htmlbars-inline-precompile'; - -moduleForComponent('section/gemini/type-renderer', 'Integration | Component | section/gemini/type renderer', { - integration: true -}); - -test('it renders', function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.on('myAction', function(val) { ... }); - - this.render(hbs`{{section/gemini/type-renderer}}`); - - assert.equal(this.$().text().trim(), ''); - - // Template block usage: - this.render(hbs` - {{#section/gemini/type-renderer}} - template block text - {{/section/gemini/type-renderer}} - `); - - assert.equal(this.$().text().trim(), 'template block text'); -}); diff --git a/app/tests/unit/helpers/document/file-icon-test.js b/app/tests/unit/helpers/document/file-icon-test.js deleted file mode 100644 index 89dca6ac..00000000 --- a/app/tests/unit/helpers/document/file-icon-test.js +++ /dev/null @@ -1,14 +0,0 @@ -import { documentFileIcon } from '../../../../helpers/document/file-icon'; -import { module, test } from 'qunit'; - -module('Unit | Helper | document/file icon'); - -test('should be file icon of ZIP', function(assert) { - let result = documentFileIcon(["zIp"]); - assert.equal(result, "zip.png"); -}); - -test('should be file icon of ZIP (tar)', function(assert) { - let result = documentFileIcon(["TAR"]); - assert.equal(result, "zip.png"); -}); diff --git a/app/tests/unit/helpers/formatted-date-test.js b/app/tests/unit/helpers/formatted-date-test.js deleted file mode 100644 index 3e77b535..00000000 --- a/app/tests/unit/helpers/formatted-date-test.js +++ /dev/null @@ -1,9 +0,0 @@ -import { formattedDate } from '../../../helpers/formatted-date'; -import { module, test } from 'qunit'; - -module('Unit | Helper | formatted date'); - -test('should format date', function(assert) { - let result = formattedDate([new Date("1995-12-17T20:18:00"), "Do MMMM YYYY, HH:mm"]); - assert.equal(result, "17th December 1995, 20:18"); -}); diff --git a/app/tests/unit/helpers/time-ago-test.js b/app/tests/unit/helpers/time-ago-test.js deleted file mode 100644 index 82a99e84..00000000 --- a/app/tests/unit/helpers/time-ago-test.js +++ /dev/null @@ -1,9 +0,0 @@ -import { timeAgo } from '../../../helpers/time-ago'; -import { module, test } from 'qunit'; - -module('Unit | Helper | time ago'); - -test('should format date as time ago', function(assert) { - let result = timeAgo([new Date()]); - assert.equal(result, "a few seconds ago"); -}); diff --git a/app/tests/unit/helpers/user-initials-test.js b/app/tests/unit/helpers/user-initials-test.js deleted file mode 100644 index a64893f9..00000000 --- a/app/tests/unit/helpers/user-initials-test.js +++ /dev/null @@ -1,9 +0,0 @@ -import { userInitials } from '../../../helpers/user-initials'; -import { module, test } from 'qunit'; - -module('Unit | Helper | user initials'); - -test('should uppercase initials from firstname lastname', function(assert) { - let result = userInitials(["Some", "name"]); - assert.equal(result, "SN"); -}); diff --git a/app/tests/unit/initializers/audit-test.js b/app/tests/unit/initializers/audit-test.js deleted file mode 100644 index 7f80c3b1..00000000 --- a/app/tests/unit/initializers/audit-test.js +++ /dev/null @@ -1,22 +0,0 @@ -import Ember from 'ember'; -import AuditInitializer from '../../../initializers/audit'; -import { module, test } from 'qunit'; - -let application; - -module('Unit | Initializer | audit', { - beforeEach() { - Ember.run(function() { - application = Ember.Application.create(); - application.deferReadiness(); - }); - } -}); - -// Replace this with your real tests. -test('it works', function(assert) { - AuditInitializer.initialize(application); - - // you would normally confirm the results of the initializer here - assert.ok(true); -}); diff --git a/app/tests/unit/mixins/notifier-test.js b/app/tests/unit/mixins/notifier-test.js deleted file mode 100644 index 1885603b..00000000 --- a/app/tests/unit/mixins/notifier-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import Ember from 'ember'; -import NotifierMixin from '../../../mixins/notifier'; -import { module, test } from 'qunit'; - -module('Unit | Mixin | notifier'); - -// Replace this with your real tests. -test('it works', function(assert) { - let NotifierObject = Ember.Object.extend(NotifierMixin); - let subject = NotifierObject.create(); - assert.ok(subject); -}); diff --git a/app/tests/unit/mixins/tooltip-test.js b/app/tests/unit/mixins/tooltip-test.js deleted file mode 100644 index 31bdac82..00000000 --- a/app/tests/unit/mixins/tooltip-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import Ember from 'ember'; -import TooltipMixin from '../../../mixins/tooltip'; -import { module, test } from 'qunit'; - -module('Unit | Mixin | tooltip'); - -// Replace this with your real tests. -test('it works', function(assert) { - let TooltipObject = Ember.Object.extend(TooltipMixin); - let subject = TooltipObject.create(); - assert.ok(subject); -}); diff --git a/app/tests/unit/pods/document/wizard/route-test.js b/app/tests/unit/pods/document/wizard/route-test.js deleted file mode 100644 index a05271f5..00000000 --- a/app/tests/unit/pods/document/wizard/route-test.js +++ /dev/null @@ -1,11 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('route:document/wizard', 'Unit | Route | document/wizard', { - // Specify the other units that are required for this test. - // needs: ['controller:foo'] -}); - -test('it exists', function(assert) { - let route = this.subject(); - assert.ok(route); -}); diff --git a/app/tests/unit/routes/document/wizard-test.js b/app/tests/unit/routes/document/wizard-test.js deleted file mode 100644 index a05271f5..00000000 --- a/app/tests/unit/routes/document/wizard-test.js +++ /dev/null @@ -1,11 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('route:document/wizard', 'Unit | Route | document/wizard', { - // Specify the other units that are required for this test. - // needs: ['controller:foo'] -}); - -test('it exists', function(assert) { - let route = this.subject(); - assert.ok(route); -}); diff --git a/app/tests/unit/services/section-test.js b/app/tests/unit/services/section-test.js deleted file mode 100644 index 6b77e35d..00000000 --- a/app/tests/unit/services/section-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('service:section', 'Unit | Service | section', { - // Specify the other units that are required for this test. - // needs: ['service:foo'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let service = this.subject(); - assert.ok(service); -}); diff --git a/app/tests/unit/utils/date-test.js b/app/tests/unit/utils/date-test.js deleted file mode 100644 index a13ad94c..00000000 --- a/app/tests/unit/utils/date-test.js +++ /dev/null @@ -1,33 +0,0 @@ -import dateUtil from '../../../utils/date'; -import { module, test } from 'qunit'; - -module('Unit | Utility | date helpers'); - -test("should calculate time ago of a few seconds", function(assert) { - let result = dateUtil.timeAgo(new Date()); - assert.equal(result, "a few seconds ago"); -}); - -test("should calculate time ago of a day", function(assert) { - var temp = new Date(); - temp.setDate(temp.getDate()-1); - let result = dateUtil.timeAgo(temp); - assert.equal(result, "a day ago"); -}); - -test("should calculate time ago of 2 days", function(assert) { - var temp = new Date(); - temp.setDate(temp.getDate()-2); - let result = dateUtil.timeAgo(temp); - assert.equal(result, "2 days ago"); -}); - -test("should handle ISO date", function(assert) { - let result = dateUtil.toIsoDate(new Date("1995, 12, 17")); - assert.equal(result, "1995-12-17T00:00:00+00:00"); -}); - -test("should format short date", function(assert) { - let result = dateUtil.toShortDate(new Date("1995, 12, 17")); - assert.equal(result, "1995/12/17"); -}); diff --git a/app/tests/unit/utils/encoding-test.js b/app/tests/unit/utils/encoding-test.js deleted file mode 100644 index aaf2cc08..00000000 --- a/app/tests/unit/utils/encoding-test.js +++ /dev/null @@ -1,9 +0,0 @@ -import encodingUtil from '../../../utils/encoding'; -import { module, test } from 'qunit'; - -module('Unit | Utility | encoding helpers'); - -test("should correctly Base64 encode", function(assert) { - let result = encodingUtil.Base64.encode("test"); - assert.equal(result, "dGVzdA=="); -}); diff --git a/app/tests/unit/utils/string-test.js b/app/tests/unit/utils/string-test.js deleted file mode 100644 index f90c3864..00000000 --- a/app/tests/unit/utils/string-test.js +++ /dev/null @@ -1,14 +0,0 @@ -import stringUtil from '../../../utils/string'; -import { module, test } from 'qunit'; - -module('Unit | Utility | string'); - -test("should find string suffix", function(assert) { - let result = stringUtil.endsWith("some words", "words"); - assert.ok(result); -}); - -test("should generate slug", function(assert) { - let result = stringUtil.makeSlug("something to slug"); - assert.equal(result, "something-to-slug"); -}); From 1a0f9f5cd96147aa350efd16c1f5eb026c5c296d Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 12 May 2016 20:08:39 +0200 Subject: [PATCH 04/49] Add missing html head meta tags --- app/tests/acceptance/index-test.js | 4 +++- app/tests/index.html | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/tests/acceptance/index-test.js b/app/tests/acceptance/index-test.js index b91d1d0a..9a587756 100644 --- a/app/tests/acceptance/index-test.js +++ b/app/tests/acceptance/index-test.js @@ -10,10 +10,12 @@ moduleForAcceptance('Acceptance | /'); test('visiting /', function(assert) { visit('/'); + return pauseTest(); + // setup mirage for /api/public/meta -> { allowAnonymousAccess: false} andThen(function() { - assert.equal(currentURL(), '/login'); + assert.equal(currentURL(), '/auth/login'); }); }); diff --git a/app/tests/index.html b/app/tests/index.html index 8c89846b..87c5d442 100644 --- a/app/tests/index.html +++ b/app/tests/index.html @@ -7,6 +7,9 @@ Documize Tests + + + {{content-for "head"}} {{content-for "test-head"}} From 9ba3f3b3f26b31d001eaa8994a40d11cf704ede0 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 13 May 2016 17:30:04 +0200 Subject: [PATCH 05/49] Removed storeConfigInMeta=false from ember-cli-build.js EmberCLI uses this functionality to provide custom environment variables for Testing environment. Without this, Testing doesn't get proper locationType. Why was this changed? --- app/ember-cli-build.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/ember-cli-build.js b/app/ember-cli-build.js index 2e634c8b..7f2cfe05 100644 --- a/app/ember-cli-build.js +++ b/app/ember-cli-build.js @@ -15,9 +15,6 @@ var isDevelopment = EmberApp.env() === 'development'; module.exports = function(defaults) { var app = new EmberApp(defaults, { - tests: true, - storeConfigInMeta: false, - fingerprint: { enabled: true, extensions: ['js', 'css'], From e2037958f45a3490b2d5760965744295a38c6f34 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 13 May 2016 17:48:46 +0200 Subject: [PATCH 06/49] Added option to disable audit in tests --- app/app/services/audit.js | 2 +- app/config/environment.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/app/services/audit.js b/app/app/services/audit.js index 1bf39d6a..7bb98016 100644 --- a/app/app/services/audit.js +++ b/app/app/services/audit.js @@ -16,7 +16,7 @@ import config from '../config/environment'; export default Ember.Service.extend({ sessionService: Ember.inject.service('session'), ready: false, - enabled: true, + enabled: config.APP.auditEnabled, init() { this.start(); diff --git a/app/config/environment.js b/app/config/environment.js index 5ddcd95a..564eeea7 100644 --- a/app/config/environment.js +++ b/app/config/environment.js @@ -15,7 +15,7 @@ module.exports = function(environment) { var ENV = { modulePrefix: 'documize', podModulePrefix: 'documize/pods', - locationType: 'history', + locationType: 'auto', environment: environment, baseURL: '/', apiHost: '', @@ -28,12 +28,18 @@ module.exports = function(environment) { "ember-cli-mirage": { enabled: false }, - APP: {} + APP: { + // Allows to disable audit service in tests + auditEnabled: true + } }; if (environment === 'development') { ENV.APP.LOG_TRANSITIONS = true; ENV.APP.LOG_TRANSITIONS_INTERNAL = true; + ENV['ember-cli-mirage'] = { + enabled: false + }; ENV.apiHost = "https://localhost:5001"; // ENV.apiHost = "https://demo1.dev:5001"; @@ -52,9 +58,9 @@ module.exports = function(environment) { ENV['ember-cli-mirage'] = { enabled: true }; + ENV.APP.auditEnabled = false; ENV.apiHost = "https://localhost:5001"; - // ENV.apiHost = "https://demo1.dev:5001"; } if (environment === 'production') { From 38062eeb82396d7acb65364d82647351ac8fc5e5 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 13 May 2016 18:58:46 +0200 Subject: [PATCH 07/49] Added ability to stub session --- app/tests/helpers/module-for-acceptance.js | 11 +++++++++-- app/tests/helpers/stub-session.js | 12 ++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/tests/helpers/stub-session.js diff --git a/app/tests/helpers/module-for-acceptance.js b/app/tests/helpers/module-for-acceptance.js index 8c8b74ec..562c95a5 100644 --- a/app/tests/helpers/module-for-acceptance.js +++ b/app/tests/helpers/module-for-acceptance.js @@ -10,14 +10,21 @@ export default function(name, options = {}) { if (options.beforeEach) { options.beforeEach.apply(this, arguments); } + + this.register = (fullName, Factory) => { + let instance = this.application.__deprecatedInstance__; + let registry = instance.register ? instance : instance.registry; + + return registry.register(fullName, Factory); + }; }, afterEach() { + destroyApp(this.application); + if (options.afterEach) { options.afterEach.apply(this, arguments); } - - destroyApp(this.application); } }); } diff --git a/app/tests/helpers/stub-session.js b/app/tests/helpers/stub-session.js new file mode 100644 index 00000000..8bcc4027 --- /dev/null +++ b/app/tests/helpers/stub-session.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; + +const Session = Ember.Service.extend({ + login(credentials) { + // TODO: figure out what to do with credentials + return new Ember.RSVP.resolve(); + } +}); + +export default Ember.Test.registerAsyncHelper('stubSession', function(app, test, attrs={}) { + test.register('service:session', Session.extend(attrs)); +}); From e7843e17b902d283ef33eba961f2a49032491337 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 13 May 2016 19:02:58 +0200 Subject: [PATCH 08/49] Use get method to prevent exeptions when properties are missing --- app/app/services/browser.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/app/services/browser.js b/app/app/services/browser.js index c42bec2c..b390595c 100644 --- a/app/app/services/browser.js +++ b/app/app/services/browser.js @@ -19,15 +19,15 @@ export default Ember.Service.extend({ }, setTitle(title) { - document.title = title + " | " + this.get('sessionService').appMeta.title; + document.title = title + " | " + this.get('sessionService.appMeta.title'); }, setTitleReverse(title) { - document.title = this.get('sessionService').appMeta.title + " | " + title; + document.title = this.get('sessionService.appMeta.title') + " | " + title; }, setTitleAsPhrase(title) { - document.title = this.get('sessionService').appMeta.title + " " + title; + document.title = this.get('sessionService.appMeta.title') + " " + title; }, setTitleWithoutSuffix(title) { @@ -38,7 +38,7 @@ export default Ember.Service.extend({ $('meta[name=description]').remove(); if (is.null(description) || is.undefined(description)) { - description = this.get('sessionService').appMeta.message; + description = this.get('sessionService.appMeta.message'); } $('head').append(''); From c07aaafd13e057369f099e5e2b3dd183a1ba3b4e Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 13 May 2016 19:33:30 +0200 Subject: [PATCH 09/49] Use get method to prevent exeptions when properties are missing --- app/app/routes/application.js | 4 ++-- app/app/services/document.js | 5 +++-- app/app/services/folder.js | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/app/routes/application.js b/app/app/routes/application.js index ade10ade..da384933 100644 --- a/app/app/routes/application.js +++ b/app/app/routes/application.js @@ -23,7 +23,7 @@ export default Ember.Route.extend({ // Session ready? return session.boot().then(function() { // Need to authenticate? - if (!session.appMeta.allowAnonymousAccess && !session.authenticated && + if (!session.get("appMeta.allowAnonymousAccess") && !session.get("authenticated") && is.not.startWith(transition.targetName, 'auth.')) { if (!self.transitioning) { session.set('previousTransition', transition); @@ -52,4 +52,4 @@ export default Ember.Route.extend({ return true; } }, -}); \ No newline at end of file +}); diff --git a/app/app/services/document.js b/app/app/services/document.js index dc230af9..8f036c95 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -36,7 +36,8 @@ export default Ember.Service.extend({ // Returns all documents for specified folder. getAllByFolder(folderId) { - let url = this.get('sessionService').appMeta.getUrl(`documents?folder=${folderId}`); + let appMeta = this.get('sessionService.appMeta') + let url = appMeta.getUrl(`documents?folder=${folderId}`); return new Ember.RSVP.Promise(function(resolve, reject) { $.ajax({ @@ -460,4 +461,4 @@ export default Ember.Service.extend({ }); }); }, -}); \ No newline at end of file +}); diff --git a/app/app/services/folder.js b/app/app/services/folder.js index b0ed6b18..432641ca 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -22,7 +22,8 @@ export default BaseService.extend({ // Add a new folder. add(folder) { - let url = this.get('sessionService').appMeta.getUrl(`folders`); + let appMeta = this.get('sessionService.appMeta'); + let url = appMeta.getUrl(`folders`); return new Ember.RSVP.Promise(function(resolve, reject) { $.ajax({ @@ -43,7 +44,8 @@ export default BaseService.extend({ // Returns folder model for specified folder id. getFolder(id) { - let url = this.get('sessionService').appMeta.getUrl(`folders/${id}`); + let appMeta = this.get('sessionService.appMeta') + let url = appMeta.getUrl(`folders/${id}`); return new Ember.RSVP.Promise(function(resolve, reject) { $.ajax({ @@ -157,7 +159,8 @@ export default BaseService.extend({ // reloads and caches folders. reload() { - let url = this.get('sessionService').appMeta.getUrl(`folders`); + let appMeta = this.get('sessionService.appMeta') + let url = appMeta.getUrl(`folders`); return new Ember.RSVP.Promise(function(resolve, reject) { $.ajax({ From 51f934a0ee9c579f674751e764456888979dbcb6 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 13 May 2016 19:35:10 +0200 Subject: [PATCH 10/49] Add appMeta model and getSessionItem method --- app/tests/helpers/stub-session.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/tests/helpers/stub-session.js b/app/tests/helpers/stub-session.js index 8bcc4027..572a0280 100644 --- a/app/tests/helpers/stub-session.js +++ b/app/tests/helpers/stub-session.js @@ -1,9 +1,20 @@ import Ember from 'ember'; +import Models from 'documize/utils/model'; const Session = Ember.Service.extend({ + appMeta: Ember.computed(function(){ + return Models.AppMeta.create(); + }), login(credentials) { // TODO: figure out what to do with credentials return new Ember.RSVP.resolve(); + }, + + boot(){ + return new Ember.RSVP.resolve(); + }, + getSessionItem(key){ + return this.get(`data.${key}`); } }); From fc57dffc152a591a893ae34f5cfcac1510ea930c Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 19 May 2016 12:09:24 +0200 Subject: [PATCH 11/49] Wrap async code in Ember.run --- app/app/services/folder.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/app/services/folder.js b/app/app/services/folder.js index 432641ca..50ff0a42 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -291,8 +291,9 @@ export default BaseService.extend({ canEdit = permission.canEdit; } }); - - self.set('canEditCurrentFolder', canEdit && self.get('sessionService').authenticated); + Ember.run(() => { + self.set('canEditCurrentFolder', canEdit && self.get('sessionService').authenticated); + }); } }); }, From 06d21f20c8411274e666f485b1f1f61bdd02176e Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 19 May 2016 17:30:31 +0200 Subject: [PATCH 12/49] Inject different session and audit services for tests --- app/tests/helpers/stub-audit.js | 69 +++++++++++ app/tests/helpers/stub-session.js | 193 ++++++++++++++++++++++++++++-- 2 files changed, 255 insertions(+), 7 deletions(-) create mode 100644 app/tests/helpers/stub-audit.js diff --git a/app/tests/helpers/stub-audit.js b/app/tests/helpers/stub-audit.js new file mode 100644 index 00000000..53778b97 --- /dev/null +++ b/app/tests/helpers/stub-audit.js @@ -0,0 +1,69 @@ +import Ember from 'ember'; +import netUtil from 'documize/utils/net'; +import config from 'documize/config/environment'; + +const Audit = Ember.Service.extend({ + sessionService: Ember.inject.service('session'), + ready: false, + enabled: true, + + init() { + this.start(); + }, + + record(id) { + if (!this.get('enabled')) { + return; + } + + if (!this.get('ready')) { + this.start(); + } + + // Intercom('trackEvent', id); //jshint ignore: line + // Intercom('update'); //jshint ignore: line + }, + + stop() { + // Intercom('shutdown'); //jshint ignore: line + }, + + start() { + let session = this.get('sessionService'); + + if (!this.get('enabled') || !session.authenticated || this.get('ready')) { + return; + } + + this.set('ready', true); + + let appId = config.environment === 'production' ? 'c6cocn4z' : 'itgvb1vo'; + + // window.intercomSettings = { + // app_id: appId, + // name: session.user.firstname + " " + session.user.lastname, + // email: session.user.email, + // user_id: session.user.id, + // "administrator": session.user.admin, + // company: + // { + // id: session.get('appMeta.orgId'), + // name: session.get('appMeta.title').string, + // "domain": netUtil.getSubdomain(), + // "version": session.get('appMeta.version') + // } + // }; + // + // if (!session.get('isMobile')) { + // window.intercomSettings.widget = { + // activator: "#IntercomDefaultWidget" + // }; + // } + // + // window.Intercom('boot', window.intercomSettings); + }, +}); + +export default Ember.Test.registerAsyncHelper('stubAudit', function(app, test, attrs={}) { + test.register('service:audit', Audit.extend(attrs)); +}); diff --git a/app/tests/helpers/stub-session.js b/app/tests/helpers/stub-session.js index 572a0280..b725ff1c 100644 --- a/app/tests/helpers/stub-session.js +++ b/app/tests/helpers/stub-session.js @@ -1,20 +1,199 @@ import Ember from 'ember'; -import Models from 'documize/utils/model'; +import models from 'documize/utils/model'; +import encodingUtil from 'documize/utils/encoding'; +import netUtil from 'documize/utils/net'; const Session = Ember.Service.extend({ - appMeta: Ember.computed(function(){ - return Models.AppMeta.create(); - }), + + ready: false, + appMeta: null, + isMac: false, + isMobile: false, + previousTransition: null, + user: null, + authenticated: false, + folderPermissions: null, + currentFolder: null, + + init: function() { + this.set('user', models.UserModel.create()); + this.appMeta = models.AppMeta.create(); + + this.set('isMac', is.mac()); + this.set('isMobile', is.mobile()); + }, + isAdmin: function() { + if (this.authenticated && is.not.null(this.user) && this.user.id !== "") { + return this.user.admin; + } + return false; + }.property('user'), + + isEditor: function() { + if (this.authenticated && is.not.null(this.user) && this.user.id !== "") { + return this.user.editor || this.user.admin; + } + return false; + }.property('user'), + login(credentials) { // TODO: figure out what to do with credentials - return new Ember.RSVP.resolve(); + var self = this; + var url = self.appMeta.getUrl('public/authenticate'); + let domain = netUtil.getSubdomain(); + + this.clearSession(); + + return new Ember.RSVP.Promise(function(resolve, reject) { + if (is.empty(credentials.email) || is.empty(credentials.password)) { + reject("invalid"); + return; + } + + var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password); + var header = { + 'Authorization': 'Basic ' + encoded + }; + + $.ajax({ + url: url, + type: 'POST', + headers: header, + success: function(response) { + self.setSession(response.token, models.UserModel.create(response.user)); + self.get('ready', true); + resolve(response); + }, + error: function(reason) { + reject(reason); + } + }); + }); }, - boot(){ - return new Ember.RSVP.resolve(); + // Goodbye + logout: function() { + this.clearSession(); }, + + // Session management + setSession: function(token, user) { + this.set('user', user); + this.set('authenticated', true); + + this.storeSessionItem('token', token); + this.storeSessionItem('user', JSON.stringify(user)); + + $.ajaxPrefilter(function(options, originalOptions, jqXHR) { + jqXHR.setRequestHeader('Authorization', 'Bearer ' + token); + }); + }, + + clearSession: function() { + this.set('user', null); + this.set('authenticated', false); + // localStorage.clear(); + }, + + storeSessionItem: function(key, data) { + // localStorage[key] = data; + // console.log(data); + }, + + getSessionItem: function(key) { + // return localStorage[key]; + // console.log(data); + }, + + clearSessionItem: function(key) { + // delete localStorage[key]; + }, + + // boot(){ + // console.log(this.get('appMeta')); + // return new Ember.RSVP.resolve(); + // }, + + boot() { + let self = this; + let dbhash = ""; + + if (is.not.null(document.head.querySelector("[property=dbhash]"))) { + dbhash = document.head.querySelector("[property=dbhash]").content; + } + + if (dbhash.length > 0 && dbhash !== "{{.DBhash}}") { + self.get('appMeta').set('orgId', "response.orgId"); + self.get('appMeta').setSafe('title', "Documize Setup"); + self.get('appMeta').set('version', "response.version"); + self.get('appMeta').setSafe('message', "response.message"); + self.get('appMeta').set('allowAnonymousAccess', false); + self.set('ready', true); + return new Ember.RSVP.Promise(function(resolve) { + resolve(); + }); + } + + if (this.get('ready')) { + return new Ember.RSVP.Promise(function(resolve) { + resolve(); + }); + } + + return new Ember.RSVP.Promise(function(resolve) { + $.ajax({ + url: self.get('appMeta').getUrl("public/meta"), + type: 'GET', + contentType: 'json', + success: function(response) { + self.get('appMeta').set('orgId', response.orgId); + self.get('appMeta').setSafe('title', response.title); + self.get('appMeta').set('version', response.version); + self.get('appMeta').setSafe('message', response.message); + self.get('appMeta').set('allowAnonymousAccess', response.allowAnonymousAccess); + + let token = self.getSessionItem('token'); + + if (is.not.undefined(token)) { + // We now validate current token + let tokenCheckUrl = self.get('appMeta').getUrl(`public/validate?token=${token}`); + + $.ajax({ + url: tokenCheckUrl, + type: 'GET', + contentType: 'json', + success: function(user) { + self.setSession(token, models.UserModel.create(user)); + self.set('ready', true); + resolve(); + }, + error: function(reason) { + if (reason.status === 401 || reason.status === 403) { + localStorage.clear(); + window.location.href = "/auth/login"; + } + } + }); + } else { + self.set('ready', true); + resolve(); + } + }, + error: function(reason) { + if (reason.status === 401 || reason.status === 403) { + window.location.href = "https://documize.com"; + } + } + }); + }); + }, + getSessionItem(key){ return this.get(`data.${key}`); + }, + + sso: function(credentials) { + } }); From a46beecdf5f9ac12250a7c6d11aaa9685afc3432 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 19 May 2016 17:31:23 +0200 Subject: [PATCH 13/49] Add user login helper --- app/tests/helpers/user-login.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/tests/helpers/user-login.js diff --git a/app/tests/helpers/user-login.js b/app/tests/helpers/user-login.js new file mode 100644 index 00000000..e21ff370 --- /dev/null +++ b/app/tests/helpers/user-login.js @@ -0,0 +1,9 @@ +import Ember from 'ember'; + +export default Ember.Test.registerAsyncHelper('userLogin', function(app) { + visit('/auth/login'); + + fillIn('#authEmail', 'brizdigital@gmail.com'); + fillIn('#authPassword', 'zinyando123'); + click('button'); +}); From 5a4dc1534fc81aa4ed0866e7e61e5f1898684b8e Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 19 May 2016 17:32:58 +0200 Subject: [PATCH 14/49] Initial auth tests and tests for allowAnonymousAccess --- app/tests/acceptance/authentication-test.js | 26 ++++++++++++++ app/tests/acceptance/index-test.js | 38 +++++++++++++-------- 2 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 app/tests/acceptance/authentication-test.js diff --git a/app/tests/acceptance/authentication-test.js b/app/tests/acceptance/authentication-test.js new file mode 100644 index 00000000..0f778fba --- /dev/null +++ b/app/tests/acceptance/authentication-test.js @@ -0,0 +1,26 @@ +import { test } from 'qunit'; +import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; + +moduleForAcceptance('Acceptance | authentication'); + +test('visiting /auth/login and logging in', function(assert) { + visit('/auth/login'); + + fillIn('#authEmail', 'brizdigital@gmail.com'); + fillIn('#authPassword', 'zinyando123'); + click('button'); + + andThen(function() { + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + }); +}); + +test('logging out a user', function(assert) { + userLogin(); + + visit('/auth/logout'); // logs a user out + + andThen(function() { + assert.equal(currentURL(), '/'); + }); +}); diff --git a/app/tests/acceptance/index-test.js b/app/tests/acceptance/index-test.js index 9a587756..1a7565fa 100644 --- a/app/tests/acceptance/index-test.js +++ b/app/tests/acceptance/index-test.js @@ -1,21 +1,29 @@ -import { test } from 'qunit'; +import { test, skip } from 'qunit'; import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; +// import stubSession from '../helpers/stub-session'; moduleForAcceptance('Acceptance | /'); -// TODO: when accessing / with /api/public/meta -> { allowAnonymousAccess: false } then take user to login -// TODO: when accessing / with /api/public/meta -> { allowAnonymousAccess: true } then take user to folers.index -// TODO: when accessing / with /api/public/meta -> { allowAnonymousAccess: true } and user is authenticated -> show authenticated user information +skip('visiting / when not authenticated and with { allowAnonymousAccess: false } takes user to login', function(assert) { + visit('/'); -test('visiting /', function(assert) { - visit('/'); - - return pauseTest(); - - // setup mirage for /api/public/meta -> { allowAnonymousAccess: false} - - - andThen(function() { - assert.equal(currentURL(), '/auth/login'); - }); + andThen(function() { + assert.equal(currentURL(), '/auth/login'); + }); +}); + +skip('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) { + visit('/'); + + andThen(function() { + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + }); +}); + +skip('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function(assert) { + userLogin(); + + andThen(function() { + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + }); }); From 6ca10b277c5d8eebaec1ae7fb5d37a3de7519ff4 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 19 May 2016 17:36:55 +0200 Subject: [PATCH 15/49] Add helpers to moduleForAcceptance and added helper names to prevent jshint warnings --- app/tests/helpers/module-for-acceptance.js | 2 ++ app/tests/helpers/start-app.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/app/tests/helpers/module-for-acceptance.js b/app/tests/helpers/module-for-acceptance.js index 562c95a5..292ebf5d 100644 --- a/app/tests/helpers/module-for-acceptance.js +++ b/app/tests/helpers/module-for-acceptance.js @@ -6,6 +6,8 @@ export default function(name, options = {}) { module(name, { beforeEach() { this.application = startApp(); + stubAudit(this); + stubSession(this); if (options.beforeEach) { options.beforeEach.apply(this, arguments); diff --git a/app/tests/helpers/start-app.js b/app/tests/helpers/start-app.js index e098f1d5..b6394337 100644 --- a/app/tests/helpers/start-app.js +++ b/app/tests/helpers/start-app.js @@ -1,6 +1,9 @@ import Ember from 'ember'; import Application from '../../app'; import config from '../../config/environment'; +import './stub-session'; +import './stub-audit'; +import './user-login'; export default function startApp(attrs) { let application; From f4b003525d61f540bf7b682e4b95e1d3feac19be Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 19 May 2016 17:46:13 +0200 Subject: [PATCH 16/49] Add missing routes to mirage --- app/app/mirage/config.js | 322 +++++++++++++++++++++++++++++---------- app/tests/.jshintrc | 6 +- 2 files changed, 245 insertions(+), 83 deletions(-) diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index eee36605..360b16dd 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -1,90 +1,248 @@ export default function() { - // These comments are here to help you get started. Feel free to delete them. + this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D'); + this.urlPrefix = 'https://localhost:5001'; // make this `http://localhost:8080`, for example, if your API is on a different server + this.namespace = 'api'; // make this `api`, for example, if your API is namespaced + // this.timing = 400; // delay for each request, automatically set to 0 during testing - /* - Config (with defaults). - - Note: these only affect routes defined *after* them! - */ - // this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server - this.namespace = 'api/public'; // make this `api`, for example, if your API is namespaced - // this.timing = 400; // delay for each request, automatically set to 0 during testing - - /* - Route shorthand cheatsheet - */ - /* - GET shorthands - - this.get() - - // Collections - this.get('/contacts'); - this.get('/contacts', 'users'); - this.get('/contacts', ['contacts', 'addresses']); - - // Single objects - this.get('/contacts/:id'); - this.get('/contacts/:id', 'user'); - this.get('/contacts/:id', ['contact', 'addresses']); - */ - - this.get('/authenticate', function() { - return { - - }; - }); - - /* - POST shorthands - - this.post('/contacts'); - this.post('/contacts', 'user'); // specify the type of resource to be created - */ - - /* - PUT shorthands - - this.put('/contacts/:id'); - this.put('/contacts/:id', 'user'); // specify the type of resource to be updated - */ - - /* - DELETE shorthands - - this.del('/contacts/:id'); - this.del('/contacts/:id', 'user'); // specify the type of resource to be deleted - - // Single object + related resources. Make sure parent resource is first. - this.del('/contacts/:id', ['contact', 'addresses']); - */ - - /* - Function fallback. Manipulate data in the db via - - - db.{collection} - - db.{collection}.find(id) - - db.{collection}.where(query) - - db.{collection}.update(target, attrs) - - db.{collection}.remove(target) - - // Example: return a single object with related models - this.get('/contacts/:id', function(db, request) { - var contactId = +request.params.id; - - return { - contact: db.contacts.find(contactId), - addresses: db.addresses.where({contact_id: contactId}) - }; + this.get('/public/meta', function () { + return { + "orgId":"VzMuyEw_3WqiafcD", + "title":"EmberSherpa", + "message":"This Documize instance contains all our team documentation", + "url":"", + "allowAnonymousAccess":true, + "version":"11.2" + }; }); - */ -} + this.get('/public/validate', function (db, request) { + let serverToken = request.queryParams.token; + let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0" -/* -You can optionally export a config that is only loaded during tests -export function testConfig() { + if(token = serverToken){ + return { + "id":"VzMuyEw_3WqiafcE", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "firstname":"Lennex", + "lastname":"Zinyando", + "email":"brizdigital@gmail.com", + "initials":"LZ", + "active":true, + "editor":true, + "admin":true, + "accounts":[{ + "id":"VzMuyEw_3WqiafcF", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "admin":true, + "editor":true, + "userId":"VzMuyEw_3WqiafcE", + "orgId":"VzMuyEw_3WqiafcD", + "company":"EmberSherpa", + "title":"EmberSherpa", + "message":"This Documize instance contains all our team documentation", + "domain":"" + } + ] + }; + } +}); -} +this.get('/users/0/permissions', function () { + return [ + { + "folderId":"VzMygEw_3WrtFzto", + "userId":"", + "canView":true, + "canEdit":false + } + ]; +}); + +this.get('/templates', function () { + return []; +}); + +this.get('/folders/VzMuyEw_3WqiafcG', function () { + return { + "id":"VzMuyEw_3WqiafcG", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "name":"My Project", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":2 + }; +}); + +this.get('/documents', function (db, request) { + let folder_id = request.queryParams.folder; + + if (folder_id = "VzMuyEw_3WqiafcG"){ + return [ + { + "id":"VzMwX0w_3WrtFztd", + "created":"2016-05-11T13:15:11Z", + "revised":"2016-05-11T13:22:16Z", + "orgId":"VzMuyEw_3WqiafcD", + "folderId":"VzMuyEw_3WqiafcG", + "userId":"VzMuyEw_3WqiafcE", + "job":"", + "location":"template-0", + "name":"Empty Document", + "excerpt":"My test document", + "tags":"", + "template":false + },{ + "id":"VzMvJEw_3WqiafcI", + "created":"2016-05-11T13:09:56Z", + "revised":"2016-05-11T13:09:56Z", + "orgId":"VzMuyEw_3WqiafcD", + "folderId":"VzMuyEw_3WqiafcG", + "userId":"VzMuyEw_3WqiafcE", + "job":"0bf9b076-cb74-4e8e-75be-8ee2d24a8171", + "location":"/var/folders/d6/kr81d2fs5bsbm8rz2p092fy80000gn/T/documize/_uploads/0bf9b076-cb74-4e8e-75be-8ee2d24a8171/README.md", + "name":"README", + "excerpt":"To Document/ Instructions. GO. go- bindata- assetsfs. SSL.", + "tags":"", + "template":false + } + ]; + } else if (folder_id = "VzMygEw_3WrtFzto"){ + return { + "id":"VzMygEw_3WrtFzto", + "created":"2016-05-11T13:24:17Z", + "revised":"2016-05-11T13:25:51Z", + "name":"Test", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":1 + }; + } +}); + +this.get('/folders', function() { + return [ + { + "id":"VzMuyEw_3WqiafcG", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "name":"My Project","orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":2 + },{ + "id":"VzMygEw_3WrtFzto", + "created":"2016-05-11T13:24:17Z", + "revised":"2016-05-11T13:25:51Z", + "name":"Test", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":1 + } + ]; +}); + +this.post('/public/authenticate', () => { + return { + "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0", + "user":{ + "id":"VzMuyEw_3WqiafcE", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "firstname":"Lennex", + "lastname":"Zinyando", + "email":"brizdigital@gmail.com", + "initials":"LZ", + "active":true, + "editor":true, + "admin":true, + "accounts":[ + { + "id":"VzMuyEw_3WqiafcF", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "admin":true, + "editor":true, + "userId":"VzMuyEw_3WqiafcE", + "orgId":"VzMuyEw_3WqiafcD", + "company":"EmberSherpa", + "title":"EmberSherpa", + "message":"This Documize instance contains all our team documentation", + "domain":"" + } + ] + } + }; +}); + +this.get('/users/VzMuyEw_3WqiafcE/permissions', () => { + return [ + { + "folderId":"VzMuyEw_3WqiafcG", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true + },{ + "folderId":"VzMygEw_3WrtFzto", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true + },{ + "folderId":"VzMygEw_3WrtFzto", + "userId":"", + "canView":true, + "canEdit":false + } + ]; +}); + +this.get('/folders/VzMygEw_3WrtFzto', () => { + return { + "id":"VzMygEw_3WrtFzto", + "created":"2016-05-11T13:24:17Z", + "revised":"2016-05-11T13:25:51Z", + "name":"Test", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":1 + }; +}); + +this.get('/folders/VzMuyEw_3WqiafcG', () => { + return { + "id":"VzMuyEw_3WqiafcG", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "name":"My Project", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":2 + }; +}); + +this.get('/folders/VzMuyEw_3WqiafcG', () => { + return { + "id":"VzMuyEw_3WqiafcG", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "name":"My Project", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":2 + }; +}); + +/** +very helpful for debugging */ +this.handledRequest = function(verb, path, request) { + console.log(`👊${verb} ${path}`); +}; + +this.unhandledRequest = function(verb, path, request) { + console.log(`🔥${verb} ${path}`); +}; + +} diff --git a/app/tests/.jshintrc b/app/tests/.jshintrc index 4f9f51d8..868af65a 100644 --- a/app/tests/.jshintrc +++ b/app/tests/.jshintrc @@ -22,7 +22,11 @@ "andThen", "currentURL", "currentPath", - "currentRouteName" + "currentRouteName", + "stubSession", + "stubAudit", + "pauseTest", + "userLogin" ], "node": false, "browser": false, From 0db8152143293e88fbe62b96db19ffc9b8ffef43 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 24 May 2016 18:39:08 +0200 Subject: [PATCH 17/49] Add more stubbed api routes --- app/app/mirage/config.js | 591 +++++++++++++++++---------- app/app/mirage/factories/app-meta.js | 15 + app/app/mirage/scenarios/default.js | 1 + 3 files changed, 395 insertions(+), 212 deletions(-) create mode 100644 app/app/mirage/factories/app-meta.js diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index 360b16dd..6fb1648a 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -1,153 +1,348 @@ export default function() { this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D'); - this.urlPrefix = 'https://localhost:5001'; // make this `http://localhost:8080`, for example, if your API is on a different server - this.namespace = 'api'; // make this `api`, for example, if your API is namespaced + this.urlPrefix = 'https://localhost:5001'; // make this `http://localhost:8080`, for example, if your API is on a different server + this.namespace = 'api'; // make this `api`, for example, if your API is namespaced // this.timing = 400; // delay for each request, automatically set to 0 during testing - this.get('/public/meta', function () { + this.get('/public/meta', function() { return { - "orgId":"VzMuyEw_3WqiafcD", - "title":"EmberSherpa", - "message":"This Documize instance contains all our team documentation", - "url":"", - "allowAnonymousAccess":true, - "version":"11.2" + "orgId": "VzMuyEw_3WqiafcD", + "title": "EmberSherpa", + "message": "This Documize instance contains all our team documentation", + "url": "", + "allowAnonymousAccess": false, + "version": "11.2" }; }); - this.get('/public/validate', function (db, request) { + this.get('/public/validate', function(db, request) { let serverToken = request.queryParams.token; - let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0" + let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0"; - if(token = serverToken){ + if (token = serverToken) { return { - "id":"VzMuyEw_3WqiafcE", - "created":"2016-05-11T15:08:24Z", - "revised":"2016-05-11T15:08:24Z", - "firstname":"Lennex", - "lastname":"Zinyando", - "email":"brizdigital@gmail.com", - "initials":"LZ", - "active":true, - "editor":true, - "admin":true, - "accounts":[{ - "id":"VzMuyEw_3WqiafcF", - "created":"2016-05-11T15:08:24Z", - "revised":"2016-05-11T15:08:24Z", - "admin":true, - "editor":true, - "userId":"VzMuyEw_3WqiafcE", - "orgId":"VzMuyEw_3WqiafcD", - "company":"EmberSherpa", - "title":"EmberSherpa", - "message":"This Documize instance contains all our team documentation", - "domain":"" - } - ] - }; - } -}); - -this.get('/users/0/permissions', function () { - return [ - { - "folderId":"VzMygEw_3WrtFzto", - "userId":"", - "canView":true, - "canEdit":false + "id": "VzMuyEw_3WqiafcE", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "firstname": "Lennex", + "lastname": "Zinyando", + "email": "brizdigital@gmail.com", + "initials": "LZ", + "active": true, + "editor": true, + "admin": true, + "accounts": [{ + "id": "VzMuyEw_3WqiafcF", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "admin": true, + "editor": true, + "userId": "VzMuyEw_3WqiafcE", + "orgId": "VzMuyEw_3WqiafcD", + "company": "EmberSherpa", + "title": "EmberSherpa", + "message": "This Documize instance contains all our team documentation", + "domain": "" + }] + }; } - ]; -}); + }); -this.get('/templates', function () { - return []; -}); + this.get('/users/0/permissions', function() { + return [{ + "folderId": "VzMygEw_3WrtFzto", + "userId": "", + "canView": true, + "canEdit": false + }]; + }); -this.get('/folders/VzMuyEw_3WqiafcG', function () { - return { - "id":"VzMuyEw_3WqiafcG", - "created":"2016-05-11T15:08:24Z", - "revised":"2016-05-11T15:08:24Z", - "name":"My Project", - "orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":2 - }; -}); + this.get('/templates', function() { + return []; + }); -this.get('/documents', function (db, request) { - let folder_id = request.queryParams.folder; - - if (folder_id = "VzMuyEw_3WqiafcG"){ - return [ - { - "id":"VzMwX0w_3WrtFztd", - "created":"2016-05-11T13:15:11Z", - "revised":"2016-05-11T13:22:16Z", - "orgId":"VzMuyEw_3WqiafcD", - "folderId":"VzMuyEw_3WqiafcG", - "userId":"VzMuyEw_3WqiafcE", - "job":"", - "location":"template-0", - "name":"Empty Document", - "excerpt":"My test document", - "tags":"", - "template":false - },{ - "id":"VzMvJEw_3WqiafcI", - "created":"2016-05-11T13:09:56Z", - "revised":"2016-05-11T13:09:56Z", - "orgId":"VzMuyEw_3WqiafcD", - "folderId":"VzMuyEw_3WqiafcG", - "userId":"VzMuyEw_3WqiafcE", - "job":"0bf9b076-cb74-4e8e-75be-8ee2d24a8171", - "location":"/var/folders/d6/kr81d2fs5bsbm8rz2p092fy80000gn/T/documize/_uploads/0bf9b076-cb74-4e8e-75be-8ee2d24a8171/README.md", - "name":"README", - "excerpt":"To Document/ Instructions. GO. go- bindata- assetsfs. SSL.", - "tags":"", - "template":false - } - ]; - } else if (folder_id = "VzMygEw_3WrtFzto"){ + this.get('/folders/VzMuyEw_3WqiafcG', function() { return { - "id":"VzMygEw_3WrtFzto", - "created":"2016-05-11T13:24:17Z", - "revised":"2016-05-11T13:25:51Z", - "name":"Test", - "orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":1 + "id": "VzMuyEw_3WqiafcG", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "name": "My Project", + "orgId": "VzMuyEw_3WqiafcD", + "userId": "VzMuyEw_3WqiafcE", + "folderType": 2 }; - } -}); + }); -this.get('/folders', function() { - return [ - { - "id":"VzMuyEw_3WqiafcG", - "created":"2016-05-11T15:08:24Z", - "revised":"2016-05-11T15:08:24Z", - "name":"My Project","orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":2 - },{ - "id":"VzMygEw_3WrtFzto", - "created":"2016-05-11T13:24:17Z", - "revised":"2016-05-11T13:25:51Z", - "name":"Test", - "orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":1 + this.get('/documents', function(db, request) { + let folder_id = request.queryParams.folder; + + if (folder_id = "VzMuyEw_3WqiafcG") { + return [{ + "id": "VzMwX0w_3WrtFztd", + "created": "2016-05-11T13:15:11Z", + "revised": "2016-05-11T13:22:16Z", + "orgId": "VzMuyEw_3WqiafcD", + "folderId": "VzMuyEw_3WqiafcG", + "userId": "VzMuyEw_3WqiafcE", + "job": "", + "location": "template-0", + "name": "Empty Document", + "excerpt": "My test document", + "tags": "", + "template": false + }, { + "id": "VzMvJEw_3WqiafcI", + "created": "2016-05-11T13:09:56Z", + "revised": "2016-05-11T13:09:56Z", + "orgId": "VzMuyEw_3WqiafcD", + "folderId": "VzMuyEw_3WqiafcG", + "userId": "VzMuyEw_3WqiafcE", + "job": "0bf9b076-cb74-4e8e-75be-8ee2d24a8171", + "location": "/var/folders/d6/kr81d2fs5bsbm8rz2p092fy80000gn/T/documize/_uploads/0bf9b076-cb74-4e8e-75be-8ee2d24a8171/README.md", + "name": "README", + "excerpt": "To Document/ Instructions. GO. go- bindata- assetsfs. SSL.", + "tags": "", + "template": false + }]; + } else if (folder_id = "VzMygEw_3WrtFzto") { + return { + "id": "VzMygEw_3WrtFzto", + "created": "2016-05-11T13:24:17Z", + "revised": "2016-05-11T13:25:51Z", + "name": "Test", + "orgId": "VzMuyEw_3WqiafcD", + "userId": "VzMuyEw_3WqiafcE", + "folderType": 1 + }; } - ]; -}); + }); -this.post('/public/authenticate', () => { - return { - "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0", - "user":{ + this.get('/folders', function() { + return [{ + "id": "VzMuyEw_3WqiafcG", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "name": "My Project", + "orgId": "VzMuyEw_3WqiafcD", + "userId": "VzMuyEw_3WqiafcE", + "folderType": 2 + }, { + "id": "VzMygEw_3WrtFzto", + "created": "2016-05-11T13:24:17Z", + "revised": "2016-05-11T13:25:51Z", + "name": "Test", + "orgId": "VzMuyEw_3WqiafcD", + "userId": "VzMuyEw_3WqiafcE", + "folderType": 1 + }]; + }); + + this.post('/public/authenticate', () => { + return { + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0", + "user": { + "id": "VzMuyEw_3WqiafcE", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "firstname": "Lennex", + "lastname": "Zinyando", + "email": "brizdigital@gmail.com", + "initials": "LZ", + "active": true, + "editor": true, + "admin": true, + "accounts": [{ + "id": "VzMuyEw_3WqiafcF", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "admin": true, + "editor": true, + "userId": "VzMuyEw_3WqiafcE", + "orgId": "VzMuyEw_3WqiafcD", + "company": "EmberSherpa", + "title": "EmberSherpa", + "message": "This Documize instance contains all our team documentation", + "domain": "" + }] + } + }; + }); + + this.get('/users/VzMuyEw_3WqiafcE/permissions', () => { + return [{ + "folderId": "VzMuyEw_3WqiafcG", + "userId": "VzMuyEw_3WqiafcE", + "canView": true, + "canEdit": true + }, { + "folderId": "VzMygEw_3WrtFzto", + "userId": "VzMuyEw_3WqiafcE", + "canView": true, + "canEdit": true + }, { + "folderId": "VzMygEw_3WrtFzto", + "userId": "", + "canView": true, + "canEdit": false + }]; + }); + + this.get('/folders/VzMygEw_3WrtFzto', () => { + return { + "id": "VzMygEw_3WrtFzto", + "created": "2016-05-11T13:24:17Z", + "revised": "2016-05-11T13:25:51Z", + "name": "Test", + "orgId": "VzMuyEw_3WqiafcD", + "userId": "VzMuyEw_3WqiafcE", + "folderType": 1 + }; + }); + + this.get('/folders/VzMuyEw_3WqiafcG', () => { + return { + "id": "VzMuyEw_3WqiafcG", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "name": "My Project", + "orgId": "VzMuyEw_3WqiafcD", + "userId": "VzMuyEw_3WqiafcE", + "folderType": 2 + }; + }); + + this.get('/folders/VzMuyEw_3WqiafcG', () => { + return { + "id": "VzMuyEw_3WqiafcG", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "name": "My Project", + "orgId": "VzMuyEw_3WqiafcD", + "userId": "VzMuyEw_3WqiafcE", + "folderType": 2 + }; + }); + + this.get('/organizations/VzMuyEw_3WqiafcD', () => { + return { + "id": "VzMuyEw_3WqiafcD", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-23T11:23:20Z", + "title": "EmberSherpa", + "message": "This Documize instance contains all our team documentation", + "url": "", + "domain": "", + "email": "brizdigital@gmail.com", + "allowAnonymousAccess": false + }; + }); + + this.put('/organizations/VzMuyEw_3WqiafcD', (db, request) => { + let title = JSON.parse(request.requestBody).title; + let message = JSON.parse(request.requestBody).title; + let allowAnonymousAccess = JSON.parse(request.requestBody).allowAnonymousAccess; + + return { + "id": "VzMuyEw_3WqiafcD", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-23T11:23:20Z", + "title": `${title}`, + "message": `${message}`, + "url": "", + "domain": "", + "email": "brizdigital@gmail.com", + "allowAnonymousAccess": `${allowAnonymousAccess}` + }; + }); + + this.get('/users', () => { + return [{ + "id": "VzMyp0w_3WrtFztq", + "created": "2016-05-11T13:24:55Z", + "revised": "2016-05-11T13:33:47Z", + "firstname": "Len", + "lastname": "Random", + "email": "zinyando@gmail.com", + "initials": "LR", + "active": true, + "editor": true, + "admin": false, + "accounts": [{ + "id": "VzMyp0w_3WrtFztr", + "created": "2016-05-11T13:24:55Z", + "revised": "2016-05-11T13:24:55Z", + "admin": false, + "editor": true, + "userId": "VzMyp0w_3WrtFztq", + "orgId": "VzMuyEw_3WqiafcD", + "company": "EmberSherpa", + "title": "EmberSherpa", + "message": "This Documize instance contains all our team documentation", + "domain": "" + }] + }, { + "id": "VzMuyEw_3WqiafcE", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "firstname": "Lennex", + "lastname": "Zinyando", + "email": "brizdigital@gmail.com", + "initials": "LZ", + "active": true, + "editor": true, + "admin": true, + "accounts": [{ + "id": "VzMuyEw_3WqiafcF", + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "admin": true, + "editor": true, + "userId": "VzMuyEw_3WqiafcE", + "orgId": "VzMuyEw_3WqiafcD", + "company": "EmberSherpa", + "title": "EmberSherpa", + "message": "This Documize instance contains all our team documentation", + "domain": "" + }] + }]; + }); + + this.post('/users', (db, request) => { + let firstname = JSON.parse(request.requestBody).firstname; + let lastname = JSON.parse(request.requestBody).lastname; + let email = JSON.parse(request.requestBody).email; + + return { + "id":"V0RmtUw_3QeDAMW7", + "created":"2016-05-24T14:35:33Z", + "revised":"2016-05-24T14:35:33Z", + "firstname":`${firstname}`, + "lastname":`${lastname}`, + "email":`${email}`, + "initials":"TU", + "active":true, + "editor":true, + "admin":false, + "accounts":[{ + "id":"V0RmtUw_3QeDAMW8", + "created":"2016-05-24T14:35:34Z", + "revised":"2016-05-24T14:35:34Z", + "admin":false, + "editor":true, + "userId":"V0RmtUw_3QeDAMW7", + "orgId":"VzMuyEw_3WqiafcD", + "company":"EmberSherpa", + "title":"EmberSherpa", + "message":"This Documize instance contains all our team documentation", + "domain":"" + } + ]}; + }); + + this.get('/users/VzMuyEw_3WqiafcE', () => { + + return { "id":"VzMuyEw_3WqiafcE", "created":"2016-05-11T15:08:24Z", "revised":"2016-05-11T15:08:24Z", @@ -158,91 +353,63 @@ this.post('/public/authenticate', () => { "active":true, "editor":true, "admin":true, - "accounts":[ - { - "id":"VzMuyEw_3WqiafcF", - "created":"2016-05-11T15:08:24Z", - "revised":"2016-05-11T15:08:24Z", - "admin":true, - "editor":true, - "userId":"VzMuyEw_3WqiafcE", - "orgId":"VzMuyEw_3WqiafcD", - "company":"EmberSherpa", - "title":"EmberSherpa", - "message":"This Documize instance contains all our team documentation", - "domain":"" - } - ] - } + "accounts":[{ + "id":"VzMuyEw_3WqiafcF", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "admin":true, + "editor":true, + "userId":"VzMuyEw_3WqiafcE", + "orgId":"VzMuyEw_3WqiafcD", + "company":"EmberSherpa", + "title":"EmberSherpa", + "message":"This Documize instance contains all our team documentation", + "domain":"" + } + ]}; + }); + + this.put('/users/VzMuyEw_3WqiafcE', (db, request) => { + let firstname = JSON.parse(request.requestBody).firstname; + let lastname = JSON.parse(request.requestBody).lastname; + let email = JSON.parse(request.requestBody).email; + + return { + "id":"VzMuyEw_3WqiafcE", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "firstname":`${firstname}`, + "lastname":`${lastname}`, + "email":`${email}`, + "initials":"LZ", + "active":true, + "editor":true, + "admin":true, + "accounts":[{ + "id":"VzMuyEw_3WqiafcF", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "admin":true, + "editor":true, + "userId":"VzMuyEw_3WqiafcE", + "orgId":"VzMuyEw_3WqiafcD", + "company":"EmberSherpa", + "title":"EmberSherpa", + "message":"This Documize instance contains all our team documentation", + "domain":"" + } + ]}; + }); + + /** + very helpful for debugging + */ + this.handledRequest = function(verb, path, request) { + console.log(`👊${verb} ${path}`); }; -}); -this.get('/users/VzMuyEw_3WqiafcE/permissions', () => { - return [ - { - "folderId":"VzMuyEw_3WqiafcG", - "userId":"VzMuyEw_3WqiafcE", - "canView":true, - "canEdit":true - },{ - "folderId":"VzMygEw_3WrtFzto", - "userId":"VzMuyEw_3WqiafcE", - "canView":true, - "canEdit":true - },{ - "folderId":"VzMygEw_3WrtFzto", - "userId":"", - "canView":true, - "canEdit":false - } - ]; -}); - -this.get('/folders/VzMygEw_3WrtFzto', () => { - return { - "id":"VzMygEw_3WrtFzto", - "created":"2016-05-11T13:24:17Z", - "revised":"2016-05-11T13:25:51Z", - "name":"Test", - "orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":1 + this.unhandledRequest = function(verb, path, request) { + console.log(`🔥${verb} ${path}`); }; -}); - -this.get('/folders/VzMuyEw_3WqiafcG', () => { - return { - "id":"VzMuyEw_3WqiafcG", - "created":"2016-05-11T15:08:24Z", - "revised":"2016-05-11T15:08:24Z", - "name":"My Project", - "orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":2 - }; -}); - -this.get('/folders/VzMuyEw_3WqiafcG', () => { - return { - "id":"VzMuyEw_3WqiafcG", - "created":"2016-05-11T15:08:24Z", - "revised":"2016-05-11T15:08:24Z", - "name":"My Project", - "orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":2 - }; -}); - -/** -very helpful for debugging -*/ -this.handledRequest = function(verb, path, request) { - console.log(`👊${verb} ${path}`); -}; - -this.unhandledRequest = function(verb, path, request) { - console.log(`🔥${verb} ${path}`); -}; } diff --git a/app/app/mirage/factories/app-meta.js b/app/app/mirage/factories/app-meta.js new file mode 100644 index 00000000..64040c2b --- /dev/null +++ b/app/app/mirage/factories/app-meta.js @@ -0,0 +1,15 @@ +/* + This is an example factory definition. + + Create more files in this directory to define additional factories. +*/ +import Mirage/*, {faker} */ from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({ + orgId: "VzMuyEw_3WqiafcD", + title: "EmberSherpa", + message: "This Documize instance contains all our team documentation", + url: "", + allowAnonymousAccess: false, + version: "11.2" +}); diff --git a/app/app/mirage/scenarios/default.js b/app/app/mirage/scenarios/default.js index e07271cc..bebdc703 100644 --- a/app/app/mirage/scenarios/default.js +++ b/app/app/mirage/scenarios/default.js @@ -4,4 +4,5 @@ export default function(/* server */) { // data will not be loaded in your tests. // server.createList('contact', 10); + server.createList('app-meta', 1); } From 58ca1379115e71e1fc0aafef7e9922a2c38023fb Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 24 May 2016 18:42:07 +0200 Subject: [PATCH 18/49] Tests for when Anon access is enabled or disabled --- .../acceptance/anon-access-disabled-test.js | 16 +++++++++++++ .../acceptance/anon-access-enabled-test.js | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 app/tests/acceptance/anon-access-disabled-test.js create mode 100644 app/tests/acceptance/anon-access-enabled-test.js diff --git a/app/tests/acceptance/anon-access-disabled-test.js b/app/tests/acceptance/anon-access-disabled-test.js new file mode 100644 index 00000000..e905631e --- /dev/null +++ b/app/tests/acceptance/anon-access-disabled-test.js @@ -0,0 +1,16 @@ +import { test, skip } from 'qunit'; +import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; + +moduleForAcceptance('Acceptance | Anon access disabled'); + + +test('visiting / when not authenticated and with { allowAnonymousAccess: false } takes user to login', function(assert) { + visit('/'); + + andThen(function() { + assert.equal(currentURL(), '/auth/login'); + findWithAssert('#authEmail'); + findWithAssert('#authPassword'); + findWithAssert('button'); + }); +}); diff --git a/app/tests/acceptance/anon-access-enabled-test.js b/app/tests/acceptance/anon-access-enabled-test.js new file mode 100644 index 00000000..b38425ea --- /dev/null +++ b/app/tests/acceptance/anon-access-enabled-test.js @@ -0,0 +1,24 @@ +import { test, skip } from 'qunit'; +import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; + +moduleForAcceptance('Acceptance | Anon access enabled'); + +test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) { + server.create('app-meta', { allowAnonymousAccess: true }); + visit('/'); + + return pauseTest(); + + andThen(function() { + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + }); +}); + +skip('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function(assert) { + server.create('app-meta', { allowAnonymousAccess: true }); + userLogin(); + + andThen(function() { + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + }); +}); From 4ac921ca43109da435f09b85baed048c5893d0d7 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 24 May 2016 18:43:25 +0200 Subject: [PATCH 19/49] Add user profile tests --- app/tests/acceptance/user-profile-test.js | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/tests/acceptance/user-profile-test.js diff --git a/app/tests/acceptance/user-profile-test.js b/app/tests/acceptance/user-profile-test.js new file mode 100644 index 00000000..24319133 --- /dev/null +++ b/app/tests/acceptance/user-profile-test.js @@ -0,0 +1,39 @@ +import { test } from 'qunit'; +import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; + +moduleForAcceptance('Acceptance | user profile'); + +test('visiting /profile', function(assert) { + userLogin(); + visit('/profile'); + + andThen(function() { + assert.equal(currentURL(), '/profile'); + assert.equal(find('#firstname').val(), 'Lennex', 'Firstaname input displays correct value'); + assert.equal(find('#lastname').val(), 'Zinyando', 'Lastname input displays correct value'); + assert.equal(find('#email').val(), 'brizdigital@gmail.com', 'Email input displays correct value'); + }); +}); + +test('changing user details and email ', function(assert) { + userLogin(); + visit('/profile'); + + andThen(function() { + assert.equal(currentURL(), '/profile'); + assert.equal(find('.name').text().trim(), 'Lennex Zinyando', 'Profile name displayed'); + assert.equal(find('#firstname').val(), 'Lennex', 'Firstaname input displays correct value'); + assert.equal(find('#lastname').val(), 'Zinyando', 'Lastname input displays correct value'); + assert.equal(find('#email').val(), 'brizdigital@gmail.com', 'Email input displays correct value'); + }); + + fillIn('#firstname', 'Test'); + fillIn('#lastname', 'User'); + fillIn('#email', 'test.user@domain.com'); + click('.button-blue'); + + andThen(function() { + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + assert.equal(find('.name').text().trim(), 'Test User', 'Profile name displayed'); + }); +}); From 6e933d4939706298b35194c13437b36b03f17a7a Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 24 May 2016 18:44:05 +0200 Subject: [PATCH 20/49] Start work on user settings tests --- app/tests/acceptance/user-settings-test.js | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 app/tests/acceptance/user-settings-test.js diff --git a/app/tests/acceptance/user-settings-test.js b/app/tests/acceptance/user-settings-test.js new file mode 100644 index 00000000..b7f318b7 --- /dev/null +++ b/app/tests/acceptance/user-settings-test.js @@ -0,0 +1,91 @@ +import { test, skip } from 'qunit'; +import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; + +moduleForAcceptance('Acceptance | User Settings'); + +test('visiting /settings/general', function(assert) { + userLogin(); + visit('/settings/general'); + + andThen(function() { + assert.equal(currentURL(), '/settings/general'); + assert.equal(find('#siteTitle').val(), 'EmberSherpa', 'Website title input is filled in correctly'); + assert.equal(find('textarea').val(), 'This Documize instance contains all our team documentation', 'Message is set correctly'); + assert.equal(find('#allowAnonymousAccess').is(':checked'), false, 'Allow anonymouus checkbox is unchecked'); + }); +}); + +test('changing the Website title and descripttion', function(assert) { + userLogin(); + visit('/settings/general'); + + andThen(function() { + let websiteTitle = find('.content .title').text().trim(); + let websiteTitleInput = find('#siteTitle').val(); + assert.equal(websiteTitleInput, websiteTitle, 'Website title is set to EmberSherpa'); + }); + + fillIn('#siteTitle', 'Documize Tests'); + click('.button-blue'); + + andThen(function() { + let websiteTitle = find('.content .title').text().trim(); + let websiteTitleInput = find('#siteTitle').val(); + assert.equal(websiteTitleInput, websiteTitle, 'Website title is set to Documize Tests'); + }); +}); + +test('visiting /settings/folders', function(assert) { + userLogin(); + visit('/settings/folders'); + + andThen(function() { + checkForCommonAsserts(); + assert.equal(currentURL(), '/settings/folders'); + }); +}); + +test('visiting /settings/users', function(assert) { + userLogin(); + visit('/settings/users'); + + andThen(function() { + checkForCommonAsserts(); + findWithAssert('.user-list'); + let numberOfUsers = find('.user-list tr').length; + assert.equal(numberOfUsers, 3, '2 Users listed'); + assert.equal(currentURL(), '/settings/users'); + }); +}); + +test('add a new user', function(assert) { + userLogin(); + visit('/settings/users'); + + andThen(function() { + checkForCommonAsserts(); + findWithAssert('.user-list'); + let numberOfUsers = find('.user-list tr').length; + assert.equal(numberOfUsers, 3, '2 Users listed'); + assert.equal(currentURL(), '/settings/users'); + }); + + fillIn('#newUserFirstname', 'Test'); + fillIn('#newUserLastname', 'User'); + fillIn('#newUserEmail', 'test.user@domain.com'); + click('.button-blue'); + + andThen(function() { + let numberOfUsers = find('.user-list tr').length; + assert.equal(numberOfUsers, 4, '3 Users listed'); + assert.equal(currentURL(), '/settings/users'); + }); +}); + +function checkForCommonAsserts() { + findWithAssert('.sidebar-menu'); + findWithAssert('#user-button'); + findWithAssert('#accounts-button'); + findWithAssert('a:contains(Dashboard)'); + findWithAssert('a:contains(Settings)'); +} From 20849c53a8591520e3dddd62882dace99e61120e Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 24 May 2016 18:45:26 +0200 Subject: [PATCH 21/49] Minor tweaks and changes --- app/tests/.jshintrc | 3 ++- app/tests/acceptance/authentication-test.js | 9 +++++---- app/tests/helpers/start-app.js | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/tests/.jshintrc b/app/tests/.jshintrc index 868af65a..551f69f0 100644 --- a/app/tests/.jshintrc +++ b/app/tests/.jshintrc @@ -26,7 +26,8 @@ "stubSession", "stubAudit", "pauseTest", - "userLogin" + "userLogin", + "skip" ], "node": false, "browser": false, diff --git a/app/tests/acceptance/authentication-test.js b/app/tests/acceptance/authentication-test.js index 0f778fba..3393bf0e 100644 --- a/app/tests/acceptance/authentication-test.js +++ b/app/tests/acceptance/authentication-test.js @@ -1,9 +1,9 @@ -import { test } from 'qunit'; +import { test, skip } from 'qunit'; import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; -moduleForAcceptance('Acceptance | authentication'); +moduleForAcceptance('Acceptance | Authentication'); -test('visiting /auth/login and logging in', function(assert) { +skip('visiting /auth/login and logging in', function(assert) { visit('/auth/login'); fillIn('#authEmail', 'brizdigital@gmail.com'); @@ -15,10 +15,11 @@ test('visiting /auth/login and logging in', function(assert) { }); }); -test('logging out a user', function(assert) { +skip('logging out a user', function(assert) { userLogin(); visit('/auth/logout'); // logs a user out + return pauseTest(); andThen(function() { assert.equal(currentURL(), '/'); diff --git a/app/tests/helpers/start-app.js b/app/tests/helpers/start-app.js index b6394337..d13762e0 100644 --- a/app/tests/helpers/start-app.js +++ b/app/tests/helpers/start-app.js @@ -4,6 +4,7 @@ import config from '../../config/environment'; import './stub-session'; import './stub-audit'; import './user-login'; +import './allow-anonymous-access'; export default function startApp(attrs) { let application; From 6e71dbc234fabd802af70fbe3d90b94b8e4506a0 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 24 May 2016 18:47:50 +0200 Subject: [PATCH 22/49] Move anon tests into separate files --- app/tests/acceptance/index-test.js | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 app/tests/acceptance/index-test.js diff --git a/app/tests/acceptance/index-test.js b/app/tests/acceptance/index-test.js deleted file mode 100644 index 1a7565fa..00000000 --- a/app/tests/acceptance/index-test.js +++ /dev/null @@ -1,29 +0,0 @@ -import { test, skip } from 'qunit'; -import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; -// import stubSession from '../helpers/stub-session'; - -moduleForAcceptance('Acceptance | /'); - -skip('visiting / when not authenticated and with { allowAnonymousAccess: false } takes user to login', function(assert) { - visit('/'); - - andThen(function() { - assert.equal(currentURL(), '/auth/login'); - }); -}); - -skip('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) { - visit('/'); - - andThen(function() { - assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); - }); -}); - -skip('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function(assert) { - userLogin(); - - andThen(function() { - assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); - }); -}); From 3f0d98a5b0fe398d133f40eda3a1b95b142967ad Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 25 May 2016 21:10:28 +0200 Subject: [PATCH 23/49] Install ember-ajax and refactor add method in user service and controller --- app/app/pods/customize/users/controller.js | 23 +++++---- app/app/services/user.js | 57 ++++++---------------- app/package.json | 2 +- 3 files changed, 27 insertions(+), 55 deletions(-) diff --git a/app/app/pods/customize/users/controller.js b/app/app/pods/customize/users/controller.js index c788ea0c..b684154f 100644 --- a/app/app/pods/customize/users/controller.js +++ b/app/app/pods/customize/users/controller.js @@ -20,23 +20,22 @@ export default Ember.Controller.extend(NotifierMixin, { return; } - var self = this; $("#newUserFirstname").removeClass("error"); $("#newUserLastname").removeClass("error"); $("#newUserEmail").removeClass("error"); - this.get('userService').add(this.get('newUser')).then(function(/*user*/) { - self.showNotification('Added'); - self.set('newUser', { firstname: "", lastname: "", email: "", active: true }); - $("#newUserFirstname").focus(); - - self.get('userService').getAll().then(function(users) { - self.set('model', users); + this.get('userService') + .add(this.get('newUser')) + .then((user) => { + this.showNotification('Added'); + this.set('newUser', { firstname: "", lastname: "", email: "", active: true }); + $("#newUserFirstname").focus(); + this.get('model').pushObject(user); + }) + .catch(function(){ + let msg = error.status === 409 ? 'Unable to add duplicate user' : 'Unable to add user'; + self.showNotification(msg); }); - }, function(error) { - let msg = error.status === 409 ? 'Unable to add duplicate user' : 'Unable to add user'; - self.showNotification(msg); - }); }, onDelete(user) { diff --git a/app/app/services/user.js b/app/app/services/user.js index 186d863a..121f5a8f 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -14,24 +14,18 @@ import models from '../utils/model'; export default Ember.Service.extend({ sessionService: Ember.inject.service('session'), + ajax: Ember.inject.service(), // Adds a new user. add(user) { let url = this.get('sessionService').appMeta.getUrl(`users`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'POST', - data: JSON.stringify(user), - contentType: 'json', - success: function(response) { - resolve(models.UserModel.create(response)); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + type: 'POST', + data: JSON.stringify(user), + contentType: 'json' + }).then(function(response){ + return models.UserModel.create(response); }); }, @@ -57,21 +51,9 @@ export default Ember.Service.extend({ getAll() { let url = this.get('sessionService').appMeta.getUrl(`users`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let data = []; - _.each(response, function(obj) { - data.pushObject(models.UserModel.create(obj)); - }); - - resolve(data); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response) => { + return response.map(function(obj){ + return models.UserModel.create(obj); }); }); }, @@ -104,19 +86,10 @@ export default Ember.Service.extend({ let userId = user.get('id'); let url = this.get('sessionService').appMeta.getUrl(`users/${userId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'PUT', - data: JSON.stringify(user), - contentType: 'json', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + type: 'PUT', + data: JSON.stringify(user), + contentType: 'json' }); }, @@ -209,4 +182,4 @@ export default Ember.Service.extend({ }); }); } -}); \ No newline at end of file +}); diff --git a/app/package.json b/app/package.json index 155890d2..afab26ad 100644 --- a/app/package.json +++ b/app/package.json @@ -20,7 +20,7 @@ "license": "MIT", "devDependencies": { "broccoli-asset-rev": "^2.4.2", - "ember-ajax": "0.7.1", + "ember-ajax": "2.3.2", "ember-cli": "2.5.0", "ember-cli-app-version": "^1.0.0", "ember-cli-babel": "^5.1.6", From 43eb62f08e0d59e5654b3807b35f2037e619363b Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 25 May 2016 21:13:15 +0200 Subject: [PATCH 24/49] Add wait-to-appear helper --- app/tests/helpers/wait-to-appear.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/tests/helpers/wait-to-appear.js diff --git a/app/tests/helpers/wait-to-appear.js b/app/tests/helpers/wait-to-appear.js new file mode 100644 index 00000000..d700120d --- /dev/null +++ b/app/tests/helpers/wait-to-appear.js @@ -0,0 +1,22 @@ +import Ember from 'ember'; + +function isVisible(selector) { + return $(selector).length > 0; +} + +function checkVisibility(selector, interval, resolve, visibility) { + if (isVisible(selector) === visibility) { + resolve($(selector)); + } else { + console.log('waiting for visibility'); + Ember.run.later(null, function() { + checkVisibility(selector, interval, resolve, visibility); + }, interval); + } +} + +export default Ember.Test.registerAsyncHelper('waitToAppear', function(app, selector, interval = 200) { + return new Ember.RSVP.Promise(function(resolve) { + checkVisibility(selector, interval, resolve, true); + }); +}); From 403406674c92aee1a1a6a59ba55804a50da153b9 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 25 May 2016 21:14:30 +0200 Subject: [PATCH 25/49] Initial document space tests --- app/tests/acceptance/documents-space-test.js | 83 ++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 app/tests/acceptance/documents-space-test.js diff --git a/app/tests/acceptance/documents-space-test.js b/app/tests/acceptance/documents-space-test.js new file mode 100644 index 00000000..1ddacb79 --- /dev/null +++ b/app/tests/acceptance/documents-space-test.js @@ -0,0 +1,83 @@ +import { test, skip } from 'qunit'; +import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; + +moduleForAcceptance('Acceptance | documents space'); + +skip('Adding a new folder space', function(assert) { + userLogin(); + visit('/s/VzMuyEw_3WqiafcG/my-project'); + + andThen(function() { + let personalSpaces = find('.section div:contains(PERSONAL)').length + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + assert.equal(personalSpaces, 1, '1 personal space is listed'); + }); + + click('#add-folder-button'); + waitToAppear('#new-folder-name'); + fillIn("#new-folder-name", 'Test Folder'); + click('.actions div:contains(add)'); + + andThen(function() { + assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder'); + }); +}); + +skip('Adding a document to a space', function(assert) { + userLogin(); + visit('/s/VzMuyEw_3WqiafcG/my-project'); + + andThen(function() { + + let numberOfDocuments = find('.documents-list li').length + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + assert.equal(numberOfDocuments, 2, '2 documents listed'); + }); + + click('#start-document-button'); + waitToAppear('.drop-content'); + click('.drop-content'); + return pauseTest(); + + andThen(function() { + return pauseTest(); + assert.equal(currentURL(), 's/V0Vy5Uw_3QeDAMW9/test-folder'); + }); +}); + +test('visiting space settings page', function(assert) { + userLogin(); + visit('/s/VzMuyEw_3WqiafcG/my-project'); + + click('#folder-settings-button'); + + andThen(function() { + checkForCommonAsserts(); + assert.equal(find('#folderName').val().trim(), 'My Project', 'Space name displayed in input box'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); + }); +}); + +test('changing space name', function(assert) { + userLogin(); + visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); + + fillIn('#folderName', 'Test Space'); + click('.button-blue'); + + andThen(function() { + let spaceName = find('.breadcrumb-menu .selected').text().trim(); + checkForCommonAsserts(); + assert.equal(spaceName, 'Test Space', 'Space name has been changed'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); + return pauseTest(); + }); +}); + +function checkForCommonAsserts() { + findWithAssert('.sidebar-menu'); + findWithAssert('.options li:contains(General)'); + findWithAssert('.options li:contains(Share)'); + findWithAssert('.options li:contains(Permissions)'); + findWithAssert('.options li:contains(Delete)'); +} From dcb610e1568f13831b874f93a6c0cb00bd1fb815 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 25 May 2016 21:16:23 +0200 Subject: [PATCH 26/49] Add more tests and missing routes to mirage --- app/app/mirage/config.js | 115 +++++++++++++++--- .../acceptance/anon-access-enabled-test.js | 2 +- app/tests/acceptance/user-settings-test.js | 3 +- app/tests/helpers/start-app.js | 1 + 4 files changed, 103 insertions(+), 18 deletions(-) diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index 6fb1648a..ab7b92b6 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -115,6 +115,8 @@ export default function() { "userId": "VzMuyEw_3WqiafcE", "folderType": 1 }; + } else if (folder_id = 'V0Vy5Uw_3QeDAMW9'){ + return null; } }); @@ -136,6 +138,45 @@ export default function() { "userId": "VzMuyEw_3WqiafcE", "folderType": 1 }]; + // return [ + // { + // "id":"VzMuyEw_3WqiafcG", + // "created":"2016-05-11T15:08:24Z", + // "revised":"2016-05-11T15:08:24Z", + // "name":"My Project", + // "orgId":"VzMuyEw_3WqiafcD", + // "userId":"VzMuyEw_3WqiafcE", + // "folderType":2 + // },{ + // "id":"VzMygEw_3WrtFzto", + // "created":"2016-05-11T13:24:17Z", + // "revised":"2016-05-11T13:25:51Z", + // "name":"Test", + // "orgId":"VzMuyEw_3WqiafcD", + // "userId":"VzMuyEw_3WqiafcE", + // "folderType":1 + // },{ + // "id":"V0Vy5Uw_3QeDAMW9", + // "created":"2016-05-25T09:39:49Z", + // "revised":"2016-05-25T09:39:49Z", + // "name":"Test Folder", + // "orgId":"VzMuyEw_3WqiafcD", + // "userId":"VzMuyEw_3WqiafcE", + // "folderType":2 + // } + // ]; + }); + + this.post('/folders', function() { + return { + "id":"V0Vy5Uw_3QeDAMW9", + "created":"2016-05-25T09:39:49Z", + "revised":"2016-05-25T09:39:49Z", + "name":"Test Folder", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":2 + }; }); this.post('/public/authenticate', () => { @@ -170,22 +211,52 @@ export default function() { }); this.get('/users/VzMuyEw_3WqiafcE/permissions', () => { - return [{ - "folderId": "VzMuyEw_3WqiafcG", - "userId": "VzMuyEw_3WqiafcE", - "canView": true, - "canEdit": true - }, { - "folderId": "VzMygEw_3WrtFzto", - "userId": "VzMuyEw_3WqiafcE", - "canView": true, - "canEdit": true - }, { - "folderId": "VzMygEw_3WrtFzto", - "userId": "", - "canView": true, - "canEdit": false - }]; + return [ + { + "folderId":"V0Vy5Uw_3QeDAMW9", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true + },{ + "folderId":"VzMuyEw_3WqiafcG", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true + },{ + "folderId":"VzMygEw_3WrtFzto", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true + },{ + "folderId":"VzMygEw_3WrtFzto", + "userId":"", + "canView":true, + "canEdit":false + } + ]; + }); + + this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => { + return [ + { + "folderId":"VzMuyEw_3WqiafcG", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true + } + ]; + }); + + this.put('/folders/VzMuyEw_3WqiafcG', () => { + return { + "id":"VzMuyEw_3WqiafcG", + "created":"2016-05-11T15:08:24Z", + "revised":"2016-05-11T15:08:24Z", + "name":"Test Space", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":2 + }; }); this.get('/folders/VzMygEw_3WrtFzto', () => { @@ -200,6 +271,18 @@ export default function() { }; }); + this.get('/folders/V0Vy5Uw_3QeDAMW9', () => { + return { + "id":"V0Vy5Uw_3QeDAMW9", + "created":"2016-05-25T09:39:49Z", + "revised":"2016-05-25T09:39:49Z", + "name":"Test Folder", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":2 + }; + }); + this.get('/folders/VzMuyEw_3WqiafcG', () => { return { "id": "VzMuyEw_3WqiafcG", diff --git a/app/tests/acceptance/anon-access-enabled-test.js b/app/tests/acceptance/anon-access-enabled-test.js index b38425ea..e2dc7614 100644 --- a/app/tests/acceptance/anon-access-enabled-test.js +++ b/app/tests/acceptance/anon-access-enabled-test.js @@ -3,7 +3,7 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | Anon access enabled'); -test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) { +skip('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) { server.create('app-meta', { allowAnonymousAccess: true }); visit('/'); diff --git a/app/tests/acceptance/user-settings-test.js b/app/tests/acceptance/user-settings-test.js index b7f318b7..1e50c918 100644 --- a/app/tests/acceptance/user-settings-test.js +++ b/app/tests/acceptance/user-settings-test.js @@ -74,12 +74,13 @@ test('add a new user', function(assert) { fillIn('#newUserLastname', 'User'); fillIn('#newUserEmail', 'test.user@domain.com'); click('.button-blue'); - + return pauseTest(); andThen(function() { let numberOfUsers = find('.user-list tr').length; assert.equal(numberOfUsers, 4, '3 Users listed'); assert.equal(currentURL(), '/settings/users'); }); + }); function checkForCommonAsserts() { diff --git a/app/tests/helpers/start-app.js b/app/tests/helpers/start-app.js index d13762e0..bb66ea3a 100644 --- a/app/tests/helpers/start-app.js +++ b/app/tests/helpers/start-app.js @@ -5,6 +5,7 @@ import './stub-session'; import './stub-audit'; import './user-login'; import './allow-anonymous-access'; +import './wait-to-appear'; export default function startApp(attrs) { let application; From ec605d8917ad6a3ade9e5f0fb8e522fa5ad1df2d Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 30 May 2016 20:20:21 +0200 Subject: [PATCH 27/49] Add more tests --- app/tests/acceptance/documents-space-test.js | 94 ++++++++++++++++++-- app/tests/acceptance/user-settings-test.js | 2 +- 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/app/tests/acceptance/documents-space-test.js b/app/tests/acceptance/documents-space-test.js index 1ddacb79..65084fdf 100644 --- a/app/tests/acceptance/documents-space-test.js +++ b/app/tests/acceptance/documents-space-test.js @@ -3,19 +3,19 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | documents space'); -skip('Adding a new folder space', function(assert) { +test('Adding a new folder space', function(assert) { userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); andThen(function() { - let personalSpaces = find('.section div:contains(PERSONAL)').length + let personalSpaces = find('.section div:contains(PERSONAL)').length; assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); assert.equal(personalSpaces, 1, '1 personal space is listed'); }); click('#add-folder-button'); waitToAppear('#new-folder-name'); - fillIn("#new-folder-name", 'Test Folder'); + fillIn(".input-control input", 'Test Folder'); click('.actions div:contains(add)'); andThen(function() { @@ -29,7 +29,7 @@ skip('Adding a document to a space', function(assert) { andThen(function() { - let numberOfDocuments = find('.documents-list li').length + let numberOfDocuments = find('.documents-list li').length; assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); assert.equal(numberOfDocuments, 2, '2 documents listed'); }); @@ -40,7 +40,6 @@ skip('Adding a document to a space', function(assert) { return pauseTest(); andThen(function() { - return pauseTest(); assert.equal(currentURL(), 's/V0Vy5Uw_3QeDAMW9/test-folder'); }); }); @@ -70,7 +69,90 @@ test('changing space name', function(assert) { checkForCommonAsserts(); assert.equal(spaceName, 'Test Space', 'Space name has been changed'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); - return pauseTest(); + // return pauseTest(); + }); +}); + +test('sharing a space', function(assert) { + userLogin(); + visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); + + click(('.sidebar-menu .options li:contains(Share)')); + fillIn('#inviteEmail', 'share-test@gmail.com'); + click('.button-blue'); + + andThen(function() { + checkForCommonAsserts(); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); + }); +}); + + +// Test will pass after moving to factories +test('changing space permissions', function(assert) { + userLogin(); + return pauseTest(); + andThen(function() { + let numberOfPublicFolders = find('.folders-list div:first .list a').length; + assert.equal(numberOfPublicFolders, 1, '1 folder listed as public'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + }); + + visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); + click(('.sidebar-menu .options li:contains(Permissions)')); + + click('tr:contains(Everyone) #canView-'); + click('tr:contains(Everyone) #canEdit-'); + click('.button-blue'); + + visit('/s/VzMuyEw_3WqiafcG/my-project'); + + andThen(function() { + let numberOfPublicFolders = find('.folders-list div:first .list a').length; + assert.equal(numberOfPublicFolders, 2, '2 folder listed as public'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + }); +}); + +test('deleting a space', function(assert) { + userLogin(); + visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); + + click('.sidebar-menu .options li:contains(Delete)'); + + andThen(function() { + checkForCommonAsserts(); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); + }); +}); + +test('deleting a document', function(assert) { + userLogin(); + visit('/s/VzMuyEw_3WqiafcG/my-project'); + + andThen(function() { + let deleteButton = find('#delete-documents-button'); + let numberOfDocuments = find('.documents-list li'); + assert.equal(numberOfDocuments.length, 2, '2 documents are displayed'); + assert.equal(deleteButton.length, 0, 'Delete button not displayed'); + }); + + click('.documents-list li:first .checkbox'); + + andThen(function() { + let deleteButton = find('#delete-documents-button'); + assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document'); + }); + + click('#delete-documents-button'); + + waitToAppear('.drop-content'); + click('.flat-red'); + return pauseTest(); + + andThen(function() { + let deleteButton = find('#delete-documents-button'); + assert.equal(deleteButton.length, 1, 'Delete button displayed'); }); }); diff --git a/app/tests/acceptance/user-settings-test.js b/app/tests/acceptance/user-settings-test.js index 1e50c918..8dc61b6d 100644 --- a/app/tests/acceptance/user-settings-test.js +++ b/app/tests/acceptance/user-settings-test.js @@ -74,7 +74,7 @@ test('add a new user', function(assert) { fillIn('#newUserLastname', 'User'); fillIn('#newUserEmail', 'test.user@domain.com'); click('.button-blue'); - return pauseTest(); + andThen(function() { let numberOfUsers = find('.user-list tr').length; assert.equal(numberOfUsers, 4, '3 Users listed'); From b0ce9e74f83202674fb397a688cb610702516ad0 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 30 May 2016 20:22:09 +0200 Subject: [PATCH 28/49] Stub user notifications component --- app/tests/.jshintrc | 3 ++- app/tests/helpers/module-for-acceptance.js | 1 + app/tests/helpers/start-app.js | 1 + app/tests/helpers/stub-user-notification.js | 23 +++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/tests/helpers/stub-user-notification.js diff --git a/app/tests/.jshintrc b/app/tests/.jshintrc index 551f69f0..861b980d 100644 --- a/app/tests/.jshintrc +++ b/app/tests/.jshintrc @@ -27,7 +27,8 @@ "stubAudit", "pauseTest", "userLogin", - "skip" + "skip", + "waitToAppear" ], "node": false, "browser": false, diff --git a/app/tests/helpers/module-for-acceptance.js b/app/tests/helpers/module-for-acceptance.js index 292ebf5d..6d6818e0 100644 --- a/app/tests/helpers/module-for-acceptance.js +++ b/app/tests/helpers/module-for-acceptance.js @@ -8,6 +8,7 @@ export default function(name, options = {}) { this.application = startApp(); stubAudit(this); stubSession(this); + stubUserNotification(this); if (options.beforeEach) { options.beforeEach.apply(this, arguments); diff --git a/app/tests/helpers/start-app.js b/app/tests/helpers/start-app.js index bb66ea3a..3c0d1486 100644 --- a/app/tests/helpers/start-app.js +++ b/app/tests/helpers/start-app.js @@ -6,6 +6,7 @@ import './stub-audit'; import './user-login'; import './allow-anonymous-access'; import './wait-to-appear'; +import './stub-user-notification'; export default function startApp(attrs) { let application; diff --git a/app/tests/helpers/stub-user-notification.js b/app/tests/helpers/stub-user-notification.js new file mode 100644 index 00000000..1e464340 --- /dev/null +++ b/app/tests/helpers/stub-user-notification.js @@ -0,0 +1,23 @@ +import Ember from 'ember'; +import miscUtil from 'documize/utils/misc'; + +const userNotification = Ember.Component.extend({ + notifications: [], + + didInsertElement() { + // this.eventBus.subscribe('notifyUser', this, 'showNotification'); + }, + + willDestroyElement() { + // this.eventBus.unsubscribe('notifyUser'); + }, + + showNotification(msg) { + // console.log(msg); + } +}); + + +export default Ember.Test.registerAsyncHelper('stubUserNotification', function(app, test, attrs={}) { + test.register('component:userNotification', userNotification.extend(attrs)); +}); From 57a1e30df7b55af4bfcf1bd61abde3dc1bea3e10 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 30 May 2016 20:32:24 +0200 Subject: [PATCH 29/49] WIP helper for tests with allow anon access set to true --- app/tests/helpers/allow-anonymous-access.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/tests/helpers/allow-anonymous-access.js diff --git a/app/tests/helpers/allow-anonymous-access.js b/app/tests/helpers/allow-anonymous-access.js new file mode 100644 index 00000000..e3081eaa --- /dev/null +++ b/app/tests/helpers/allow-anonymous-access.js @@ -0,0 +1,6 @@ +// import Ember from 'ember'; +// +// export default Ember.Test.registerAsyncHelper('allowAnonymousAccess', function(app) { +// var sessionService = Ember.getOwner(this).lookup("service:session"); +// console.log(sessionService); +// }); From 11fd32cf831b008450bc203fd20ec78d421eafae Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 30 May 2016 20:34:54 +0200 Subject: [PATCH 30/49] Start work to use factories in mirage instead of gard coded respenses --- app/app/mirage/config.js | 14 ++++++++++++++ app/app/mirage/factories/app-meta.js | 15 --------------- app/app/mirage/factories/meta.js | 15 +++++++++++++++ app/app/mirage/scenarios/default.js | 1 - 4 files changed, 29 insertions(+), 16 deletions(-) delete mode 100644 app/app/mirage/factories/app-meta.js create mode 100644 app/app/mirage/factories/meta.js diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index ab7b92b6..ee399f10 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -16,6 +16,12 @@ export default function() { }; }); + // this.get('/public/meta', function(db) { + // return { + // meta: db.meta; + // }; + // }); + this.get('/public/validate', function(db, request) { let serverToken = request.queryParams.token; let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0"; @@ -484,6 +490,14 @@ export default function() { ]}; }); + this.post('/folders/VzMuyEw_3WqiafcG/invitation', () => { + return {}; + }); + + this.put('/folders/VzMuyEw_3WqiafcG/permissions', () => { + return {}; + }); + /** very helpful for debugging */ diff --git a/app/app/mirage/factories/app-meta.js b/app/app/mirage/factories/app-meta.js deleted file mode 100644 index 64040c2b..00000000 --- a/app/app/mirage/factories/app-meta.js +++ /dev/null @@ -1,15 +0,0 @@ -/* - This is an example factory definition. - - Create more files in this directory to define additional factories. -*/ -import Mirage/*, {faker} */ from 'ember-cli-mirage'; - -export default Mirage.Factory.extend({ - orgId: "VzMuyEw_3WqiafcD", - title: "EmberSherpa", - message: "This Documize instance contains all our team documentation", - url: "", - allowAnonymousAccess: false, - version: "11.2" -}); diff --git a/app/app/mirage/factories/meta.js b/app/app/mirage/factories/meta.js new file mode 100644 index 00000000..df259323 --- /dev/null +++ b/app/app/mirage/factories/meta.js @@ -0,0 +1,15 @@ +/* + This is an example factory definition. + + Create more files in this directory to define additional factories. +*/ +import Mirage from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({ + orgId() { return "VzMuyEw_3WqiafcD"; }, + title() { return "EmberSherpa"; }, + message() { return "This Documize instance contains all our team documentation"; }, + url() { return ""; }, + allowAnonymousAccess() { return false; }, + version() { return "11.2"; } +}); diff --git a/app/app/mirage/scenarios/default.js b/app/app/mirage/scenarios/default.js index bebdc703..e07271cc 100644 --- a/app/app/mirage/scenarios/default.js +++ b/app/app/mirage/scenarios/default.js @@ -4,5 +4,4 @@ export default function(/* server */) { // data will not be loaded in your tests. // server.createList('contact', 10); - server.createList('app-meta', 1); } From f9fc236e270d847ef309967d769afcc04363b7ac Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 30 May 2016 20:53:41 +0200 Subject: [PATCH 31/49] Enable login test --- app/tests/acceptance/authentication-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/tests/acceptance/authentication-test.js b/app/tests/acceptance/authentication-test.js index 3393bf0e..0b640dfb 100644 --- a/app/tests/acceptance/authentication-test.js +++ b/app/tests/acceptance/authentication-test.js @@ -3,7 +3,7 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | Authentication'); -skip('visiting /auth/login and logging in', function(assert) { +test('visiting /auth/login and logging in', function(assert) { visit('/auth/login'); fillIn('#authEmail', 'brizdigital@gmail.com'); From 81ecb7539122c6108f0b1f5dfb3cd7e93197f923 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 31 May 2016 14:34:42 +0200 Subject: [PATCH 32/49] Use app meta factory in tests --- app/app/mirage/config.js | 25 +++++++++--------- app/app/mirage/factories/meta.js | 26 +++++++++++-------- .../acceptance/anon-access-disabled-test.js | 3 ++- .../acceptance/anon-access-enabled-test.js | 26 ++++++++++++------- app/tests/acceptance/authentication-test.js | 3 ++- app/tests/acceptance/documents-space-test.js | 12 ++++++--- app/tests/acceptance/user-settings-test.js | 7 ++++- 7 files changed, 62 insertions(+), 40 deletions(-) diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index ee399f10..0f99e3d3 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -5,23 +5,22 @@ export default function() { this.namespace = 'api'; // make this `api`, for example, if your API is namespaced // this.timing = 400; // delay for each request, automatically set to 0 during testing - this.get('/public/meta', function() { - return { - "orgId": "VzMuyEw_3WqiafcD", - "title": "EmberSherpa", - "message": "This Documize instance contains all our team documentation", - "url": "", - "allowAnonymousAccess": false, - "version": "11.2" - }; - }); - - // this.get('/public/meta', function(db) { + // this.get('/public/meta', function() { // return { - // meta: db.meta; + // "orgId": "VzMuyEw_3WqiafcD", + // "title": "EmberSherpa", + // "message": "This Documize instance contains all our team documentation", + // "url": "", + // "allowAnonymousAccess": false, + // "version": "11.2" // }; // }); + this.get('/public/meta', function(db) { + console.log(db.meta[0]); + return db.meta[0]; + }); + this.get('/public/validate', function(db, request) { let serverToken = request.queryParams.token; let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0"; diff --git a/app/app/mirage/factories/meta.js b/app/app/mirage/factories/meta.js index df259323..16a91a82 100644 --- a/app/app/mirage/factories/meta.js +++ b/app/app/mirage/factories/meta.js @@ -1,15 +1,19 @@ -/* - This is an example factory definition. - - Create more files in this directory to define additional factories. -*/ import Mirage from 'ember-cli-mirage'; +// export default Mirage.Factory.extend({ +// orgId() { return 'VzMuyEw_3WqiafcD'; }, +// title() { return 'EmberSherpa'; }, +// message() { return 'This Documize instance contains all our team documentation'; }, +// url() { return ''; }, +// allowAnonymousAccess() { return false; }, +// version() { return '11.2'; } +// }); + export default Mirage.Factory.extend({ - orgId() { return "VzMuyEw_3WqiafcD"; }, - title() { return "EmberSherpa"; }, - message() { return "This Documize instance contains all our team documentation"; }, - url() { return ""; }, - allowAnonymousAccess() { return false; }, - version() { return "11.2"; } + "orgId": "VzMuyEw_3WqiafcD", + "title": "EmberSherpa", + "message": "This Documize instance contains all our team documentation", + "url": "", + "allowAnonymousAccess": false, + "version": "11.2" }); diff --git a/app/tests/acceptance/anon-access-disabled-test.js b/app/tests/acceptance/anon-access-disabled-test.js index e905631e..837b13a2 100644 --- a/app/tests/acceptance/anon-access-disabled-test.js +++ b/app/tests/acceptance/anon-access-disabled-test.js @@ -1,10 +1,11 @@ -import { test, skip } from 'qunit'; +import { test } from 'qunit'; import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | Anon access disabled'); test('visiting / when not authenticated and with { allowAnonymousAccess: false } takes user to login', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); visit('/'); andThen(function() { diff --git a/app/tests/acceptance/anon-access-enabled-test.js b/app/tests/acceptance/anon-access-enabled-test.js index e2dc7614..53fdb2d7 100644 --- a/app/tests/acceptance/anon-access-enabled-test.js +++ b/app/tests/acceptance/anon-access-enabled-test.js @@ -1,24 +1,32 @@ -import { test, skip } from 'qunit'; +import { test } from 'qunit'; import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | Anon access enabled'); -skip('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) { - server.create('app-meta', { allowAnonymousAccess: true }); +test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) { + server.create('meta', { allowAnonymousAccess: true }); visit('/'); - return pauseTest(); - andThen(function() { - assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + assert.equal(find('.login').length, 1, 'Login button is displayed'); + assert.equal(find('.document-card').length, 2, '2 document displayed'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard and public spaces are displayed without being signed in'); }); }); -skip('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function(assert) { - server.create('app-meta', { allowAnonymousAccess: true }); +test('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function(assert) { + server.create('meta', { allowAnonymousAccess: true }); + visit('/'); + + andThen(function() { + assert.equal(find('.login').length, 1, 'Login button is displayed'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard displayed without being signed in'); + }); + userLogin(); andThen(function() { - assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + assert.equal(find('.login').length, 0, 'Login button is not displayed'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard is displayed after user is signed in'); }); }); diff --git a/app/tests/acceptance/authentication-test.js b/app/tests/acceptance/authentication-test.js index 0b640dfb..44140250 100644 --- a/app/tests/acceptance/authentication-test.js +++ b/app/tests/acceptance/authentication-test.js @@ -4,6 +4,7 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | Authentication'); test('visiting /auth/login and logging in', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); visit('/auth/login'); fillIn('#authEmail', 'brizdigital@gmail.com'); @@ -16,10 +17,10 @@ test('visiting /auth/login and logging in', function(assert) { }); skip('logging out a user', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/auth/logout'); // logs a user out - return pauseTest(); andThen(function() { assert.equal(currentURL(), '/'); diff --git a/app/tests/acceptance/documents-space-test.js b/app/tests/acceptance/documents-space-test.js index 65084fdf..efe28f2e 100644 --- a/app/tests/acceptance/documents-space-test.js +++ b/app/tests/acceptance/documents-space-test.js @@ -4,6 +4,7 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | documents space'); test('Adding a new folder space', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); @@ -24,6 +25,7 @@ test('Adding a new folder space', function(assert) { }); skip('Adding a document to a space', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); @@ -37,7 +39,6 @@ skip('Adding a document to a space', function(assert) { click('#start-document-button'); waitToAppear('.drop-content'); click('.drop-content'); - return pauseTest(); andThen(function() { assert.equal(currentURL(), 's/V0Vy5Uw_3QeDAMW9/test-folder'); @@ -45,6 +46,7 @@ skip('Adding a document to a space', function(assert) { }); test('visiting space settings page', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); @@ -58,6 +60,7 @@ test('visiting space settings page', function(assert) { }); test('changing space name', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); @@ -69,11 +72,11 @@ test('changing space name', function(assert) { checkForCommonAsserts(); assert.equal(spaceName, 'Test Space', 'Space name has been changed'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); - // return pauseTest(); }); }); test('sharing a space', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); @@ -90,8 +93,8 @@ test('sharing a space', function(assert) { // Test will pass after moving to factories test('changing space permissions', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); - return pauseTest(); andThen(function() { let numberOfPublicFolders = find('.folders-list div:first .list a').length; assert.equal(numberOfPublicFolders, 1, '1 folder listed as public'); @@ -115,6 +118,7 @@ test('changing space permissions', function(assert) { }); test('deleting a space', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); @@ -127,6 +131,7 @@ test('deleting a space', function(assert) { }); test('deleting a document', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); @@ -148,7 +153,6 @@ test('deleting a document', function(assert) { waitToAppear('.drop-content'); click('.flat-red'); - return pauseTest(); andThen(function() { let deleteButton = find('#delete-documents-button'); diff --git a/app/tests/acceptance/user-settings-test.js b/app/tests/acceptance/user-settings-test.js index 8dc61b6d..ab8ad80d 100644 --- a/app/tests/acceptance/user-settings-test.js +++ b/app/tests/acceptance/user-settings-test.js @@ -4,6 +4,7 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | User Settings'); test('visiting /settings/general', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/settings/general'); @@ -15,7 +16,8 @@ test('visiting /settings/general', function(assert) { }); }); -test('changing the Website title and descripttion', function(assert) { +test('changing the Website title and description', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/settings/general'); @@ -36,6 +38,7 @@ test('changing the Website title and descripttion', function(assert) { }); test('visiting /settings/folders', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/settings/folders'); @@ -46,6 +49,7 @@ test('visiting /settings/folders', function(assert) { }); test('visiting /settings/users', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/settings/users'); @@ -59,6 +63,7 @@ test('visiting /settings/users', function(assert) { }); test('add a new user', function(assert) { + server.create('meta', { allowAnonymousAccess: false }); userLogin(); visit('/settings/users'); From 78e22379dc304117d1718ff790026f678999131f Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 3 Jun 2016 13:36:32 +0200 Subject: [PATCH 33/49] Add waitToDisappear helper and minor cleanup --- app/tests/helpers/start-app.js | 2 +- app/tests/helpers/stub-user-notification.js | 7 +++---- app/tests/helpers/wait-to-appear.js | 17 ++++++++------- app/tests/helpers/wait-to-disappear.js | 23 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 app/tests/helpers/wait-to-disappear.js diff --git a/app/tests/helpers/start-app.js b/app/tests/helpers/start-app.js index 3c0d1486..024b70d1 100644 --- a/app/tests/helpers/start-app.js +++ b/app/tests/helpers/start-app.js @@ -4,8 +4,8 @@ import config from '../../config/environment'; import './stub-session'; import './stub-audit'; import './user-login'; -import './allow-anonymous-access'; import './wait-to-appear'; +import './wait-to-disappear'; import './stub-user-notification'; export default function startApp(attrs) { diff --git a/app/tests/helpers/stub-user-notification.js b/app/tests/helpers/stub-user-notification.js index 1e464340..255b8ffd 100644 --- a/app/tests/helpers/stub-user-notification.js +++ b/app/tests/helpers/stub-user-notification.js @@ -1,19 +1,18 @@ import Ember from 'ember'; -import miscUtil from 'documize/utils/misc'; const userNotification = Ember.Component.extend({ notifications: [], didInsertElement() { - // this.eventBus.subscribe('notifyUser', this, 'showNotification'); + this.eventBus.subscribe('notifyUser', this, 'notifyHandler'); }, willDestroyElement() { - // this.eventBus.unsubscribe('notifyUser'); + this.eventBus.unsubscribe('notifyUser'); }, showNotification(msg) { - // console.log(msg); + return msg; } }); diff --git a/app/tests/helpers/wait-to-appear.js b/app/tests/helpers/wait-to-appear.js index d700120d..16ec0054 100644 --- a/app/tests/helpers/wait-to-appear.js +++ b/app/tests/helpers/wait-to-appear.js @@ -5,14 +5,15 @@ function isVisible(selector) { } function checkVisibility(selector, interval, resolve, visibility) { - if (isVisible(selector) === visibility) { - resolve($(selector)); - } else { - console.log('waiting for visibility'); - Ember.run.later(null, function() { - checkVisibility(selector, interval, resolve, visibility); - }, interval); - } + if (isVisible(selector) === visibility) { + console.log("found in appear"); + resolve($(selector)); + } else { + Ember.run.later(null, function() { + console.log("waiting in appear"); + checkVisibility(selector, interval, resolve, visibility); + }, interval); + } } export default Ember.Test.registerAsyncHelper('waitToAppear', function(app, selector, interval = 200) { diff --git a/app/tests/helpers/wait-to-disappear.js b/app/tests/helpers/wait-to-disappear.js new file mode 100644 index 00000000..476c7373 --- /dev/null +++ b/app/tests/helpers/wait-to-disappear.js @@ -0,0 +1,23 @@ +import Ember from 'ember'; + +function isVisible(selector) { + return $(selector).length > 0; +} + +function checkVisibility(selector, interval, resolve, visibility) { + if (isVisible(selector) === visibility) { + console.log("found"); + resolve($(selector)); + } else { + Ember.run.later(null, function() { + console.log("waiting"); + checkVisibility(selector, interval, resolve, visibility); + }, interval); + } +} + +export default Ember.Test.registerAsyncHelper('waitToDisappear', function(app, selector, interval = 200) { + return new Ember.RSVP.Promise(function(resolve) { + checkVisibility(selector, interval, resolve, false); + }); +}); From 97d2bd2a0ea1c564244ceed1b8120b6acedee331 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 3 Jun 2016 13:41:57 +0200 Subject: [PATCH 34/49] Delete unused helper --- app/tests/helpers/allow-anonymous-access.js | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 app/tests/helpers/allow-anonymous-access.js diff --git a/app/tests/helpers/allow-anonymous-access.js b/app/tests/helpers/allow-anonymous-access.js deleted file mode 100644 index e3081eaa..00000000 --- a/app/tests/helpers/allow-anonymous-access.js +++ /dev/null @@ -1,6 +0,0 @@ -// import Ember from 'ember'; -// -// export default Ember.Test.registerAsyncHelper('allowAnonymousAccess', function(app) { -// var sessionService = Ember.getOwner(this).lookup("service:session"); -// console.log(sessionService); -// }); From 99e4057fada9f9e927fbd483bba538918995eb86 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 8 Jun 2016 15:09:08 +0200 Subject: [PATCH 35/49] Add factories to refactor cleanup mirage config --- app/app/mirage/factories/folder.js | 11 +++++++++++ app/app/mirage/factories/folder_permission.js | 8 ++++++++ app/app/mirage/factories/meta.js | 9 --------- app/app/mirage/factories/permission.js | 8 ++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 app/app/mirage/factories/folder.js create mode 100644 app/app/mirage/factories/folder_permission.js create mode 100644 app/app/mirage/factories/permission.js diff --git a/app/app/mirage/factories/folder.js b/app/app/mirage/factories/folder.js new file mode 100644 index 00000000..aa4cdd4c --- /dev/null +++ b/app/app/mirage/factories/folder.js @@ -0,0 +1,11 @@ +import Mirage, {faker} from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({ + "id": faker.list.cycle('VzMuyEw_3WqiafcG', 'VzMygEw_3WrtFzto'), + "created": "2016-05-11T15:08:24Z", + "revised": "2016-05-11T15:08:24Z", + "name": faker.list.cycle('My Project', 'Test'), + "orgId": "VzMuyEw_3WqiafcD", + "userId": "VzMuyEw_3WqiafcE", + "folderType": faker.list.cycle(1, 2) +}); diff --git a/app/app/mirage/factories/folder_permission.js b/app/app/mirage/factories/folder_permission.js new file mode 100644 index 00000000..0fed7da7 --- /dev/null +++ b/app/app/mirage/factories/folder_permission.js @@ -0,0 +1,8 @@ +import Mirage, {faker} from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({ + "folderId":"VzMuyEw_3WqiafcG", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true +}); diff --git a/app/app/mirage/factories/meta.js b/app/app/mirage/factories/meta.js index 16a91a82..eb824eff 100644 --- a/app/app/mirage/factories/meta.js +++ b/app/app/mirage/factories/meta.js @@ -1,14 +1,5 @@ import Mirage from 'ember-cli-mirage'; -// export default Mirage.Factory.extend({ -// orgId() { return 'VzMuyEw_3WqiafcD'; }, -// title() { return 'EmberSherpa'; }, -// message() { return 'This Documize instance contains all our team documentation'; }, -// url() { return ''; }, -// allowAnonymousAccess() { return false; }, -// version() { return '11.2'; } -// }); - export default Mirage.Factory.extend({ "orgId": "VzMuyEw_3WqiafcD", "title": "EmberSherpa", diff --git a/app/app/mirage/factories/permission.js b/app/app/mirage/factories/permission.js new file mode 100644 index 00000000..83ab4985 --- /dev/null +++ b/app/app/mirage/factories/permission.js @@ -0,0 +1,8 @@ +import Mirage, {faker} from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({ + "folderId": faker.list.cycle('V0Vy5Uw_3QeDAMW9', 'VzMuyEw_3WqiafcG', 'VzMygEw_3WrtFzto', 'VzMygEw_3WrtFzto'), + "userId": faker.list.cycle('VzMuyEw_3WqiafcE', 'VzMuyEw_3WqiafcE', 'VzMuyEw_3WqiafcE', ''), + "canView":true, + "canEdit": faker.list.cycle(true, true, true, false) +}); From 05bd894d454978082c623c4d286fa1b67fd73320 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 8 Jun 2016 15:10:27 +0200 Subject: [PATCH 36/49] Clean up helpers --- app/tests/helpers/stub-user-notification.js | 6 +++--- app/tests/helpers/wait-to-appear.js | 2 -- app/tests/helpers/wait-to-disappear.js | 2 -- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/tests/helpers/stub-user-notification.js b/app/tests/helpers/stub-user-notification.js index 255b8ffd..1df4e2e6 100644 --- a/app/tests/helpers/stub-user-notification.js +++ b/app/tests/helpers/stub-user-notification.js @@ -4,15 +4,15 @@ const userNotification = Ember.Component.extend({ notifications: [], didInsertElement() { - this.eventBus.subscribe('notifyUser', this, 'notifyHandler'); + // this.eventBus.subscribe('notifyUser', this, 'notifyHandler'); }, willDestroyElement() { - this.eventBus.unsubscribe('notifyUser'); + // this.eventBus.unsubscribe('notifyUser'); }, showNotification(msg) { - return msg; + // return msg; } }); diff --git a/app/tests/helpers/wait-to-appear.js b/app/tests/helpers/wait-to-appear.js index 16ec0054..9292d84c 100644 --- a/app/tests/helpers/wait-to-appear.js +++ b/app/tests/helpers/wait-to-appear.js @@ -6,11 +6,9 @@ function isVisible(selector) { function checkVisibility(selector, interval, resolve, visibility) { if (isVisible(selector) === visibility) { - console.log("found in appear"); resolve($(selector)); } else { Ember.run.later(null, function() { - console.log("waiting in appear"); checkVisibility(selector, interval, resolve, visibility); }, interval); } diff --git a/app/tests/helpers/wait-to-disappear.js b/app/tests/helpers/wait-to-disappear.js index 476c7373..8947e6d8 100644 --- a/app/tests/helpers/wait-to-disappear.js +++ b/app/tests/helpers/wait-to-disappear.js @@ -6,11 +6,9 @@ function isVisible(selector) { function checkVisibility(selector, interval, resolve, visibility) { if (isVisible(selector) === visibility) { - console.log("found"); resolve($(selector)); } else { Ember.run.later(null, function() { - console.log("waiting"); checkVisibility(selector, interval, resolve, visibility); }, interval); } From 368bb6850e09bd9a961ef26b65563860d4c43dac Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 8 Jun 2016 15:11:54 +0200 Subject: [PATCH 37/49] Use factories in tests --- .../acceptance/anon-access-disabled-test.js | 1 + .../acceptance/anon-access-enabled-test.js | 2 + app/tests/acceptance/authentication-test.js | 12 +++--- app/tests/acceptance/documents-space-test.js | 43 ++++++++++++++----- app/tests/acceptance/user-profile-test.js | 2 + app/tests/acceptance/user-settings-test.js | 3 ++ 6 files changed, 47 insertions(+), 16 deletions(-) diff --git a/app/tests/acceptance/anon-access-disabled-test.js b/app/tests/acceptance/anon-access-disabled-test.js index 837b13a2..5a260c6a 100644 --- a/app/tests/acceptance/anon-access-disabled-test.js +++ b/app/tests/acceptance/anon-access-disabled-test.js @@ -6,6 +6,7 @@ moduleForAcceptance('Acceptance | Anon access disabled'); test('visiting / when not authenticated and with { allowAnonymousAccess: false } takes user to login', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); visit('/'); andThen(function() { diff --git a/app/tests/acceptance/anon-access-enabled-test.js b/app/tests/acceptance/anon-access-enabled-test.js index 53fdb2d7..8b0f23c0 100644 --- a/app/tests/acceptance/anon-access-enabled-test.js +++ b/app/tests/acceptance/anon-access-enabled-test.js @@ -5,6 +5,7 @@ moduleForAcceptance('Acceptance | Anon access enabled'); test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function(assert) { server.create('meta', { allowAnonymousAccess: true }); + server.createList('folder', 2); visit('/'); andThen(function() { @@ -16,6 +17,7 @@ test('visiting / when not authenticated and with { allowAnonymousAccess: true } test('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function(assert) { server.create('meta', { allowAnonymousAccess: true }); + server.createList('folder', 2); visit('/'); andThen(function() { diff --git a/app/tests/acceptance/authentication-test.js b/app/tests/acceptance/authentication-test.js index 44140250..2a53d7e0 100644 --- a/app/tests/acceptance/authentication-test.js +++ b/app/tests/acceptance/authentication-test.js @@ -1,10 +1,11 @@ -import { test, skip } from 'qunit'; +import { test } from 'qunit'; import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | Authentication'); test('visiting /auth/login and logging in', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); visit('/auth/login'); fillIn('#authEmail', 'brizdigital@gmail.com'); @@ -12,17 +13,18 @@ test('visiting /auth/login and logging in', function(assert) { click('button'); andThen(function() { - assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Login successfull'); }); }); -skip('logging out a user', function(assert) { +test('logging out a user', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); userLogin(); - visit('/auth/logout'); // logs a user out + visit('/auth/logout'); andThen(function() { - assert.equal(currentURL(), '/'); + assert.equal(currentURL(), '/auth/login', 'Login successfull'); }); }); diff --git a/app/tests/acceptance/documents-space-test.js b/app/tests/acceptance/documents-space-test.js index efe28f2e..0a0b0b4f 100644 --- a/app/tests/acceptance/documents-space-test.js +++ b/app/tests/acceptance/documents-space-test.js @@ -1,10 +1,13 @@ import { test, skip } from 'qunit'; import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; +import Ember from 'ember'; -moduleForAcceptance('Acceptance | documents space'); +moduleForAcceptance('Acceptance | Documents space'); test('Adding a new folder space', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); + server.createList('permission', 4); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); @@ -15,17 +18,21 @@ test('Adding a new folder space', function(assert) { }); click('#add-folder-button'); - waitToAppear('#new-folder-name'); - fillIn(".input-control input", 'Test Folder'); - click('.actions div:contains(add)'); + + fillIn('#new-folder-name', 'body', 'Test Folder'); + + click('.actions div:contains(Add)', 'body'); + // return pauseTest(); andThen(function() { assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder'); }); }); -skip('Adding a document to a space', function(assert) { +test('Adding a document to a space', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); + server.createList('permission', 4); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); @@ -37,16 +44,20 @@ skip('Adding a document to a space', function(assert) { }); click('#start-document-button'); - waitToAppear('.drop-content'); - click('.drop-content'); + click('.actions div:contains(Add)', 'body'); andThen(function() { - assert.equal(currentURL(), 's/V0Vy5Uw_3QeDAMW9/test-folder'); + let numberOfDocuments = find('.documents-list li').length; + assert.equal(numberOfDocuments, 3, '3 documents listed'); + assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); + // return pauseTest(); }); }); test('visiting space settings page', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); + server.createList('permission', 4); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); @@ -61,6 +72,8 @@ test('visiting space settings page', function(assert) { test('changing space name', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); + server.createList('permission', 4); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); @@ -77,6 +90,8 @@ test('changing space name', function(assert) { test('sharing a space', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); + server.createList('permission', 4); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); @@ -94,6 +109,8 @@ test('sharing a space', function(assert) { // Test will pass after moving to factories test('changing space permissions', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); + server.createList('permission', 4); userLogin(); andThen(function() { let numberOfPublicFolders = find('.folders-list div:first .list a').length; @@ -119,6 +136,8 @@ test('changing space permissions', function(assert) { test('deleting a space', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); + server.createList('permission', 4); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); @@ -132,6 +151,8 @@ test('deleting a space', function(assert) { test('deleting a document', function(assert) { server.create('meta', { allowAnonymousAccess: false }); + server.createList('folder', 2); + server.createList('permission', 4); userLogin(); visit('/s/VzMuyEw_3WqiafcG/my-project'); @@ -152,11 +173,11 @@ test('deleting a document', function(assert) { click('#delete-documents-button'); waitToAppear('.drop-content'); - click('.flat-red'); + click('.actions div:contains(Delete)', 'body'); andThen(function() { - let deleteButton = find('#delete-documents-button'); - assert.equal(deleteButton.length, 1, 'Delete button displayed'); + let numberOfDocuments = find('.documents-list li'); + assert.equal(numberOfDocuments.length, 1, '1 documents is displayed'); }); }); diff --git a/app/tests/acceptance/user-profile-test.js b/app/tests/acceptance/user-profile-test.js index 24319133..3223627a 100644 --- a/app/tests/acceptance/user-profile-test.js +++ b/app/tests/acceptance/user-profile-test.js @@ -4,6 +4,7 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | user profile'); test('visiting /profile', function(assert) { + server.createList('folder', 2); userLogin(); visit('/profile'); @@ -16,6 +17,7 @@ test('visiting /profile', function(assert) { }); test('changing user details and email ', function(assert) { + server.createList('folder', 2); userLogin(); visit('/profile'); diff --git a/app/tests/acceptance/user-settings-test.js b/app/tests/acceptance/user-settings-test.js index ab8ad80d..c851b422 100644 --- a/app/tests/acceptance/user-settings-test.js +++ b/app/tests/acceptance/user-settings-test.js @@ -80,6 +80,9 @@ test('add a new user', function(assert) { fillIn('#newUserEmail', 'test.user@domain.com'); click('.button-blue'); + // waitToAppear('.user-notification:contains(Added)'); + // waitToDisappear('.user-notification:contains(Added)'); + andThen(function() { let numberOfUsers = find('.user-list tr').length; assert.equal(numberOfUsers, 4, '3 Users listed'); From ac9b749dd276d5300c9368479b2415765d635e4b Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 8 Jun 2016 15:13:23 +0200 Subject: [PATCH 38/49] Add guard to check whether tests are running --- app/app/pods/auth/logout/route.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/app/pods/auth/logout/route.js b/app/app/pods/auth/logout/route.js index cb9c72d8..cb5e8ba3 100644 --- a/app/app/pods/auth/logout/route.js +++ b/app/app/pods/auth/logout/route.js @@ -1,10 +1,15 @@ import Ember from 'ember'; +import config from 'documize/config/environment'; export default Ember.Route.extend({ activate: function(){ this.session.logout(); this.audit.record("logged-in"); this.audit.stop(); - window.document.location = this.session.appMeta.allowAnonymousAccess ? "/" : "/auth/login"; + if (config.environment === 'test') { + this.transitionTo('auth.login'); + }else{ + window.document.location = this.session.appMeta.allowAnonymousAccess ? "/" : "/auth/login"; + } } }); From 41fd9b68a28ab11deec5ebef9165ae3bcbe209e1 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 8 Jun 2016 15:15:37 +0200 Subject: [PATCH 39/49] WIP Converting routes to use factories --- app/app/mirage/config.js | 234 ++++++++++++++++----------------------- 1 file changed, 97 insertions(+), 137 deletions(-) diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index 0f99e3d3..d8118dcc 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -17,7 +17,6 @@ export default function() { // }); this.get('/public/meta', function(db) { - console.log(db.meta[0]); return db.meta[0]; }); @@ -125,54 +124,27 @@ export default function() { } }); - this.get('/folders', function() { - return [{ - "id": "VzMuyEw_3WqiafcG", - "created": "2016-05-11T15:08:24Z", - "revised": "2016-05-11T15:08:24Z", - "name": "My Project", - "orgId": "VzMuyEw_3WqiafcD", - "userId": "VzMuyEw_3WqiafcE", - "folderType": 2 - }, { - "id": "VzMygEw_3WrtFzto", - "created": "2016-05-11T13:24:17Z", - "revised": "2016-05-11T13:25:51Z", - "name": "Test", - "orgId": "VzMuyEw_3WqiafcD", - "userId": "VzMuyEw_3WqiafcE", - "folderType": 1 - }]; - // return [ - // { - // "id":"VzMuyEw_3WqiafcG", - // "created":"2016-05-11T15:08:24Z", - // "revised":"2016-05-11T15:08:24Z", - // "name":"My Project", - // "orgId":"VzMuyEw_3WqiafcD", - // "userId":"VzMuyEw_3WqiafcE", - // "folderType":2 - // },{ - // "id":"VzMygEw_3WrtFzto", - // "created":"2016-05-11T13:24:17Z", - // "revised":"2016-05-11T13:25:51Z", - // "name":"Test", - // "orgId":"VzMuyEw_3WqiafcD", - // "userId":"VzMuyEw_3WqiafcE", - // "folderType":1 - // },{ - // "id":"V0Vy5Uw_3QeDAMW9", - // "created":"2016-05-25T09:39:49Z", - // "revised":"2016-05-25T09:39:49Z", - // "name":"Test Folder", - // "orgId":"VzMuyEw_3WqiafcD", - // "userId":"VzMuyEw_3WqiafcE", - // "folderType":2 - // } - // ]; + this.get('/folders', function(db) { + return db.folders; }); - this.post('/folders', function() { + this.post('/folders', function(db, request) { + // return { + // "id":"V0Vy5Uw_3QeDAMW9", + // "created":"2016-05-25T09:39:49Z", + // "revised":"2016-05-25T09:39:49Z", + // "name":"Test Folder", + // "orgId":"VzMuyEw_3WqiafcD", + // "userId":"VzMuyEw_3WqiafcE", + // "folderType":2 + // }; + // console.log(request); + // var attrs = JSON.parse(request.requestBody).name; + // var folder = db.folders.insert(attrs); + // return folder; + }); + + this.put('/folders/V0Vy5Uw_3QeDAMW9', () => { return { "id":"V0Vy5Uw_3QeDAMW9", "created":"2016-05-25T09:39:49Z", @@ -215,102 +187,94 @@ export default function() { }; }); - this.get('/users/VzMuyEw_3WqiafcE/permissions', () => { - return [ - { - "folderId":"V0Vy5Uw_3QeDAMW9", - "userId":"VzMuyEw_3WqiafcE", - "canView":true, - "canEdit":true - },{ - "folderId":"VzMuyEw_3WqiafcG", - "userId":"VzMuyEw_3WqiafcE", - "canView":true, - "canEdit":true - },{ - "folderId":"VzMygEw_3WrtFzto", - "userId":"VzMuyEw_3WqiafcE", - "canView":true, - "canEdit":true - },{ - "folderId":"VzMygEw_3WrtFzto", - "userId":"", - "canView":true, - "canEdit":false - } - ]; + this.get('/users/VzMuyEw_3WqiafcE/permissions', (db) => { + return db.permissions; }); - this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => { - return [ - { - "folderId":"VzMuyEw_3WqiafcG", - "userId":"VzMuyEw_3WqiafcE", - "canView":true, - "canEdit":true - } - ]; + this.get('/folders/VzMuyEw_3WqiafcG/permissions', (db) => { + let folderId = 'VzMuyEw_3WqiafcG'; + let permissions = db.folder_permissions + console.log(permissions[0]); + debugger; + return permissions; + // return [ + // { + // "folderId":"VzMuyEw_3WqiafcG", + // "userId":"VzMuyEw_3WqiafcE", + // "canView":true, + // "canEdit":true + // } + // ]; }); - this.put('/folders/VzMuyEw_3WqiafcG', () => { - return { - "id":"VzMuyEw_3WqiafcG", - "created":"2016-05-11T15:08:24Z", - "revised":"2016-05-11T15:08:24Z", - "name":"Test Space", - "orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":2 - }; + this.put('/folders/VzMuyEw_3WqiafcG/permissions', (db, request) => { + let id = 'VzMuyEw_3WqiafcG'; + let roles = JSON.parse(request.requestBody).Roles; + // let permissions = db.permissions.update(id, roles[2]); + console.log(roles); + debugger; + return permissions; }); - this.get('/folders/VzMygEw_3WrtFzto', () => { - return { - "id": "VzMygEw_3WrtFzto", - "created": "2016-05-11T13:24:17Z", - "revised": "2016-05-11T13:25:51Z", - "name": "Test", - "orgId": "VzMuyEw_3WqiafcD", - "userId": "VzMuyEw_3WqiafcE", - "folderType": 1 - }; + this.put('/folders/:id', (db, request) => { + let id = request.params.id; + let attrs = JSON.parse(request.requestBody); + let folder = db.folders.update(id, attrs); + return folder; }); - this.get('/folders/V0Vy5Uw_3QeDAMW9', () => { - return { - "id":"V0Vy5Uw_3QeDAMW9", - "created":"2016-05-25T09:39:49Z", - "revised":"2016-05-25T09:39:49Z", - "name":"Test Folder", - "orgId":"VzMuyEw_3WqiafcD", - "userId":"VzMuyEw_3WqiafcE", - "folderType":2 - }; + this.get('folders/:id', (db, request) => { + let id = request.params.id; + return db.folders.find(id); }); - this.get('/folders/VzMuyEw_3WqiafcG', () => { - return { - "id": "VzMuyEw_3WqiafcG", - "created": "2016-05-11T15:08:24Z", - "revised": "2016-05-11T15:08:24Z", - "name": "My Project", - "orgId": "VzMuyEw_3WqiafcD", - "userId": "VzMuyEw_3WqiafcE", - "folderType": 2 - }; - }); - - this.get('/folders/VzMuyEw_3WqiafcG', () => { - return { - "id": "VzMuyEw_3WqiafcG", - "created": "2016-05-11T15:08:24Z", - "revised": "2016-05-11T15:08:24Z", - "name": "My Project", - "orgId": "VzMuyEw_3WqiafcD", - "userId": "VzMuyEw_3WqiafcE", - "folderType": 2 - }; - }); + // this.get('/folders/VzMygEw_3WrtFzto', () => { + // return { + // "id": "VzMygEw_3WrtFzto", + // "created": "2016-05-11T13:24:17Z", + // "revised": "2016-05-11T13:25:51Z", + // "name": "Test", + // "orgId": "VzMuyEw_3WqiafcD", + // "userId": "VzMuyEw_3WqiafcE", + // "folderType": 1 + // }; + // }); + // + // this.get('/folders/V0Vy5Uw_3QeDAMW9', () => { + // return { + // "id":"V0Vy5Uw_3QeDAMW9", + // "created":"2016-05-25T09:39:49Z", + // "revised":"2016-05-25T09:39:49Z", + // "name":"Test Folder", + // "orgId":"VzMuyEw_3WqiafcD", + // "userId":"VzMuyEw_3WqiafcE", + // "folderType":2 + // }; + // }); + // + // this.get('/folders/VzMuyEw_3WqiafcG', () => { + // return { + // "id": "VzMuyEw_3WqiafcG", + // "created": "2016-05-11T15:08:24Z", + // "revised": "2016-05-11T15:08:24Z", + // "name": "My Project", + // "orgId": "VzMuyEw_3WqiafcD", + // "userId": "VzMuyEw_3WqiafcE", + // "folderType": 2 + // }; + // }); + // + // this.get('/folders/VzMuyEw_3WqiafcG', () => { + // return { + // "id": "VzMuyEw_3WqiafcG", + // "created": "2016-05-11T15:08:24Z", + // "revised": "2016-05-11T15:08:24Z", + // "name": "My Project", + // "orgId": "VzMuyEw_3WqiafcD", + // "userId": "VzMuyEw_3WqiafcE", + // "folderType": 2 + // }; + // }); this.get('/organizations/VzMuyEw_3WqiafcD', () => { return { @@ -493,10 +457,6 @@ export default function() { return {}; }); - this.put('/folders/VzMuyEw_3WqiafcG/permissions', () => { - return {}; - }); - /** very helpful for debugging */ From a2bf51d1448ee289afb19ba20ac4e4a9f41d1ab2 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 9 Jun 2016 16:10:50 +0200 Subject: [PATCH 40/49] Refactor to ember-ajax --- app/app/services/document.js | 445 +++++++++---------------------- app/app/services/folder.js | 264 ++++++------------ app/app/services/organization.js | 40 +-- app/app/services/search.js | 20 +- app/app/services/section.js | 72 ++--- app/app/services/session.js | 141 ++++------ app/app/services/template.js | 96 +++---- app/app/services/user.js | 127 +++------ 8 files changed, 387 insertions(+), 818 deletions(-) diff --git a/app/app/services/document.js b/app/app/services/document.js index 8f036c95..1199e593 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -14,51 +14,34 @@ import models from '../utils/model'; export default Ember.Service.extend({ sessionService: Ember.inject.service('session'), + ajax: Ember.inject.service(), // Returns document model for specified document id. getDocument(documentId) { let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let doc = models.DocumentModel.create(response); - resolve(doc); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url).then((response) => { + let doc = models.DocumentModel.create(response); + return doc; }); }, // Returns all documents for specified folder. getAllByFolder(folderId) { - let appMeta = this.get('sessionService.appMeta') + let appMeta = this.get('sessionService.appMeta'); let url = appMeta.getUrl(`documents?folder=${folderId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let documents = Ember.ArrayProxy.create({ - content: Ember.A([]) - }); - - _.each(response, function(doc) { - let documentModel = models.DocumentModel.create(doc); - documents.pushObject(documentModel); - }); - - resolve(documents); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response) => { + let documents = Ember.ArrayProxy.create({ + content: Ember.A([]) }); + + _.each(response, function(doc) { + let documentModel = models.DocumentModel.create(doc); + documents.pushObject(documentModel); + }); + + return documents; }); }, @@ -66,26 +49,17 @@ export default Ember.Service.extend({ getAllByTag(tag) { let url = this.get('sessionService').appMeta.getUrl(`documents?filter=tag&tag=${tag}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let documents = Ember.ArrayProxy.create({ - content: Ember.A([]) - }); - - _.each(response, function(doc) { - let documentModel = models.DocumentModel.create(doc); - documents.pushObject(documentModel); - }); - - resolve(documents); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response) => { + let documents = Ember.ArrayProxy.create({ + content: Ember.A([]) }); + + _.each(response, function(doc) { + let documentModel = models.DocumentModel.create(doc); + documents.pushObject(documentModel); + }); + + return documents; }); }, @@ -94,371 +68,218 @@ export default Ember.Service.extend({ let id = doc.get('id'); let url = this.get('sessionService').appMeta.getUrl(`documents/${id}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'PUT', - data: JSON.stringify(doc), - contentType: 'json', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'PUT', + data: JSON.stringify(doc) + }).then((response) => { + return response; }); }, getBatchedPages: function(documentId, payload) { - var self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/batch"); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/batch"), - type: 'POST', - data: payload, - success: function(pages) { - if (is.not.array(pages)) { - pages = []; - } + return this.get('ajax').request(url, { + method: 'POST', + data: payload + }).then((pages) => { + if (is.not.array(pages)) { + pages = []; + } - resolve(pages); - }, - error: function(reason) { - reject(reason); - } - }); + return pages; }); }, changePageSequence: function(documentId, payload) { - var self = this; + var url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/sequence"); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/sequence"), - type: 'POST', - data: JSON.stringify(payload), - contentType: 'json', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: JSON.stringify(payload), + contentType: 'json' + }).then((response) => { + return response; }); }, changePageLevel(documentId, payload) { - var self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/level"); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/level"), - type: 'POST', - data: JSON.stringify(payload), - contentType: 'json', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: JSON.stringify(payload), + contentType: 'json' + }).then((response) => { + return response; }); }, deleteDocument: function(documentId) { - var self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId), - type: 'DELETE', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'DELETE' + }).then((response) => { + return response; }); }, updatePage: function(documentId, pageId, payload, skipRevision) { - var self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + revision); var revision = skipRevision ? "?r=true" : "?r=false"; - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + revision), - type: 'PUT', - data: JSON.stringify(payload), - contentType: 'json', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'PUT', + data: JSON.stringify(payload), + contentType: 'json' + }).then((response) => { + return response; }); }, // addPage inserts new page to an existing document. addPage: function(documentId, payload) { - var self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages"); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages"), - type: 'POST', - data: JSON.stringify(payload), - contentType: 'json', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: JSON.stringify(payload), + contentType: 'json' + }).then((response) => { + return response; }); }, // Nukes multiple pages from the document. deletePages: function(documentId, pageId, payload) { - var self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId), - type: 'POST', - data: JSON.stringify(payload), - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: JSON.stringify(payload), + contentType: 'json' + }).then((response) => { + return response; }); }, // Nukes a single page from the document. deletePage: function(documentId, pageId) { - var self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId), - type: 'DELETE', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'DELETE' + }).then((response) => { + return response; }); }, getPageRevisions(documentId, pageId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions"); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions"), - type: 'GET', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url).then((response) => { + return response; }); }, getPageRevisionDiff(documentId, pageId, revisionId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions/" + revisionId); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions/" + revisionId), - type: 'GET', - dataType: 'text', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + dataType: 'text' + }).then((response) => { + return response; }); }, rollbackPage(documentId, pageId, revisionId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions/" + revisionId); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions/" + revisionId), - type: 'POST', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url).then((response) => { + return response; }); }, // document meta referes to number of views, edits, approvals, etc. getMeta(documentId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/meta`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`documents/${documentId}/meta`), - type: 'GET', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url).then((response) => { + return response; }); }, // Returns all pages without the content getTableOfContents(documentId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages?content=0`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages?content=0`), - type: 'GET', - success: function(response) { - let data = []; - _.each(response, function(obj) { - data.pushObject(models.PageModel.create(obj)); - }); - resolve(data); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response) => { + let data = []; + _.each(response, function(obj) { + data.pushObject(models.PageModel.create(obj)); }); + + return data; }); }, // Returns all document pages with content getPages(documentId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages`), - type: 'GET', - success: function(response) { - let pages = []; + return this.get('ajax').request(url).then((response) => { + let pages = []; - _.each(response, function(page) { - pages.pushObject(models.PageModel.create(page)); - }); - - if (pages.length > 0) { - Ember.set(pages[0], 'firstPage', true); - } - - resolve(pages); - }, - error: function(reason) { - reject(reason); - } + _.each(response, function(page) { + pages.pushObject(models.PageModel.create(page)); }); + + if (pages.length > 0) { + Ember.set(pages[0], 'firstPage', true); + } + + return pages; }); }, // Returns document page with content getPage(documentId, pageId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages/${pageId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages/${pageId}`), - type: 'GET', - success: function(response) { - let page = models.PageModel.create(response); - resolve(page); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url).then((response) => { + let page = models.PageModel.create(response); + return page; }); }, // Returns document page meta object getPageMeta(documentId, pageId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages/${pageId}/meta`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages/${pageId}/meta`), - type: 'GET', - success: function(response) { - let meta = models.PageMetaModel.create(response); - resolve(meta); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url).then((response) => { + let meta = models.PageMetaModel.create(response); + return meta; }); }, // document attachments without the actual content getAttachments(documentId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/attachments`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`documents/${documentId}/attachments`), - type: 'GET', - success: function(response) { - let data = []; - _.each(response, function(obj) { - data.pushObject(models.AttachmentModel.create(obj)); - }); - resolve(data); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response) => { + let data = []; + _.each(response, function(obj) { + data.pushObject(models.AttachmentModel.create(obj)); }); + return data; }); }, // nuke an attachment deleteAttachment(documentId, attachmentId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/attachments/${attachmentId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`documents/${documentId}/attachments/${attachmentId}`), - type: 'DELETE', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'DELETE' + }).then((response) => { + return response; }); }, }); diff --git a/app/app/services/folder.js b/app/app/services/folder.js index 50ff0a42..1ec18394 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -15,6 +15,7 @@ import BaseService from '../services/base'; export default BaseService.extend({ sessionService: Ember.inject.service('session'), + ajax: Ember.inject.service(), // selected folder currentFolder: null, @@ -25,40 +26,22 @@ export default BaseService.extend({ let appMeta = this.get('sessionService.appMeta'); let url = appMeta.getUrl(`folders`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'POST', - data: JSON.stringify(folder), - contentType: 'json', - success: function(folder) { - let folderModel = models.FolderModel.create(folder); - resolve(folderModel); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: JSON.stringify(folder) + }).then((folder)=>{ + let folderModel = models.FolderModel.create(folder); + return folderModel; }); }, // Returns folder model for specified folder id. getFolder(id) { - let appMeta = this.get('sessionService.appMeta') + let appMeta = this.get('sessionService.appMeta'); let url = appMeta.getUrl(`folders/${id}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let folder = models.FolderModel.create(response); - resolve(folder); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url).then((response)=>{ + let folder = models.FolderModel.create(response); + return folder; }); }, @@ -80,57 +63,31 @@ export default BaseService.extend({ let id = folder.get('id'); let url = this.get('sessionService').appMeta.getUrl(`folders/${id}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'PUT', - data: JSON.stringify(folder), - contentType: 'json', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'PUT', + data: JSON.stringify(folder) + }).then((response)=>{ + return response; }); }, remove: function(folderId, moveToId) { - var self = this; - var url = self.get('sessionService').appMeta.getUrl('folders/' + folderId + "/move/" + moveToId); + var url = this.get('sessionService').appMeta.getUrl('folders/' + folderId + "/move/" + moveToId); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'DELETE', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'DELETE' + }).then((response)=>{ + return response; }); }, onboard: function(folderId, payload) { - var self = this; - var url = self.get('sessionService').appMeta.getUrl('public/share/' + folderId); + var url = this.get('sessionService').appMeta.getUrl('public/share/' + folderId); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: "POST", - data: payload, - contentType: "application/json", - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: payload + }).then((response)=>{ + return response; }); }, @@ -138,107 +95,65 @@ export default BaseService.extend({ getProtectedFolderInfo: function() { var url = this.get('sessionService').appMeta.getUrl('folders?filter=viewers'); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let data = []; - _.each(response, function(obj) { - data.pushObject(models.ProtectedFolderParticipant.create(obj)); - }); - - resolve(data); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response)=>{ + let data = []; + _.each(response, function(obj) { + data.pushObject(models.ProtectedFolderParticipant.create(obj)); }); + + return data; }); }, // reloads and caches folders. reload() { - let appMeta = this.get('sessionService.appMeta') + let appMeta = this.get('sessionService.appMeta'); let url = appMeta.getUrl(`folders`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let data = []; - _.each(response, function(obj) { - data.pushObject(models.FolderModel.create(obj)); - }); - resolve(data); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response)=>{ + let data = []; + _.each(response, function(obj) { + data.pushObject(models.FolderModel.create(obj)); }); + + return data; }); }, // so who can see/edit this folder? getPermissions(folderId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`folders/${folderId}/permissions`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`folders/${folderId}/permissions`), - type: 'GET', - success: function(response) { - let data = []; - _.each(response, function(obj) { - data.pushObject(models.FolderPermissionModel.create(obj)); - }); - resolve(data); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response)=>{ + let data = []; + _.each(response, function(obj) { + data.pushObject(models.FolderPermissionModel.create(obj)); }); + + return data; }); }, // persist folder permissions savePermissions(folderId, payload) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`folders/${folderId}/permissions`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`folders/${folderId}/permissions`), - type: 'PUT', - contentType: 'json', - data: JSON.stringify(payload), - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'PUT', + data: JSON.stringify(payload) + }).then((response) => { + return response; }); }, // share this folder with new users! share(folderId, invitation) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl(`folders/${folderId}/invitation`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl(`folders/${folderId}/invitation`), - type: 'POST', - contentType: 'json', - data: JSON.stringify(invitation), - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: JSON.stringify(invitation) + }).then((response) => { + return response; }); }, @@ -258,43 +173,38 @@ export default BaseService.extend({ } let url = this.get('sessionService').appMeta.getUrl('users/' + userId + "/permissions"); - let self = this; - $.ajax({ - url: url, - type: 'GET', - success: function(folderPermissions) { - // safety check - self.set('canEditCurrentFolder', false); + return this.get('ajax').request(url).then((folderPermissions) => { + // safety check + this.set('canEditCurrentFolder', false); - if (folderPermissions.length === 0) { - return; + if (folderPermissions.length === 0) { + return; + } + + let result = []; + let folderId = folder.get('id'); + + folderPermissions.forEach(function(item) { + if (item.folderId === folderId) { + result.push(item); + } + }); + + let canEdit = false; + + result.forEach(function(permission) { + if (permission.userId === userId) { + canEdit = permission.canEdit; } - let result = []; - let folderId = folder.get('id'); - - folderPermissions.forEach(function(item) { - if (item.folderId === folderId) { - result.push(item); - } - }); - - let canEdit = false; - - result.forEach(function(permission) { - if (permission.userId === userId) { - canEdit = permission.canEdit; - } - - if (permission.userId === "" && !canEdit) { - canEdit = permission.canEdit; - } - }); - Ember.run(() => { - self.set('canEditCurrentFolder', canEdit && self.get('sessionService').authenticated); - }); - } + if (permission.userId === "" && !canEdit) { + canEdit = permission.canEdit; + } + }); + Ember.run(() => { + this.set('canEditCurrentFolder', canEdit && this.get('sessionService').authenticated); + }); }); }, -}); \ No newline at end of file +}); diff --git a/app/app/services/organization.js b/app/app/services/organization.js index 24ee457e..8a353546 100644 --- a/app/app/services/organization.js +++ b/app/app/services/organization.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -14,23 +14,15 @@ import models from '../utils/model'; export default Ember.Service.extend({ sessionService: Ember.inject.service('session'), + ajax: Ember.inject.service(), // Returns attributes for specified org id. getOrg(id) { let url = this.get('sessionService').appMeta.getUrl(`organizations/${id}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let org = models.OrganizationModel.create(response); - resolve(org); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url).then((response) =>{ + let org = models.OrganizationModel.create(response); + return org; }); }, @@ -43,19 +35,11 @@ export default Ember.Service.extend({ this.get('sessionService').get('appMeta').setSafe('message', org.message); this.get('sessionService').get('appMeta').setSafe('title', org.title); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'PUT', - data: JSON.stringify(org), - contentType: 'json', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'PUT', + data: JSON.stringify(org) + }).then((response) => { + return response; }); } -}); \ No newline at end of file +}); diff --git a/app/app/services/search.js b/app/app/services/search.js index c4f88d92..94ed87d4 100644 --- a/app/app/services/search.js +++ b/app/app/services/search.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -13,22 +13,14 @@ import Ember from 'ember'; export default Ember.Service.extend({ sessionService: Ember.inject.service('session'), + ajax: Ember.inject.service(), // getUsers returns all users for organization. find(keywords) { let url = this.get('sessionService').appMeta.getUrl("search?keywords=" + encodeURIComponent(keywords)); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url).then((response) => { + return response; }); }, -}); \ No newline at end of file +}); diff --git a/app/app/services/section.js b/app/app/services/section.js index b7da9c7c..14533cca 100644 --- a/app/app/services/section.js +++ b/app/app/services/section.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -15,26 +15,21 @@ import BaseService from '../services/base'; export default BaseService.extend({ sessionService: Ember.inject.service('session'), + ajax: Ember.inject.service(), // Returns all available sections. getAll() { let url = this.get('sessionService').appMeta.getUrl(`sections`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let data = []; - _.each(response, function(obj) { - data.pushObject(models.SectionModel.create(obj)); - }); - resolve(data); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url,{ + method: 'GET' + }).then((response)=>{ + let data = []; + _.each(response, function(obj) { + data.pushObject(models.SectionModel.create(obj)); }); + + return data; }); }, @@ -46,19 +41,10 @@ export default BaseService.extend({ let endpoint = `sections?documentID=${documentId}§ion=${section}&method=${method}`; let url = this.get('sessionService').appMeta.getUrl(endpoint); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'POST', - data: JSON.stringify(data), - contentType: "application/json", - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: JSON.stringify(data) + }).then((response)=>{ + return response; }); }, @@ -66,26 +52,16 @@ export default BaseService.extend({ refresh(documentId) { let url = this.get('sessionService').appMeta.getUrl(`sections/refresh?documentID=${documentId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - // resolve(response); - let pages = []; + return this.get('ajax').request(url).then((response)=>{ + let pages = []; - if (is.not.null(response) && is.array(response) && response.length > 0) { - _.each(response, function(page) { - pages.pushObject(models.PageModel.create(page)); - }); - } + if (is.not.null(response) && is.array(response) && response.length > 0) { + _.each(response, function(page) { + pages.pushObject(models.PageModel.create(page)); + }); + } - resolve(pages); - }, - error: function(reason) { - reject(reason); - } - }); + return pages; }); } -}); \ No newline at end of file +}); diff --git a/app/app/services/session.js b/app/app/services/session.js index 818d6f6a..851311bc 100644 --- a/app/app/services/session.js +++ b/app/app/services/session.js @@ -24,6 +24,7 @@ export default Ember.Service.extend({ authenticated: false, folderPermissions: null, currentFolder: null, + ajax: Ember.inject.service(), isAdmin: function() { if (this.authenticated && is.not.null(this.user) && this.user.id !== "") { @@ -50,68 +51,48 @@ export default Ember.Service.extend({ // Authentication login: function(credentials) { - var self = this; - var url = self.appMeta.getUrl('public/authenticate'); + let url = this.appMeta.getUrl('public/authenticate'); let domain = netUtil.getSubdomain(); this.clearSession(); - return new Ember.RSVP.Promise(function(resolve, reject) { - if (is.empty(credentials.email) || is.empty(credentials.password)) { - reject("invalid"); - return; - } + if (is.empty(credentials.email) || is.empty(credentials.password)) { + return Ember.RSVP.reject("invalid"); + } - var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password); - var header = { - 'Authorization': 'Basic ' + encoded - }; + var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password); + var headers = { + 'Authorization': 'Basic ' + encoded + }; - $.ajax({ - url: url, - type: 'POST', - headers: header, - success: function(response) { - self.setSession(response.token, models.UserModel.create(response.user)); - self.get('ready', true); - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + headers + }).then((response)=>{ + this.setSession(response.token, models.UserModel.create(response.user)); + this.get('ready', true); + return response; }); }, // SSO in the form of 'domain:email:password' sso: function(credentials) { - var self = this; - var url = self.appMeta.getUrl('public/authenticate'); + let url = this.appMeta.getUrl('public/authenticate'); this.clearSession(); - return new Ember.RSVP.Promise(function(resolve, reject) { - if (is.empty(credentials.email) || is.empty(credentials.password)) { - reject("invalid"); - return; - } + if (is.empty(credentials.email) || is.empty(credentials.password)) { + return Ember.RSVP.reject("invalid"); + } - var header = { - 'Authorization': 'Basic ' + credentials - }; + var headers = { + 'Authorization': 'Basic ' + credentials + }; - $.ajax({ - url: url, - type: 'POST', - headers: header, - success: function(response) { - self.setSession(response.token, models.UserModel.create(response.user)); - self.get('ready', true); - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + headers + }).then((response)=>{ + this.setSession(response.token, models.UserModel.create(response.user)); + this.get('ready', true); + resolve(response); }); }, @@ -192,51 +173,35 @@ export default Ember.Service.extend({ // this.set('popupBlocked', false); // } - return new Ember.RSVP.Promise(function(resolve) { - $.ajax({ - url: self.get('appMeta').getUrl("public/meta"), - type: 'GET', - contentType: 'json', - success: function(response) { - self.get('appMeta').set('orgId', response.orgId); - self.get('appMeta').setSafe('title', response.title); - self.get('appMeta').set('version', response.version); - self.get('appMeta').setSafe('message', response.message); - self.get('appMeta').set('allowAnonymousAccess', response.allowAnonymousAccess); + let url = this.get('appMeta').getUrl("public/meta"); - let token = self.getSessionItem('token'); + return this.get('ajax').request(url) + .then((response) => { + this.get('appMeta').set('orgId', response.orgId); + this.get('appMeta').setSafe('title', response.title); + this.get('appMeta').set('version', response.version); + this.get('appMeta').setSafe('message', response.message); + this.get('appMeta').set('allowAnonymousAccess', response.allowAnonymousAccess); - if (is.not.undefined(token)) { - // We now validate current token - let tokenCheckUrl = self.get('appMeta').getUrl(`public/validate?token=${token}`); + let token = this.getSessionItem('token'); - $.ajax({ - url: tokenCheckUrl, - type: 'GET', - contentType: 'json', - success: function(user) { - self.setSession(token, models.UserModel.create(user)); - self.set('ready', true); - resolve(); - }, - error: function(reason) { - if (reason.status === 401 || reason.status === 403) { - localStorage.clear(); - window.location.href = "/auth/login"; - } - } - }); - } else { - self.set('ready', true); - resolve(); - } - }, - error: function(reason) { + if (is.not.undefined(token)) { + // We now validate current token + let tokenCheckUrl = this.get('appMeta').getUrl(`public/validate?token=${token}`); + + return this.get('ajax').request(tokenCheckUrl, { + method: 'GET', + contentType: 'json' + }).then((response) => { + this.setSession(token, models.UserModel.create(user)); + this.set('ready', true); + }).catch((reason) => { if (reason.status === 401 || reason.status === 403) { - window.location.href = "https://documize.com"; + localStorage.clear(); + window.location.href = "/auth/login"; } - } - }); + }); + } }); } -}); \ No newline at end of file +}); diff --git a/app/app/services/template.js b/app/app/services/template.js index 471d6eee..fea37076 100644 --- a/app/app/services/template.js +++ b/app/app/services/template.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -14,85 +14,55 @@ import models from '../utils/model'; export default Ember.Service.extend({ sessionService: Ember.inject.service('session'), + ajax: Ember.inject.service(), importStockTemplate: function(folderId, templateId) { - let self = this; - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("templates/" + templateId + "/folder/" + folderId + "?type=stock"), - type: 'POST', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + let url = this.get('sessionService').appMeta.getUrl("templates/" + templateId + "/folder/" + folderId + "?type=stock"); + + return this.get('ajax').post(url).then((response)=>{ + return response; }); }, importSavedTemplate: function(folderId, templateId) { - let self = this; + let url = this.get('sessionService').appMeta.getUrl("templates/" + templateId + "/folder/" + folderId + "?type=saved"); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("templates/" + templateId + "/folder/" + folderId + "?type=saved"), - type: 'POST', - success: function(doc) { - let docModel = models.DocumentModel.create(doc); - resolve(docModel); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url).then((doc)=>{ + let docModel = models.DocumentModel.create(doc); + return docModel; }); }, getSavedTemplates() { - let self = this; + let url = this.get('sessionService').appMeta.getUrl("templates"); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("templates"), - type: 'GET', - success: function(response) { - if (is.not.array(response)) { - response = []; - } - let templates = Ember.ArrayProxy.create({ - content: Ember.A([]) - }); - - _.each(response, function(template) { - let templateModel = models.TemplateModel.create(template); - templates.pushObject(templateModel); - }); - - resolve(templates); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url, { + type: 'GET' + }).then((response) => { + if (is.not.array(response)) { + response = []; + } + let templates = Ember.ArrayProxy.create({ + content: Ember.A([]) }); + + _.each(response, function(template) { + let templateModel = models.TemplateModel.create(template); + templates.pushObject(templateModel); + }); + + return templates; }); }, getStockTemplates() { - let self = this; + let url = this.get('sessionService').appMeta.getUrl("templates/stock"); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: self.get('sessionService').appMeta.getUrl("templates/stock"), - type: 'GET', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + type: 'GET' + }).then((response) => { + return response; }); } -}); \ No newline at end of file +}); diff --git a/app/app/services/user.js b/app/app/services/user.js index 121f5a8f..0ad6babc 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -33,17 +33,10 @@ export default Ember.Service.extend({ getUser(userId) { let url = this.get('sessionService').appMeta.getUrl(`users/${userId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - resolve(models.UserModel.create(response)); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + type: 'GET' + }).then((response) => { + return models.UserModel.create(response); }); }, @@ -62,22 +55,13 @@ export default Ember.Service.extend({ getFolderUsers(folderId) { let url = this.get('sessionService').appMeta.getUrl(`users/folder/${folderId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'GET', - success: function(response) { - let data = []; - _.each(response, function(obj) { - data.pushObject(models.UserModel.create(obj)); - }); - - resolve(data); - }, - error: function(reason) { - reject(reason); - } + return this.get('ajax').request(url).then((response)=>{ + let data = []; + _.each(response, function(obj) { + data.pushObject(models.UserModel.create(obj)); }); + + return data; }); }, @@ -97,18 +81,10 @@ export default Ember.Service.extend({ updatePassword(userId, password) { let url = this.get('sessionService').appMeta.getUrl(`users/${userId}/password`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'POST', - data: password, - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + data: password + }).then((response)=>{ + return response; }); }, @@ -116,46 +92,30 @@ export default Ember.Service.extend({ remove(userId) { let url = this.get('sessionService').appMeta.getUrl(`users/${userId}`); - return new Ember.RSVP.Promise(function(resolve, reject) { - $.ajax({ - url: url, - type: 'DELETE', - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').request(url, { + method: 'DELETE' + }).then((response) => { + return response; }); }, // Request password reset. forgotPassword(email) { - var url = this.get('sessionService').appMeta.getUrl('public/forgot'); + let url = this.get('sessionService').appMeta.getUrl('public/forgot'); - return new Ember.RSVP.Promise(function(resolve, reject) { - if (is.empty(email)) { - reject("invalid"); - return; - } + if (is.empty(email)) { + reject("invalid"); + return; + } - var data = JSON.stringify({ - Email: email - }); + let data = JSON.stringify({ + Email: email + }); - $.ajax({ - url: url, - type: 'POST', - dataType: 'json', - data: data, - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.request('ajax').post(url, { + data: data + }).then((response)=>{ + return response; }); }, @@ -163,23 +123,14 @@ export default Ember.Service.extend({ resetPassword(token, password) { var url = this.get('sessionService').appMeta.getUrl('public/reset/' + token); - return new Ember.RSVP.Promise(function(resolve, reject) { - if (is.empty(token) || is.empty(password)) { - reject("invalid"); - return; - } + if (is.empty(token) || is.empty(password)) { + return Ember.RSVP.reject("invalid"); + } - $.ajax({ - url: url, - type: 'POST', - data: password, - success: function(response) { - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.request('ajax').post(url, { + data: password + }).then((response)=>{ + return response; }); } }); From df62973eb4e6a8260698222f19fb9900a5979fef Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 9 Jun 2016 16:12:10 +0200 Subject: [PATCH 41/49] Minor tweaks and fixes to broken tests --- .../acceptance/anon-access-enabled-test.js | 3 +- app/tests/acceptance/user-profile-test.js | 2 +- app/tests/helpers/stub-session.js | 172 +++++++++--------- 3 files changed, 88 insertions(+), 89 deletions(-) diff --git a/app/tests/acceptance/anon-access-enabled-test.js b/app/tests/acceptance/anon-access-enabled-test.js index 8b0f23c0..5ec94855 100644 --- a/app/tests/acceptance/anon-access-enabled-test.js +++ b/app/tests/acceptance/anon-access-enabled-test.js @@ -7,10 +7,11 @@ test('visiting / when not authenticated and with { allowAnonymousAccess: true } server.create('meta', { allowAnonymousAccess: true }); server.createList('folder', 2); visit('/'); + // return pauseTest(); andThen(function() { assert.equal(find('.login').length, 1, 'Login button is displayed'); - assert.equal(find('.document-card').length, 2, '2 document displayed'); + assert.equal(find('.documents-list .document').length, 2, '2 document displayed'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Dashboard and public spaces are displayed without being signed in'); }); }); diff --git a/app/tests/acceptance/user-profile-test.js b/app/tests/acceptance/user-profile-test.js index 3223627a..a0be37c7 100644 --- a/app/tests/acceptance/user-profile-test.js +++ b/app/tests/acceptance/user-profile-test.js @@ -36,6 +36,6 @@ test('changing user details and email ', function(assert) { andThen(function() { assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); - assert.equal(find('.name').text().trim(), 'Test User', 'Profile name displayed'); + assert.equal(find('.content .name').text().trim(), 'Test User', 'Profile name displayed'); }); }); diff --git a/app/tests/helpers/stub-session.js b/app/tests/helpers/stub-session.js index b725ff1c..738a126f 100644 --- a/app/tests/helpers/stub-session.js +++ b/app/tests/helpers/stub-session.js @@ -14,14 +14,8 @@ const Session = Ember.Service.extend({ authenticated: false, folderPermissions: null, currentFolder: null, + ajax: Ember.inject.service(), - init: function() { - this.set('user', models.UserModel.create()); - this.appMeta = models.AppMeta.create(); - - this.set('isMac', is.mac()); - this.set('isMobile', is.mobile()); - }, isAdmin: function() { if (this.authenticated && is.not.null(this.user) && this.user.id !== "") { return this.user.admin; @@ -36,38 +30,57 @@ const Session = Ember.Service.extend({ return false; }.property('user'), - login(credentials) { - // TODO: figure out what to do with credentials - var self = this; - var url = self.appMeta.getUrl('public/authenticate'); + // Boot up + init: function() { + this.set('user', models.UserModel.create()); + this.appMeta = models.AppMeta.create(); + + this.set('isMac', is.mac()); + this.set('isMobile', is.mobile()); + }, + + login: function(credentials) { + let url = this.appMeta.getUrl('public/authenticate'); let domain = netUtil.getSubdomain(); this.clearSession(); - return new Ember.RSVP.Promise(function(resolve, reject) { - if (is.empty(credentials.email) || is.empty(credentials.password)) { - reject("invalid"); - return; - } + if (is.empty(credentials.email) || is.empty(credentials.password)) { + return Ember.RSVP.reject("invalid"); + } - var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password); - var header = { - 'Authorization': 'Basic ' + encoded - }; + var encoded = encodingUtil.Base64.encode(domain + ":" + credentials.email + ":" + credentials.password); + var headers = { + 'Authorization': 'Basic ' + encoded + }; - $.ajax({ - url: url, - type: 'POST', - headers: header, - success: function(response) { - self.setSession(response.token, models.UserModel.create(response.user)); - self.get('ready', true); - resolve(response); - }, - error: function(reason) { - reject(reason); - } - }); + return this.get('ajax').post(url, { + headers + }).then((response)=>{ + this.setSession(response.token, models.UserModel.create(response.user)); + this.get('ready', true); + return response; + }); + }, + + sso: function(credentials) { + let url = this.appMeta.getUrl('public/authenticate'); + this.clearSession(); + + if (is.empty(credentials.email) || is.empty(credentials.password)) { + return Ember.RSVP.reject("invalid"); + } + + var headers = { + 'Authorization': 'Basic ' + credentials + }; + + return this.get('ajax').post(url, { + headers + }).then((response)=>{ + this.setSession(response.token, models.UserModel.create(response.user)); + this.get('ready', true); + resolve(response); }); }, @@ -84,8 +97,13 @@ const Session = Ember.Service.extend({ this.storeSessionItem('token', token); this.storeSessionItem('user', JSON.stringify(user)); + let self = this; + $.ajaxPrefilter(function(options, originalOptions, jqXHR) { - jqXHR.setRequestHeader('Authorization', 'Bearer ' + token); + // We only tack on auth header for Documize API calls + if (is.startWith(options.url, self.get('appMeta.url'))) { + jqXHR.setRequestHeader('Authorization', 'Bearer ' + token); + } }); }, @@ -109,11 +127,6 @@ const Session = Ember.Service.extend({ // delete localStorage[key]; }, - // boot(){ - // console.log(this.get('appMeta')); - // return new Ember.RSVP.resolve(); - // }, - boot() { let self = this; let dbhash = ""; @@ -140,60 +153,45 @@ const Session = Ember.Service.extend({ }); } - return new Ember.RSVP.Promise(function(resolve) { - $.ajax({ - url: self.get('appMeta').getUrl("public/meta"), - type: 'GET', - contentType: 'json', - success: function(response) { - self.get('appMeta').set('orgId', response.orgId); - self.get('appMeta').setSafe('title', response.title); - self.get('appMeta').set('version', response.version); - self.get('appMeta').setSafe('message', response.message); - self.get('appMeta').set('allowAnonymousAccess', response.allowAnonymousAccess); + // var blockedPopupTest = window.open("http://maintenance.documize.com", "directories=no,height=1,width=1,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no"); + // + // if (!blockedPopupTest) { + // this.set('popupBlocked', true); + // } else { + // blockedPopupTest.close(); + // this.set('popupBlocked', false); + // } - let token = self.getSessionItem('token'); + let url = this.get('appMeta').getUrl("public/meta"); - if (is.not.undefined(token)) { - // We now validate current token - let tokenCheckUrl = self.get('appMeta').getUrl(`public/validate?token=${token}`); + return this.get('ajax').request(url) + .then((response) => { + this.get('appMeta').set('orgId', response.orgId); + this.get('appMeta').setSafe('title', response.title); + this.get('appMeta').set('version', response.version); + this.get('appMeta').setSafe('message', response.message); + this.get('appMeta').set('allowAnonymousAccess', response.allowAnonymousAccess); - $.ajax({ - url: tokenCheckUrl, - type: 'GET', - contentType: 'json', - success: function(user) { - self.setSession(token, models.UserModel.create(user)); - self.set('ready', true); - resolve(); - }, - error: function(reason) { - if (reason.status === 401 || reason.status === 403) { - localStorage.clear(); - window.location.href = "/auth/login"; - } - } - }); - } else { - self.set('ready', true); - resolve(); - } - }, - error: function(reason) { + let token = this.getSessionItem('token'); + + if (is.not.undefined(token)) { + // We now validate current token + let tokenCheckUrl = this.get('appMeta').getUrl(`public/validate?token=${token}`); + + return this.get('ajax').request(tokenCheckUrl, { + method: 'GET', + contentType: 'json' + }).then((response) => { + this.setSession(token, models.UserModel.create(user)); + this.set('ready', true); + }).catch((reason) => { if (reason.status === 401 || reason.status === 403) { - window.location.href = "https://documize.com"; + localStorage.clear(); + window.location.href = "/auth/login"; } - } - }); + }); + } }); - }, - - getSessionItem(key){ - return this.get(`data.${key}`); - }, - - sso: function(credentials) { - } }); From bb08df142f6a1209c8ab973aef991af3f3e0524b Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 9 Jun 2016 16:14:16 +0200 Subject: [PATCH 42/49] WIP refactor to use factories --- app/app/mirage/config.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index d8118dcc..3a5b325e 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -192,28 +192,26 @@ export default function() { }); this.get('/folders/VzMuyEw_3WqiafcG/permissions', (db) => { - let folderId = 'VzMuyEw_3WqiafcG'; - let permissions = db.folder_permissions - console.log(permissions[0]); - debugger; - return permissions; - // return [ - // { - // "folderId":"VzMuyEw_3WqiafcG", - // "userId":"VzMuyEw_3WqiafcE", - // "canView":true, - // "canEdit":true - // } - // ]; + // let folderId = 'VzMuyEw_3WqiafcG'; + // let permissions = db.folder_permissions + // console.log(permissions[0]); + // debugger; + // return permissions; + return [ + { + "folderId":"VzMuyEw_3WqiafcG", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true + } + ]; }); this.put('/folders/VzMuyEw_3WqiafcG/permissions', (db, request) => { let id = 'VzMuyEw_3WqiafcG'; let roles = JSON.parse(request.requestBody).Roles; // let permissions = db.permissions.update(id, roles[2]); - console.log(roles); - debugger; - return permissions; + // return permissions; }); this.put('/folders/:id', (db, request) => { From 4f6ad04995c5340bdb04830061ce53b681749fb6 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 9 Jun 2016 18:56:07 +0200 Subject: [PATCH 43/49] Fix ember-ajax refactor issues --- app/app/services/document.js | 2 +- app/app/services/session.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/app/services/document.js b/app/app/services/document.js index 1199e593..beb89c8c 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -124,8 +124,8 @@ export default Ember.Service.extend({ }, updatePage: function(documentId, pageId, payload, skipRevision) { - let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + revision); var revision = skipRevision ? "?r=true" : "?r=false"; + let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + revision); return this.get('ajax').request(url, { method: 'PUT', diff --git a/app/app/services/session.js b/app/app/services/session.js index 851311bc..1de1fa04 100644 --- a/app/app/services/session.js +++ b/app/app/services/session.js @@ -92,7 +92,7 @@ export default Ember.Service.extend({ }).then((response)=>{ this.setSession(response.token, models.UserModel.create(response.user)); this.get('ready', true); - resolve(response); + return response; }); }, @@ -192,7 +192,7 @@ export default Ember.Service.extend({ return this.get('ajax').request(tokenCheckUrl, { method: 'GET', contentType: 'json' - }).then((response) => { + }).then((user) => { this.setSession(token, models.UserModel.create(user)); this.set('ready', true); }).catch((reason) => { From 9fa6e0d05508cb2cc610710a8a52036b48361f85 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 9 Jun 2016 18:56:35 +0200 Subject: [PATCH 44/49] Fix permissions test --- app/app/mirage/config.js | 81 +++++++++++++------- app/tests/acceptance/documents-space-test.js | 3 +- app/tests/helpers/stub-audit.js | 4 +- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index 3a5b325e..5317cb41 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -129,31 +129,20 @@ export default function() { }); this.post('/folders', function(db, request) { - // return { - // "id":"V0Vy5Uw_3QeDAMW9", - // "created":"2016-05-25T09:39:49Z", - // "revised":"2016-05-25T09:39:49Z", - // "name":"Test Folder", - // "orgId":"VzMuyEw_3WqiafcD", - // "userId":"VzMuyEw_3WqiafcE", - // "folderType":2 - // }; - // console.log(request); - // var attrs = JSON.parse(request.requestBody).name; - // var folder = db.folders.insert(attrs); - // return folder; - }); - - this.put('/folders/V0Vy5Uw_3QeDAMW9', () => { - return { + var name = JSON.parse(request.requestBody).name; + let newFolder = { "id":"V0Vy5Uw_3QeDAMW9", "created":"2016-05-25T09:39:49Z", "revised":"2016-05-25T09:39:49Z", - "name":"Test Folder", + "name":name, "orgId":"VzMuyEw_3WqiafcD", "userId":"VzMuyEw_3WqiafcE", "folderType":2 }; + + let folder = db.folders.insert(newFolder); + console.log(newFolder); + return folder; }); this.post('/public/authenticate', () => { @@ -192,11 +181,6 @@ export default function() { }); this.get('/folders/VzMuyEw_3WqiafcG/permissions', (db) => { - // let folderId = 'VzMuyEw_3WqiafcG'; - // let permissions = db.folder_permissions - // console.log(permissions[0]); - // debugger; - // return permissions; return [ { "folderId":"VzMuyEw_3WqiafcG", @@ -207,20 +191,61 @@ export default function() { ]; }); - this.put('/folders/VzMuyEw_3WqiafcG/permissions', (db, request) => { - let id = 'VzMuyEw_3WqiafcG'; - let roles = JSON.parse(request.requestBody).Roles; - // let permissions = db.permissions.update(id, roles[2]); - // return permissions; + this.put('/folders/VzMygEw_3WrtFzto/permissions', () => { + return [ + { + "orgId":"VzMuyEw_3WqiafcD", + "folderId":"VzMygEw_3WrtFzto", + "userId":"", + "canEdit":true, + "canView":true + },{ + "orgId":"VzMuyEw_3WqiafcD", + "folderId":"VzMygEw_3WrtFzto", + "userId":"VzMyp0w_3WrtFztq", + "canEdit":false, + "canView":false + },{ + "orgId":"", + "folderId":"VzMygEw_3WrtFzto", + "userId":"VzMuyEw_3WqiafcE", + "canEdit":true, + "canView":true + } + ]; + }); + + this.get('/folders/VzMygEw_3WrtFzto/permissions', () => { + return [ + { + "folderId":"VzMygEw_3WrtFzto", + "userId":"VzMuyEw_3WqiafcE", + "canView":true, + "canEdit":true + } + ]; }); this.put('/folders/:id', (db, request) => { let id = request.params.id; let attrs = JSON.parse(request.requestBody); let folder = db.folders.update(id, attrs); + console.log(folder); return folder; }); + this.put('/folders/V0Vy5Uw_3QeDAMW9', () => { + return { + "id":"V0Vy5Uw_3QeDAMW9", + "created":"2016-05-25T09:39:49Z", + "revised":"2016-05-25T09:39:49Z", + "name":"Test Folder", + "orgId":"VzMuyEw_3WqiafcD", + "userId":"VzMuyEw_3WqiafcE", + "folderType":2 + }; + }); + this.get('folders/:id', (db, request) => { let id = request.params.id; return db.folders.find(id); diff --git a/app/tests/acceptance/documents-space-test.js b/app/tests/acceptance/documents-space-test.js index 0a0b0b4f..8bd76ece 100644 --- a/app/tests/acceptance/documents-space-test.js +++ b/app/tests/acceptance/documents-space-test.js @@ -22,7 +22,6 @@ test('Adding a new folder space', function(assert) { fillIn('#new-folder-name', 'body', 'Test Folder'); click('.actions div:contains(Add)', 'body'); - // return pauseTest(); andThen(function() { assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder'); @@ -118,7 +117,7 @@ test('changing space permissions', function(assert) { assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); }); - visit('/s/VzMuyEw_3WqiafcG/my-project/settings'); + visit('/s/VzMygEw_3WrtFzto/test/settings'); click(('.sidebar-menu .options li:contains(Permissions)')); click('tr:contains(Everyone) #canView-'); diff --git a/app/tests/helpers/stub-audit.js b/app/tests/helpers/stub-audit.js index 53778b97..2d9c6037 100644 --- a/app/tests/helpers/stub-audit.js +++ b/app/tests/helpers/stub-audit.js @@ -64,6 +64,6 @@ const Audit = Ember.Service.extend({ }, }); -export default Ember.Test.registerAsyncHelper('stubAudit', function(app, test, attrs={}) { +export default Ember.Test.registerAsyncHelper('stubAudit', function(app, test, attrs = {}) { test.register('service:audit', Audit.extend(attrs)); -}); +}); \ No newline at end of file From d856879e827ba1e06d29dbce1ecf4a391e36ae0b Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 10 Jun 2016 11:25:12 +0200 Subject: [PATCH 45/49] Comment out tests with tooltips --- app/tests/acceptance/documents-space-test.js | 159 +++++++++---------- 1 file changed, 79 insertions(+), 80 deletions(-) diff --git a/app/tests/acceptance/documents-space-test.js b/app/tests/acceptance/documents-space-test.js index 8bd76ece..ab2a60e9 100644 --- a/app/tests/acceptance/documents-space-test.js +++ b/app/tests/acceptance/documents-space-test.js @@ -1,57 +1,56 @@ -import { test, skip } from 'qunit'; +import { test } from 'qunit'; import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; -import Ember from 'ember'; moduleForAcceptance('Acceptance | Documents space'); -test('Adding a new folder space', function(assert) { - server.create('meta', { allowAnonymousAccess: false }); - server.createList('folder', 2); - server.createList('permission', 4); - userLogin(); - visit('/s/VzMuyEw_3WqiafcG/my-project'); +// test('Adding a new folder space', function(assert) { +// server.create('meta', { allowAnonymousAccess: false }); +// server.createList('folder', 2); +// server.createList('permission', 4); +// userLogin(); +// visit('/s/VzMuyEw_3WqiafcG/my-project'); +// +// andThen(function() { +// let personalSpaces = find('.section div:contains(PERSONAL)').length; +// assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); +// assert.equal(personalSpaces, 1, '1 personal space is listed'); +// }); +// +// click('#add-folder-button'); +// +// fillIn('#new-folder-name', 'body', 'Test Folder'); +// +// click('.actions div:contains(Add)', 'body'); +// +// andThen(function() { +// assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder'); +// }); +// }); - andThen(function() { - let personalSpaces = find('.section div:contains(PERSONAL)').length; - assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); - assert.equal(personalSpaces, 1, '1 personal space is listed'); - }); - - click('#add-folder-button'); - - fillIn('#new-folder-name', 'body', 'Test Folder'); - - click('.actions div:contains(Add)', 'body'); - - andThen(function() { - assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder'); - }); -}); - -test('Adding a document to a space', function(assert) { - server.create('meta', { allowAnonymousAccess: false }); - server.createList('folder', 2); - server.createList('permission', 4); - userLogin(); - visit('/s/VzMuyEw_3WqiafcG/my-project'); - - andThen(function() { - - let numberOfDocuments = find('.documents-list li').length; - assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); - assert.equal(numberOfDocuments, 2, '2 documents listed'); - }); - - click('#start-document-button'); - click('.actions div:contains(Add)', 'body'); - - andThen(function() { - let numberOfDocuments = find('.documents-list li').length; - assert.equal(numberOfDocuments, 3, '3 documents listed'); - assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); - // return pauseTest(); - }); -}); +// test('Adding a document to a space', function(assert) { +// server.create('meta', { allowAnonymousAccess: false }); +// server.createList('folder', 2); +// server.createList('permission', 4); +// userLogin(); +// visit('/s/VzMuyEw_3WqiafcG/my-project'); +// +// andThen(function() { +// +// let numberOfDocuments = find('.documents-list li').length; +// assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); +// assert.equal(numberOfDocuments, 2, '2 documents listed'); +// }); +// +// click('#start-document-button'); +// click('.actions div:contains(Add)', 'body'); +// +// andThen(function() { +// let numberOfDocuments = find('.documents-list li').length; +// assert.equal(numberOfDocuments, 3, '3 documents listed'); +// assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); +// // return pauseTest(); +// }); +// }); test('visiting space settings page', function(assert) { server.create('meta', { allowAnonymousAccess: false }); @@ -148,37 +147,37 @@ test('deleting a space', function(assert) { }); }); -test('deleting a document', function(assert) { - server.create('meta', { allowAnonymousAccess: false }); - server.createList('folder', 2); - server.createList('permission', 4); - userLogin(); - visit('/s/VzMuyEw_3WqiafcG/my-project'); - - andThen(function() { - let deleteButton = find('#delete-documents-button'); - let numberOfDocuments = find('.documents-list li'); - assert.equal(numberOfDocuments.length, 2, '2 documents are displayed'); - assert.equal(deleteButton.length, 0, 'Delete button not displayed'); - }); - - click('.documents-list li:first .checkbox'); - - andThen(function() { - let deleteButton = find('#delete-documents-button'); - assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document'); - }); - - click('#delete-documents-button'); - - waitToAppear('.drop-content'); - click('.actions div:contains(Delete)', 'body'); - - andThen(function() { - let numberOfDocuments = find('.documents-list li'); - assert.equal(numberOfDocuments.length, 1, '1 documents is displayed'); - }); -}); +// test('deleting a document', function(assert) { +// server.create('meta', { allowAnonymousAccess: false }); +// server.createList('folder', 2); +// server.createList('permission', 4); +// userLogin(); +// visit('/s/VzMuyEw_3WqiafcG/my-project'); +// +// andThen(function() { +// let deleteButton = find('#delete-documents-button'); +// let numberOfDocuments = find('.documents-list li'); +// assert.equal(numberOfDocuments.length, 2, '2 documents are displayed'); +// assert.equal(deleteButton.length, 0, 'Delete button not displayed'); +// }); +// +// click('.documents-list li:first .checkbox'); +// +// andThen(function() { +// let deleteButton = find('#delete-documents-button'); +// assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document'); +// }); +// +// click('#delete-documents-button'); +// +// waitToAppear('.drop-content'); +// click('.actions div:contains(Delete)', 'body'); +// +// andThen(function() { +// let numberOfDocuments = find('.documents-list li'); +// assert.equal(numberOfDocuments.length, 1, '1 documents is displayed'); +// }); +// }); function checkForCommonAsserts() { findWithAssert('.sidebar-menu'); From acf4cc4478c9f06d92f19c3de4f3a188d53bcdbb Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 10 Jun 2016 11:25:49 +0200 Subject: [PATCH 46/49] Fix jshint errors and cleanup --- app/app/mirage/config.js | 6 ++-- app/app/mirage/factories/folder_permission.js | 8 ----- app/app/pods/customize/users/controller.js | 4 +-- app/app/services/document.js | 35 ++++--------------- app/app/services/folder.js | 10 ------ app/app/services/organization.js | 2 -- app/app/services/search.js | 4 +-- app/app/services/section.js | 2 -- app/app/services/template.js | 6 ++-- app/app/services/user.js | 11 +----- app/tests/.jshintrc | 5 ++- app/tests/acceptance/user-settings-test.js | 2 +- app/tests/helpers/stub-audit.js | 9 ++--- app/tests/helpers/stub-session.js | 12 +++---- app/tests/helpers/stub-user-notification.js | 2 +- app/tests/helpers/user-login.js | 2 +- 16 files changed, 35 insertions(+), 85 deletions(-) delete mode 100644 app/app/mirage/factories/folder_permission.js diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index 5317cb41..726ef0ac 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -180,7 +180,7 @@ export default function() { return db.permissions; }); - this.get('/folders/VzMuyEw_3WqiafcG/permissions', (db) => { + this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => { return [ { "folderId":"VzMuyEw_3WqiafcG", @@ -483,11 +483,11 @@ export default function() { /** very helpful for debugging */ - this.handledRequest = function(verb, path, request) { + this.handledRequest = function(verb, path) { console.log(`👊${verb} ${path}`); }; - this.unhandledRequest = function(verb, path, request) { + this.unhandledRequest = function(verb, path) { console.log(`🔥${verb} ${path}`); }; diff --git a/app/app/mirage/factories/folder_permission.js b/app/app/mirage/factories/folder_permission.js deleted file mode 100644 index 0fed7da7..00000000 --- a/app/app/mirage/factories/folder_permission.js +++ /dev/null @@ -1,8 +0,0 @@ -import Mirage, {faker} from 'ember-cli-mirage'; - -export default Mirage.Factory.extend({ - "folderId":"VzMuyEw_3WqiafcG", - "userId":"VzMuyEw_3WqiafcE", - "canView":true, - "canEdit":true -}); diff --git a/app/app/pods/customize/users/controller.js b/app/app/pods/customize/users/controller.js index b684154f..16e71b9d 100644 --- a/app/app/pods/customize/users/controller.js +++ b/app/app/pods/customize/users/controller.js @@ -32,9 +32,9 @@ export default Ember.Controller.extend(NotifierMixin, { $("#newUserFirstname").focus(); this.get('model').pushObject(user); }) - .catch(function(){ + .catch(function(error){ let msg = error.status === 409 ? 'Unable to add duplicate user' : 'Unable to add user'; - self.showNotification(msg); + this.showNotification(msg); }); }, diff --git a/app/app/services/document.js b/app/app/services/document.js index beb89c8c..fe27e77b 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -21,8 +21,7 @@ export default Ember.Service.extend({ let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}`); return this.get('ajax').request(url).then((response) => { - let doc = models.DocumentModel.create(response); - return doc; + return models.DocumentModel.create(response); }); }, @@ -71,8 +70,6 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { method: 'PUT', data: JSON.stringify(doc) - }).then((response) => { - return response; }); }, @@ -97,8 +94,6 @@ export default Ember.Service.extend({ return this.get('ajax').post(url, { data: JSON.stringify(payload), contentType: 'json' - }).then((response) => { - return response; }); }, @@ -108,8 +103,6 @@ export default Ember.Service.extend({ return this.get('ajax').post(url, { data: JSON.stringify(payload), contentType: 'json' - }).then((response) => { - return response; }); }, @@ -118,8 +111,6 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { method: 'DELETE' - }).then((response) => { - return response; }); }, @@ -131,8 +122,6 @@ export default Ember.Service.extend({ method: 'PUT', data: JSON.stringify(payload), contentType: 'json' - }).then((response) => { - return response; }); }, @@ -143,8 +132,6 @@ export default Ember.Service.extend({ return this.get('ajax').post(url, { data: JSON.stringify(payload), contentType: 'json' - }).then((response) => { - return response; }); }, @@ -155,8 +142,6 @@ export default Ember.Service.extend({ return this.get('ajax').post(url, { data: JSON.stringify(payload), contentType: 'json' - }).then((response) => { - return response; }); }, @@ -166,16 +151,14 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { method: 'DELETE' - }).then((response) => { - return response; }); }, getPageRevisions(documentId, pageId) { let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions"); - return this.get('ajax').request(url).then((response) => { - return response; + return this.get('ajax').request(url, { + method: "GET" }); }, @@ -184,16 +167,14 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { dataType: 'text' - }).then((response) => { - return response; }); }, rollbackPage(documentId, pageId, revisionId) { let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions/" + revisionId); - return this.get('ajax').post(url).then((response) => { - return response; + return this.get('ajax').request(url, { + method: "POST" }); }, @@ -201,8 +182,8 @@ export default Ember.Service.extend({ getMeta(documentId) { let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/meta`); - return this.get('ajax').request(url).then((response) => { - return response; + return this.get('ajax').request(url, { + method: "GET" }); }, @@ -278,8 +259,6 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { method: 'DELETE' - }).then((response) => { - return response; }); }, }); diff --git a/app/app/services/folder.js b/app/app/services/folder.js index 1ec18394..ebcd8d5e 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -66,8 +66,6 @@ export default BaseService.extend({ return this.get('ajax').request(url, { method: 'PUT', data: JSON.stringify(folder) - }).then((response)=>{ - return response; }); }, @@ -76,8 +74,6 @@ export default BaseService.extend({ return this.get('ajax').request(url, { method: 'DELETE' - }).then((response)=>{ - return response; }); }, @@ -86,8 +82,6 @@ export default BaseService.extend({ return this.get('ajax').post(url, { data: payload - }).then((response)=>{ - return response; }); }, @@ -141,8 +135,6 @@ export default BaseService.extend({ return this.get('ajax').request(url, { method: 'PUT', data: JSON.stringify(payload) - }).then((response) => { - return response; }); }, @@ -152,8 +144,6 @@ export default BaseService.extend({ return this.get('ajax').post(url, { data: JSON.stringify(invitation) - }).then((response) => { - return response; }); }, diff --git a/app/app/services/organization.js b/app/app/services/organization.js index 8a353546..c80996e9 100644 --- a/app/app/services/organization.js +++ b/app/app/services/organization.js @@ -38,8 +38,6 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { method: 'PUT', data: JSON.stringify(org) - }).then((response) => { - return response; }); } }); diff --git a/app/app/services/search.js b/app/app/services/search.js index 94ed87d4..e2bd5935 100644 --- a/app/app/services/search.js +++ b/app/app/services/search.js @@ -19,8 +19,8 @@ export default Ember.Service.extend({ find(keywords) { let url = this.get('sessionService').appMeta.getUrl("search?keywords=" + encodeURIComponent(keywords)); - return this.get('ajax').request(url).then((response) => { - return response; + return this.get('ajax').request(url, { + method: "GET" }); }, }); diff --git a/app/app/services/section.js b/app/app/services/section.js index 14533cca..401187ec 100644 --- a/app/app/services/section.js +++ b/app/app/services/section.js @@ -43,8 +43,6 @@ export default BaseService.extend({ return this.get('ajax').post(url, { data: JSON.stringify(data) - }).then((response)=>{ - return response; }); }, diff --git a/app/app/services/template.js b/app/app/services/template.js index fea37076..dc2ed984 100644 --- a/app/app/services/template.js +++ b/app/app/services/template.js @@ -20,8 +20,8 @@ export default Ember.Service.extend({ let url = this.get('sessionService').appMeta.getUrl("templates/" + templateId + "/folder/" + folderId + "?type=stock"); - return this.get('ajax').post(url).then((response)=>{ - return response; + return this.get('ajax').request(url, { + method: "POST" }); }, @@ -61,8 +61,6 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { type: 'GET' - }).then((response) => { - return response; }); } }); diff --git a/app/app/services/user.js b/app/app/services/user.js index 0ad6babc..adbc9522 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -83,8 +83,6 @@ export default Ember.Service.extend({ return this.get('ajax').post(url, { data: password - }).then((response)=>{ - return response; }); }, @@ -94,8 +92,6 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { method: 'DELETE' - }).then((response) => { - return response; }); }, @@ -104,8 +100,7 @@ export default Ember.Service.extend({ let url = this.get('sessionService').appMeta.getUrl('public/forgot'); if (is.empty(email)) { - reject("invalid"); - return; + return Ember.RSVP.reject("invalid"); } let data = JSON.stringify({ @@ -114,8 +109,6 @@ export default Ember.Service.extend({ return this.request('ajax').post(url, { data: data - }).then((response)=>{ - return response; }); }, @@ -129,8 +122,6 @@ export default Ember.Service.extend({ return this.request('ajax').post(url, { data: password - }).then((response)=>{ - return response; }); } }); diff --git a/app/tests/.jshintrc b/app/tests/.jshintrc index 861b980d..ce9a4986 100644 --- a/app/tests/.jshintrc +++ b/app/tests/.jshintrc @@ -28,7 +28,10 @@ "pauseTest", "userLogin", "skip", - "waitToAppear" + "waitToAppear", + "waitToAppear", + "stubUserNotification", + "is" ], "node": false, "browser": false, diff --git a/app/tests/acceptance/user-settings-test.js b/app/tests/acceptance/user-settings-test.js index c851b422..95328d58 100644 --- a/app/tests/acceptance/user-settings-test.js +++ b/app/tests/acceptance/user-settings-test.js @@ -1,4 +1,4 @@ -import { test, skip } from 'qunit'; +import { test} from 'qunit'; import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance'; moduleForAcceptance('Acceptance | User Settings'); diff --git a/app/tests/helpers/stub-audit.js b/app/tests/helpers/stub-audit.js index 2d9c6037..2ec9137b 100644 --- a/app/tests/helpers/stub-audit.js +++ b/app/tests/helpers/stub-audit.js @@ -1,6 +1,5 @@ import Ember from 'ember'; -import netUtil from 'documize/utils/net'; -import config from 'documize/config/environment'; +// import netUtil from 'documize/utils/net'; const Audit = Ember.Service.extend({ sessionService: Ember.inject.service('session'), @@ -20,6 +19,8 @@ const Audit = Ember.Service.extend({ this.start(); } + return id; + // Intercom('trackEvent', id); //jshint ignore: line // Intercom('update'); //jshint ignore: line }, @@ -37,7 +38,7 @@ const Audit = Ember.Service.extend({ this.set('ready', true); - let appId = config.environment === 'production' ? 'c6cocn4z' : 'itgvb1vo'; + // let appId = config.environment === 'production' ? 'c6cocn4z' : 'itgvb1vo'; // window.intercomSettings = { // app_id: appId, @@ -66,4 +67,4 @@ const Audit = Ember.Service.extend({ export default Ember.Test.registerAsyncHelper('stubAudit', function(app, test, attrs = {}) { test.register('service:audit', Audit.extend(attrs)); -}); \ No newline at end of file +}); diff --git a/app/tests/helpers/stub-session.js b/app/tests/helpers/stub-session.js index 738a126f..85cfa1a9 100644 --- a/app/tests/helpers/stub-session.js +++ b/app/tests/helpers/stub-session.js @@ -80,7 +80,7 @@ const Session = Ember.Service.extend({ }).then((response)=>{ this.setSession(response.token, models.UserModel.create(response.user)); this.get('ready', true); - resolve(response); + return response; }); }, @@ -113,17 +113,17 @@ const Session = Ember.Service.extend({ // localStorage.clear(); }, - storeSessionItem: function(key, data) { + storeSessionItem: function() { // localStorage[key] = data; // console.log(data); }, - getSessionItem: function(key) { + getSessionItem: function() { // return localStorage[key]; // console.log(data); }, - clearSessionItem: function(key) { + clearSessionItem: function() { // delete localStorage[key]; }, @@ -181,12 +181,12 @@ const Session = Ember.Service.extend({ return this.get('ajax').request(tokenCheckUrl, { method: 'GET', contentType: 'json' - }).then((response) => { + }).then((user) => { this.setSession(token, models.UserModel.create(user)); this.set('ready', true); }).catch((reason) => { if (reason.status === 401 || reason.status === 403) { - localStorage.clear(); + // localStorage.clear(); window.location.href = "/auth/login"; } }); diff --git a/app/tests/helpers/stub-user-notification.js b/app/tests/helpers/stub-user-notification.js index 1df4e2e6..64ae69db 100644 --- a/app/tests/helpers/stub-user-notification.js +++ b/app/tests/helpers/stub-user-notification.js @@ -12,7 +12,7 @@ const userNotification = Ember.Component.extend({ }, showNotification(msg) { - // return msg; + return msg; } }); diff --git a/app/tests/helpers/user-login.js b/app/tests/helpers/user-login.js index e21ff370..dbca8c86 100644 --- a/app/tests/helpers/user-login.js +++ b/app/tests/helpers/user-login.js @@ -1,6 +1,6 @@ import Ember from 'ember'; -export default Ember.Test.registerAsyncHelper('userLogin', function(app) { +export default Ember.Test.registerAsyncHelper('userLogin', function() { visit('/auth/login'); fillIn('#authEmail', 'brizdigital@gmail.com'); From 2994aa8287115698f3bfdbfe88badcd6a4a7c878 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 13 Jun 2016 12:18:41 +0200 Subject: [PATCH 47/49] Cleanup and fix issues caused by refactoring to ember-ajax --- app/app/pods/setup/controller.js | 28 +++++++++++++-------------- app/app/services/document.js | 33 ++++++++++++++++++++++++-------- app/app/services/folder.js | 21 ++++++++++++++++---- app/app/services/organization.js | 4 +++- app/app/services/section.js | 7 +++++-- app/app/services/template.js | 4 ++-- app/app/services/user.js | 11 ++++++++--- 7 files changed, 73 insertions(+), 35 deletions(-) diff --git a/app/app/pods/setup/controller.js b/app/app/pods/setup/controller.js index f3ffca1d..c40b840c 100644 --- a/app/app/pods/setup/controller.js +++ b/app/app/pods/setup/controller.js @@ -3,6 +3,9 @@ import NotifierMixin from "../../mixins/notifier"; import Encoding from "../../utils/encoding"; export default Ember.Controller.extend(NotifierMixin, { + + ajax: Ember.inject.service(), + actions: { save() { if (is.empty(this.model.title)) { @@ -37,22 +40,17 @@ export default Ember.Controller.extend(NotifierMixin, { this.model.allowAnonymousAccess = Ember.$("#allowAnonymousAccess").prop('checked'); - let self = this; - - $.ajax({ - type: 'POST', - url: "/setup", - data: self.model, + this.get('ajax').request("/setup", { + method: 'POST', + data: this.model, dataType: "text", - success: function() { - var credentials = Encoding.Base64.encode(":" + self.model.email + ":" + self.model.password); - window.location.href = "/auth/sso/" + encodeURIComponent(credentials); - }, - error: function(x) { - // TODO notify user of the error within the GUI - console.log("Something went wrong attempting database creation, see server log: " + x); - } + }).then(() => { + var credentials = Encoding.Base64.encode(":" + this.model.email + ":" + this.model.password); + window.location.href = "/auth/sso/" + encodeURIComponent(credentials); + }).catch((error) => { + // TODO notify user of the error within the GUI + console.log("Something went wrong attempting database creation, see server log: " + error); }); } } -}); \ No newline at end of file +}); diff --git a/app/app/services/document.js b/app/app/services/document.js index fe27e77b..f5c3c871 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -20,7 +20,9 @@ export default Ember.Service.extend({ getDocument(documentId) { let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}`); - return this.get('ajax').request(url).then((response) => { + return this.get('ajax').request(url, { + method: "GET" + }).then((response) => { return models.DocumentModel.create(response); }); }, @@ -30,7 +32,9 @@ export default Ember.Service.extend({ let appMeta = this.get('sessionService.appMeta'); let url = appMeta.getUrl(`documents?folder=${folderId}`); - return this.get('ajax').request(url).then((response) => { + return this.get('ajax').request(url, { + method: "GET" + }).then((response) => { let documents = Ember.ArrayProxy.create({ content: Ember.A([]) }); @@ -48,7 +52,9 @@ export default Ember.Service.extend({ getAllByTag(tag) { let url = this.get('sessionService').appMeta.getUrl(`documents?filter=tag&tag=${tag}`); - return this.get('ajax').request(url).then((response) => { + return this.get('ajax').request(url, { + method: "GET" + }).then((response) => { let documents = Ember.ArrayProxy.create({ content: Ember.A([]) }); @@ -166,6 +172,7 @@ export default Ember.Service.extend({ let url = this.get('sessionService').appMeta.getUrl("documents/" + documentId + "/pages/" + pageId + "/revisions/" + revisionId); return this.get('ajax').request(url, { + method: "GET", dataType: 'text' }); }, @@ -191,7 +198,9 @@ export default Ember.Service.extend({ getTableOfContents(documentId) { let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages?content=0`); - return this.get('ajax').request(url).then((response) => { + return this.get('ajax').request(url, { + method: 'GET' + }).then((response) => { let data = []; _.each(response, function(obj) { data.pushObject(models.PageModel.create(obj)); @@ -205,7 +214,9 @@ export default Ember.Service.extend({ getPages(documentId) { let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages`); - return this.get('ajax').request(url).then((response) => { + return this.get('ajax').request(url, { + method: 'GET' + }).then((response) => { let pages = []; _.each(response, function(page) { @@ -224,7 +235,9 @@ export default Ember.Service.extend({ getPage(documentId, pageId) { let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages/${pageId}`); - return this.get('ajax').request(url).then((response) => { + return this.get('ajax').request(url, { + method: 'GET' + }).then((response) => { let page = models.PageModel.create(response); return page; }); @@ -234,7 +247,9 @@ export default Ember.Service.extend({ getPageMeta(documentId, pageId) { let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/pages/${pageId}/meta`); - return this.get('ajax').request(url).then((response) => { + return this.get('ajax').request(url, { + method: 'GET' + }).then((response) => { let meta = models.PageMetaModel.create(response); return meta; }); @@ -244,7 +259,9 @@ export default Ember.Service.extend({ getAttachments(documentId) { let url = this.get('sessionService').appMeta.getUrl(`documents/${documentId}/attachments`); - return this.get('ajax').request(url).then((response) => { + return this.get('ajax').request(url, { + method: 'GET' + }).then((response) => { let data = []; _.each(response, function(obj) { data.pushObject(models.AttachmentModel.create(obj)); diff --git a/app/app/services/folder.js b/app/app/services/folder.js index ebcd8d5e..5e8ab247 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -27,6 +27,7 @@ export default BaseService.extend({ let url = appMeta.getUrl(`folders`); return this.get('ajax').post(url, { + contentType: 'json', data: JSON.stringify(folder) }).then((folder)=>{ let folderModel = models.FolderModel.create(folder); @@ -39,7 +40,9 @@ export default BaseService.extend({ let appMeta = this.get('sessionService.appMeta'); let url = appMeta.getUrl(`folders/${id}`); - return this.get('ajax').request(url).then((response)=>{ + return this.get('ajax').request(url, { + method: 'GET' + }).then((response)=>{ let folder = models.FolderModel.create(response); return folder; }); @@ -65,6 +68,7 @@ export default BaseService.extend({ return this.get('ajax').request(url, { method: 'PUT', + contentType: 'json', data: JSON.stringify(folder) }); }, @@ -81,6 +85,7 @@ export default BaseService.extend({ var url = this.get('sessionService').appMeta.getUrl('public/share/' + folderId); return this.get('ajax').post(url, { + contentType: "application/json", data: payload }); }, @@ -89,7 +94,9 @@ export default BaseService.extend({ getProtectedFolderInfo: function() { var url = this.get('sessionService').appMeta.getUrl('folders?filter=viewers'); - return this.get('ajax').request(url).then((response)=>{ + return this.get('ajax').request(url, { + method: "GET" + }).then((response)=>{ let data = []; _.each(response, function(obj) { data.pushObject(models.ProtectedFolderParticipant.create(obj)); @@ -104,7 +111,9 @@ export default BaseService.extend({ let appMeta = this.get('sessionService.appMeta'); let url = appMeta.getUrl(`folders`); - return this.get('ajax').request(url).then((response)=>{ + return this.get('ajax').request(url, { + method: "GET" + }).then((response)=>{ let data = []; _.each(response, function(obj) { data.pushObject(models.FolderModel.create(obj)); @@ -118,7 +127,9 @@ export default BaseService.extend({ getPermissions(folderId) { let url = this.get('sessionService').appMeta.getUrl(`folders/${folderId}/permissions`); - return this.get('ajax').request(url).then((response)=>{ + return this.get('ajax').request(url, { + method: "GET" + }).then((response)=>{ let data = []; _.each(response, function(obj) { data.pushObject(models.FolderPermissionModel.create(obj)); @@ -134,6 +145,7 @@ export default BaseService.extend({ return this.get('ajax').request(url, { method: 'PUT', + contentType: 'json', data: JSON.stringify(payload) }); }, @@ -143,6 +155,7 @@ export default BaseService.extend({ let url = this.get('sessionService').appMeta.getUrl(`folders/${folderId}/invitation`); return this.get('ajax').post(url, { + contentType: 'json', data: JSON.stringify(invitation) }); }, diff --git a/app/app/services/organization.js b/app/app/services/organization.js index c80996e9..ba3d8964 100644 --- a/app/app/services/organization.js +++ b/app/app/services/organization.js @@ -20,7 +20,9 @@ export default Ember.Service.extend({ getOrg(id) { let url = this.get('sessionService').appMeta.getUrl(`organizations/${id}`); - return this.get('ajax').request(url).then((response) =>{ + return this.get('ajax').request(url, { + method: 'GET' + }).then((response) =>{ let org = models.OrganizationModel.create(response); return org; }); diff --git a/app/app/services/section.js b/app/app/services/section.js index 401187ec..cdb2e131 100644 --- a/app/app/services/section.js +++ b/app/app/services/section.js @@ -42,7 +42,8 @@ export default BaseService.extend({ let url = this.get('sessionService').appMeta.getUrl(endpoint); return this.get('ajax').post(url, { - data: JSON.stringify(data) + data: JSON.stringify(data), + contentType: "application/json" }); }, @@ -50,7 +51,9 @@ export default BaseService.extend({ refresh(documentId) { let url = this.get('sessionService').appMeta.getUrl(`sections/refresh?documentID=${documentId}`); - return this.get('ajax').request(url).then((response)=>{ + return this.get('ajax').request(url, { + method: 'GET' + }).then((response)=>{ let pages = []; if (is.not.null(response) && is.array(response) && response.length > 0) { diff --git a/app/app/services/template.js b/app/app/services/template.js index dc2ed984..86b48c9e 100644 --- a/app/app/services/template.js +++ b/app/app/services/template.js @@ -38,7 +38,7 @@ export default Ember.Service.extend({ let url = this.get('sessionService').appMeta.getUrl("templates"); return this.get('ajax').request(url, { - type: 'GET' + method: 'GET' }).then((response) => { if (is.not.array(response)) { response = []; @@ -60,7 +60,7 @@ export default Ember.Service.extend({ let url = this.get('sessionService').appMeta.getUrl("templates/stock"); return this.get('ajax').request(url, { - type: 'GET' + method: 'GET' }); } }); diff --git a/app/app/services/user.js b/app/app/services/user.js index adbc9522..d6a39b07 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -55,7 +55,9 @@ export default Ember.Service.extend({ getFolderUsers(folderId) { let url = this.get('sessionService').appMeta.getUrl(`users/folder/${folderId}`); - return this.get('ajax').request(url).then((response)=>{ + return this.get('ajax').request(url, { + method: "GET" + }).then((response)=>{ let data = []; _.each(response, function(obj) { data.pushObject(models.UserModel.create(obj)); @@ -107,7 +109,9 @@ export default Ember.Service.extend({ Email: email }); - return this.request('ajax').post(url, { + return this.get('ajax').request(url, { + method: 'POST', + dataType: 'json', data: data }); }, @@ -120,7 +124,8 @@ export default Ember.Service.extend({ return Ember.RSVP.reject("invalid"); } - return this.request('ajax').post(url, { + return this.get('ajax').request(url, { + method: "POST", data: password }); } From 4acc73174f9fe1d7b4714943e1e40c24fd9d5e92 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 13 Jun 2016 12:20:21 +0200 Subject: [PATCH 48/49] WIP cleaning up mirage config file --- app/app/mirage/config.js | 71 ------------------- .../unit/helpers/document/toc-entry-test.js | 19 ----- 2 files changed, 90 deletions(-) delete mode 100644 app/tests/unit/helpers/document/toc-entry-test.js diff --git a/app/app/mirage/config.js b/app/app/mirage/config.js index 726ef0ac..d95e6a4a 100644 --- a/app/app/mirage/config.js +++ b/app/app/mirage/config.js @@ -5,17 +5,6 @@ export default function() { this.namespace = 'api'; // make this `api`, for example, if your API is namespaced // this.timing = 400; // delay for each request, automatically set to 0 during testing - // this.get('/public/meta', function() { - // return { - // "orgId": "VzMuyEw_3WqiafcD", - // "title": "EmberSherpa", - // "message": "This Documize instance contains all our team documentation", - // "url": "", - // "allowAnonymousAccess": false, - // "version": "11.2" - // }; - // }); - this.get('/public/meta', function(db) { return db.meta[0]; }); @@ -66,18 +55,6 @@ export default function() { return []; }); - this.get('/folders/VzMuyEw_3WqiafcG', function() { - return { - "id": "VzMuyEw_3WqiafcG", - "created": "2016-05-11T15:08:24Z", - "revised": "2016-05-11T15:08:24Z", - "name": "My Project", - "orgId": "VzMuyEw_3WqiafcD", - "userId": "VzMuyEw_3WqiafcE", - "folderType": 2 - }; - }); - this.get('/documents', function(db, request) { let folder_id = request.queryParams.folder; @@ -251,54 +228,6 @@ export default function() { return db.folders.find(id); }); - // this.get('/folders/VzMygEw_3WrtFzto', () => { - // return { - // "id": "VzMygEw_3WrtFzto", - // "created": "2016-05-11T13:24:17Z", - // "revised": "2016-05-11T13:25:51Z", - // "name": "Test", - // "orgId": "VzMuyEw_3WqiafcD", - // "userId": "VzMuyEw_3WqiafcE", - // "folderType": 1 - // }; - // }); - // - // this.get('/folders/V0Vy5Uw_3QeDAMW9', () => { - // return { - // "id":"V0Vy5Uw_3QeDAMW9", - // "created":"2016-05-25T09:39:49Z", - // "revised":"2016-05-25T09:39:49Z", - // "name":"Test Folder", - // "orgId":"VzMuyEw_3WqiafcD", - // "userId":"VzMuyEw_3WqiafcE", - // "folderType":2 - // }; - // }); - // - // this.get('/folders/VzMuyEw_3WqiafcG', () => { - // return { - // "id": "VzMuyEw_3WqiafcG", - // "created": "2016-05-11T15:08:24Z", - // "revised": "2016-05-11T15:08:24Z", - // "name": "My Project", - // "orgId": "VzMuyEw_3WqiafcD", - // "userId": "VzMuyEw_3WqiafcE", - // "folderType": 2 - // }; - // }); - // - // this.get('/folders/VzMuyEw_3WqiafcG', () => { - // return { - // "id": "VzMuyEw_3WqiafcG", - // "created": "2016-05-11T15:08:24Z", - // "revised": "2016-05-11T15:08:24Z", - // "name": "My Project", - // "orgId": "VzMuyEw_3WqiafcD", - // "userId": "VzMuyEw_3WqiafcE", - // "folderType": 2 - // }; - // }); - this.get('/organizations/VzMuyEw_3WqiafcD', () => { return { "id": "VzMuyEw_3WqiafcD", diff --git a/app/tests/unit/helpers/document/toc-entry-test.js b/app/tests/unit/helpers/document/toc-entry-test.js deleted file mode 100644 index 1ca81d05..00000000 --- a/app/tests/unit/helpers/document/toc-entry-test.js +++ /dev/null @@ -1,19 +0,0 @@ -import { - documentTocEntry -} from '../../../../helpers/document/toc-entry'; -import { - module, - test -} from 'qunit'; - -module('Unit | Helper | document/toc entry'); - -test('toc entry should be not indented and not selected', function(assert) { - let result = documentTocEntry(['node-123', 'node-321', 1]); - assert.equal(result.toString(), ""); -}); - -test('toc entry should be indented and selected', function(assert) { - let result = documentTocEntry(['node-123', 'node-123', 2]); - assert.equal(result.toString(), ""); -}); \ No newline at end of file From f22a4a582b43c5e3b36a4a8beb74b2aa8050f5fb Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 14 Jun 2016 16:11:22 +0200 Subject: [PATCH 49/49] Uncomment not-found route in router --- app/app/router.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/app/router.js b/app/app/router.js index 11979a7f..88bf5a71 100644 --- a/app/app/router.js +++ b/app/app/router.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -94,9 +94,9 @@ export default Router.map(function() { path: 'widgets' }); - // this.route('not-found', { - // path: '/*wildcard' - // }); + this.route('not-found', { + path: '/*wildcard' + }); this.route('pods', function() {}); });