123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- import assert from 'assert';
- import { SIGN_IN, SIGN_OUT } from 'misago/reducers/auth';
- import { Auth } from 'misago/services/auth';
- let auth = null;
- describe("Auth", function() {
- it("synces authenticated session", function(done) {
- let store = {
- getState: function() {
- return {
- auth: {
- isAuthenticated: true,
- user: {
- username: 'BobBoberson'
- }
- }
- };
- }
- };
- let local = {
- set: function(name, value) {
- assert.equal(name, 'auth', "synced session key is valid");
- assert.deepEqual(value, {
- isAuthenticated: true,
- username: 'BobBoberson'
- }, "new session state is valid");
- done();
- },
- watch: function() {
- /* noop */
- }
- };
- let modal = {
- hide: function() {
- /* noop */
- }
- };
- auth = new Auth();
- auth.init(store, local, modal);
- });
- it("synces anonymous session", function(done) {
- let store = {
- getState: function() {
- return {
- auth: {
- isAuthenticated: false
- }
- };
- }
- };
- let local = {
- set: function(name, value) {
- assert.equal(name, 'auth', "synced session key is valid");
- assert.deepEqual(value, {
- isAuthenticated: false
- }, "new session state is valid");
- done();
- },
- watch: function() {
- /* noop */
- }
- };
- let modal = {
- hide: function() {
- /* noop */
- }
- };
- auth = new Auth();
- auth.init(store, local, modal);
- });
- it("watches session sign in", function(done) {
- let store = {
- getState: function() {
- return {
- auth: {
- isAuthenticated: false
- }
- };
- },
- dispatch(action) {
- assert.deepEqual(action, {
- type: SIGN_IN,
- user: {
- username: 'BobBoberson'
- }
- }, "action was dispatched");
- done();
- }
- };
- let local = {
- set: function() {
- /* noop */
- },
- watch: function(name, callable) {
- assert.equal(name, 'auth', "watched session key is valid");
- assert.ok(callable, "callback is provided");
- callable({
- isAuthenticated: true,
- username: 'BobBoberson'
- });
- }
- };
- let modal = {
- hide: function() {
- /* noop */
- }
- };
- auth = new Auth();
- auth.init(store, local, modal);
- });
- it("watches session sign out", function(done) {
- let store = {
- getState: function() {
- return {
- auth: {
- isAuthenticated: false
- }
- };
- },
- dispatch(action) {
- assert.deepEqual(action, {
- type: SIGN_OUT,
- soft: false
- }, "action was dispatched");
- done();
- }
- };
- let local = {
- set: function() {
- /* noop */
- },
- watch: function(name, callable) {
- assert.equal(name, 'auth', "watched session key is valid");
- assert.ok(callable, "callback is provided");
- callable({
- isAuthenticated: false
- });
- }
- };
- let modal = {
- hide: function() {
- assert.ok(true, 'modal was hidden');
- }
- };
- auth = new Auth();
- auth.init(store, local, modal);
- });
- });
|