From 81ecb7539122c6108f0b1f5dfb3cd7e93197f923 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 31 May 2016 14:34:42 +0200 Subject: [PATCH] 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');