|
|
|
|
@ -17,7 +17,7 @@ import { LogService } from "../../platform/abstractions/log.service";
@@ -17,7 +17,7 @@ import { LogService } from "../../platform/abstractions/log.service";
|
|
|
|
|
import { MessagingService } from "../../platform/abstractions/messaging.service"; |
|
|
|
|
import { Utils } from "../../platform/misc/utils"; |
|
|
|
|
import { UserId } from "../../types/guid"; |
|
|
|
|
import { AccountInfo, accountInfoEqual } from "../abstractions/account.service"; |
|
|
|
|
import { AccountInfo } from "../abstractions/account.service"; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
ACCOUNT_ACCOUNTS, |
|
|
|
|
@ -27,63 +27,6 @@ import {
@@ -27,63 +27,6 @@ import {
|
|
|
|
|
AccountServiceImplementation, |
|
|
|
|
} from "./account.service"; |
|
|
|
|
|
|
|
|
|
describe("accountInfoEqual", () => { |
|
|
|
|
const accountInfo = mockAccountInfoWith(); |
|
|
|
|
|
|
|
|
|
it("compares nulls", () => { |
|
|
|
|
expect(accountInfoEqual(null, null)).toBe(true); |
|
|
|
|
expect(accountInfoEqual(null, accountInfo)).toBe(false); |
|
|
|
|
expect(accountInfoEqual(accountInfo, null)).toBe(false); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("compares all keys, not just those defined in AccountInfo", () => { |
|
|
|
|
const different = { ...accountInfo, extra: "extra" }; |
|
|
|
|
|
|
|
|
|
expect(accountInfoEqual(accountInfo, different)).toBe(false); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("compares name", () => { |
|
|
|
|
const same = { ...accountInfo }; |
|
|
|
|
const different = { ...accountInfo, name: "name2" }; |
|
|
|
|
|
|
|
|
|
expect(accountInfoEqual(accountInfo, same)).toBe(true); |
|
|
|
|
expect(accountInfoEqual(accountInfo, different)).toBe(false); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("compares email", () => { |
|
|
|
|
const same = { ...accountInfo }; |
|
|
|
|
const different = { ...accountInfo, email: "email2" }; |
|
|
|
|
|
|
|
|
|
expect(accountInfoEqual(accountInfo, same)).toBe(true); |
|
|
|
|
expect(accountInfoEqual(accountInfo, different)).toBe(false); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("compares emailVerified", () => { |
|
|
|
|
const same = { ...accountInfo }; |
|
|
|
|
const different = { ...accountInfo, emailVerified: false }; |
|
|
|
|
|
|
|
|
|
expect(accountInfoEqual(accountInfo, same)).toBe(true); |
|
|
|
|
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 = mockAccountInfoWith({ 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", () => { |
|
|
|
|
let messagingService: MockProxy<MessagingService>; |
|
|
|
|
let logService: MockProxy<LogService>; |
|
|
|
|
@ -281,7 +224,7 @@ describe("accountService", () => {
@@ -281,7 +224,7 @@ describe("accountService", () => {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("should update the account with a new creation date", async () => { |
|
|
|
|
const newCreationDate = "2024-12-31T00:00:00.000Z"; |
|
|
|
|
const newCreationDate = new Date("2024-12-31T00:00:00.000Z"); |
|
|
|
|
await sut.setAccountCreationDate(userId, newCreationDate); |
|
|
|
|
const currentState = await firstValueFrom(accountsState.state$); |
|
|
|
|
|
|
|
|
|
@ -297,6 +240,24 @@ describe("accountService", () => {
@@ -297,6 +240,24 @@ describe("accountService", () => {
|
|
|
|
|
expect(currentState).toEqual(initialState); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("should not update if the creation date has the same timestamp but different Date object", async () => { |
|
|
|
|
const sameTimestamp = new Date(userInfo.creationDate.getTime()); |
|
|
|
|
await sut.setAccountCreationDate(userId, sameTimestamp); |
|
|
|
|
const currentState = await firstValueFrom(accountsState.state$); |
|
|
|
|
|
|
|
|
|
expect(currentState).toEqual(initialState); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("should update if the creation date has a different timestamp", async () => { |
|
|
|
|
const differentDate = new Date(userInfo.creationDate.getTime() + 1000); |
|
|
|
|
await sut.setAccountCreationDate(userId, differentDate); |
|
|
|
|
const currentState = await firstValueFrom(accountsState.state$); |
|
|
|
|
|
|
|
|
|
expect(currentState).toEqual({ |
|
|
|
|
[userId]: { ...userInfo, creationDate: differentDate }, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("should update from undefined to a defined creation date", async () => { |
|
|
|
|
const accountWithoutCreationDate = mockAccountInfoWith({ |
|
|
|
|
...userInfo, |
|
|
|
|
@ -304,7 +265,7 @@ describe("accountService", () => {
@@ -304,7 +265,7 @@ describe("accountService", () => {
|
|
|
|
|
}); |
|
|
|
|
accountsState.stateSubject.next({ [userId]: accountWithoutCreationDate }); |
|
|
|
|
|
|
|
|
|
const newCreationDate = "2024-06-15T12:30:00.000Z"; |
|
|
|
|
const newCreationDate = new Date("2024-06-15T12:30:00.000Z"); |
|
|
|
|
await sut.setAccountCreationDate(userId, newCreationDate); |
|
|
|
|
const currentState = await firstValueFrom(accountsState.state$); |
|
|
|
|
|
|
|
|
|
@ -313,14 +274,19 @@ describe("accountService", () => {
@@ -313,14 +274,19 @@ describe("accountService", () => {
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it("should update to a different creation date string format", async () => { |
|
|
|
|
const newCreationDate = "2023-03-15T08:45:30.123Z"; |
|
|
|
|
await sut.setAccountCreationDate(userId, newCreationDate); |
|
|
|
|
const currentState = await firstValueFrom(accountsState.state$); |
|
|
|
|
|
|
|
|
|
expect(currentState).toEqual({ |
|
|
|
|
[userId]: { ...userInfo, creationDate: newCreationDate }, |
|
|
|
|
it("should not update when both creation dates are undefined", async () => { |
|
|
|
|
const accountWithoutCreationDate = mockAccountInfoWith({ |
|
|
|
|
...userInfo, |
|
|
|
|
creationDate: undefined, |
|
|
|
|
}); |
|
|
|
|
accountsState.stateSubject.next({ [userId]: accountWithoutCreationDate }); |
|
|
|
|
|
|
|
|
|
// Attempt to set to undefined (shouldn't trigger update)
|
|
|
|
|
const currentStateBefore = await firstValueFrom(accountsState.state$); |
|
|
|
|
|
|
|
|
|
// We can't directly call setAccountCreationDate with undefined, but we can verify
|
|
|
|
|
// the behavior through setAccountInfo which accountInfoEqual uses internally
|
|
|
|
|
expect(currentStateBefore[userId].creationDate).toBeUndefined(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|