mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
ActiveUserState Update should return the userId of the impacted user. (#7869)
This allows us to ensure that linked updates all go to the same user without risking active account changes in the middle of an operation.
This commit is contained in:
@@ -147,11 +147,15 @@ export class FakeStateProvider implements StateProvider {
|
||||
return this.getActive<T>(keyDefinition).state$;
|
||||
}
|
||||
|
||||
async setUserState<T>(keyDefinition: KeyDefinition<T>, value: T, userId?: UserId): Promise<void> {
|
||||
async setUserState<T>(
|
||||
keyDefinition: KeyDefinition<T>,
|
||||
value: T,
|
||||
userId?: UserId,
|
||||
): Promise<[UserId, T]> {
|
||||
if (userId) {
|
||||
await this.getUser(userId, keyDefinition).update(() => value);
|
||||
return [userId, await this.getUser(userId, keyDefinition).update(() => value)];
|
||||
} else {
|
||||
await this.getActive(keyDefinition).update(() => value);
|
||||
return await this.getActive(keyDefinition).update(() => value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ export class FakeActiveUserState<T> implements ActiveUserState<T> {
|
||||
async update<TCombine>(
|
||||
configureState: (state: T, dependency: TCombine) => T,
|
||||
options?: StateUpdateOptions<T, TCombine>,
|
||||
): Promise<T> {
|
||||
): Promise<[UserId, T]> {
|
||||
options = populateOptionsWithDefault(options);
|
||||
const current = await firstValueFrom(this.state$.pipe(timeout(options.msTimeout)));
|
||||
const combinedDependencies =
|
||||
@@ -178,12 +178,12 @@ export class FakeActiveUserState<T> implements ActiveUserState<T> {
|
||||
? await firstValueFrom(options.combineLatestWith.pipe(timeout(options.msTimeout)))
|
||||
: null;
|
||||
if (!options.shouldUpdate(current, combinedDependencies)) {
|
||||
return current;
|
||||
return [this.userId, current];
|
||||
}
|
||||
const newState = configureState(current, combinedDependencies);
|
||||
this.stateSubject.next([this.userId, newState]);
|
||||
this.nextMock([this.userId, newState]);
|
||||
return newState;
|
||||
return [this.userId, newState];
|
||||
}
|
||||
|
||||
updateMock = this.update as jest.MockedFunction<typeof this.update>;
|
||||
|
||||
Reference in New Issue
Block a user