Skip to content

Commit

Permalink
test: add test for new storage
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-sotatek committed May 4, 2024
1 parent a1d34f8 commit 4b68285
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 85 deletions.
1 change: 0 additions & 1 deletion src/core/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Agent {
private storageSession!: SqliteSession | IonicSession;

private basicStorageService!: BasicStorage;

private identifierStorage!: IdentifierStorage;
private credentialStorage!: CredentialStorage;
private connectionStorage!: ConnectionStorage;
Expand Down
3 changes: 0 additions & 3 deletions src/core/agent/services/agentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import { CredentialStorage } from "../records/credentialStorage";
import { AgentServicesProps } from "../agent.types";

abstract class AgentService {
// protected readonly basicStorage: StorageApi;
protected readonly signifyClient: SignifyClient;
protected readonly eventService: EventService;
// protected readonly identifierStorage: IdentifierStorage;
// protected readonly credentialStorage: CredentialStorage;

constructor(agentServicesProps: AgentServicesProps) {
this.signifyClient = agentServicesProps.signifyClient;
Expand Down
40 changes: 25 additions & 15 deletions src/core/agent/services/credentialService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
} from "../records/credentialMetadataRecord.types";
import { CredentialMetadataRecord } from "../records/credentialMetadataRecord";
import { EventService } from "./eventService";
import { RecordType } from "../../storage/storage.types";
import { NotificationRoute } from "../agent.types";

const basicStorage = jest.mocked({
Expand Down Expand Up @@ -111,14 +110,25 @@ const credentialStorage = jest.mocked({
});

const agentServicesProps = {
basicStorage: basicStorage as any,
signifyClient: signifyClient as any,
eventService: new EventService(),
identifierStorage: identifierStorage as any,
credentialStorage: credentialStorage as any,
};

const credentialService = new CredentialService(agentServicesProps);
const notificationStorage = jest.mocked({
save: jest.fn(),
delete: jest.fn(),
deleteById: jest.fn(),
update: jest.fn(),
findById: jest.fn(),
findAllByQuery: jest.fn(),
getAll: jest.fn(),
});

const credentialService = new CredentialService(
agentServicesProps,
credentialStorage as any,
notificationStorage as any
);

const now = new Date();
const nowISO = now.toISOString();
Expand Down Expand Up @@ -396,38 +406,38 @@ describe("Credential service of agent", () => {
});

test("Should be able to getUnhandledIpexGrantNotifications", async () => {
const basicRecord = {
const notificationRecord = {
_tags: {
isDismiss: true,
type: RecordType.KERIA_NOTIFICATION,
route: NotificationRoute.Credential,
},
id: "AIeGgKkS23FDK4mxpfodpbWhTydFz2tdM64DER6EdgG-",
createdAt: new Date(),
content: {
a: {
r: NotificationRoute.Credential,
d: "EF6Nmxz8hs0oVc4loyh2J5Sq9H3Z7apQVqjO6e4chtsp",
},
};
basicStorage.findAllByQuery = jest.fn().mockResolvedValue([basicRecord]);
notificationStorage.findAllByQuery = jest
.fn()
.mockResolvedValue([notificationRecord]);
expect(
await credentialService.getUnhandledIpexGrantNotifications()
).toStrictEqual([
{
id: basicRecord.id,
createdAt: basicRecord.createdAt,
a: basicRecord.content,
id: notificationRecord.id,
createdAt: notificationRecord.createdAt,
a: notificationRecord.a,
},
]);
});

test("Should pass the filter throught findAllByQuery when call getUnhandledIpexGrantNotifications", async () => {
basicStorage.findAllByQuery = jest.fn().mockResolvedValue([]);
notificationStorage.findAllByQuery = jest.fn().mockResolvedValue([]);
await credentialService.getUnhandledIpexGrantNotifications({
isDismissed: false,
});
expect(basicStorage.findAllByQuery).toBeCalledWith({
type: RecordType.KERIA_NOTIFICATION,
expect(notificationStorage.findAllByQuery).toBeCalledWith({
route: NotificationRoute.Credential,
isDismissed: false,
});
Expand Down
8 changes: 4 additions & 4 deletions src/core/agent/services/delegationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const identifierStorage = jest.mocked({
});

const agentServicesProps = {
basicStorage: {} as any,
signifyClient: signifyClient as any,
eventService: new EventService(),
identifierStorage: identifierStorage as any,
credentialStorage: {} as any,
};

const delegationService = new DelegationService(agentServicesProps);
const delegationService = new DelegationService(
agentServicesProps,
identifierStorage as any
);

describe("Delegation sig service of agent", () => {
beforeEach(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/core/agent/services/identifierService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ const credentialStorage = jest.mocked({
});

const agentServicesProps = {
basicStorage: basicStorage as any,
signifyClient: signifyClient as any,
eventService: new EventService(),
identifierStorage: identifierStorage as any,
credentialStorage: credentialStorage as any,
};

const identifierService = new IdentifierService(agentServicesProps);
const identifierService = new IdentifierService(
agentServicesProps,
identifierStorage as any
);

jest.mock("../../../core/agent/agent", () => ({
Agent: {
Expand Down
20 changes: 10 additions & 10 deletions src/core/agent/services/ipexCommunicationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventService } from "./eventService";
import { IpexCommunicationService } from "./ipexCommunicationService";
import { CredentialStatus } from "./credentialService.types";

const basicStorage = jest.mocked({
const notificationStorage = jest.mocked({
open: jest.fn(),
save: jest.fn(),
delete: jest.fn(),
Expand All @@ -13,7 +13,7 @@ const basicStorage = jest.mocked({
return {
id,
createdAt: "2024-04-29T11:01:04.903Z",
content: {
a: {
d: "saidForUuid",
},
};
Expand Down Expand Up @@ -133,11 +133,8 @@ const signifyClient = jest.mocked({
const eventService = new EventService();

const agentServicesProps = {
basicStorage: basicStorage as any,
signifyClient: signifyClient as any,
eventService,
identifierStorage: identifierStorage as any,
credentialStorage: credentialStorage as any,
};

jest.mock("../../../core/agent/agent", () => ({
Expand All @@ -151,7 +148,10 @@ jest.mock("../../../core/agent/agent", () => ({
}));

const ipexCommunicationService = new IpexCommunicationService(
agentServicesProps
agentServicesProps,
identifierStorage as any,
credentialStorage as any,
notificationStorage as any
);

describe("Ipex communication service of agent", () => {
Expand All @@ -176,7 +176,7 @@ describe("Ipex communication service of agent", () => {
id: "id",
status: CredentialStatus.CONFIRMED,
});
expect(basicStorage.deleteById).toBeCalledWith(id);
expect(notificationStorage.deleteById).toBeCalledWith(id);
});

test("cannot accept ACDC if the notification is missing in the DB", async () => {
Expand All @@ -190,10 +190,10 @@ describe("Ipex communication service of agent", () => {
test("cannot accept ACDC if identifier is not locally stored", async () => {
// @TODO - foconnor: Ensure syncing process resovles this edge case of identifier in cloud but not local prior to release.
const id = "uuid";
basicStorage.findById = jest.fn().mockResolvedValue({
notificationStorage.findById = jest.fn().mockResolvedValue({
id,
createdAt: "2024-04-29T11:01:04.903Z",
content: {
a: {
d: "saidForUuid",
},
});
Expand All @@ -205,7 +205,7 @@ describe("Ipex communication service of agent", () => {
);
expect(credentialStorage.saveCredentialMetadataRecord).toBeCalled();
expect(credentialStorage.updateCredentialMetadata).not.toBeCalled();
expect(basicStorage.deleteById).not.toBeCalled();
expect(notificationStorage.deleteById).not.toBeCalled();
});

// This test should go when this has been made event driven.
Expand Down
2 changes: 1 addition & 1 deletion src/core/agent/services/ipexCommunicationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class IpexCommunicationService extends AgentService {

protected readonly identifierStorage: IdentifierStorage;
protected readonly credentialStorage: CredentialStorage;
protected readonly notificationStorage!: NotificationStorage;
protected readonly notificationStorage: NotificationStorage;

constructor(
agentServiceProps: AgentServicesProps,
Expand Down
38 changes: 19 additions & 19 deletions src/core/agent/services/multiSigService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { ConnectionStatus, NotificationRoute } from "../agent.types";
import { Agent } from "../agent";
import { EventService } from "./eventService";
import { MultiSigService } from "./multiSigService";
import { RecordType } from "../../storage/storage.types";

const basicStorage = jest.mocked({
const notificationStorage = jest.mocked({
open: jest.fn(),
save: jest.fn(),
delete: jest.fn(),
Expand Down Expand Up @@ -101,14 +100,15 @@ const identifierStorage = jest.mocked({
});

const agentServicesProps = {
basicStorage: basicStorage as any,
signifyClient: signifyClient as any,
eventService: new EventService(),
identifierStorage: identifierStorage as any,
credentialStorage: {} as any,
};

const multiSigService = new MultiSigService(agentServicesProps);
const multiSigService = new MultiSigService(
agentServicesProps,
identifierStorage as any,
notificationStorage as any
);

let mockResolveOobi = jest.fn();
let mockGetIdentifiers = jest.fn();
Expand Down Expand Up @@ -346,7 +346,7 @@ describe("Multisig sig service of agent", () => {

test("can join the multisig inception", async () => {
const multisigIdentifier = "newMultisigIdentifierAid";
basicStorage.findById = jest.fn().mockResolvedValue({
notificationStorage.findById = jest.fn().mockResolvedValue({
content: {
d: "d",
},
Expand Down Expand Up @@ -618,7 +618,7 @@ describe("Multisig sig service of agent", () => {
identifierStorage.getIdentifierMetadata = jest
.fn()
.mockResolvedValue(metadata);
basicStorage.findById = jest.fn().mockResolvedValue({
notificationStorage.findById = jest.fn().mockResolvedValue({
content: {
d: "d",
},
Expand Down Expand Up @@ -662,7 +662,7 @@ describe("Multisig sig service of agent", () => {
identifierStorage.getIdentifierMetadata = jest
.fn()
.mockResolvedValue(metadata);
basicStorage.findById = jest.fn().mockResolvedValue({
notificationStorage.findById = jest.fn().mockResolvedValue({
content: {
d: "d",
},
Expand Down Expand Up @@ -1021,38 +1021,38 @@ describe("Multisig sig service of agent", () => {
});

test("Can get unhandled Multisig Identifier notifications", async () => {
const basicRecord = {
const notificationRecord = {
_tags: {
isDismiss: true,
type: RecordType.KERIA_NOTIFICATION,
route: NotificationRoute.MultiSigIcp,
},
id: "AIeGgKkS23FDK4mxpfodpbWhTydFz2tdM64DER6EdgG-",
createdAt: new Date(),
content: {
a: {
r: NotificationRoute.MultiSigIcp,
d: "EF6Nmxz8hs0oVc4loyh2J5Sq9H3Z7apQVqjO6e4chtsp",
},
};
basicStorage.findAllByQuery = jest.fn().mockResolvedValue([basicRecord]);
notificationStorage.findAllByQuery = jest
.fn()
.mockResolvedValue([notificationRecord]);
expect(
await multiSigService.getUnhandledMultisigIdentifiers()
).toStrictEqual([
{
id: basicRecord.id,
createdAt: basicRecord.createdAt,
a: basicRecord.content,
id: notificationRecord.id,
createdAt: notificationRecord.createdAt,
a: notificationRecord.a,
},
]);
});

test("Should pass the filter throught findAllByQuery when call getUnhandledMultisigIdentifiers", async () => {
basicStorage.findAllByQuery = jest.fn().mockResolvedValue([]);
notificationStorage.findAllByQuery = jest.fn().mockResolvedValue([]);
await multiSigService.getUnhandledMultisigIdentifiers({
isDismissed: false,
});
expect(basicStorage.findAllByQuery).toBeCalledWith({
type: RecordType.KERIA_NOTIFICATION,
expect(notificationStorage.findAllByQuery).toBeCalledWith({
route: NotificationRoute.MultiSigIcp,
isDismissed: false,
$or: [
Expand Down
1 change: 0 additions & 1 deletion src/core/storage/ionicStorage/ionicStorage.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IonicStorage } from "./ionicStorage";
import { RecordType } from "../storage.types";
import { BasicRecord } from "../../agent/records";

const startTime = new Date();
Expand Down
3 changes: 1 addition & 2 deletions src/core/storage/sqliteStorage/sqliteStorage.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { SqliteStorage } from "./sqliteStorage";
import { convertDbQuery } from "./utils";
import { RecordType, StorageRecord } from "../storage.types";
import { StorageRecord } from "../storage.types";
import { BasicRecord } from "../../agent/records";
import { SqliteSession } from "./sqliteSession";

const startTime = new Date();

Expand Down
4 changes: 0 additions & 4 deletions src/ui/pages/CreatePassword/CreatePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { ScrollablePageLayout } from "../../components/layout/ScrollablePageLayo
import { PageFooter } from "../../components/PageFooter";
import { passwordStrengthChecker } from "../../utils/passwordStrengthChecker";
import { PasswordValidation } from "../../components/PasswordValidation";
import { RecordType } from "../../../core/storage/storage.types";
import { useAppIonRouter } from "../../hooks";

const CreatePassword = () => {
Expand Down Expand Up @@ -68,9 +67,6 @@ const CreatePassword = () => {
await Agent.agent.basicStorage.save({
id: MiscRecordId.OP_PASS_HINT,
content: { value: hintValue },
tags: {
type: RecordType.OP_PASS_HINT,
},
});
}
}
Expand Down

0 comments on commit 4b68285

Please sign in to comment.