registration-test.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. import destroyModal from '../helpers/destroy-modal';
  5. import getToastMessage from '../helpers/toast-message';
  6. var application;
  7. module('Acceptance: Register', {
  8. beforeEach: function() {
  9. application = startApp();
  10. },
  11. afterEach: function() {
  12. window.MisagoData['misagoSettings']['account_activation'] = 'none';
  13. destroyModal();
  14. Ember.run(application, 'destroy');
  15. Ember.$.mockjax.clear();
  16. }
  17. });
  18. test('registration is closed', function(assert) {
  19. window.MisagoData['misagoSettings']['account_activation'] = 'closed';
  20. assert.expect(1);
  21. visit('/');
  22. click('.navbar-guest-nav button.btn-success');
  23. andThen(function() {
  24. assert.equal(Ember.$.trim(find('.modal-register-closed .lead').text()), 'New registrations are currently not being accepted.');
  25. });
  26. });
  27. test('register with empty credentials', function(assert) {
  28. assert.expect(1);
  29. visit('/');
  30. click('.navbar-guest-nav button.btn-success');
  31. click('#appModal .btn-primary');
  32. andThen(function() {
  33. assert.equal(getToastMessage(), 'Form contains errors.');
  34. });
  35. });
  36. test('register with invalid credentials', function(assert) {
  37. assert.expect(1);
  38. visit('/');
  39. click('.navbar-guest-nav button.btn-success');
  40. fillIn('#appModal #id_username', 'a');
  41. fillIn('#appModal #id_password', 'b');
  42. fillIn('#appModal #id_email', 'c');
  43. click('#appModal .btn-primary');
  44. andThen(function() {
  45. assert.equal(getToastMessage(), 'Form contains errors.');
  46. });
  47. });
  48. test('register with rejected credentials', function(assert) {
  49. assert.expect(1);
  50. Ember.$.mockjax({
  51. url: "/api/users/",
  52. status: 400
  53. });
  54. visit('/');
  55. click('.navbar-guest-nav button.btn-success');
  56. fillIn('#appModal #id_username', 'Lorem');
  57. fillIn('#appModal #id_password', 'ipsum123');
  58. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  59. click('#appModal .btn-primary');
  60. andThen(function() {
  61. assert.equal(getToastMessage(), 'Form contains errors.');
  62. });
  63. });
  64. test('register banned', function(assert) {
  65. assert.expect(3);
  66. Ember.$.mockjax({
  67. url: "/api/users/",
  68. status: 403,
  69. responseText: {
  70. 'detail': 'Thy are banned!',
  71. 'ban': {
  72. 'expires_on': null,
  73. 'message': {
  74. 'plain': 'You are banned for trolling.',
  75. 'html': '<p>You are banned for trolling.</p>',
  76. }
  77. }
  78. }
  79. });
  80. visit('/');
  81. click('.navbar-guest-nav button.btn-success');
  82. fillIn('#appModal #id_username', 'Lorem');
  83. fillIn('#appModal #id_password', 'ipsum123');
  84. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  85. click('#appModal .btn-primary');
  86. andThen(function() {
  87. assert.equal(currentPath(), 'error-banned');
  88. var banMessage = find('.lead p').text();
  89. assert.equal(banMessage, 'You are banned for trolling.');
  90. var expirationMessage = Ember.$.trim(find('.error-message>p').text());
  91. assert.equal(expirationMessage, 'This ban is permanent.');
  92. });
  93. });
  94. test('register active user', function(assert) {
  95. assert.expect(1);
  96. Ember.$.mockjax({
  97. url: "/api/users/",
  98. status: 200,
  99. responseText: {
  100. 'activation': 'active',
  101. 'username': 'BobBoberson',
  102. 'email': 'bob@weebl.com'
  103. }
  104. });
  105. visit('/');
  106. click('.navbar-guest-nav button.btn-success');
  107. fillIn('#appModal #id_username', 'Lorem');
  108. fillIn('#appModal #id_password', 'ipsum123');
  109. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  110. click('#appModal .btn-primary');
  111. andThen(function() {
  112. var expectedMessage = 'BobBoberson, your account has been registered successfully.';
  113. assert.equal(Ember.$.trim(find('.modal-register-done .lead').text()), expectedMessage);
  114. });
  115. });
  116. test('register admin-activated user', function(assert) {
  117. assert.expect(1);
  118. Ember.$.mockjax({
  119. url: "/api/users/",
  120. status: 200,
  121. responseText: {
  122. 'activation': 'activation_by_admin',
  123. 'username': 'BobBoberson',
  124. 'email': 'bob@weebl.com'
  125. }
  126. });
  127. visit('/');
  128. click('.navbar-guest-nav button.btn-success');
  129. fillIn('#appModal #id_username', 'Lorem');
  130. fillIn('#appModal #id_password', 'ipsum123');
  131. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  132. click('#appModal .btn-primary');
  133. andThen(function() {
  134. var expectedMessage = 'BobBoberson, your account has been registered successfully, but site administrator has to activate it before you will be able to sing in.';
  135. assert.equal(Ember.$.trim(find('.modal-register-done .lead').text()), expectedMessage);
  136. });
  137. });
  138. test('register self-activated user', function(assert) {
  139. assert.expect(1);
  140. Ember.$.mockjax({
  141. url: "/api/users/",
  142. status: 200,
  143. responseText: {
  144. 'activation': 'activation_by_user',
  145. 'username': 'BobBoberson',
  146. 'email': 'bob@weebl.com'
  147. }
  148. });
  149. visit('/');
  150. click('.navbar-guest-nav button.btn-success');
  151. fillIn('#appModal #id_username', 'Lorem');
  152. fillIn('#appModal #id_password', 'ipsum123');
  153. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  154. click('#appModal .btn-primary');
  155. andThen(function() {
  156. var expectedMessage = 'BobBoberson, your account has been registered successfully, but you have to activate it before you will be able to sign in.';
  157. assert.equal(Ember.$.trim(find('.modal-register-done .lead').text()), expectedMessage);
  158. });
  159. });