1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 18:23:31 +00:00

Fixed tests to initialize creation date

This commit is contained in:
Todd Martin
2025-12-09 16:34:32 -05:00
parent 31d236ebb0
commit 57631fb0ce
17 changed files with 80 additions and 16 deletions

View File

@@ -75,6 +75,7 @@ describe("AccountSwitcherService", () => {
name: "Test User 1",
email: "test1@email.com",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
};
avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc"));
@@ -113,6 +114,7 @@ describe("AccountSwitcherService", () => {
email: `test${i}@email.com`,
emailVerified: true,
name: "Test User ${i}",
creationDate: "2024-01-01T00:00:00.000Z",
};
seedStatuses[`${i}` as UserId] = AuthenticationStatus.Unlocked;
}
@@ -137,6 +139,7 @@ describe("AccountSwitcherService", () => {
name: "Test User 1",
email: "",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
};
accountsSubject.next({ ["1" as UserId]: user1AccountInfo });
authStatusSubject.next({ ["1" as UserId]: AuthenticationStatus.LoggedOut });

View File

@@ -85,6 +85,7 @@ describe("NotificationBackground", () => {
email: "test@example.com",
emailVerified: true,
name: "Test User",
creationDate: "2024-01-01T00:00:00.000Z",
});
beforeEach(() => {

View File

@@ -28,11 +28,13 @@ const accounts: Record<UserId, AccountInfo> = {
name: "some user",
email: "some.user@example.com",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
},
[AnotherUser]: {
name: "some other user",
email: "some.other.user@example.com",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
},
};

View File

@@ -28,7 +28,12 @@ describe("VaultBannersService", () => {
const getEmailVerified = jest.fn().mockResolvedValue(true);
const lastSync$ = new BehaviorSubject<Date | null>(null);
const accounts$ = new BehaviorSubject<Record<UserId, AccountInfo>>({
[userId]: { email: "test@bitwarden.com", emailVerified: true, name: "name" } as AccountInfo,
[userId]: {
email: "test@bitwarden.com",
emailVerified: true,
name: "name",
creationDate: "2024-01-01T00:00:00.000Z",
} as AccountInfo,
});
const pendingAuthRequests$ = new BehaviorSubject<Array<AuthRequestResponse>>([]);

View File

@@ -27,11 +27,13 @@ const accounts: Record<UserId, AccountInfo> = {
name: "some user",
email: "some.user@example.com",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
},
[AnotherUser]: {
name: "some other user",
email: "some.other.user@example.com",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
},
};

View File

@@ -17,6 +17,7 @@ export function mockAccountServiceWith(
name: "name",
email: "email",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
},
};
@@ -104,6 +105,10 @@ export class FakeAccountService implements AccountService {
await this.mock.setAccountEmailVerified(userId, emailVerified);
}
async setAccountCreationDate(userId: UserId, creationDate: string): Promise<void> {
await this.mock.setAccountCreationDate(userId, creationDate);
}
async switchAccount(userId: UserId): Promise<void> {
const next =
userId == null ? null : { id: userId, ...this.accountsSubject["_buffer"]?.[0]?.[userId] };
@@ -127,4 +132,5 @@ const loggedOutInfo: AccountInfo = {
name: undefined,
email: "",
emailVerified: false,
creationDate: undefined,
};

View File

@@ -77,7 +77,7 @@ export abstract class AccountService {
* @param userId
* @param creationDate
*/
abstract setCreationDate(userId: UserId, creationDate: string): Promise<void>;
abstract setAccountCreationDate(userId: UserId, creationDate: string): Promise<void>;
/**
* updates the `accounts$` observable with the new VerifyNewDeviceLogin property for the account.
* @param userId

View File

@@ -293,7 +293,7 @@ describe("accountService", () => {
it("should update the account with a new creation date", async () => {
const newCreationDate = "2024-12-31T00:00:00.000Z";
await sut.setCreationDate(userId, newCreationDate);
await sut.setAccountCreationDate(userId, newCreationDate);
const currentState = await firstValueFrom(accountsState.state$);
expect(currentState).toEqual({
@@ -302,7 +302,7 @@ describe("accountService", () => {
});
it("should not update if the creation date is the same", async () => {
await sut.setCreationDate(userId, userInfo.creationDate);
await sut.setAccountCreationDate(userId, userInfo.creationDate);
const currentState = await firstValueFrom(accountsState.state$);
expect(currentState).toEqual(initialState);
@@ -316,7 +316,7 @@ describe("accountService", () => {
accountsState.stateSubject.next({ [userId]: accountWithoutCreationDate });
const newCreationDate = "2024-06-15T12:30:00.000Z";
await sut.setCreationDate(userId, newCreationDate);
await sut.setAccountCreationDate(userId, newCreationDate);
const currentState = await firstValueFrom(accountsState.state$);
expect(currentState).toEqual({
@@ -326,7 +326,7 @@ describe("accountService", () => {
it("should update to a different creation date string format", async () => {
const newCreationDate = "2023-03-15T08:45:30.123Z";
await sut.setCreationDate(userId, newCreationDate);
await sut.setAccountCreationDate(userId, newCreationDate);
const currentState = await firstValueFrom(accountsState.state$);
expect(currentState).toEqual({

View File

@@ -168,7 +168,7 @@ export class AccountServiceImplementation implements InternalAccountService {
await this.setAccountInfo(userId, { emailVerified });
}
async setCreationDate(userId: UserId, creationDate: string): Promise<void> {
async setAccountCreationDate(userId: UserId, creationDate: string): Promise<void> {
await this.setAccountInfo(userId, { creationDate });
}

View File

@@ -53,9 +53,15 @@ describe("AuthRequestAnsweringService", () => {
email: "user@example.com",
emailVerified: true,
name: "User",
creationDate: "2024-01-01T00:00:00.000Z",
});
accountService.accounts$ = of({
[userId]: { email: "user@example.com", emailVerified: true, name: "User" },
[userId]: {
email: "user@example.com",
emailVerified: true,
name: "User",
creationDate: "2024-01-01T00:00:00.000Z",
},
});
(masterPasswordService.forceSetPasswordReason$ as jest.Mock).mockReturnValue(
of(ForceSetPasswordReason.None),

View File

@@ -100,6 +100,7 @@ describe("PasswordResetEnrollmentServiceImplementation", () => {
name: "Test User 1",
email: "test1@email.com",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
};
activeAccountSubject.next(Object.assign(user1AccountInfo, { id: "userId" as UserId }));

View File

@@ -174,7 +174,12 @@ describe("DefaultServerNotificationsService (multi-user)", () => {
const currentAccounts = (userAccounts$.getValue() as Record<string, any>) ?? {};
userAccounts$.next({
...currentAccounts,
[userId]: { email: "email", name: "Test Name", emailVerified: true },
[userId]: {
email: "email",
name: "Test Name",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
},
} as any);
}

View File

@@ -139,11 +139,22 @@ describe("NotificationsService", () => {
activeAccount.next(null);
accounts.next({} as any);
} else {
activeAccount.next({ id: userId, email: "email", name: "Test Name", emailVerified: true });
activeAccount.next({
id: userId,
email: "email",
name: "Test Name",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
});
const current = (accounts.getValue() as Record<string, any>) ?? {};
accounts.next({
...current,
[userId]: { email: "email", name: "Test Name", emailVerified: true },
[userId]: {
email: "email",
name: "Test Name",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
},
} as any);
}
}
@@ -349,7 +360,13 @@ describe("NotificationsService", () => {
describe("processNotification", () => {
beforeEach(async () => {
appIdService.getAppId.mockResolvedValue("test-app-id");
activeAccount.next({ id: mockUser1, email: "email", name: "Test Name", emailVerified: true });
activeAccount.next({
id: mockUser1,
email: "email",
name: "Test Name",
emailVerified: true,
creationDate: "2024-01-01T00:00:00.000Z",
});
});
describe("NotificationType.LogOut", () => {

View File

@@ -92,7 +92,12 @@ describe("DefaultSdkService", () => {
.calledWith(userId)
.mockReturnValue(new BehaviorSubject(mock<Environment>()));
accountService.accounts$ = of({
[userId]: { email: "email", emailVerified: true, name: "name" } as AccountInfo,
[userId]: {
email: "email",
emailVerified: true,
name: "name",
creationDate: "2024-01-01T00:00:00.000Z",
} as AccountInfo,
});
kdfConfigService.getKdfConfig$
.calledWith(userId)

View File

@@ -76,7 +76,12 @@ describe("DefaultRegisterSdkService", () => {
.calledWith(userId)
.mockReturnValue(new BehaviorSubject(mock<Environment>()));
accountService.accounts$ = of({
[userId]: { email: "email", emailVerified: true, name: "name" } as AccountInfo,
[userId]: {
email: "email",
emailVerified: true,
name: "name",
creationDate: "2024-01-01T00:00:00.000Z",
} as AccountInfo,
});
});
@@ -125,7 +130,12 @@ describe("DefaultRegisterSdkService", () => {
it("destroys the internal SDK client when the account is removed (logout)", async () => {
const accounts$ = new BehaviorSubject({
[userId]: { email: "email", emailVerified: true, name: "name" } as AccountInfo,
[userId]: {
email: "email",
emailVerified: true,
name: "name",
creationDate: "2024-01-01T00:00:00.000Z",
} as AccountInfo,
});
accountService.accounts$ = accounts$;

View File

@@ -272,7 +272,7 @@ export class DefaultSyncService extends CoreSyncService {
await this.tokenService.setSecurityStamp(response.securityStamp, response.id);
await this.accountService.setAccountEmailVerified(response.id, response.emailVerified);
await this.accountService.setAccountVerifyNewDeviceLogin(response.id, response.verifyDevices);
await this.accountService.setCreationDate(response.id, response.creationDate);
await this.accountService.setAccountCreationDate(response.id, response.creationDate);
await this.billingAccountProfileStateService.setHasPremium(
response.premiumPersonally,

View File

@@ -51,6 +51,7 @@ describe("AddEditFolderDialogComponent", () => {
email: "",
emailVerified: true,
name: undefined,
creationDate: undefined,
};
await TestBed.configureTestingModule({