From 82831a46bb5d292a62d25b918fd773750f34ab4c Mon Sep 17 00:00:00 2001 From: Todd Martin Date: Wed, 10 Dec 2025 08:57:06 -0500 Subject: [PATCH] Additional test fixes. --- .../services/accounts/lock.services.spec.ts | 26 ++++++++++-------- .../src/auth/services/auth.service.spec.ts | 27 +++++++++++-------- .../services/vault-timeout.service.spec.ts | 7 ++--- .../default-environment.service.spec.ts | 19 +++++++------ .../tools/send/services/send.service.spec.ts | 8 +++--- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/libs/auth/src/common/services/accounts/lock.services.spec.ts b/libs/auth/src/common/services/accounts/lock.services.spec.ts index e22a6f71581..41e3768d80b 100644 --- a/libs/auth/src/common/services/accounts/lock.services.spec.ts +++ b/libs/auth/src/common/services/accounts/lock.services.spec.ts @@ -8,7 +8,7 @@ import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key- import { VaultTimeoutSettingsService } from "@bitwarden/common/key-management/vault-timeout"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { SystemService } from "@bitwarden/common/platform/abstractions/system.service"; -import { mockAccountServiceWith } from "@bitwarden/common/spec"; +import { mockAccountServiceWith, mockAccountInfoWith } from "@bitwarden/common/spec"; import { UserId } from "@bitwarden/common/types/guid"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction"; @@ -79,17 +79,21 @@ describe("DefaultLockService", () => { ); it("locks the active account last", async () => { - await accountService.addAccount(mockUser2, { - name: "name2", - email: "email2@example.com", - emailVerified: false, - }); + await accountService.addAccount( + mockUser2, + mockAccountInfoWith({ + name: "name2", + email: "email2@example.com", + }), + ); - await accountService.addAccount(mockUser3, { - name: "name3", - email: "name3@example.com", - emailVerified: false, - }); + await accountService.addAccount( + mockUser3, + mockAccountInfoWith({ + name: "name3", + email: "name3@example.com", + }), + ); const lockSpy = jest.spyOn(sut, "lock").mockResolvedValue(undefined); diff --git a/libs/common/src/auth/services/auth.service.spec.ts b/libs/common/src/auth/services/auth.service.spec.ts index 5dcb8c372e5..c7ff55e6bb1 100644 --- a/libs/common/src/auth/services/auth.service.spec.ts +++ b/libs/common/src/auth/services/auth.service.spec.ts @@ -10,6 +10,7 @@ import { makeStaticByteArray, mockAccountServiceWith, trackEmissions, + mockAccountInfoWith, } from "../../../spec"; import { ApiService } from "../../abstractions/api.service"; import { MessagingService } from "../../platform/abstractions/messaging.service"; @@ -58,9 +59,10 @@ describe("AuthService", () => { const accountInfo = { status: AuthenticationStatus.Unlocked, id: userId, - email: "email", - emailVerified: false, - name: "name", + ...mockAccountInfoWith({ + email: "email", + name: "name", + }), }; beforeEach(() => { @@ -112,9 +114,10 @@ describe("AuthService", () => { const accountInfo2 = { status: AuthenticationStatus.Unlocked, id: Utils.newGuid() as UserId, - email: "email2", - emailVerified: false, - name: "name2", + ...mockAccountInfoWith({ + email: "email2", + name: "name2", + }), }; const emissions = trackEmissions(sut.activeAccountStatus$); @@ -131,11 +134,13 @@ describe("AuthService", () => { it("requests auth status for all known users", async () => { const userId2 = Utils.newGuid() as UserId; - await accountService.addAccount(userId2, { - email: "email2", - emailVerified: false, - name: "name2", - }); + await accountService.addAccount( + userId2, + mockAccountInfoWith({ + email: "email2", + name: "name2", + }), + ); const mockFn = jest.fn().mockReturnValue(of(AuthenticationStatus.Locked)); sut.authStatusFor$ = mockFn; diff --git a/libs/common/src/key-management/vault-timeout/services/vault-timeout.service.spec.ts b/libs/common/src/key-management/vault-timeout/services/vault-timeout.service.spec.ts index c3c7190665a..8f7f93f368c 100644 --- a/libs/common/src/key-management/vault-timeout/services/vault-timeout.service.spec.ts +++ b/libs/common/src/key-management/vault-timeout/services/vault-timeout.service.spec.ts @@ -109,9 +109,10 @@ describe("VaultTimeoutService", () => { if (globalSetups?.userId) { accountService.activeAccountSubject.next({ id: globalSetups.userId as UserId, - email: null, - emailVerified: false, - name: null, + ...mockAccountInfoWith({ + email: null, + name: null, + }), }); } accountService.accounts$ = of( diff --git a/libs/common/src/platform/services/default-environment.service.spec.ts b/libs/common/src/platform/services/default-environment.service.spec.ts index 553f80f83b8..9e8a41616a3 100644 --- a/libs/common/src/platform/services/default-environment.service.spec.ts +++ b/libs/common/src/platform/services/default-environment.service.spec.ts @@ -1,6 +1,6 @@ import { firstValueFrom } from "rxjs"; -import { FakeStateProvider, awaitAsync } from "../../../spec"; +import { FakeStateProvider, awaitAsync, mockAccountInfoWith } from "../../../spec"; import { FakeAccountService } from "../../../spec/fake-account-service"; import { UserId } from "../../types/guid"; import { CloudRegion, Region } from "../abstractions/environment.service"; @@ -28,16 +28,14 @@ describe("EnvironmentService", () => { beforeEach(async () => { accountService = new FakeAccountService({ - [testUser]: { + [testUser]: mockAccountInfoWith({ name: "name", email: "email", - emailVerified: false, - }, - [alternateTestUser]: { + }), + [alternateTestUser]: mockAccountInfoWith({ name: "name", email: "email", - emailVerified: false, - }, + }), }); stateProvider = new FakeStateProvider(accountService); @@ -47,9 +45,10 @@ describe("EnvironmentService", () => { const switchUser = async (userId: UserId) => { accountService.activeAccountSubject.next({ id: userId, - email: "test@example.com", - name: `Test Name ${userId}`, - emailVerified: false, + ...mockAccountInfoWith({ + email: "test@example.com", + name: `Test Name ${userId}`, + }), }); await awaitAsync(); }; diff --git a/libs/common/src/tools/send/services/send.service.spec.ts b/libs/common/src/tools/send/services/send.service.spec.ts index 96fb2f43c88..397ae905e31 100644 --- a/libs/common/src/tools/send/services/send.service.spec.ts +++ b/libs/common/src/tools/send/services/send.service.spec.ts @@ -11,6 +11,7 @@ import { FakeStateProvider, awaitAsync, mockAccountServiceWith, + mockAccountInfoWith, } from "../../../../spec"; import { KeyGenerationService } from "../../../key-management/crypto"; import { EncryptService } from "../../../key-management/crypto/abstractions/encrypt.service"; @@ -71,9 +72,10 @@ describe("SendService", () => { accountService.activeAccountSubject.next({ id: mockUserId, - email: "email", - emailVerified: false, - name: "name", + ...mockAccountInfoWith({ + email: "email", + name: "name", + }), }); // Initial encrypted state