activate-test.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. import getToastMessage from '../helpers/toast-message';
  5. var application;
  6. module('Acceptance: Account Activation', {
  7. beforeEach: function() {
  8. application = startApp();
  9. },
  10. afterEach: function() {
  11. Ember.$('#hidden-login-form').off('submit.stopInTest');
  12. Ember.$('#appModal').off();
  13. Ember.$('body').removeClass('modal-open');
  14. Ember.run(application, 'destroy');
  15. Ember.$.mockjax.clear();
  16. }
  17. });
  18. test('visiting /activation', function(assert) {
  19. assert.expect(1);
  20. visit('/activation');
  21. andThen(function() {
  22. assert.equal(currentPath(), 'activation.index');
  23. });
  24. });
  25. test('request activation link without entering e-mail', function(assert) {
  26. assert.expect(2);
  27. visit('/activation');
  28. click('.activation-page form .btn-primary');
  29. andThen(function() {
  30. assert.equal(currentPath(), 'activation.index');
  31. assert.equal(getToastMessage(), 'Enter e-mail address.');
  32. });
  33. });
  34. test('request activation link with invalid e-mail', function(assert) {
  35. assert.expect(2);
  36. var message = 'Entered e-mail is invalid.';
  37. Ember.$.mockjax({
  38. url: '/api/auth/send-activation/',
  39. status: 400,
  40. responseText: {
  41. 'detail': message,
  42. 'code': 'invalid_email'
  43. }
  44. });
  45. visit('/activation');
  46. fillIn('.activation-page form input', 'not-valid-email');
  47. click('.activation-page form .btn-primary');
  48. andThen(function() {
  49. assert.equal(currentPath(), 'activation.index');
  50. assert.equal(getToastMessage(), message);
  51. });
  52. });
  53. test('request activation link with non-existing e-mail', function(assert) {
  54. assert.expect(2);
  55. var message = 'No user with this e-mail exists.';
  56. Ember.$.mockjax({
  57. url: '/api/auth/send-activation/',
  58. status: 400,
  59. responseText: {
  60. 'detail': message,
  61. 'code': 'not_found'
  62. }
  63. });
  64. visit('/activation');
  65. fillIn('.activation-page form input', 'not-valid-email');
  66. click('.activation-page form .btn-primary');
  67. andThen(function() {
  68. assert.equal(currentPath(), 'activation.index');
  69. assert.equal(getToastMessage(), message);
  70. });
  71. });
  72. test('request activation link with user-activated account', function(assert) {
  73. assert.expect(2);
  74. var message = 'You have to activate your account before you will be able to sign in.';
  75. Ember.$.mockjax({
  76. url: '/api/auth/send-activation/',
  77. status: 400,
  78. responseText: {
  79. 'detail': message,
  80. 'code': 'inactive_user'
  81. }
  82. });
  83. visit('/activation');
  84. fillIn('.activation-page form input', 'valid@mail.com');
  85. click('.activation-page form .btn-primary');
  86. andThen(function() {
  87. assert.equal(currentPath(), 'activation.index');
  88. assert.equal(getToastMessage(), message);
  89. });
  90. });
  91. test('request activation link with admin-activated account', function(assert) {
  92. assert.expect(2);
  93. var message = 'Your account has to be activated by Administrator before you will be able to sign in.';
  94. Ember.$.mockjax({
  95. url: '/api/auth/send-activation/',
  96. status: 400,
  97. responseText: {
  98. 'detail': message,
  99. 'code': 'inactive_admin'
  100. }
  101. });
  102. visit('/activation');
  103. fillIn('.activation-page form input', 'valid@mail.com');
  104. click('.activation-page form .btn-primary');
  105. andThen(function() {
  106. assert.equal(currentPath(), 'activation.index');
  107. assert.equal(getToastMessage(), message);
  108. });
  109. });
  110. test('request activation link with banned account', function(assert) {
  111. assert.expect(2);
  112. Ember.$.mockjax({
  113. url: '/api/auth/send-activation/',
  114. status: 400,
  115. responseText: {
  116. 'detail': {
  117. 'expires_on': null,
  118. 'message': {
  119. 'plain': 'You are banned for trolling.',
  120. 'html': '<p>You are banned for trolling.</p>',
  121. }
  122. },
  123. 'code': 'banned'
  124. }
  125. });
  126. visit('/activation');
  127. fillIn('.activation-page form input', 'valid@mail.com');
  128. click('.activation-page form .btn-primary');
  129. andThen(function() {
  130. var errorMessage = find('.error-page .lead p').text();
  131. assert.equal(errorMessage, 'You are banned for trolling.');
  132. var expirationMessage = Ember.$.trim(find('.error-message>p').text());
  133. assert.equal(expirationMessage, 'This ban is permanent.');
  134. });
  135. });
  136. test('request activation link', function(assert) {
  137. assert.expect(1);
  138. Ember.$.mockjax({
  139. url: '/api/auth/send-activation/',
  140. status: 200,
  141. responseText: {
  142. 'username': 'BobBoberson',
  143. 'email': 'valid@mail.com'
  144. }
  145. });
  146. visit('/activation');
  147. fillIn('.activation-page form input', 'valid@mail.com');
  148. click('.activation-page form .btn-primary');
  149. andThen(function() {
  150. var pageHeader = Ember.$.trim(find('.page-header h1').text());
  151. assert.equal(pageHeader, 'Activation link sent');
  152. });
  153. });
  154. test('invalid token is handled', function(assert) {
  155. assert.expect(2);
  156. var message = 'Token was rejected.';
  157. Ember.$.mockjax({
  158. url: '/api/auth/activate-account/1/token/',
  159. status: 400,
  160. responseText: {
  161. 'detail': message
  162. }
  163. });
  164. visit('/activation/1/token/');
  165. andThen(function() {
  166. assert.equal(currentPath(), 'activation.index');
  167. assert.equal(getToastMessage(), message);
  168. });
  169. });
  170. test('permission denied is handled', function(assert) {
  171. assert.expect(2);
  172. var message = 'Token was rejected.';
  173. Ember.$.mockjax({
  174. url: '/api/auth/activate-account/1/token/',
  175. status: 403,
  176. responseText: {
  177. 'detail': message
  178. }
  179. });
  180. visit('/activation/1/token/');
  181. andThen(function() {
  182. assert.equal(currentPath(), 'error-403');
  183. var errorMessage = Ember.$.trim(find('.error-page .lead').text());
  184. assert.equal(errorMessage, message);
  185. });
  186. });
  187. test('account is activated', function(assert) {
  188. assert.expect(2);
  189. var message = 'Yur account has been activated!';
  190. Ember.$.mockjax({
  191. url: '/api/auth/activate-account/1/token/',
  192. status: 200,
  193. responseText: {
  194. 'detail': message
  195. }
  196. });
  197. visit('/activation/1/token/');
  198. andThen(function() {
  199. assert.equal(currentPath(), 'index');
  200. assert.equal(getToastMessage(), message);
  201. });
  202. });