Skip to content

Commit

Permalink
feat(core): create individual identifier reliability (incl: end role …
Browse files Browse the repository at this point in the history
…auth) (#855)

* feat: AC 3-5-6

* fix: update flow create individual identifier reliability

* fix: resolve comment

* fix: resolve comment

* fix: update unit test for CreateIdentifier.tsx

* fix: resolve comment

* fix: make the function more idempotent

* fix: get identifier metadata exist

* fix: remove pending identifier in basic storage after creation

* fix: resolve comment
  • Loading branch information
Sotatek-BaoHoanga authored Dec 18, 2024
1 parent ca483e2 commit 4513b8d
Show file tree
Hide file tree
Showing 16 changed files with 678 additions and 183 deletions.
8 changes: 8 additions & 0 deletions src/core/agent/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const mockConnectionService = {
resolvePendingConnections: jest.fn(),
};
const mockIdentifierService = {
resolvePendingIdentifier: jest.fn(),
removeIdentifiersPendingDeletion: jest.fn(),
};

Expand Down Expand Up @@ -158,6 +159,10 @@ describe("test cases of bootAndConnect function", () => {
mockIdentifierService.removeIdentifiersPendingDeletion = jest
.fn()
.mockReturnValue(undefined);
mockIdentifierService.resolvePendingIdentifier = jest
.fn()
.mockReturnValue(undefined);

await agent.bootAndConnect(mockAgentUrls);

expect(signifyReady).toHaveBeenCalled();
Expand Down Expand Up @@ -274,6 +279,9 @@ describe("test cases of recoverKeriaAgent function", () => {
mockIdentifierService.removeIdentifiersPendingDeletion = jest
.fn()
.mockReturnValue(undefined);
mockIdentifierService.resolvePendingIdentifier = jest
.fn()
.mockReturnValue(undefined);

await agent.recoverKeriaAgent(mockSeedPhrase, mockConnectUrl);

Expand Down
4 changes: 3 additions & 1 deletion src/core/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class Agent {
this.agentServicesProps,
this.identifierStorage,
this.operationPendingStorage,
this.connections
this.connections,
this.basicStorage
);
}
return this.identifierService;
Expand Down Expand Up @@ -335,6 +336,7 @@ class Agent {
this.connections.removeConnectionsPendingDeletion();
this.connections.resolvePendingConnections();
this.identifiers.removeIdentifiersPendingDeletion();
this.identifiers.resolvePendingIdentifier();
}

this.agentServicesProps.eventEmitter.emit<KeriaStatusChangedEvent>({
Expand Down
1 change: 1 addition & 0 deletions src/core/agent/agent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum MiscRecordId {
LOGIN_METADATA = "login-metadata",
CAMERA_DIRECTION = "camera-direction",
FAILED_NOTIFICATIONS = "failed-notifications",
IDENTIFIERS_PENDING_CREATION = "identifiers-pending-creation",
}

interface ConnectionShortDetails {
Expand Down
10 changes: 10 additions & 0 deletions src/core/agent/event.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConnectionStatus, KeriaNotification } from "./agent.types";
import { IdentifierMetadataRecordProps } from "./records";
import { OperationPendingRecord } from "./records/operationPendingRecord";
import { OperationPendingRecordType } from "./records/operationPendingRecord.type";
import {
Expand All @@ -21,6 +22,7 @@ enum EventTypes {
KeriaStatusChanged = "KeriaStatusChanged",
NotificationRemoved = "NotificationRemoved",
IdentifierRemoved = "IdentifierRemoved",
IdentifierAdded = "IdentifierAdded",
}

interface NotificationAddedEvent extends BaseEventEmitter {
Expand Down Expand Up @@ -92,6 +94,13 @@ interface IdentifierRemovedEvent extends BaseEventEmitter {
};
}

interface IdentifierAddedEvent extends BaseEventEmitter {
type: typeof EventTypes.IdentifierAdded;
payload: {
identifier: IdentifierMetadataRecordProps;
};
}

export type {
NotificationAddedEvent,
OperationCompleteEvent,
Expand All @@ -103,5 +112,6 @@ export type {
NotificationRemovedEvent,
ConnectionRemovedEvent,
IdentifierRemovedEvent,
IdentifierAddedEvent,
};
export { EventTypes };
23 changes: 23 additions & 0 deletions src/core/agent/records/identifierStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,27 @@ describe("Identifier storage test", () => {
);
expect(storageService.update).toBeCalled();
});

test("Should get all identifier pending deletion", async () => {
storageService.findAllByQuery.mockResolvedValue([
{
...identifierMetadataRecord,
pendingDeletion: true,
},
{
...identifierMetadataRecord2,
pendingDeletion: true,
},
]);
expect(await identifierStorage.getIdentifiersPendingDeletion()).toEqual([
{
...identifierMetadataRecord,
pendingDeletion: true,
},
{
...identifierMetadataRecord2,
pendingDeletion: true,
},
]);
});
});
7 changes: 6 additions & 1 deletion src/core/agent/records/identifierStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ class IdentifierStorage {
metadata: Partial<
Pick<
IdentifierMetadataRecord,
"displayName" | "theme" | "isPending" | "isDeleted" | "groupMetadata" | "pendingDeletion"
| "displayName"
| "theme"
| "isPending"
| "isDeleted"
| "groupMetadata"
| "pendingDeletion"
>
>
): Promise<void> {
Expand Down
Loading

0 comments on commit 4513b8d

Please sign in to comment.