Skip to content

Commit

Permalink
CR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lmuntaner committed Jul 1, 2024
1 parent 270c219 commit 84c55ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
24 changes: 11 additions & 13 deletions src/frontend/src/repositories/identityMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ const mockIdentityMetadata: IdentityMetadata = {

// Used to await that the getter has resolved.
let getterResponse: MetadataMapV2 | null | undefined = null;
const getterMockSuccess = vi.fn().mockImplementation(async () => {
// The `await` is necessary to make sure that the `getterResponse` is set before the test continues.
getterResponse = await mockRawMetadata;
const getterMockSuccess = vi.fn().mockImplementation(() => {
getterResponse = mockRawMetadata;
return mockRawMetadata;
});
const getterMockError = vi.fn().mockImplementation(async () => {
// The `await` is necessary to make sure that the `getterResponse` is set before the test continues.
getterResponse = await null;
const getterMockError = vi.fn().mockImplementation(() => {
getterResponse = null;
throw new Error("test error");
});
const setterMockSuccess = vi.fn();
Expand All @@ -49,7 +47,7 @@ test("IdentityMetadataRepository loads data on init in the background", async ()
expect(instance.getMetadata()).toEqual(mockIdentityMetadata);
});

test("IdentityMetadataRepository returns no metadata without raising an error if fetching fails", async () => {
test("IdentityMetadataRepository returns undefined without raising an error if fetching fails", async () => {
const instance = IdentityMetadataRepository.init({
getter: getterMockError,
setter: setterMockSuccess,
Expand All @@ -76,7 +74,7 @@ test("IdentityMetadataRepository changes data in memory", async () => {
await vi.waitFor(() => expect(getterResponse).toEqual(mockRawMetadata));

const newRecoveryPageShownTimestampMillis = 9876543210;
await instance.setPartialMetadata({
await instance.updateIdentityMetadata({
recoveryPageShownTimestampMillis: newRecoveryPageShownTimestampMillis,
});

Expand All @@ -85,7 +83,7 @@ test("IdentityMetadataRepository changes data in memory", async () => {
});
});

test.only("IdentityMetadataRepository commits updated metadata to canister", async () => {
test("IdentityMetadataRepository commits updated metadata to canister", async () => {
const instance = IdentityMetadataRepository.init({
getter: getterMockSuccess,
setter: setterMockSuccess,
Expand All @@ -94,7 +92,7 @@ test.only("IdentityMetadataRepository commits updated metadata to canister", asy
await vi.waitFor(() => expect(getterResponse).toEqual(mockRawMetadata));

const newRecoveryPageShownTimestampMillis = 9876543210;
await instance.setPartialMetadata({
await instance.updateIdentityMetadata({
recoveryPageShownTimestampMillis: newRecoveryPageShownTimestampMillis,
});

Expand Down Expand Up @@ -136,7 +134,7 @@ test("IdentityMetadataRepository doesn't raise an error if committing fails", as
const newMetadata = {
recoveryPageShownTimestampMillis: newRecoveryPageShownTimestampMillis,
};
await instance.setPartialMetadata(newMetadata);
await instance.updateIdentityMetadata(newMetadata);

expect(setterMockError).not.toHaveBeenCalled();
const committed = await instance.commitMetadata();
Expand All @@ -154,7 +152,7 @@ test("IdentityMetadataRepository doesn't raise an error if committing fails", as
expect(instance.getMetadata()).toEqual(newMetadata);
});

test("IdentityMetadataRepository commits all received metadata to canister after update", async () => {
test("IdentityMetadataRepository commits additional metadata to canister after update", async () => {
const anotherMetadataEntry: [string, { String: string }] = [
"otherKey",
{ String: "otherValue" },
Expand All @@ -179,7 +177,7 @@ test("IdentityMetadataRepository commits all received metadata to canister after
await vi.waitFor(() => expect(getterResponse).toEqual(mockMoreRawMetadata));

const newRecoveryPageShownTimestampMillis = 9876543210;
await instance.setPartialMetadata({
await instance.updateIdentityMetadata({
recoveryPageShownTimestampMillis: newRecoveryPageShownTimestampMillis,
});

Expand Down
4 changes: 3 additions & 1 deletion src/frontend/src/repositories/identityMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export class IdentityMetadataRepository {
* @param {Partial<IdentityMetadata>} partialMetadata
* @returns {Promise<void>} To indicate that the metadata has been set.
*/
setPartialMetadata = (partialMetadata: Partial<IdentityMetadata>): void => {
updateIdentityMetadata = (
partialMetadata: Partial<IdentityMetadata>
): void => {
if (this.metadataIsLoaded(this.rawMetadata)) {
let updatedMetadata: MetadataMapV2 = [...this.rawMetadata];
this.updatedMetadata = true;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/utils/iiConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export class AuthenticatedConnection extends Connection {
setPartialMetadata = async (
partialMetadata: Partial<IdentityMetadata>
): Promise<void> => {
await this.metadataRepository.setPartialMetadata(partialMetadata);
await this.metadataRepository.updateIdentityMetadata(partialMetadata);
};

commitMetadata = async (): Promise<boolean> => {
Expand Down

0 comments on commit 84c55ec

Please sign in to comment.