auth-deny-test.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. var application, container, service;
  5. module('Acceptance: Auth denyAuthenticated and denyAnonymous tests', {
  6. beforeEach: function() {
  7. application = startApp();
  8. container = application.__container__;
  9. service = container.lookup('service:auth');
  10. },
  11. afterEach: function() {
  12. Ember.run(application, 'destroy');
  13. }
  14. });
  15. test('guest can access protected route', function(assert) {
  16. assert.expect(1);
  17. visit('/activation');
  18. andThen(function() {
  19. assert.equal(currentPath(), 'activation.index');
  20. });
  21. });
  22. test('authenticated is denied access to protected route', function(assert) {
  23. assert.expect(2);
  24. service.set('isAuthenticated', true);
  25. visit('/activation');
  26. andThen(function() {
  27. assert.equal(currentPath(), 'error-403');
  28. var errorMessage = Ember.$.trim(find('.error-message .lead').text());
  29. assert.equal(errorMessage, 'Only guests can activate accounts.');
  30. });
  31. });
  32. test('authenticated can access protected route', function(assert) {
  33. assert.expect(1);
  34. service.set('isAuthenticated', true);
  35. visit('/options/forum-options');
  36. andThen(function() {
  37. assert.equal(currentPath(), 'options.forum');
  38. });
  39. });
  40. test('guest is denied access to protected route', function(assert) {
  41. assert.expect(2);
  42. visit('/options/forum-options');
  43. andThen(function() {
  44. assert.equal(currentPath(), 'error-403');
  45. var errorMessage = Ember.$.trim(find('.error-message .lead').text());
  46. assert.equal(errorMessage, 'You have to sign in to change options.');
  47. });
  48. });