From 656a20272a89942adcc6272186481cf1ffe7ecab Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 4 Oct 2018 12:16:41 +0100 Subject: [PATCH] Fixed non-admin redirects on integration routes no issue - after un-nesting the built-in integration routes they no longer had the automatic redirect for non-admins - added our non-admin redirect behaviour to all of the integration routes - added our non-admin redirect behaviour to the Zapier route which didn't even have an authenticated redirect previously - added acceptance test for Zapier route so verify the new behaviour - wrapped the Zapier widget ` + {{!-- we don't want the script loading during tests because it errors --}} + {{#unless isTesting}} + + {{/unless}} diff --git a/ghost/admin/tests/acceptance/settings/zapier-test.js b/ghost/admin/tests/acceptance/settings/zapier-test.js new file mode 100644 index 0000000000..cb71ec5918 --- /dev/null +++ b/ghost/admin/tests/acceptance/settings/zapier-test.js @@ -0,0 +1,75 @@ +import destroyApp from '../../helpers/destroy-app'; +import startApp from '../../helpers/start-app'; +import { + afterEach, + beforeEach, + describe, + it +} from 'mocha'; +import {authenticateSession, invalidateSession} from 'ghost-admin/tests/helpers/ember-simple-auth'; +import {expect} from 'chai'; + +describe('Acceptance: Settings - Integrations - Zapier', function () { + let application; + + beforeEach(function () { + application = startApp(); + }); + + afterEach(function () { + destroyApp(application); + }); + + it('redirects to signin when not authenticated', async function () { + invalidateSession(application); + await visit('/settings/integrations/zapier'); + + expect(currentURL(), 'currentURL').to.equal('/signin'); + }); + + it('redirects to team page when authenticated as contributor', async function () { + let role = server.create('role', {name: 'Contributor'}); + server.create('user', {roles: [role], slug: 'test-user'}); + + authenticateSession(application); + await visit('/settings/integrations/zapier'); + + expect(currentURL(), 'currentURL').to.equal('/team/test-user'); + }); + + it('redirects to team page when authenticated as author', async function () { + let role = server.create('role', {name: 'Author'}); + server.create('user', {roles: [role], slug: 'test-user'}); + + authenticateSession(application); + await visit('/settings/integrations/zapier'); + + expect(currentURL(), 'currentURL').to.equal('/team/test-user'); + }); + + it('redirects to team page when authenticated as editor', async function () { + let role = server.create('role', {name: 'Editor'}); + server.create('user', {roles: [role], slug: 'test-user'}); + + authenticateSession(application); + await visit('/settings/integrations/zapier'); + + expect(currentURL(), 'currentURL').to.equal('/team'); + }); + + describe('when logged in', function () { + beforeEach(function () { + let role = server.create('role', {name: 'Administrator'}); + server.create('user', {roles: [role]}); + + return authenticateSession(application); + }); + + it('it loads', async function () { + await visit('/settings/integrations/zapier'); + + // has correct url + expect(currentURL(), 'currentURL').to.equal('/settings/integrations/zapier'); + }); + }); +});