Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fix/DTIS-260-sessi…
Browse files Browse the repository at this point in the history
…on-manage

# Conflicts:
#	src/ui/components/AppWrapper/AppWrapper.tsx
  • Loading branch information
jimcase committed May 7, 2024
2 parents f1f72d4 + e17deae commit 30c7878
Show file tree
Hide file tree
Showing 71 changed files with 3,209 additions and 396 deletions.
75 changes: 59 additions & 16 deletions src/core/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ import { EventService } from "./services/eventService";
import {
BasicRecord,
BasicStorage,
ConnectionNoteRecord,
ConnectionNoteStorage,
ConnectionRecord,
ConnectionStorage,
CredentialMetadataRecord,
CredentialStorage,
IdentifierMetadataRecord,
IdentifierStorage,
NotificationRecord,
NotificationStorage,
} from "./records";
import { KeyStoreKeys, SecureStorage } from "../storage";
import { MultiSigService } from "./services/multiSigService";
Expand All @@ -44,6 +50,12 @@ class Agent {
private storageSession!: SqliteSession | IonicSession;

private basicStorageService!: BasicStorage;
private identifierStorage!: IdentifierStorage;
private credentialStorage!: CredentialStorage;
private connectionStorage!: ConnectionStorage;
private connectionNoteStorage!: ConnectionNoteStorage;
private notificationStorage!: NotificationStorage;

private signifyClient!: SignifyClient;
static ready = false;

Expand All @@ -58,37 +70,56 @@ class Agent {

get identifiers() {
if (!this.identifierService) {
this.identifierService = new IdentifierService(this.agentServicesProps);
this.identifierService = new IdentifierService(
this.agentServicesProps,
this.identifierStorage
);
}
return this.identifierService;
}

get multiSigs() {
if (!this.multiSigService) {
this.multiSigService = new MultiSigService(this.agentServicesProps);
this.multiSigService = new MultiSigService(
this.agentServicesProps,
this.identifierStorage,
this.notificationStorage
);
}
return this.multiSigService;
}

get ipexCommunications() {
if (!this.ipexCommunicationService) {
this.ipexCommunicationService = new IpexCommunicationService(
this.agentServicesProps
this.agentServicesProps,
this.identifierStorage,
this.credentialStorage,
this.notificationStorage
);
}
return this.ipexCommunicationService;
}

get connections() {
if (!this.connectionService) {
this.connectionService = new ConnectionService(this.agentServicesProps);
this.connectionService = new ConnectionService(
this.agentServicesProps,
this.connectionStorage,
this.connectionNoteStorage,
this.credentialStorage
);
}
return this.connectionService;
}

get credentials() {
if (!this.credentialService) {
this.credentialService = new CredentialService(this.agentServicesProps);
this.credentialService = new CredentialService(
this.agentServicesProps,
this.credentialStorage,
this.notificationStorage
);
}
return this.credentialService;
}
Expand All @@ -100,7 +131,8 @@ class Agent {
get signifyNotifications() {
if (!this.signifyNotificationService) {
this.signifyNotificationService = new SignifyNotificationService(
this.agentServicesProps
this.agentServicesProps,
this.notificationStorage
);
}
return this.signifyNotificationService;
Expand All @@ -122,6 +154,25 @@ class Agent {
async start(): Promise<void> {
if (!Agent.ready) {
await this.storageSession.open(walletId);
this.basicStorageService = new BasicStorage(
this.getStorageService<BasicRecord>(this.storageSession)
);
this.identifierStorage = new IdentifierStorage(
this.getStorageService<IdentifierMetadataRecord>(this.storageSession)
);
this.credentialStorage = new CredentialStorage(
this.getStorageService<CredentialMetadataRecord>(this.storageSession)
);
this.connectionStorage = new ConnectionStorage(
this.getStorageService<ConnectionRecord>(this.storageSession)
);
this.connectionNoteStorage = new ConnectionNoteStorage(
this.getStorageService<ConnectionNoteRecord>(this.storageSession)
);
this.notificationStorage = new NotificationStorage(
this.getStorageService<NotificationRecord>(this.storageSession)
);

await signifyReady();
const bran = await this.getBran();
// @TODO - foconnor: Review of Tier level.
Expand All @@ -137,20 +188,12 @@ class Agent {
await this.signifyClient.boot();
await this.signifyClient.connect();
}
this.basicStorageService = new BasicStorage(
this.getStorageService<BasicRecord>(this.storageSession)
);

this.agentServicesProps = {
basicStorage: this.basicStorageService,
signifyClient: this.signifyClient,
eventService: new EventService(),
identifierStorage: new IdentifierStorage(
this.getStorageService<IdentifierMetadataRecord>(this.storageSession)
),
credentialStorage: new CredentialStorage(
this.getStorageService<CredentialMetadataRecord>(this.storageSession)
),
};

Agent.ready = true;
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/agent/agent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ interface KeriaNotificationMarker {
}

interface AgentServicesProps {
basicStorage: BasicStorage;
signifyClient: SignifyClient;
eventService: EventService;
identifierStorage: IdentifierStorage;
credentialStorage: CredentialStorage;
}

interface CreateIdentifierResult {
Expand Down
41 changes: 41 additions & 0 deletions src/core/agent/records/connectionNoteRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { v4 as uuidv4 } from "uuid";
import { BaseRecord, Tags } from "../../storage/storage.types";

interface ConnectionNoteRecordStorageProps {
id?: string;
createdAt?: Date;
tags?: Tags;
connectionId: string;
title: string;
message: string;
}

class ConnectionNoteRecord extends BaseRecord {
connectionId!: string;
title!: string;
message!: string;
static readonly type = "ConnectionRecord";
readonly type = ConnectionNoteRecord.type;

constructor(props: ConnectionNoteRecordStorageProps) {
super();
if (props) {
this.id = props.id ?? uuidv4();
this.createdAt = props.createdAt ?? new Date();
this.connectionId = props.connectionId;
this.title = props.title;
this.message = props.message;
this._tags = props.tags ?? {};
}
}

getTags() {
return {
connectionId: this.connectionId,
...this._tags,
};
}
}

export type { ConnectionNoteRecordStorageProps };
export { ConnectionNoteRecord };
143 changes: 143 additions & 0 deletions src/core/agent/records/connectionNoteStorage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Query, StorageService } from "../../storage/storage.types";
import {
ConnectionNoteRecord,
ConnectionNoteRecordStorageProps,
} from "./connectionNoteRecord";
import { ConnectionNoteStorage } from "./connectionNoteStorage";

const storageService = jest.mocked<StorageService<ConnectionNoteRecord>>({
save: jest.fn(),
delete: jest.fn(),
deleteById: jest.fn(),
update: jest.fn(),
findById: jest.fn(),
findAllByQuery: jest.fn(),
getAll: jest.fn(),
});

const connectionNoteStorage = new ConnectionNoteStorage(storageService);

const id1 = "id1";
const id2 = "id2";

const now = new Date();

const connectionNoteRecordProps: ConnectionNoteRecordStorageProps = {
id: id1,
createdAt: now,
connectionId: "connectionId",
title: "title",
message: "message",
tags: {},
};

const connectionNoteRecordA = new ConnectionNoteRecord(
connectionNoteRecordProps
);

const connectionNoteRecordB = new ConnectionNoteRecord({
...connectionNoteRecordProps,
id: id2,
});

describe("ConnectionNote Storage", () => {
beforeEach(() => {
jest.resetAllMocks();
});

test("Should save connectionNote record", async () => {
storageService.save.mockResolvedValue(connectionNoteRecordA);
await connectionNoteStorage.save(connectionNoteRecordProps);
expect(storageService.save).toBeCalledWith(connectionNoteRecordA);
});

test("Should delete connectionNote record", async () => {
storageService.delete.mockResolvedValue();
await connectionNoteStorage.delete(connectionNoteRecordA);
expect(storageService.delete).toBeCalledWith(connectionNoteRecordA);
});

test("Should delete connectionNote record by ID", async () => {
storageService.deleteById.mockResolvedValue();
await connectionNoteStorage.deleteById(connectionNoteRecordA.id);
expect(storageService.deleteById).toBeCalledWith(connectionNoteRecordA.id);
});

test("Should update connectionNote record", async () => {
storageService.update.mockResolvedValue();
await connectionNoteStorage.update(connectionNoteRecordA);
expect(storageService.update).toBeCalledWith(connectionNoteRecordA);
});

test("Should find connectionNote record by ID", async () => {
storageService.findById.mockResolvedValue(connectionNoteRecordA);
const result = await connectionNoteStorage.findById(
connectionNoteRecordA.id
);
expect(result).toEqual(connectionNoteRecordA);
});

test("Should find all connectionNote records by query", async () => {
const query: Query<ConnectionNoteRecord> = {
connectionId: "connectionId",
};
const records = [connectionNoteRecordA, connectionNoteRecordB];
storageService.findAllByQuery.mockResolvedValue(records);
const result = await connectionNoteStorage.findAllByQuery(query);
expect(result).toEqual(records);
});

test("Should get all connectionNote records", async () => {
const records = [connectionNoteRecordA, connectionNoteRecordB];
storageService.getAll.mockResolvedValue(records);
const result = await connectionNoteStorage.getAll();
expect(result).toEqual(records);
});

// tests error
test("Should handle saving error", async () => {
storageService.save.mockRejectedValue(new Error("Saving error"));
await expect(
connectionNoteStorage.save(connectionNoteRecordProps)
).rejects.toThrow("Saving error");
});

test("Should handle deleting error", async () => {
storageService.delete.mockRejectedValue(new Error("Deleting error"));
await expect(
connectionNoteStorage.delete(connectionNoteRecordA)
).rejects.toThrow("Deleting error");
});

test("Should handle updating error", async () => {
storageService.update.mockRejectedValue(new Error("Updating error"));
await expect(
connectionNoteStorage.update(connectionNoteRecordA)
).rejects.toThrow("Updating error");
});

test("Should handle finding error", async () => {
storageService.findById.mockRejectedValue(new Error("Finding error"));
await expect(
connectionNoteStorage.findById(connectionNoteRecordA.id)
).rejects.toThrow("Finding error");
});

test("Should handle not found", async () => {
storageService.findById.mockResolvedValue(null);
const result = await connectionNoteStorage.findById("nonexistentId");
expect(result).toBeNull();
});

test("Should handle empty result", async () => {
storageService.findAllByQuery.mockResolvedValue([]);
const result = await connectionNoteStorage.findAllByQuery({ filter: {} });
expect(result).toEqual([]);
});

test("Should handle empty result for getAll", async () => {
storageService.getAll.mockResolvedValue([]);
const result = await connectionNoteStorage.getAll();
expect(result).toEqual([]);
});
});
40 changes: 40 additions & 0 deletions src/core/agent/records/connectionNoteStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Query, StorageService } from "../../storage/storage.types";
import {
ConnectionNoteRecord,
ConnectionNoteRecordStorageProps,
} from "./connectionNoteRecord";

class ConnectionNoteStorage {
private storageService: StorageService<ConnectionNoteRecord>;

constructor(storageService: StorageService<ConnectionNoteRecord>) {
this.storageService = storageService;
}

save(props: ConnectionNoteRecordStorageProps): Promise<ConnectionNoteRecord> {
const record = new ConnectionNoteRecord(props);
return this.storageService.save(record);
}
delete(record: ConnectionNoteRecord): Promise<void> {
return this.storageService.delete(record);
}
deleteById(id: string): Promise<void> {
return this.storageService.deleteById(id);
}
update(record: ConnectionNoteRecord): Promise<void> {
return this.storageService.update(record);
}
findById(id: string): Promise<ConnectionNoteRecord | null> {
return this.storageService.findById(id, ConnectionNoteRecord);
}
findAllByQuery(
query: Query<ConnectionNoteRecord>
): Promise<ConnectionNoteRecord[]> {
return this.storageService.findAllByQuery(query, ConnectionNoteRecord);
}
getAll(): Promise<ConnectionNoteRecord[]> {
return this.storageService.getAll(ConnectionNoteRecord);
}
}

export { ConnectionNoteStorage };

0 comments on commit 30c7878

Please sign in to comment.