Skip to content

Commit

Permalink
refactor: minor improvements before merging
Browse files Browse the repository at this point in the history
  • Loading branch information
iFergal committed Apr 30, 2024
1 parent 4ec34a0 commit bc729ca
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/core/agent/records/credentialStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class CredentialStorage {
}

async saveCredentialMetadataRecord(data: CredentialMetadataRecordProps) {
const record = new CredentialMetadataRecord({
...data,
});
const record = new CredentialMetadataRecord(data);
return this.storageService.save(record);
}

Expand Down
4 changes: 1 addition & 3 deletions src/core/agent/records/identifierStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class IdentifierStorage {
async createIdentifierMetadataRecord(
data: IdentifierMetadataRecordProps
): Promise<void> {
const record = new IdentifierMetadataRecord({
...data,
});
const record = new IdentifierMetadataRecord(data);
await this.storageService.save(record);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/agent/services/credentialService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ describe("Credential service of agent", () => {
).rejects.toThrowError(CredentialService.CREDENTIAL_NOT_FOUND);
});

test("Should be able to getUnreadIpexGrantNotifications", async () => {
test("Should be able to getUnhandledIpexGrantNotifications", async () => {
const basicRecord = {
_tags: {
isDismiss: true,
Expand All @@ -411,7 +411,7 @@ describe("Credential service of agent", () => {
};
basicStorage.findAllByQuery = jest.fn().mockResolvedValue([basicRecord]);
expect(
await credentialService.getUnreadIpexGrantNotifications()
await credentialService.getUnhandledIpexGrantNotifications()
).toStrictEqual([
{
id: basicRecord.id,
Expand All @@ -421,9 +421,9 @@ describe("Credential service of agent", () => {
]);
});

test("Should pass the filter throught findAllByQuery when call getUnreadIpexGrantNotifications", async () => {
test("Should pass the filter throught findAllByQuery when call getUnhandledIpexGrantNotifications", async () => {
basicStorage.findAllByQuery = jest.fn().mockResolvedValue([]);
await credentialService.getUnreadIpexGrantNotifications({
await credentialService.getUnhandledIpexGrantNotifications({
isDismissed: false,
});
expect(basicStorage.findAllByQuery).toBeCalledWith({
Expand Down
2 changes: 1 addition & 1 deletion src/core/agent/services/credentialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class CredentialService extends AgentService {
return metadata;
}

async getUnreadIpexGrantNotifications(
async getUnhandledIpexGrantNotifications(
filters: {
isDismissed?: boolean;
} = {}
Expand Down
8 changes: 5 additions & 3 deletions src/core/agent/services/identifierService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class IdentifierService extends AgentService {
"id" | "createdAt" | "isArchived" | "signifyName"
>
): Promise<CreateIdentifierResult> {
this.validIdentifierMetadata(metadata);
const signifyName = uuidv4();
const operation = await this.signifyClient
.identifiers()
Expand All @@ -95,7 +96,6 @@ class IdentifierService extends AgentService {
.identifiers()
.addEndRole(signifyName, "agent", this.signifyClient.agent!.pre);
const identifier = operation.serder.ked.i;
this.validIdentifierMetadata(metadata);
await this.identifierStorage.createIdentifierMetadataRecord({
id: identifier,
...metadata,
Expand Down Expand Up @@ -187,8 +187,10 @@ class IdentifierService extends AgentService {
const rotateResult = await this.signifyClient
.identifiers()
.rotate(metadata.signifyName);
let operation = await rotateResult.op();
operation = await waitAndGetDoneOp(this.signifyClient, operation);
const operation = await waitAndGetDoneOp(
this.signifyClient,
await rotateResult.op()
);
if (!operation.done) {
throw new Error(IdentifierService.FAILED_TO_ROTATE_AID);
}
Expand Down
5 changes: 5 additions & 0 deletions src/core/storage/storage.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { instanceToPlain } from "class-transformer";
import { BasicRecord } from "../agent/records";

// Intented for interop with Askar.
type Tags = Record<string | number, unknown>;

abstract class BaseRecord {
protected _tags: Tags = {} as Tags;

Expand Down Expand Up @@ -58,11 +60,13 @@ enum RecordType {

type SimpleQuery<T extends BaseRecord> = Partial<ReturnType<T["getTags"]>> &
Tags;

interface AdvancedQuery<T extends BaseRecord> {
$and?: Query<T>[];
$or?: Query<T>[];
$not?: Query<T>;
}

type Query<T extends BaseRecord> = AdvancedQuery<T> | SimpleQuery<T>;

interface StorageApi {
Expand Down Expand Up @@ -90,6 +94,7 @@ interface StorageService<T extends BaseRecord> {
): Promise<T[]>;
getAll(recordClass: BaseRecordConstructor<T>): Promise<T[]>;
}

interface StorageRecord {
name: string;
value: string;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jest.mock("../core/agent/agent", () => ({
createMetadata: jest.fn(),
isCredentialDone: jest.fn(),
updateMetadataCompleted: jest.fn(),
getUnreadIpexGrantNotifications: jest.fn(),
getUnhandledIpexGrantNotifications: jest.fn(),
onAcdcStateChanged: jest.fn(),
syncACDCs: jest.fn(),
},
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/AppWrapper/AppWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jest.mock("../../../core/agent/agent", () => ({
createMetadata: jest.fn(),
isCredentialDone: jest.fn(),
updateMetadataCompleted: jest.fn(),
getUnreadIpexGrantNotifications: jest.fn(),
getUnhandledIpexGrantNotifications: jest.fn(),
onAcdcStateChanged: jest.fn(),
syncACDCs: jest.fn(),
},
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/AppWrapper/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ const AppWrapper = (props: { children: ReactNode }) => {

const oldMessages = (
await Promise.all([
Agent.agent.credentials.getUnreadIpexGrantNotifications({
Agent.agent.credentials.getUnhandledIpexGrantNotifications({
isDismissed: false,
}),
Agent.agent.multiSigs.getUnhandledMultisigIdentifiers({
Expand Down

0 comments on commit bc729ca

Please sign in to comment.