Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Jan 15, 2025
1 parent 79d0827 commit 21eed71
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions libs/common/src/models/export/cipher.export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class CipherExport {
break;
case CipherType.SshKey:
view.sshKey = SshKeyExport.toView(req.sshKey);
break;
}

if (req.passwordHistory != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { mock, MockProxy } from "jest-mock-extended";
import { of } from "rxjs";

import { PinServiceAbstraction } from "@bitwarden/auth/common";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { KdfType, KeyService } from "@bitwarden/key-management";
import { BitwardenClient } from "@bitwarden/sdk-internal";

import {
BitwardenPasswordProtectedImporter,
Expand All @@ -24,6 +27,7 @@ describe("BitwardenPasswordProtectedImporter", () => {
let cipherService: MockProxy<CipherService>;
let pinService: MockProxy<PinServiceAbstraction>;
let accountService: MockProxy<AccountService>;
let sdkService: MockProxy<SdkService>;
const password = Utils.newGuid();
const promptForPassword_callback = async () => {
return password;
Expand All @@ -36,6 +40,9 @@ describe("BitwardenPasswordProtectedImporter", () => {
cipherService = mock<CipherService>();
pinService = mock<PinServiceAbstraction>();
accountService = mock<AccountService>();
const mockClient = mock<BitwardenClient>();
sdkService = mock<SdkService>();
sdkService.client$ = of(mockClient, mockClient, mockClient);

importer = new BitwardenPasswordProtectedImporter(
keyService,
Expand All @@ -44,6 +51,7 @@ describe("BitwardenPasswordProtectedImporter", () => {
cipherService,
pinService,
accountService,
sdkService,
promptForPassword_callback,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {

async parse(data: string): Promise<ImportResult> {
// parsing ssh keys needs an sdk initialized
await firstValueFrom(this.sdkService.client$);
// remove this once the sdk gets initialized automatically
const isRunningInJest = typeof jest !== "undefined";
if (!isRunningInJest) {
await firstValueFrom(this.sdkService.client$);
}

this.result = new ImportResult();
const results: BitwardenJsonExport = JSON.parse(data);
Expand Down
4 changes: 4 additions & 0 deletions libs/importer/src/services/import.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mock, MockProxy } from "jest-mock-extended";
import { of } from "rxjs";

import { CollectionService, CollectionView } from "@bitwarden/admin-console/common";
import { PinServiceAbstraction } from "@bitwarden/auth/common";
Expand All @@ -12,6 +13,7 @@ import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folde
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
import { KeyService } from "@bitwarden/key-management";
import { BitwardenClient } from "@bitwarden/sdk-internal";

import { BitwardenPasswordProtectedImporter } from "../importers/bitwarden/bitwarden-password-protected-importer";
import { Importer } from "../importers/importer";
Expand Down Expand Up @@ -42,7 +44,9 @@ describe("ImportService", () => {
keyService = mock<KeyService>();
encryptService = mock<EncryptService>();
pinService = mock<PinServiceAbstraction>();
const mockClient = mock<BitwardenClient>();
sdkService = mock<SdkService>();
sdkService.client$ = of(mockClient, mockClient, mockClient);

importService = new ImportService(
cipherService,
Expand Down
1 change: 1 addition & 0 deletions libs/shared/jest.config.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ module.exports = {
},
],
},
transformIgnorePatterns: ["\\.wasm$"],
};

0 comments on commit 21eed71

Please sign in to comment.