mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
Add creationDate of account to AccountInfo
This commit is contained in:
@@ -2,14 +2,11 @@ import { Observable } from "rxjs";
|
|||||||
|
|
||||||
import { UserId } from "../../types/guid";
|
import { UserId } from "../../types/guid";
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds information about an account for use in the AccountService
|
|
||||||
* if more information is added, be sure to update the equality method.
|
|
||||||
*/
|
|
||||||
export type AccountInfo = {
|
export type AccountInfo = {
|
||||||
email: string;
|
email: string;
|
||||||
emailVerified: boolean;
|
emailVerified: boolean;
|
||||||
name: string | undefined;
|
name: string | undefined;
|
||||||
|
creationDate: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Account = { id: UserId } & AccountInfo;
|
export type Account = { id: UserId } & AccountInfo;
|
||||||
@@ -75,6 +72,12 @@ export abstract class AccountService {
|
|||||||
* @param emailVerified
|
* @param emailVerified
|
||||||
*/
|
*/
|
||||||
abstract setAccountEmailVerified(userId: UserId, emailVerified: boolean): Promise<void>;
|
abstract setAccountEmailVerified(userId: UserId, emailVerified: boolean): Promise<void>;
|
||||||
|
/**
|
||||||
|
* updates the `accounts$` observable with the creation date for the account.
|
||||||
|
* @param userId
|
||||||
|
* @param creationDate
|
||||||
|
*/
|
||||||
|
abstract setCreationDate(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
|
||||||
|
|||||||
@@ -27,7 +27,12 @@ import {
|
|||||||
} from "./account.service";
|
} from "./account.service";
|
||||||
|
|
||||||
describe("accountInfoEqual", () => {
|
describe("accountInfoEqual", () => {
|
||||||
const accountInfo: AccountInfo = { name: "name", email: "email", emailVerified: true };
|
const accountInfo: AccountInfo = {
|
||||||
|
name: "name",
|
||||||
|
email: "email",
|
||||||
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
|
};
|
||||||
|
|
||||||
it("compares nulls", () => {
|
it("compares nulls", () => {
|
||||||
expect(accountInfoEqual(null, null)).toBe(true);
|
expect(accountInfoEqual(null, null)).toBe(true);
|
||||||
@@ -64,6 +69,28 @@ describe("accountInfoEqual", () => {
|
|||||||
expect(accountInfoEqual(accountInfo, same)).toBe(true);
|
expect(accountInfoEqual(accountInfo, same)).toBe(true);
|
||||||
expect(accountInfoEqual(accountInfo, different)).toBe(false);
|
expect(accountInfoEqual(accountInfo, different)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("compares creationDate", () => {
|
||||||
|
const same = { ...accountInfo };
|
||||||
|
const different = { ...accountInfo, creationDate: "2024-12-31T00:00:00.000Z" };
|
||||||
|
|
||||||
|
expect(accountInfoEqual(accountInfo, same)).toBe(true);
|
||||||
|
expect(accountInfoEqual(accountInfo, different)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("compares undefined creationDate", () => {
|
||||||
|
const accountWithoutCreationDate: AccountInfo = {
|
||||||
|
name: "name",
|
||||||
|
email: "email",
|
||||||
|
emailVerified: true,
|
||||||
|
creationDate: undefined,
|
||||||
|
};
|
||||||
|
const same = { ...accountWithoutCreationDate };
|
||||||
|
const different = { ...accountWithoutCreationDate, creationDate: "2024-01-01T00:00:00.000Z" };
|
||||||
|
|
||||||
|
expect(accountInfoEqual(accountWithoutCreationDate, same)).toBe(true);
|
||||||
|
expect(accountInfoEqual(accountWithoutCreationDate, different)).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("accountService", () => {
|
describe("accountService", () => {
|
||||||
@@ -76,7 +103,12 @@ describe("accountService", () => {
|
|||||||
let activeAccountIdState: FakeGlobalState<UserId>;
|
let activeAccountIdState: FakeGlobalState<UserId>;
|
||||||
let accountActivityState: FakeGlobalState<Record<UserId, Date>>;
|
let accountActivityState: FakeGlobalState<Record<UserId, Date>>;
|
||||||
const userId = Utils.newGuid() as UserId;
|
const userId = Utils.newGuid() as UserId;
|
||||||
const userInfo = { email: "email", name: "name", emailVerified: true };
|
const userInfo = {
|
||||||
|
email: "email",
|
||||||
|
name: "name",
|
||||||
|
emailVerified: true,
|
||||||
|
creationDate: "2024-01-01T00:00:00.000Z",
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
messagingService = mock();
|
messagingService = mock();
|
||||||
@@ -253,6 +285,56 @@ describe("accountService", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("setCreationDate", () => {
|
||||||
|
const initialState = { [userId]: userInfo };
|
||||||
|
beforeEach(() => {
|
||||||
|
accountsState.stateSubject.next(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update the account with a new creation date", async () => {
|
||||||
|
const newCreationDate = "2024-12-31T00:00:00.000Z";
|
||||||
|
await sut.setCreationDate(userId, newCreationDate);
|
||||||
|
const currentState = await firstValueFrom(accountsState.state$);
|
||||||
|
|
||||||
|
expect(currentState).toEqual({
|
||||||
|
[userId]: { ...userInfo, creationDate: newCreationDate },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not update if the creation date is the same", async () => {
|
||||||
|
await sut.setCreationDate(userId, userInfo.creationDate);
|
||||||
|
const currentState = await firstValueFrom(accountsState.state$);
|
||||||
|
|
||||||
|
expect(currentState).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update from undefined to a defined creation date", async () => {
|
||||||
|
const accountWithoutCreationDate: AccountInfo = {
|
||||||
|
...userInfo,
|
||||||
|
creationDate: undefined,
|
||||||
|
};
|
||||||
|
accountsState.stateSubject.next({ [userId]: accountWithoutCreationDate });
|
||||||
|
|
||||||
|
const newCreationDate = "2024-06-15T12:30:00.000Z";
|
||||||
|
await sut.setCreationDate(userId, newCreationDate);
|
||||||
|
const currentState = await firstValueFrom(accountsState.state$);
|
||||||
|
|
||||||
|
expect(currentState).toEqual({
|
||||||
|
[userId]: { ...accountWithoutCreationDate, creationDate: newCreationDate },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update to a different creation date string format", async () => {
|
||||||
|
const newCreationDate = "2023-03-15T08:45:30.123Z";
|
||||||
|
await sut.setCreationDate(userId, newCreationDate);
|
||||||
|
const currentState = await firstValueFrom(accountsState.state$);
|
||||||
|
|
||||||
|
expect(currentState).toEqual({
|
||||||
|
[userId]: { ...userInfo, creationDate: newCreationDate },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("setAccountVerifyNewDeviceLogin", () => {
|
describe("setAccountVerifyNewDeviceLogin", () => {
|
||||||
const initialState = true;
|
const initialState = true;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -294,6 +376,7 @@ describe("accountService", () => {
|
|||||||
email: "",
|
email: "",
|
||||||
emailVerified: false,
|
emailVerified: false,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
|
creationDate: undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ const LOGGED_OUT_INFO: AccountInfo = {
|
|||||||
email: "",
|
email: "",
|
||||||
emailVerified: false,
|
emailVerified: false,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
|
creationDate: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,6 +168,10 @@ export class AccountServiceImplementation implements InternalAccountService {
|
|||||||
await this.setAccountInfo(userId, { emailVerified });
|
await this.setAccountInfo(userId, { emailVerified });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setCreationDate(userId: UserId, creationDate: string): Promise<void> {
|
||||||
|
await this.setAccountInfo(userId, { creationDate });
|
||||||
|
}
|
||||||
|
|
||||||
async clean(userId: UserId) {
|
async clean(userId: UserId) {
|
||||||
await this.setAccountInfo(userId, LOGGED_OUT_INFO);
|
await this.setAccountInfo(userId, LOGGED_OUT_INFO);
|
||||||
await this.removeAccountActivity(userId);
|
await this.removeAccountActivity(userId);
|
||||||
|
|||||||
@@ -272,6 +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.billingAccountProfileStateService.setHasPremium(
|
await this.billingAccountProfileStateService.setHasPremium(
|
||||||
response.premiumPersonally,
|
response.premiumPersonally,
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ export abstract class SingleUserStateProvider {
|
|||||||
abstract get<T>(userId: UserId, userKeyDefinition: UserKeyDefinition<T>): SingleUserState<T>;
|
abstract get<T>(userId: UserId, userKeyDefinition: UserKeyDefinition<T>): SingleUserState<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A provider for getting an implementation of state scoped to a given key, but always pointing
|
/**
|
||||||
* to the currently active user
|
* @deprecated ActiveUserStateProvider is deprecated. Use SingleUserStateProvider instead.
|
||||||
|
* See [state README](../../README.md#should-i-use-activeuserstate) for details.
|
||||||
*/
|
*/
|
||||||
export abstract class ActiveUserStateProvider {
|
export abstract class ActiveUserStateProvider {
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user