mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-07 09:31:31 +01:00
Fixed folder state test
This commit is contained in:
parent
07593b6544
commit
bb0d489116
@ -1,10 +1,13 @@
|
||||
import { mock } from "jest-mock-extended";
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
|
||||
import { KeyService } from "../../../../../key-management/src/abstractions/key.service";
|
||||
import { FolderService } from "../../abstractions/folder/folder.service.abstraction";
|
||||
import { FolderData } from "../../models/data/folder.data";
|
||||
import { Folder } from "../../models/domain/folder";
|
||||
import { FolderView } from "../../models/view/folder.view";
|
||||
|
||||
import { FOLDER_DECRYPTED_FOLDERS, FOLDER_ENCRYPTED_FOLDERS } from "./folder.state";
|
||||
|
||||
@ -32,7 +35,9 @@ describe("encrypted folders", () => {
|
||||
|
||||
describe("derived decrypted folders", () => {
|
||||
const keyService = mock<KeyService>();
|
||||
const folderService = mock<FolderService>();
|
||||
const encryptService = mock<EncryptService>();
|
||||
const i18nService = mock<I18nService>();
|
||||
const mockUserId = Utils.newGuid() as UserId;
|
||||
const sut = FOLDER_DECRYPTED_FOLDERS;
|
||||
let data: FolderData;
|
||||
|
||||
@ -42,6 +47,13 @@ describe("derived decrypted folders", () => {
|
||||
name: "encName",
|
||||
revisionDate: "2024-01-31T12:00:00.000Z",
|
||||
};
|
||||
|
||||
keyService.userKey$.mockReturnValue(new BehaviorSubject("mockOriginalUserKey" as any));
|
||||
|
||||
i18nService.collator = new Intl.Collator("en");
|
||||
i18nService.t.mockReturnValue("No Folder");
|
||||
|
||||
encryptService.decryptToUtf8.mockResolvedValue("DEC");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -63,16 +75,48 @@ describe("derived decrypted folders", () => {
|
||||
});
|
||||
|
||||
it("should derive encrypted folders", async () => {
|
||||
const folderViewMock = new FolderView(new Folder(data));
|
||||
keyService.hasUserKey.mockResolvedValue(true);
|
||||
folderService.decryptFolders.mockResolvedValue([folderViewMock]);
|
||||
const encryptedFoldersState: [UserId, Record<string, FolderData>] = [mockUserId, { id: data }];
|
||||
|
||||
const encryptedFoldersState = { id: data };
|
||||
const derivedStateResult = await sut.derive(encryptedFoldersState, {
|
||||
folderService,
|
||||
encryptService,
|
||||
i18nService,
|
||||
keyService,
|
||||
});
|
||||
|
||||
expect(derivedStateResult).toEqual([folderViewMock]);
|
||||
expect(derivedStateResult).toHaveLength(2);
|
||||
expect(derivedStateResult[0]).toMatchObject({
|
||||
id: "id",
|
||||
name: "DEC",
|
||||
});
|
||||
expect(derivedStateResult[1]).toMatchObject({
|
||||
id: null,
|
||||
name: "No Folder",
|
||||
});
|
||||
});
|
||||
|
||||
it("should return empty array when no folder data", async () => {
|
||||
const encryptedFoldersState: [UserId, Record<string, FolderData>] = [mockUserId, null];
|
||||
|
||||
const derivedStateResult = await sut.derive(encryptedFoldersState, {
|
||||
encryptService,
|
||||
i18nService,
|
||||
keyService,
|
||||
});
|
||||
|
||||
expect(derivedStateResult).toEqual([]);
|
||||
});
|
||||
|
||||
it("should return empty array when no user key", async () => {
|
||||
keyService.userKey$.mockReturnValue(new BehaviorSubject(null));
|
||||
|
||||
const encryptedFoldersState: [UserId, Record<string, FolderData>] = [mockUserId, { id: data }];
|
||||
|
||||
const derivedStateResult = await sut.derive(encryptedFoldersState, {
|
||||
encryptService,
|
||||
i18nService,
|
||||
keyService,
|
||||
});
|
||||
|
||||
expect(derivedStateResult).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user