account-activation.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. (function () {
  2. 'use strict';
  3. var app = null;
  4. QUnit.acceptance("Activate Account", {
  5. beforeEach: function() {
  6. app = initTestMisago();
  7. },
  8. afterEach: function() {
  9. app.destroy();
  10. }
  11. });
  12. QUnit.test('with backend banned', function(assert) {
  13. $.mockjax({
  14. url: '/test-api/auth/activate-account/123/som3token/',
  15. status: 403,
  16. responseText: {
  17. 'detail': 'You are banned!',
  18. 'ban': {
  19. 'expires_on': null,
  20. 'message': {
  21. 'plain': 'This is test ban.',
  22. 'html': '<p>This is test ban.</p>'
  23. }
  24. }
  25. }
  26. });
  27. app.router.route('/activation/123/som3token/');
  28. var done = assert.async();
  29. onElement('.page-error.page-error-banned .message-body', function() {
  30. assert.ok(true, "Permission denied error page was displayed.");
  31. assert.equal(
  32. getElementText('.page .message-body .lead'),
  33. "This is test ban.",
  34. "Banned page displayed ban message.");
  35. done();
  36. });
  37. });
  38. QUnit.test('with backend rejection', function(assert) {
  39. var message = 'Some activation error.';
  40. $.mockjax({
  41. url: '/test-api/auth/activate-account/123/som3token/',
  42. status: 400,
  43. responseText: {
  44. 'detail': message
  45. }
  46. });
  47. app.router.route('/activation/123/som3token/');
  48. var done = assert.async();
  49. onElement('.message-body p', function() {
  50. assert.equal(getElementText('.message-body p:last-child'), message,
  51. "activation failed with backend message.");
  52. done();
  53. });
  54. });
  55. QUnit.test('with success', function(assert) {
  56. $.mockjax({
  57. url: '/test-api/auth/activate-account/123/som3token/',
  58. status: 200,
  59. responseText: {
  60. 'username': 'Bob'
  61. }
  62. });
  63. app.router.route('/activation/123/som3token/');
  64. var done = assert.async();
  65. onElement('.message-body p.lead', function() {
  66. assert.equal(
  67. getElementText('.message-body p.lead'),
  68. "Bob, your account has been successfully activated!",
  69. "activation succeded.");
  70. done();
  71. });
  72. });
  73. }());