123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- import Ember from 'ember';
- import { module, test } from 'qunit';
- import startApp from '../helpers/start-app';
- import getToastMessage from '../helpers/toast-message';
- var application;
- module('Acceptance: Account Activation', {
- beforeEach: function() {
- application = startApp();
- },
- afterEach: function() {
- Ember.$('#hidden-login-form').off('submit.stopInTest');
- Ember.$('#appModal').off();
- Ember.$('body').removeClass('modal-open');
- Ember.run(application, 'destroy');
- Ember.$.mockjax.clear();
- }
- });
- test('visiting /activation', function(assert) {
- assert.expect(1);
- visit('/activation');
- andThen(function() {
- assert.equal(currentPath(), 'activation.index');
- });
- });
- test('request activation link without entering e-mail', function(assert) {
- assert.expect(2);
- visit('/activation');
- click('.activation-page form .btn-primary');
- andThen(function() {
- assert.equal(currentPath(), 'activation.index');
- assert.equal(getToastMessage(), 'Enter e-mail address.');
- });
- });
- test('request activation link with invalid e-mail', function(assert) {
- assert.expect(2);
- var message = 'Entered e-mail is invalid.';
- Ember.$.mockjax({
- url: '/api/auth/send-activation/',
- status: 400,
- responseText: {
- 'detail': message,
- 'code': 'invalid_email'
- }
- });
- visit('/activation');
- fillIn('.activation-page form input', 'not-valid-email');
- click('.activation-page form .btn-primary');
- andThen(function() {
- assert.equal(currentPath(), 'activation.index');
- assert.equal(getToastMessage(), message);
- });
- });
- test('request activation link with non-existing e-mail', function(assert) {
- assert.expect(2);
- var message = 'No user with this e-mail exists.';
- Ember.$.mockjax({
- url: '/api/auth/send-activation/',
- status: 400,
- responseText: {
- 'detail': message,
- 'code': 'not_found'
- }
- });
- visit('/activation');
- fillIn('.activation-page form input', 'not-valid-email');
- click('.activation-page form .btn-primary');
- andThen(function() {
- assert.equal(currentPath(), 'activation.index');
- assert.equal(getToastMessage(), message);
- });
- });
- test('request activation link with user-activated account', function(assert) {
- assert.expect(2);
- var message = 'You have to activate your account before you will be able to sign in.';
- Ember.$.mockjax({
- url: '/api/auth/send-activation/',
- status: 400,
- responseText: {
- 'detail': message,
- 'code': 'inactive_user'
- }
- });
- visit('/activation');
- fillIn('.activation-page form input', 'valid@mail.com');
- click('.activation-page form .btn-primary');
- andThen(function() {
- assert.equal(currentPath(), 'activation.index');
- assert.equal(getToastMessage(), message);
- });
- });
- test('request activation link with admin-activated account', function(assert) {
- assert.expect(2);
- var message = 'Your account has to be activated by Administrator before you will be able to sign in.';
- Ember.$.mockjax({
- url: '/api/auth/send-activation/',
- status: 400,
- responseText: {
- 'detail': message,
- 'code': 'inactive_admin'
- }
- });
- visit('/activation');
- fillIn('.activation-page form input', 'valid@mail.com');
- click('.activation-page form .btn-primary');
- andThen(function() {
- assert.equal(currentPath(), 'activation.index');
- assert.equal(getToastMessage(), message);
- });
- });
- test('request activation link with banned account', function(assert) {
- assert.expect(2);
- Ember.$.mockjax({
- url: '/api/auth/send-activation/',
- status: 400,
- responseText: {
- 'detail': {
- 'expires_on': null,
- 'message': {
- 'plain': 'You are banned for trolling.',
- 'html': '<p>You are banned for trolling.</p>',
- }
- },
- 'code': 'banned'
- }
- });
- visit('/activation');
- fillIn('.activation-page form input', 'valid@mail.com');
- click('.activation-page form .btn-primary');
- andThen(function() {
- var errorMessage = find('.error-page .lead p').text();
- assert.equal(errorMessage, 'You are banned for trolling.');
- var expirationMessage = Ember.$.trim(find('.error-message>p').text());
- assert.equal(expirationMessage, 'This ban is permanent.');
- });
- });
- test('request activation link', function(assert) {
- assert.expect(1);
- Ember.$.mockjax({
- url: '/api/auth/send-activation/',
- status: 200,
- responseText: {
- 'username': 'BobBoberson',
- 'email': 'valid@mail.com'
- }
- });
- visit('/activation');
- fillIn('.activation-page form input', 'valid@mail.com');
- click('.activation-page form .btn-primary');
- andThen(function() {
- var pageHeader = Ember.$.trim(find('.page-header h1').text());
- assert.equal(pageHeader, 'Activation link sent');
- });
- });
- test('invalid token is handled', function(assert) {
- assert.expect(2);
- var message = 'Token was rejected.';
- Ember.$.mockjax({
- url: '/api/auth/activate-account/1/token/',
- status: 400,
- responseText: {
- 'detail': message
- }
- });
- visit('/activation/1/token/');
- andThen(function() {
- assert.equal(currentPath(), 'activation.index');
- assert.equal(getToastMessage(), message);
- });
- });
- test('permission denied is handled', function(assert) {
- assert.expect(2);
- var message = 'Token was rejected.';
- Ember.$.mockjax({
- url: '/api/auth/activate-account/1/token/',
- status: 403,
- responseText: {
- 'detail': message
- }
- });
- visit('/activation/1/token/');
- andThen(function() {
- assert.equal(currentPath(), 'error-403');
- var errorMessage = Ember.$.trim(find('.error-page .lead').text());
- assert.equal(errorMessage, message);
- });
- });
- test('account is activated', function(assert) {
- assert.expect(2);
- var message = 'Yur account has been activated!';
- Ember.$.mockjax({
- url: '/api/auth/activate-account/1/token/',
- status: 200,
- responseText: {
- 'detail': message
- }
- });
- visit('/activation/1/token/');
- andThen(function() {
- assert.equal(currentPath(), 'index');
- assert.equal(getToastMessage(), message);
- });
- });
|