From 952104e416ece8158ee8d9d01e3228051a585234 Mon Sep 17 00:00:00 2001 From: Eugen Ciur <eugen@papermerge.com> Date: Sun, 27 Feb 2022 09:32:28 +0100 Subject: [PATCH] add couple of tests --- mirage/config.js | 102 +++++++++++++++++++ tests/acceptance/authenticated-index-test.js | 31 ++++++ tests/acceptance/roles-test.js | 2 +- tests/acceptance/tags-test.js | 2 +- 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 tests/acceptance/authenticated-index-test.js diff --git a/mirage/config.js b/mirage/config.js index 8e114f1..cefb723 100644 --- a/mirage/config.js +++ b/mirage/config.js @@ -103,4 +103,106 @@ export default function() { } }); + this.get('/api/nodes/1/', () => { + return { + "data": [ + { + "type": "folders", + "id":"4", + "attributes": { + "title": "Folder 1", + "created_at": "2021-11-24T20:54:38.833485+01:00", + "updated_at":"2021-11-24T20:54:38.833509+01:00" + }, + "relationships": { + "parent": { + "data":null + } + } + }, + { + "type": "folders", + "id":"5", + "attributes": { + "title": "Folder 2", + "created_at": "2021-11-24T20:54:38.833485+01:00", + "updated_at":"2021-11-24T20:54:38.833509+01:00" + }, + "relationships": { + "parent": { + "data":null + } + } + } + ], + "meta": { + "pagination": { + "page": 1, + "pages": 1, + "count": 2 + } + }, + "links": { + "first": "", + "last": "", + "next": "", + "prev": "" + } + } + }); + + this.get('/api/nodes/2/', () => { + return { + "data": [ + { + "type": "folders", + "id":"4", + "attributes": { + "title": "Folder 1", + "created_at": "2021-11-24T20:54:38.833485+01:00", + "updated_at":"2021-11-24T20:54:38.833509+01:00" + }, + "relationships": { + "parent": { + "data":null + } + } + }, + { + "type": "folders", + "id":"5", + "attributes": { + "title": "Folder 2", + "created_at": "2021-11-24T20:54:38.833485+01:00", + "updated_at":"2021-11-24T20:54:38.833509+01:00" + }, + "relationships": { + "parent": { + "data":null + } + } + } + ], + "meta": { + "pagination": { + "page": 1, + "pages": 1, + "count": 2 + } + }, + "links": { + "first": "", + "last": "", + "next": "", + "prev": "" + } + } + }); + + this.get('/api/preferences/', () => { + return { + "data": [] + } + }); + } diff --git a/tests/acceptance/authenticated-index-test.js b/tests/acceptance/authenticated-index-test.js new file mode 100644 index 0000000..6e69612 --- /dev/null +++ b/tests/acceptance/authenticated-index-test.js @@ -0,0 +1,31 @@ +import { module, test } from 'qunit'; +import { visit, currentURL } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; +import { authenticateSession } from 'ember-simple-auth/test-support'; + + +module('Acceptance | authenticated', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + hooks.beforeEach(async function () { + await authenticateSession({ + authToken: '12345', + otherData: 'some-data' + }); + }); + + test('visiting / will redirect user to his home folder', async function (assert) { + /* + * Make sure that authenticated.index routes redirects to user's home folder + */ + await visit('/'); // visit root url + assert.strictEqual(currentURL(), '/nodes/2'); // user is redirected to home folder + }); + + test('visiting /nodes/1/ will land user in his home folder', async function (assert) { + await visit('/nodes/1/'); + assert.strictEqual(currentURL(), '/nodes/1/'); + }); +}); diff --git a/tests/acceptance/roles-test.js b/tests/acceptance/roles-test.js index 8bbbccf..6a61106 100644 --- a/tests/acceptance/roles-test.js +++ b/tests/acceptance/roles-test.js @@ -20,7 +20,7 @@ module('Acceptance | roles', function (hooks) { test('visiting /roles', async function (assert) { await visit('/roles'); - assert.equal(currentURL(), '/roles'); + assert.strictEqual(currentURL(), '/roles'); assert.dom('.roles-add').hasText('New', 'The user can add new role'); }); }); diff --git a/tests/acceptance/tags-test.js b/tests/acceptance/tags-test.js index 173359a..9606d0b 100644 --- a/tests/acceptance/tags-test.js +++ b/tests/acceptance/tags-test.js @@ -20,7 +20,7 @@ module('Acceptance | tags', function (hooks) { test('visiting /tags', async function (assert) { await visit('/tags'); - assert.equal(currentURL(), '/tags'); + assert.strictEqual(currentURL(), '/tags'); assert.dom('.add-tag').hasText('New', 'The user can add new tag'); }); }); -- GitLab