@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
2 lines • 4.3 kB
JavaScript
import{requestLogin,successLogin,errorLogin,requestLogout,successLogout,errorLogout,requestUser,receiveUser,errorUser,toggleLoggedIn}from"./index";import{REQUEST_LOGIN,SUCCESS_LOGIN,ERROR_LOGIN,REQUEST_LOGOUT,SUCCESS_LOGOUT,ERROR_LOGOUT,REQUEST_USER,RECEIVE_USER,ERROR_USER,TOGGLE_LOGGED_IN}from"../../constants/ActionTypes";import{DEFAULT_LOGIN_STRATEGY}from"../../constants/user";var messages=[{type:'EUNKNOWN',message:'Something went wrong',code:1337}];describe('Action Creators: user',function(){describe('requestLogin()',function(){it('should work as expected',function(){var user='super@user.com';var password='super#password';var expected={type:REQUEST_LOGIN,user:user,password:password,strategy:DEFAULT_LOGIN_STRATEGY};expect(requestLogin(user,password)).toEqual(expected);});});describe('successLogin()',function(){it('should work as expected with no parameters',function(){var expected={type:SUCCESS_LOGIN,redirect:undefined,strategy:DEFAULT_LOGIN_STRATEGY};expect(successLogin()).toEqual(expected);});it('should work as expected with parameters',function(){var redirect='/some/url';var strategy='custom';var expected={type:SUCCESS_LOGIN,redirect:redirect,strategy:strategy};expect(successLogin(redirect,strategy)).toEqual(expected);});});describe('errorLogin()',function(){it('should work as expected',function(){var expected={type:ERROR_LOGIN,code:'EUNKNOWN',messages:messages};expect(errorLogin(messages,'EUNKNOWN')).toEqual(expected);});it('should work as expected when the messages parameter is empty',function(){var expected={type:ERROR_LOGIN,code:'EUNKNOWN',messages:[]};expect(errorLogin(undefined,'EUNKNOWN')).toEqual(expected);});it('should work as expected when the code paramter is empty',function(){var expected={type:ERROR_LOGIN,code:'',messages:messages};expect(errorLogin(messages)).toEqual(expected);});});describe('requestLogout()',function(){it('should work as expected',function(){var expected={type:REQUEST_LOGOUT};expect(requestLogout()).toEqual(expected);});});describe('successLogout()',function(){it('should work as expected when called without parameter',function(){var expected={type:SUCCESS_LOGOUT,notify:true,autoLogout:false};expect(successLogout()).toEqual(expected);});it('should work as expected when called with true',function(){var expected={type:SUCCESS_LOGOUT,notify:true,autoLogout:false};expect(successLogout(true)).toEqual(expected);});it('should work as expected when called with false',function(){var expected={type:SUCCESS_LOGOUT,notify:false,autoLogout:false};expect(successLogout(false)).toEqual(expected);});it('should work as expected when called with autoLogout parameter',function(){var expected={type:SUCCESS_LOGOUT,notify:true,autoLogout:true};expect(successLogout(undefined,true)).toEqual(expected);});});describe('errorLogout()',function(){it('should work as expected',function(){var expected={type:ERROR_LOGOUT,messages:messages,autoLogout:false};expect(errorLogout(messages)).toEqual(expected);});it('should work as expected when the messages parameter is empty',function(){var expected={type:ERROR_LOGOUT,messages:[],autoLogout:false};expect(errorLogout()).toEqual(expected);});it('should work as expected when called with autoLogout parameter',function(){var expected={type:ERROR_LOGOUT,messages:messages,autoLogout:true};expect(errorLogout(messages,true)).toEqual(expected);});});describe('requestUser()',function(){it('should work as expected',function(){var expected={type:REQUEST_USER};expect(requestUser()).toEqual(expected);});});describe('receiveUser()',function(){it('should work as expected',function(){var user={firstName:'John',lastName:'Doe',mail:'john@doe.com'};var expected={type:RECEIVE_USER,user:user};expect(receiveUser(user)).toEqual(expected);});});describe('errorUser()',function(){it('should work as expected',function(){var err=new Error();// eslint-disable-next-line extra-rules/no-single-line-objects
var expected={type:ERROR_USER,error:err};expect(errorUser(err)).toEqual(expected);});});describe('toggleLoggedIn()',function(){it('should toggle to true',function(){var expected={type:TOGGLE_LOGGED_IN,value:true};expect(toggleLoggedIn(true)).toEqual(expected);});it('should toggle to false',function(){var expected={type:TOGGLE_LOGGED_IN,value:false};expect(toggleLoggedIn(false)).toEqual(expected);});});});