auth.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import assert from 'assert';
  2. import { SIGN_IN, SIGN_OUT } from 'misago/reducers/auth';
  3. import { Auth } from 'misago/services/auth';
  4. let auth = null;
  5. describe("Auth", function() {
  6. it("synces authenticated session", function(done) {
  7. let store = {
  8. getState: function() {
  9. return {
  10. auth: {
  11. isAuthenticated: true,
  12. user: {
  13. username: 'BobBoberson'
  14. }
  15. }
  16. };
  17. }
  18. };
  19. let local = {
  20. set: function(name, value) {
  21. assert.equal(name, 'auth', "synced session key is valid");
  22. assert.deepEqual(value, {
  23. isAuthenticated: true,
  24. username: 'BobBoberson'
  25. }, "new session state is valid");
  26. done();
  27. },
  28. watch: function() {
  29. /* noop */
  30. }
  31. };
  32. let modal = {
  33. hide: function() {
  34. /* noop */
  35. }
  36. };
  37. auth = new Auth();
  38. auth.init(store, local, modal);
  39. });
  40. it("synces anonymous session", function(done) {
  41. let store = {
  42. getState: function() {
  43. return {
  44. auth: {
  45. isAuthenticated: false
  46. }
  47. };
  48. }
  49. };
  50. let local = {
  51. set: function(name, value) {
  52. assert.equal(name, 'auth', "synced session key is valid");
  53. assert.deepEqual(value, {
  54. isAuthenticated: false
  55. }, "new session state is valid");
  56. done();
  57. },
  58. watch: function() {
  59. /* noop */
  60. }
  61. };
  62. let modal = {
  63. hide: function() {
  64. /* noop */
  65. }
  66. };
  67. auth = new Auth();
  68. auth.init(store, local, modal);
  69. });
  70. it("watches session sign in", function(done) {
  71. let store = {
  72. getState: function() {
  73. return {
  74. auth: {
  75. isAuthenticated: false
  76. }
  77. };
  78. },
  79. dispatch(action) {
  80. assert.deepEqual(action, {
  81. type: SIGN_IN,
  82. user: {
  83. username: 'BobBoberson'
  84. }
  85. }, "action was dispatched");
  86. done();
  87. }
  88. };
  89. let local = {
  90. set: function() {
  91. /* noop */
  92. },
  93. watch: function(name, callable) {
  94. assert.equal(name, 'auth', "watched session key is valid");
  95. assert.ok(callable, "callback is provided");
  96. callable({
  97. isAuthenticated: true,
  98. username: 'BobBoberson'
  99. });
  100. }
  101. };
  102. let modal = {
  103. hide: function() {
  104. /* noop */
  105. }
  106. };
  107. auth = new Auth();
  108. auth.init(store, local, modal);
  109. });
  110. it("watches session sign out", function(done) {
  111. let store = {
  112. getState: function() {
  113. return {
  114. auth: {
  115. isAuthenticated: false
  116. }
  117. };
  118. },
  119. dispatch(action) {
  120. assert.deepEqual(action, {
  121. type: SIGN_OUT,
  122. soft: false
  123. }, "action was dispatched");
  124. done();
  125. }
  126. };
  127. let local = {
  128. set: function() {
  129. /* noop */
  130. },
  131. watch: function(name, callable) {
  132. assert.equal(name, 'auth', "watched session key is valid");
  133. assert.ok(callable, "callback is provided");
  134. callable({
  135. isAuthenticated: false
  136. });
  137. }
  138. };
  139. let modal = {
  140. hide: function() {
  141. assert.ok(true, 'modal was hidden');
  142. }
  143. };
  144. auth = new Auth();
  145. auth.init(store, local, modal);
  146. });
  147. });