mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
getUserState$ Helper Improvements (#8267)
* Block Sending Null to `getUser` * Update Comments & Tests Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Update Comment * Update Fake --------- Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { mock } from "jest-mock-extended";
|
||||
import { Observable, map } from "rxjs";
|
||||
import { Observable, map, of, switchMap, take } from "rxjs";
|
||||
|
||||
import {
|
||||
GlobalState,
|
||||
@@ -171,7 +171,30 @@ export class FakeStateProvider implements StateProvider {
|
||||
if (userId) {
|
||||
return this.getUser<T>(userId, keyDefinition).state$;
|
||||
}
|
||||
return this.getActive<T>(keyDefinition).state$;
|
||||
|
||||
return this.getActive(keyDefinition).state$;
|
||||
}
|
||||
|
||||
getUserStateOrDefault$<T>(
|
||||
keyDefinition: KeyDefinition<T> | UserKeyDefinition<T>,
|
||||
config: { userId: UserId | undefined; defaultValue?: T },
|
||||
): Observable<T> {
|
||||
const { userId, defaultValue = null } = config;
|
||||
if (isUserKeyDefinition(keyDefinition)) {
|
||||
this.mock.getUserStateOrDefault$(keyDefinition, config);
|
||||
} else {
|
||||
this.mock.getUserStateOrDefault$(keyDefinition, config);
|
||||
}
|
||||
if (userId) {
|
||||
return this.getUser<T>(userId, keyDefinition).state$;
|
||||
}
|
||||
|
||||
return this.activeUserId$.pipe(
|
||||
take(1),
|
||||
switchMap((userId) =>
|
||||
userId != null ? this.getUser(userId, keyDefinition).state$ : of(defaultValue),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async setUserState<T>(
|
||||
|
||||
Reference in New Issue
Block a user