import { mock, MockProxy } from "jest-mock-extended"; import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; function newGuid() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { const r = (Math.random() * 16) | 0; const v = c === "x" ? r : (r & 0x3) | 0x8; return v.toString(16); }); } export function GetUniqueString(prefix = "") { return prefix + "_" + newGuid(); } export function BuildTestObject( def: Partial> | T, constructor?: new () => T ): T { return Object.assign(constructor === null ? {} : new constructor(), def) as T; } export function mockEnc(s: string): MockProxy { const mocked = mock(); mocked.decrypt.mockResolvedValue(s); return mocked; } export function makeStaticByteArray(length: number, start = 0) { const arr = new Uint8Array(length); for (let i = 0; i < length; i++) { arr[i] = start + i; } return arr; } /** * Use to mock a return value of a static fromJSON method. */ export const mockFromJson = (stub: any) => (stub + "_fromJSON") as any;