Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACS-6576] Local storage prefix is not always created/updated properly in ADW #3602

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions projects/aca-shared/src/lib/services/app.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
PageTitleService,
AlfrescoApiServiceMock,
TranslationMock,
TranslationService
TranslationService,
UserPreferencesService
} from '@alfresco/adf-core';
import { BehaviorSubject, Observable, of, Subject } from 'rxjs';
import { HttpClientModule } from '@angular/common/http';
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('AppService', () => {
let sharedLinksApiService: SharedLinksApiService;
let contentApi: ContentApiService;
let groupService: GroupService;
let preferencesService: UserPreferencesService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -110,10 +112,12 @@ describe('AppService', () => {
useValue: {
onLogin: new Subject<any>(),
onLogout: new Subject<any>(),
isLoggedIn: () => false
isLoggedIn: () => false,
getUsername: () => null
}
},
{ provide: TranslationService, useClass: TranslationMock }
{ provide: TranslationService, useClass: TranslationMock },
{ provide: UserPreferencesService, useValue: { setStoragePrefix: () => null } }
]
});

Expand All @@ -126,6 +130,7 @@ describe('AppService', () => {
contentApi = TestBed.inject(ContentApiService);
groupService = TestBed.inject(GroupService);
service = TestBed.inject(AppService);
preferencesService = TestBed.inject(UserPreferencesService);
});

it('should be ready if [withCredentials] mode is used', (done) => {
Expand All @@ -152,6 +157,14 @@ describe('AppService', () => {
await expect(isReady).toEqual(true);
});

it('should set local storage prefix after login', () => {
spyOn(preferencesService, 'setStoragePrefix');
spyOn(auth, 'getUsername').and.returnValue('test-username');
auth.onLogin.next();

expect(preferencesService.setStoragePrefix).toHaveBeenCalledWith('test-username');
});

it('should reset search to defaults upon logout', async () => {
const resetToDefaults = spyOn(searchQueryBuilderService, 'resetToDefaults');
auth.onLogout.next(true);
Expand Down
1 change: 1 addition & 0 deletions projects/aca-shared/src/lib/services/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@

this.authenticationService.onLogin.subscribe(() => {
this.ready.next(true);
this.preferencesService.setStoragePrefix(this.authenticationService.getUsername());
});

this.authenticationService.onLogout.subscribe(() => {
Expand Down Expand Up @@ -129,7 +130,7 @@
redirectUrl = this.router.url;
}

this.router.navigate(['/login'], {

Check warning on line 133 in projects/aca-shared/src/lib/services/app.service.ts

View workflow job for this annotation

GitHub Actions / lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
queryParams: { redirectUrl }
});
}
Expand Down Expand Up @@ -164,7 +165,7 @@
this.ready$.subscribe((isReady) => {
if (isReady) {
this.loadRepositoryStatus();
this.loadUserProfile();

Check warning on line 168 in projects/aca-shared/src/lib/services/app.service.ts

View workflow job for this annotation

GitHub Actions / lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
setTimeout(() => {
this.openMobileAppDialog();
});
Expand Down
Loading