1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/tests/acceptance/signin-test.js
Kevin Ansfield 503e8d8263 Update styles for content screen, buttons, and app frame
* Updates styling on content management screen, replaces button styles, tweaks application frame style
2017-02-16 19:50:05 +00:00

182 lines
6 KiB
JavaScript

/* jshint expr:true */
import {
describe,
it,
beforeEach,
afterEach
} from 'mocha';
import $ from 'jquery';
import {expect} from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import {invalidateSession, authenticateSession} from '../helpers/ember-simple-auth';
import {enableGhostOAuth} from '../helpers/configuration';
import {Response} from 'ember-cli-mirage';
import {
stubSuccessfulOAuthConnect,
stubFailedOAuthConnect
} from '../helpers/oauth';
describe('Acceptance: Signin', function() {
let application;
beforeEach(function () {
application = startApp();
});
afterEach(function () {
destroyApp(application);
});
it('redirects if already authenticated', function () {
let role = server.create('role', {name: 'Author'});
server.create('user', {roles: [role], slug: 'test-user'});
authenticateSession(application);
visit('/signin');
andThen(() => {
expect(currentURL(), 'current url').to.equal('/');
});
});
describe('when attempting to signin', function () {
beforeEach(function () {
let role = server.create('role', {name: 'Administrator'});
server.create('user', {roles: [role], slug: 'test-user'});
server.post('/authentication/token', function (schema, {requestBody}) {
/* eslint-disable camelcase */
let {
grant_type: grantType,
username,
password,
client_id: clientId
} = $.deparam(requestBody);
expect(grantType, 'grant type').to.equal('password');
expect(username, 'username').to.equal('test@example.com');
expect(clientId, 'client id').to.equal('ghost-admin');
if (password === 'testpass') {
return {
access_token: '5JhTdKI7PpoZv4ROsFoERc6wCHALKFH5jxozwOOAErmUzWrFNARuH1q01TYTKeZkPW7FmV5MJ2fU00pg9sm4jtH3Z1LjCf8D6nNqLYCfFb2YEKyuvG7zHj4jZqSYVodN2YTCkcHv6k8oJ54QXzNTLIDMlCevkOebm5OjxGiJpafMxncm043q9u1QhdU9eee3zouGRMVVp8zkKVoo5zlGMi3zvS2XDpx7xsfk8hKHpUgd7EDDQxmMueifWv7hv6n',
expires_in: 3600,
refresh_token: 'XP13eDjwV5mxOcrq1jkIY9idhdvN3R1Br5vxYpYIub2P5Hdc8pdWMOGmwFyoUshiEB62JWHTl8H1kACJR18Z8aMXbnk5orG28br2kmVgtVZKqOSoiiWrQoeKTqrRV0t7ua8uY5HdDUaKpnYKyOdpagsSPn3WEj8op4vHctGL3svOWOjZhq6F2XeVPMR7YsbiwBE8fjT3VhTB3KRlBtWZd1rE0Qo2EtSplWyjGKv1liAEiL0ndQoLeeSOCH4rTP7',
token_type: 'Bearer'
};
} else {
return new Response(401, {}, {
errors: [{
errorType: 'UnauthorizedError',
message: 'Invalid Password'
}]
});
}
/* eslint-enable camelcase */
});
});
it('errors correctly', function () {
invalidateSession(application);
visit('/signin');
andThen(() => {
expect(currentURL(), 'signin url').to.equal('/signin');
expect(find('input[name="identification"]').length, 'email input field')
.to.equal(1);
expect(find('input[name="password"]').length, 'password input field')
.to.equal(1);
});
click('.gh-btn-blue');
andThen(() => {
expect(find('.form-group.error').length, 'number of invalid fields')
.to.equal(2);
expect(find('.main-error').length, 'main error is displayed')
.to.equal(1);
});
fillIn('[name="identification"]', 'test@example.com');
fillIn('[name="password"]', 'invalid');
click('.gh-btn-blue');
andThen(() => {
expect(currentURL(), 'current url').to.equal('/signin');
expect(find('.main-error').length, 'main error is displayed')
.to.equal(1);
expect(find('.main-error').text().trim(), 'main error text')
.to.equal('Invalid Password');
});
});
it('submits successfully', function () {
invalidateSession(application);
visit('/signin');
andThen(() => {
expect(currentURL(), 'current url').to.equal('/signin');
});
fillIn('[name="identification"]', 'test@example.com');
fillIn('[name="password"]', 'testpass');
click('.gh-btn-blue');
andThen(() => {
expect(currentURL(), 'currentURL').to.equal('/');
});
});
});
describe('using Ghost OAuth', function () {
beforeEach(function () {
enableGhostOAuth(server);
});
it('can sign in successfully', function () {
server.loadFixtures('roles');
stubSuccessfulOAuthConnect(application);
visit('/signin');
andThen(() => {
expect(currentURL(), 'current url').to.equal('/signin');
expect(
find('button.login').text().trim(),
'login button text'
).to.equal('Sign in with Ghost');
});
click('button.login');
andThen(() => {
expect(currentURL(), 'url after connect').to.equal('/');
});
});
it('handles a failed connect', function () {
stubFailedOAuthConnect(application);
visit('/signin');
click('button.login');
andThen(() => {
expect(currentURL(), 'current url').to.equal('/signin');
expect(
find('.main-error').text().trim(),
'sign-in error'
).to.match(/Authentication with Ghost\.org denied or failed/i);
});
});
});
});