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:
@@ -75,6 +75,7 @@ describe("AccountSwitcherService", () => {
|
|||||||
name: "Test User 1",
|
name: "Test User 1",
|
||||||
email: "test1@email.com",
|
email: "test1@email.com",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
};
|
};
|
||||||
|
|
||||||
avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc"));
|
avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc"));
|
||||||
@@ -113,6 +114,7 @@ describe("AccountSwitcherService", () => {
|
|||||||
email: `test${i}@email.com`,
|
email: `test${i}@email.com`,
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
name: "Test User ${i}",
|
name: "Test User ${i}",
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
};
|
};
|
||||||
seedStatuses[`${i}` as UserId] = AuthenticationStatus.Unlocked;
|
seedStatuses[`${i}` as UserId] = AuthenticationStatus.Unlocked;
|
||||||
}
|
}
|
||||||
@@ -137,6 +139,7 @@ describe("AccountSwitcherService", () => {
|
|||||||
name: "Test User 1",
|
name: "Test User 1",
|
||||||
email: "",
|
email: "",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
};
|
};
|
||||||
accountsSubject.next({ ["1" as UserId]: user1AccountInfo });
|
accountsSubject.next({ ["1" as UserId]: user1AccountInfo });
|
||||||
authStatusSubject.next({ ["1" as UserId]: AuthenticationStatus.LoggedOut });
|
authStatusSubject.next({ ["1" as UserId]: AuthenticationStatus.LoggedOut });
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ describe("NotificationBackground", () => {
|
|||||||
email: "test@example.com",
|
email: "test@example.com",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
name: "Test User",
|
name: "Test User",
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
@@ -28,11 +28,13 @@ const accounts: Record<UserId, AccountInfo> = {
|
|||||||
name: "some user",
|
name: "some user",
|
||||||
email: "some.user@example.com",
|
email: "some.user@example.com",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
},
|
},
|
||||||
[AnotherUser]: {
|
[AnotherUser]: {
|
||||||
name: "some other user",
|
name: "some other user",
|
||||||
email: "some.other.user@example.com",
|
email: "some.other.user@example.com",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,12 @@ describe("VaultBannersService", () => {
|
|||||||
const getEmailVerified = jest.fn().mockResolvedValue(true);
|
const getEmailVerified = jest.fn().mockResolvedValue(true);
|
||||||
const lastSync$ = new BehaviorSubject<Date | null>(null);
|
const lastSync$ = new BehaviorSubject<Date | null>(null);
|
||||||
const accounts$ = new BehaviorSubject<Record<UserId, AccountInfo>>({
|
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>>([]);
|
const pendingAuthRequests$ = new BehaviorSubject<Array<AuthRequestResponse>>([]);
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,13 @@ const accounts: Record<UserId, AccountInfo> = {
|
|||||||
name: "some user",
|
name: "some user",
|
||||||
email: "some.user@example.com",
|
email: "some.user@example.com",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
},
|
},
|
||||||
[AnotherUser]: {
|
[AnotherUser]: {
|
||||||
name: "some other user",
|
name: "some other user",
|
||||||
email: "some.other.user@example.com",
|
email: "some.other.user@example.com",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export function mockAccountServiceWith(
|
|||||||
name: "name",
|
name: "name",
|
||||||
email: "email",
|
email: "email",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -104,6 +105,10 @@ export class FakeAccountService implements AccountService {
|
|||||||
await this.mock.setAccountEmailVerified(userId, emailVerified);
|
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> {
|
async switchAccount(userId: UserId): Promise<void> {
|
||||||
const next =
|
const next =
|
||||||
userId == null ? null : { id: userId, ...this.accountsSubject["_buffer"]?.[0]?.[userId] };
|
userId == null ? null : { id: userId, ...this.accountsSubject["_buffer"]?.[0]?.[userId] };
|
||||||
@@ -127,4 +132,5 @@ const loggedOutInfo: AccountInfo = {
|
|||||||
name: undefined,
|
name: undefined,
|
||||||
email: "",
|
email: "",
|
||||||
emailVerified: false,
|
emailVerified: false,
|
||||||
|
creationDate: undefined,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export abstract class AccountService {
|
|||||||
* @param userId
|
* @param userId
|
||||||
* @param creationDate
|
* @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.
|
* updates the `accounts$` observable with the new VerifyNewDeviceLogin property for the account.
|
||||||
* @param userId
|
* @param userId
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ describe("accountService", () => {
|
|||||||
|
|
||||||
it("should update the account with a new creation date", async () => {
|
it("should update the account with a new creation date", async () => {
|
||||||
const newCreationDate = "2024-12-31T00:00:00.000Z";
|
const newCreationDate = "2024-12-31T00:00:00.000Z";
|
||||||
await sut.setCreationDate(userId, newCreationDate);
|
await sut.setAccountCreationDate(userId, newCreationDate);
|
||||||
const currentState = await firstValueFrom(accountsState.state$);
|
const currentState = await firstValueFrom(accountsState.state$);
|
||||||
|
|
||||||
expect(currentState).toEqual({
|
expect(currentState).toEqual({
|
||||||
@@ -302,7 +302,7 @@ describe("accountService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should not update if the creation date is the same", async () => {
|
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$);
|
const currentState = await firstValueFrom(accountsState.state$);
|
||||||
|
|
||||||
expect(currentState).toEqual(initialState);
|
expect(currentState).toEqual(initialState);
|
||||||
@@ -316,7 +316,7 @@ describe("accountService", () => {
|
|||||||
accountsState.stateSubject.next({ [userId]: accountWithoutCreationDate });
|
accountsState.stateSubject.next({ [userId]: accountWithoutCreationDate });
|
||||||
|
|
||||||
const newCreationDate = "2024-06-15T12:30:00.000Z";
|
const newCreationDate = "2024-06-15T12:30:00.000Z";
|
||||||
await sut.setCreationDate(userId, newCreationDate);
|
await sut.setAccountCreationDate(userId, newCreationDate);
|
||||||
const currentState = await firstValueFrom(accountsState.state$);
|
const currentState = await firstValueFrom(accountsState.state$);
|
||||||
|
|
||||||
expect(currentState).toEqual({
|
expect(currentState).toEqual({
|
||||||
@@ -326,7 +326,7 @@ describe("accountService", () => {
|
|||||||
|
|
||||||
it("should update to a different creation date string format", async () => {
|
it("should update to a different creation date string format", async () => {
|
||||||
const newCreationDate = "2023-03-15T08:45:30.123Z";
|
const newCreationDate = "2023-03-15T08:45:30.123Z";
|
||||||
await sut.setCreationDate(userId, newCreationDate);
|
await sut.setAccountCreationDate(userId, newCreationDate);
|
||||||
const currentState = await firstValueFrom(accountsState.state$);
|
const currentState = await firstValueFrom(accountsState.state$);
|
||||||
|
|
||||||
expect(currentState).toEqual({
|
expect(currentState).toEqual({
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ export class AccountServiceImplementation implements InternalAccountService {
|
|||||||
await this.setAccountInfo(userId, { emailVerified });
|
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 });
|
await this.setAccountInfo(userId, { creationDate });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,9 +53,15 @@ describe("AuthRequestAnsweringService", () => {
|
|||||||
email: "user@example.com",
|
email: "user@example.com",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
name: "User",
|
name: "User",
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
});
|
});
|
||||||
accountService.accounts$ = of({
|
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(
|
(masterPasswordService.forceSetPasswordReason$ as jest.Mock).mockReturnValue(
|
||||||
of(ForceSetPasswordReason.None),
|
of(ForceSetPasswordReason.None),
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ describe("PasswordResetEnrollmentServiceImplementation", () => {
|
|||||||
name: "Test User 1",
|
name: "Test User 1",
|
||||||
email: "test1@email.com",
|
email: "test1@email.com",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
};
|
};
|
||||||
activeAccountSubject.next(Object.assign(user1AccountInfo, { id: "userId" as UserId }));
|
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>) ?? {};
|
const currentAccounts = (userAccounts$.getValue() as Record<string, any>) ?? {};
|
||||||
userAccounts$.next({
|
userAccounts$.next({
|
||||||
...currentAccounts,
|
...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);
|
} as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,11 +139,22 @@ describe("NotificationsService", () => {
|
|||||||
activeAccount.next(null);
|
activeAccount.next(null);
|
||||||
accounts.next({} as any);
|
accounts.next({} as any);
|
||||||
} else {
|
} 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>) ?? {};
|
const current = (accounts.getValue() as Record<string, any>) ?? {};
|
||||||
accounts.next({
|
accounts.next({
|
||||||
...current,
|
...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);
|
} as any);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -349,7 +360,13 @@ describe("NotificationsService", () => {
|
|||||||
describe("processNotification", () => {
|
describe("processNotification", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
appIdService.getAppId.mockResolvedValue("test-app-id");
|
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", () => {
|
describe("NotificationType.LogOut", () => {
|
||||||
|
|||||||
@@ -92,7 +92,12 @@ describe("DefaultSdkService", () => {
|
|||||||
.calledWith(userId)
|
.calledWith(userId)
|
||||||
.mockReturnValue(new BehaviorSubject(mock<Environment>()));
|
.mockReturnValue(new BehaviorSubject(mock<Environment>()));
|
||||||
accountService.accounts$ = of({
|
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$
|
kdfConfigService.getKdfConfig$
|
||||||
.calledWith(userId)
|
.calledWith(userId)
|
||||||
|
|||||||
@@ -76,7 +76,12 @@ describe("DefaultRegisterSdkService", () => {
|
|||||||
.calledWith(userId)
|
.calledWith(userId)
|
||||||
.mockReturnValue(new BehaviorSubject(mock<Environment>()));
|
.mockReturnValue(new BehaviorSubject(mock<Environment>()));
|
||||||
accountService.accounts$ = of({
|
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 () => {
|
it("destroys the internal SDK client when the account is removed (logout)", async () => {
|
||||||
const accounts$ = new BehaviorSubject({
|
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$;
|
accountService.accounts$ = accounts$;
|
||||||
|
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ export class DefaultSyncService extends CoreSyncService {
|
|||||||
await this.tokenService.setSecurityStamp(response.securityStamp, response.id);
|
await this.tokenService.setSecurityStamp(response.securityStamp, response.id);
|
||||||
await this.accountService.setAccountEmailVerified(response.id, response.emailVerified);
|
await this.accountService.setAccountEmailVerified(response.id, response.emailVerified);
|
||||||
await this.accountService.setAccountVerifyNewDeviceLogin(response.id, response.verifyDevices);
|
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(
|
await this.billingAccountProfileStateService.setHasPremium(
|
||||||
response.premiumPersonally,
|
response.premiumPersonally,
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ describe("AddEditFolderDialogComponent", () => {
|
|||||||
email: "",
|
email: "",
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
|
creationDate: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
|
|||||||
Reference in New Issue
Block a user