mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 06:43:35 +00:00
[ps-2003] Ps/ps 1854 fix pin (#4193)
* Await in `has` calls. * Add disk cache to browser synced items Note: `Map` doesn't serialize nicely so it's easier to swap over to a `Record` object for out cache * Mock and await init promises in tests * Remove redundant settings checks
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { awaitAsync as flushAsyncObservables } from "@bitwarden/angular/../test-utils";
|
||||
import { awaitAsync, awaitAsync as flushAsyncObservables } from "@bitwarden/angular/../test-utils";
|
||||
import { mock, MockProxy } from "jest-mock-extended";
|
||||
import { BehaviorSubject, ReplaySubject } from "rxjs";
|
||||
|
||||
@@ -30,6 +30,7 @@ describe("session syncer", () => {
|
||||
});
|
||||
|
||||
stateService = mock<BrowserStateService>();
|
||||
stateService.hasInSessionMemory.mockResolvedValue(false);
|
||||
sut = new SessionSyncer(behaviorSubject, stateService, metaData);
|
||||
});
|
||||
|
||||
@@ -101,24 +102,26 @@ describe("session syncer", () => {
|
||||
expect(sut["ignoreNUpdates"]).toBe(1);
|
||||
});
|
||||
|
||||
it("should grab an initial value from storage if it exists", () => {
|
||||
it("should grab an initial value from storage if it exists", async () => {
|
||||
stateService.hasInSessionMemory.mockResolvedValue(true);
|
||||
//Block a call to update
|
||||
const updateSpy = jest.spyOn(sut as any, "update").mockImplementation();
|
||||
|
||||
sut.init();
|
||||
await awaitAsync();
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it("should not grab an initial value from storage if it does not exist", () => {
|
||||
it("should not grab an initial value from storage if it does not exist", async () => {
|
||||
stateService.hasInSessionMemory.mockResolvedValue(false);
|
||||
//Block a call to update
|
||||
const updateSpy = jest.spyOn(sut as any, "update").mockImplementation();
|
||||
|
||||
sut.init();
|
||||
await awaitAsync();
|
||||
|
||||
expect(updateSpy).toHaveBeenCalledWith();
|
||||
expect(updateSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -42,9 +42,12 @@ export class SessionSyncer {
|
||||
}
|
||||
|
||||
this.observe();
|
||||
if (this.stateService.hasInSessionMemory(this.metaData.sessionKey)) {
|
||||
this.update();
|
||||
}
|
||||
// must be synchronous
|
||||
this.stateService.hasInSessionMemory(this.metaData.sessionKey).then((hasInSessionMemory) => {
|
||||
if (hasInSessionMemory) {
|
||||
this.update();
|
||||
}
|
||||
});
|
||||
|
||||
this.listenForUpdates();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ export class BrowserStateService
|
||||
protected activeAccountSubject: BehaviorSubject<string>;
|
||||
@sessionSync({ ctor: Boolean })
|
||||
protected activeAccountUnlockedSubject: BehaviorSubject<boolean>;
|
||||
@sessionSync({
|
||||
initializer: Account.fromJSON as any, // TODO: Remove this any when all any types are removed from Account
|
||||
initializeAs: "record",
|
||||
})
|
||||
protected accountDiskCache: BehaviorSubject<Record<string, Account>>;
|
||||
|
||||
protected accountDeserializer = Account.fromJSON;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user