From 2528e71469bbfffb34d9aec44dc837daed40b2e9 Mon Sep 17 00:00:00 2001 From: Zack Yang Date: Wed, 31 Aug 2016 22:55:01 +0800 Subject: [PATCH] fix(localstorage): change localstorage module --- app/component/index.js | 2 +- app/component/session.provider.js | 14 +++++++------- app/component/session.spec.js | 28 ++++++++++++++-------------- package.json | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/component/index.js b/app/component/index.js index 8bdb12b..06ba8d6 100644 --- a/app/component/index.js +++ b/app/component/index.js @@ -1,6 +1,6 @@ import angular from 'angular'; import 'angular-http-auth'; -import LocalStorageModule from 'angular-local-storage'; +import LocalStorageModule from 'angular-storage'; import {sjRest} from 'sanji-rest-ui'; import authEvent from './auth.constant'; diff --git a/app/component/session.provider.js b/app/component/session.provider.js index a453120..ade9044 100644 --- a/app/component/session.provider.js +++ b/app/component/session.provider.js @@ -10,13 +10,13 @@ class SessionProvider { this.configure = cfg => Object.assign(this.config, cfg); } - $get(localStorageService) { + $get(store) { 'ngInject'; let config = this.config; let session = {}; - session[config.tokenKey] = localStorageService.get(config.tokenKey) || null; - session.user = localStorageService.get('sj-user-profile') || null; + session[config.tokenKey] = store.get(config.tokenKey) || null; + session.user = store.get('sj-user-profile') || null; return { get: get, @@ -46,7 +46,7 @@ class SessionProvider { } function setUserData(data) { - localStorageService.set('sj-user-profile', data); + store.set('sj-user-profile', data); set('user', data); } @@ -55,13 +55,13 @@ class SessionProvider { } function create(token) { - localStorageService.set(config.tokenKey, token); + store.set(config.tokenKey, token); session[config.tokenKey] = token; } function destroy() { - localStorageService.remove(config.tokenKey); - localStorageService.remove('sj-user-profile'); + store.remove(config.tokenKey); + store.remove('sj-user-profile'); session[config.tokenKey] = null; } } diff --git a/app/component/session.spec.js b/app/component/session.spec.js index d53a453..40c7f58 100644 --- a/app/component/session.spec.js +++ b/app/component/session.spec.js @@ -4,7 +4,7 @@ import 'angular-mocks'; import {sjAuth} from './index' ; let sessionProvider; -let localStorageService; +let store; describe('Provider: sessionProvider', () => { beforeEach(angular.mock.module(sjAuth)); @@ -16,8 +16,8 @@ describe('Provider: sessionProvider', () => { }); beforeEach(() => { - angular.mock.inject((_localStorageService_) => { - localStorageService = _localStorageService_; + angular.mock.inject((_store_) => { + store = _store_; }); }); @@ -31,7 +31,7 @@ describe('Provider: sessionProvider', () => { }); it('#$get(<...injects>) should return session service instance', () => { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); expect(obj.get).to.be.a('function'); expect(obj.set).to.be.a('function'); expect(obj.getTokenKey).to.be.a('function'); @@ -43,64 +43,64 @@ describe('Provider: sessionProvider', () => { describe('Service: session', () => { it('#get() should return specific value', function() { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); obj.set('test', 'hello world'); expect(obj.get('test')).to.equal('hello world'); }); it('#set(, ) should set specific key and value', function() { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); obj.set('test', 'hello world'); expect(obj.get('test')).to.equal('hello world'); }); it('#getTokenKey() should return default token key name', function() { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); expect(obj.getTokenKey()).to.equal('token'); }); it('#getTokenKey() should return settings token key name', function() { let obj; sessionProvider.configure({tokenKey: 'test'}); - obj = sessionProvider.$get(localStorageService); + obj = sessionProvider.$get(store); expect(obj.getTokenKey()).to.equal('test'); }); it('#getTokenHeader() should return default token header', function() { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); expect(obj.getTokenHeader()).to.equal('Authorization'); }); it('#getTokenHeader() should return settings token key name', function() { let obj; sessionProvider.configure({tokenHeader: 'test'}); - obj = sessionProvider.$get(localStorageService); + obj = sessionProvider.$get(store); expect(obj.getTokenHeader()).to.equal('test'); }); it('#getUserData() should return user data', function() { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); let data = {role: 'admin', username: 'admin'}; obj.setUserData(data); expect(obj.getUserData()).to.eql(data); }); it('#setUserData() should set user data', function() { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); let data = {role: 'admin', username: 'admin'}; obj.setUserData(data); expect(obj.getUserData()).to.eql(data); }); it('#create() should set token data', function() { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); let token = 'helloworld'; obj.create(token); expect(obj.get('token')).to.equal(token); }); it('#destory() should remove token data', function() { - let obj = sessionProvider.$get(localStorageService); + let obj = sessionProvider.$get(store); let token = 'helloworld'; obj.create(token); expect(obj.get('token')).to.equal(token); diff --git a/package.json b/package.json index a29ccd7..4d9d925 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "dependencies": { "angular": "~1.5.0", "angular-http-auth": "~1.3.0", - "angular-local-storage": "~0.2.7", + "angular-storage": "~0.0.15", "sanji-rest-ui": "~1.3.6" } }