123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- import assert from 'assert';
- import reducer, { SIGN_IN, SIGN_OUT, signIn, signOut } 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);
- });
- });
- describe("Auth Reducer", function() {
- it("signs user in", function() {
- let state = {
- signedIn: false
- };
- assert.deepEqual(reducer(state, signIn({username: 'Weebl'})), {
- signedIn: {
- username: 'Weebl'
- }
- }, "reducer changed store state for sign in");
- });
- it("signs user out", function() {
- let state = {
- isAuthenticated: true,
- isAnonymous: true,
- signedIn: false,
- signedOut: true
- };
- assert.deepEqual(reducer(state, signOut()), {
- isAuthenticated: false,
- isAnonymous: true,
- signedIn: false,
- signedOut: true
- }, "reducer changed store state for sign out");
- });
- it("soflty signs user out", function() {
- let state = {
- isAuthenticated: true,
- isAnonymous: true,
- signedIn: false,
- signedOut: true
- };
- assert.deepEqual(reducer(state, signOut(true)), {
- isAuthenticated: false,
- isAnonymous: true,
- signedIn: false,
- signedOut: false
- }, "reducer changed store state for soft sign out");
- });
- });
|