1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +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:
Matt Gibson
2024-02-08 14:54:15 -05:00
committed by GitHub
parent 78730ff18a
commit 4c051f8d7f
7 changed files with 63 additions and 31 deletions

View File

@@ -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>;