mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
Ps/improve state provider fakers (#7494)
* Expand state provider fakes - default null initial value for fake states - Easier mocking of key definitions through just the use of key names - allows for not exporting KeyDefinition as long as the key doesn't collide - mock of fake state provider to verify `get` calls - `nextMock` for use of the fn mock matchers on emissions of `state$` - `FakeAccountService` which allows for easy initialization and working with account switching * Small bug fix for cache key collision on key definitions unique by only storage location * Fix initial value for test
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { of } from "rxjs";
|
||||
|
||||
import { FakeAccountService, mockAccountServiceWith } from "../../../../spec/fake-account-service";
|
||||
import {
|
||||
FakeActiveUserStateProvider,
|
||||
FakeDerivedStateProvider,
|
||||
@@ -19,9 +20,11 @@ describe("DefaultStateProvider", () => {
|
||||
let singleUserStateProvider: FakeSingleUserStateProvider;
|
||||
let globalStateProvider: FakeGlobalStateProvider;
|
||||
let derivedStateProvider: FakeDerivedStateProvider;
|
||||
let accountService: FakeAccountService;
|
||||
|
||||
beforeEach(() => {
|
||||
activeUserStateProvider = new FakeActiveUserStateProvider();
|
||||
accountService = mockAccountServiceWith("fakeUserId" as UserId);
|
||||
activeUserStateProvider = new FakeActiveUserStateProvider(accountService);
|
||||
singleUserStateProvider = new FakeSingleUserStateProvider();
|
||||
globalStateProvider = new FakeGlobalStateProvider();
|
||||
derivedStateProvider = new FakeDerivedStateProvider();
|
||||
|
||||
@@ -151,8 +151,8 @@ export class KeyDefinition<T> {
|
||||
throw new Error("You must provide a userId when building a user scoped cache key.");
|
||||
}
|
||||
return userId === null
|
||||
? `${scope}_${userId}_${this.stateDefinition.name}_${this.key}`
|
||||
: `${scope}_${this.stateDefinition.name}_${this.key}`;
|
||||
? `${this.stateDefinition.storageLocation}_${scope}_${userId}_${this.stateDefinition.name}_${this.key}`
|
||||
: `${this.stateDefinition.storageLocation}_${scope}_${this.stateDefinition.name}_${this.key}`;
|
||||
}
|
||||
|
||||
private get errorKeyName() {
|
||||
|
||||
Reference in New Issue
Block a user