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:
@@ -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",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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 }));
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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$;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -51,6 +51,7 @@ describe("AddEditFolderDialogComponent", () => {
|
||||
email: "",
|
||||
emailVerified: true,
|
||||
name: undefined,
|
||||
creationDate: undefined,
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
|
||||
Reference in New Issue
Block a user