Skip to content
Snippets Groups Projects
Commit 2ebdb904 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2626 OZG-2886 getUserSettings() implementieren

parent 4cca89e4
No related branches found
No related tags found
No related merge requests found
import { createEmptyStateResource, createStateResource } from '@goofy-client/tech-shared';
import { mock, Mock, useFromMock } from '@goofy-client/test-utils';
import { UserProfileService } from '@goofy-client/user-profile-shared';
import { UserProfileResource, UserProfileService } from '@goofy-client/user-profile-shared';
import { cold, hot } from 'jest-marbles';
import { createUserProfileResource } from 'libs/user-profile-shared/test/user-profile';
import { createUserSettingsResource } from 'libs/user-settings-shared/test/user-settings';
import { UserSettingsFacade } from './+state/user-settings.facade';
import { UserSettingsService } from './user-settings.service';
describe('UserSettingsService', () => {
let service: UserSettingsService;
let facade: Mock<UserSettingsFacade>;
let userProfileService: Mock<UserProfileService>;
const userProfileService = mock(UserProfileService);
let service: UserSettingsService;
beforeEach(() => {
facade = mock(UserSettingsFacade);
userProfileService = mock(UserProfileService);
service = new UserSettingsService(useFromMock(facade), useFromMock(userProfileService));
});
xit('should be created', () => {
it('should be created', () => {
expect(service).toBeTruthy();
});
xdescribe('user settings', () => {
it('get settings for current user', () => {
const userSettings = service.getUserSettings();
describe('get user settings', () => {
const userProfileResource: UserProfileResource = createUserProfileResource();
const stateResourceCU = createStateResource(createUserSettingsResource());
const emptyStateResourceCU = createEmptyStateResource<UserProfileResource>(true);
beforeEach(() => {
const stateResourceUP = createStateResource(userProfileResource);
userProfileService.getCurrentUser.mockReturnValue(hot('a', {a: stateResourceUP}));
facade.getUserSettings.mockReturnValue(hot('-a', {a: stateResourceCU}));
})
it('should call userProfileService.getCurrentUser', () => {
service.getUserSettings();
expect(userProfileService.getCurrentUser).toHaveBeenCalled();
})
it.skip('should load user settings from facade', () => {
// Prüfen dass sowie womit aufgerufen wird
service.getUserSettings();
expect(facade.loadUserSettings).toHaveBeenCalledWith(userProfileResource);
})
it('should return user settings', () => {
const userSettings$ = service.getUserSettings();
expect(userSettings$).toBeObservable(cold('ab', {a: emptyStateResourceCU, b: stateResourceCU}));
})
})
expect(userSettings).toBe(undefined);
describe('set UserSettings.notificationsSendFor', () => {
it('should call patch method in facade', () => {
// Naming an die Implementierung anpassen/spezifizieren
})
})
});
import { Injectable } from '@angular/core';
import { StateResource } from '@goofy-client/tech-shared';
import { createEmptyStateResource, doIfLoadingRequired, StateResource } from '@goofy-client/tech-shared';
import { UserProfileService } from '@goofy-client/user-profile-shared';
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { combineLatest, Observable } from 'rxjs';
import { map, startWith, tap } from 'rxjs/operators';
import { UserSettingsFacade } from './+state/user-settings.facade';
import { UserSettingsResource } from './user-settings.model';
@Injectable({
......@@ -13,12 +13,18 @@ export class UserSettingsService {
constructor(
private userSettingsFacade: UserSettingsFacade,
private userProfileService: UserProfileService,
) {
// TODO Kein schöner Ort - geht das eleganter?
this.userProfileService.getCurrentUser().pipe(first()).subscribe();
}
) { }
getUserSettings(): Observable<StateResource<UserSettingsResource>> {
return this.userSettingsFacade.getUserSettings();
const userProfile$ = this.userProfileService.getCurrentUser();
const userSetting$ = this.userSettingsFacade.getUserSettings();
return combineLatest([userProfile$, userSetting$]).pipe(
tap(([userProfile, userSettings]) => doIfLoadingRequired(userSettings, () => {
this.userSettingsFacade.loadUserSettings(userProfile.resource)
})),
map(([, userSettings]) => userSettings),
startWith(createEmptyStateResource<UserSettingsResource>(true))
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment