mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +00:00
Allow common get and set operations from state providers (#7824)
* Allow common get and set operations from state providers * Use finnish endings for observables
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { mock } from "jest-mock-extended";
|
||||
|
||||
import { mockAccountServiceWith, trackEmissions } from "../../../../spec";
|
||||
import { AuthenticationStatus } from "../../../auth/enums/authentication-status";
|
||||
import { UserId } from "../../../types/guid";
|
||||
import {
|
||||
AbstractMemoryStorageService,
|
||||
AbstractStorageService,
|
||||
ObservableStorageService,
|
||||
} from "../../abstractions/storage.service";
|
||||
|
||||
import { DefaultActiveUserStateProvider } from "./default-active-user-state.provider";
|
||||
|
||||
describe("DefaultActiveUserStateProvider", () => {
|
||||
const memoryStorage = mock<AbstractMemoryStorageService & ObservableStorageService>();
|
||||
const diskStorage = mock<AbstractStorageService & ObservableStorageService>();
|
||||
const userId = "userId" as UserId;
|
||||
const accountInfo = {
|
||||
id: userId,
|
||||
name: "name",
|
||||
email: "email",
|
||||
status: AuthenticationStatus.Locked,
|
||||
};
|
||||
const accountService = mockAccountServiceWith(userId, accountInfo);
|
||||
let sut: DefaultActiveUserStateProvider;
|
||||
|
||||
beforeEach(() => {
|
||||
sut = new DefaultActiveUserStateProvider(accountService, memoryStorage, diskStorage);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it("should track the active User id from account service", () => {
|
||||
const emissions = trackEmissions(sut.activeUserId$);
|
||||
|
||||
accountService.activeAccountSubject.next(undefined);
|
||||
accountService.activeAccountSubject.next(accountInfo);
|
||||
|
||||
expect(emissions).toEqual([userId, undefined, userId]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user