diff --git a/npm/ng-packs/packages/oauth/src/lib/services/remember-me.service.ts b/npm/ng-packs/packages/oauth/src/lib/services/remember-me.service.ts index 84d40d982a0..ed938c5107f 100644 --- a/npm/ng-packs/packages/oauth/src/lib/services/remember-me.service.ts +++ b/npm/ng-packs/packages/oauth/src/lib/services/remember-me.service.ts @@ -17,7 +17,7 @@ export class RememberMeService { } get() { - return Boolean(JSON.parse(this.localStorageService.getItem(this.#rememberMe))); + return Boolean(JSON.parse(this.localStorageService.getItem(this.#rememberMe) || 'false')); } getFromToken(accessToken: string) { diff --git a/npm/ng-packs/packages/oauth/src/lib/tests/remember-me.service.spec.ts b/npm/ng-packs/packages/oauth/src/lib/tests/remember-me.service.spec.ts new file mode 100644 index 00000000000..0ef7116e922 --- /dev/null +++ b/npm/ng-packs/packages/oauth/src/lib/tests/remember-me.service.spec.ts @@ -0,0 +1,71 @@ +import { SpectatorService, SpyObject, createServiceFactory } from "@ngneat/spectator/jest"; +import { RememberMeService } from "../services/remember-me.service"; +import { AbpLocalStorageService } from "@abp/ng.core"; + + + +describe('RememberMeService', () => { + const key = 'remember_me'; + let spectator: SpectatorService; + let rememberMeService: RememberMeService; + let abpLocalStorageService: SpyObject; + + const createService = createServiceFactory({ + service: RememberMeService, + mocks: [AbpLocalStorageService] + }); + + + beforeEach(() => { + spectator = createService(); + rememberMeService = spectator.inject(RememberMeService); + abpLocalStorageService = spectator.inject(AbpLocalStorageService); + }); + + it('should be created', () => { + expect(1).toBe(1); + expect(rememberMeService).toBeTruthy(); + expect(abpLocalStorageService).toBeTruthy(); + }); + + it('should set remember me', () => { + rememberMeService.set(true); + expect(abpLocalStorageService.setItem).toHaveBeenCalledWith(key, 'true'); + expect(abpLocalStorageService.setItem).toHaveBeenCalledTimes(1); + }); + + it('should remove remember me', () => { + rememberMeService.remove(); + expect(abpLocalStorageService.removeItem).toHaveBeenCalledWith(key); + expect(abpLocalStorageService.removeItem).toBeCalledTimes(1); + }); + + it('if notting has ben setted, it should return false value', () => { + expect(rememberMeService.get()).toBe(false); + }); + + it('should return true value', () => { + abpLocalStorageService.getItem.mockReturnValueOnce('true'); + expect(rememberMeService.get()).toBe(true); + }); + + it('should return false value', () => { + abpLocalStorageService.getItem.mockReturnValueOnce('false'); + expect(rememberMeService.get()).toBe(false); + }); + + it('should return true when parsed token is setted to true', () => { + const data = { "remember_me": "True" }; + const base64_encoded = btoa(JSON.stringify(data)); + const tokenWithValueTrue = "random." + base64_encoded + ".random"; + expect(rememberMeService.getFromToken(tokenWithValueTrue)).toBe(true); + }); + + it('should return false when value is not setted(undefined)', () => { + const data = {}; + const base64_encoded = btoa(JSON.stringify(data)); + const tokenWithValueTrue = "random." + base64_encoded + ".random"; + expect(rememberMeService.getFromToken(tokenWithValueTrue)).toBe(false); + }); + +}); \ No newline at end of file diff --git a/npm/ng-packs/packages/theme-shared/src/lib/tests/loader-bar.component.spec.ts b/npm/ng-packs/packages/theme-shared/src/lib/tests/loader-bar.component.spec.ts index db468c4a6de..e2904e33f15 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/tests/loader-bar.component.spec.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/tests/loader-bar.component.spec.ts @@ -7,6 +7,7 @@ import { LoaderBarComponent } from '../components/loader-bar/loader-bar.componen describe('LoaderBarComponent', () => { let spectator: Spectator; + let router: Router; const events$ = new Subject(); const createComponent = createComponentFactory({