2016-03-29 11:40:44 +03:00
|
|
|
import Mirage from 'ember-cli-mirage';
|
2017-05-18 13:48:37 +03:00
|
|
|
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
2017-05-29 21:50:03 +03:00
|
|
|
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';
|
2016-03-29 11:40:44 +03:00
|
|
|
|
|
|
|
describe('Acceptance: Settings - Apps - Slack', function () {
|
|
|
|
let application;
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
beforeEach(function () {
|
2016-03-29 11:40:44 +03:00
|
|
|
application = startApp();
|
|
|
|
});
|
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
afterEach(function () {
|
2016-03-29 11:40:44 +03:00
|
|
|
destroyApp(application);
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to signin when not authenticated', async function () {
|
2016-03-29 11:40:44 +03:00
|
|
|
invalidateSession(application);
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/apps/slack');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/signin');
|
2016-03-29 11:40:44 +03:00
|
|
|
});
|
|
|
|
|
2018-02-07 12:42:46 +03:00
|
|
|
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/apps/slack');
|
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team/test-user');
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to team page when authenticated as author', async function () {
|
2016-03-29 11:40:44 +03:00
|
|
|
let role = server.create('role', {name: 'Author'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
2016-03-29 11:40:44 +03:00
|
|
|
|
|
|
|
authenticateSession(application);
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/apps/slack');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team/test-user');
|
2016-03-29 11:40:44 +03:00
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('redirects to team page when authenticated as editor', async function () {
|
2016-03-29 11:40:44 +03:00
|
|
|
let role = server.create('role', {name: 'Editor'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role], slug: 'test-user'});
|
2016-03-29 11:40:44 +03:00
|
|
|
|
|
|
|
authenticateSession(application);
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/settings/apps/slack');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(currentURL(), 'currentURL').to.equal('/team');
|
2016-03-29 11:40:44 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when logged in', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
let role = server.create('role', {name: 'Administrator'});
|
2016-11-14 16:16:51 +03:00
|
|
|
server.create('user', {roles: [role]});
|
2016-03-29 11:40:44 +03:00
|
|
|
|
|
|
|
return authenticateSession(application);
|
|
|
|
});
|
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
it('it validates and saves a slack url properly', async function () {
|
|
|
|
await visit('/settings/apps/slack');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
// has correct url
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/apps/slack');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-10-31 18:27:25 +03:00
|
|
|
await fillIn('[data-test-slack-url-input]', 'notacorrecturl');
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-save-button]');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(find('#slack-settings .error .response').text().trim(), 'inline validation response')
|
|
|
|
.to.equal('The URL must be in a format like https://hooks.slack.com/services/<your personal key>');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-05-18 13:48:37 +03:00
|
|
|
// CMD-S shortcut works
|
2017-08-11 18:28:05 +03:00
|
|
|
await fillIn('[data-test-slack-url-input]', 'https://hooks.slack.com/services/1275958430');
|
2017-05-18 13:48:37 +03:00
|
|
|
await triggerEvent('.gh-app', 'keydown', {
|
|
|
|
keyCode: 83, // s
|
|
|
|
metaKey: ctrlOrCmd === 'command',
|
|
|
|
ctrlKey: ctrlOrCmd === 'ctrl'
|
|
|
|
});
|
|
|
|
|
|
|
|
let [newRequest] = server.pretender.handledRequests.slice(-1);
|
|
|
|
let params = JSON.parse(newRequest.requestBody);
|
|
|
|
let [result] = JSON.parse(params.settings.findBy('key', 'slack').value);
|
|
|
|
|
|
|
|
expect(result.url).to.equal('https://hooks.slack.com/services/1275958430');
|
|
|
|
expect(find('#slack-settings .error .response').text().trim(), 'inline validation response')
|
|
|
|
.to.equal('');
|
|
|
|
|
2017-10-31 18:27:25 +03:00
|
|
|
await fillIn('[data-test-slack-url-input]', 'https://hooks.slack.com/services/1275958430');
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-send-notification-button]');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-07-31 12:25:09 +03:00
|
|
|
expect(find('.gh-notification').length, 'number of notifications').to.equal(1);
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(find('#slack-settings .error .response').text().trim(), 'inline validation response')
|
|
|
|
.to.equal('');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
server.put('/settings/', function () {
|
|
|
|
return new Mirage.Response(422, {}, {
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
errorType: 'ValidationError',
|
|
|
|
message: 'Test error'
|
|
|
|
}
|
|
|
|
]
|
2016-03-29 11:40:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-07-31 12:25:09 +03:00
|
|
|
await click('.gh-notification .gh-notification-close');
|
2017-08-11 18:28:05 +03:00
|
|
|
await click('[data-test-send-notification-button]');
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2016-06-30 17:45:02 +03:00
|
|
|
// we shouldn't try to send the test request if the save fails
|
2017-04-24 15:29:48 +03:00
|
|
|
let [lastRequest] = server.pretender.handledRequests.slice(-1);
|
|
|
|
expect(lastRequest.url).to.not.match(/\/slack\/test/);
|
2017-07-31 12:25:09 +03:00
|
|
|
expect(find('.gh-notification').length, 'check slack notification after api validation error').to.equal(0);
|
2016-03-29 11:40:44 +03:00
|
|
|
});
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
it('warns when leaving without saving', async function () {
|
|
|
|
await visit('/settings/apps/slack');
|
|
|
|
|
|
|
|
// has correct url
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/apps/slack');
|
|
|
|
|
|
|
|
await fillIn('[data-test-slack-url-input]', 'https://hooks.slack.com/services/1275958430');
|
|
|
|
await triggerEvent('[data-test-slack-url-input]', 'blur');
|
|
|
|
|
|
|
|
await visit('/settings/design');
|
|
|
|
|
|
|
|
expect(find('.fullscreen-modal').length, 'modal exists').to.equal(1);
|
|
|
|
|
|
|
|
// Leave without saving
|
2018-01-05 18:38:23 +03:00
|
|
|
await (click('.fullscreen-modal [data-test-leave-button]'), 'leave without saving');
|
2017-10-31 18:27:25 +03:00
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/design');
|
|
|
|
|
|
|
|
await visit('/settings/apps/slack');
|
|
|
|
|
|
|
|
expect(currentURL(), 'currentURL').to.equal('/settings/apps/slack');
|
|
|
|
|
|
|
|
// settings were not saved
|
|
|
|
expect(
|
|
|
|
find('[data-test-slack-url-input]').text().trim(),
|
|
|
|
'Slack Webhook URL'
|
|
|
|
).to.equal('');
|
|
|
|
});
|
2016-03-29 11:40:44 +03:00
|
|
|
});
|
|
|
|
});
|