Skip to content

Commit

Permalink
refactor: remove some unused stuffs and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-sotatek committed May 8, 2024
1 parent a57559d commit cea2a1f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 43 deletions.
2 changes: 1 addition & 1 deletion services/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
container_name: idw-keria
restart: unless-stopped
build:
context: github:cardano-foundation/signify-ts#c1422b041d2ff53b3d4456a29443722b95f35fb5
context: github.com/WebOfTrust/keria#da8e53fe92b9027ec5b547c00d4f54f278fbb1b2
dockerfile: ./images/keria.dockerfile
environment:
- KERI_AGENT_CORS=true
Expand Down
24 changes: 17 additions & 7 deletions src/core/agent/services/ipexCommunicationService.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventService } from "./eventService";
import { IpexCommunicationService } from "./ipexCommunicationService";
import { CredentialStatus } from "./credentialService.types";
import { IdentifierStorage } from "../records";

const notificationStorage = jest.mocked({
open: jest.fn(),
Expand Down Expand Up @@ -43,7 +44,7 @@ const credentialStorage = jest.mocked({

let credentialListMock = jest.fn();
let credentialGetMock = jest.fn();
let identifierListMock = jest.fn();
const identifierListMock = jest.fn();
let getExchangeMock = jest.fn().mockImplementation((id: string) => {
if (id == "saidForUuid") {
return {
Expand Down Expand Up @@ -329,11 +330,14 @@ describe("Ipex communication service of agent", () => {
credentialListMock = jest.fn().mockReturnValue([{}]);
identifierStorage.getIdentifierMetadata = jest
.fn()
.mockRejectedValue(new Error());
identifierListMock = jest.fn().mockReturnValue({ aids: [] });
.mockRejectedValue(
new Error(IdentifierStorage.IDENTIFIER_METADATA_RECORD_MISSING)
);
await expect(
ipexCommunicationService.offerAcdc(id, "credId")
).rejects.toThrowError(IpexCommunicationService.AID_NOT_FOUND);
).rejects.toThrowError(
IdentifierStorage.IDENTIFIER_METADATA_RECORD_MISSING
);
});

test("can grant Keri Acdc when received the ipex agree", async () => {
Expand Down Expand Up @@ -408,11 +412,17 @@ describe("Ipex communication service of agent", () => {
},
});
credentialListMock = jest.fn().mockReturnValue({ acdc: {} });
identifierStorage.getIdentifierMetadata = jest.fn().mockReturnValue(null);
identifierListMock = jest.fn().mockReturnValue({ aids: [] });
identifierStorage.getIdentifierMetadata =
identifierStorage.getIdentifierMetadata = jest
.fn()
.mockRejectedValue(
new Error(IdentifierStorage.IDENTIFIER_METADATA_RECORD_MISSING)
);
await expect(
ipexCommunicationService.grantApplyAcdc(id)
).rejects.toThrowError(IpexCommunicationService.AID_NOT_FOUND);
).rejects.toThrowError(
IdentifierStorage.IDENTIFIER_METADATA_RECORD_MISSING
);
});

test("can not grant Keri Acdc if acdc is not existed", async () => {
Expand Down
41 changes: 6 additions & 35 deletions src/core/agent/services/ipexCommunicationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class IpexCommunicationService extends AgentService {
static readonly CREDENTIAL_NOT_FOUND_WITH_SCHEMA =
"Credential not found with this schema";

static readonly AID_NOT_FOUND = "Aid not found";
static readonly CREDENTIAL_NOT_FOUND = "Credential not found";

static readonly CREDENTIAL_SERVER =
Expand Down Expand Up @@ -114,19 +113,10 @@ class IpexCommunicationService extends AgentService {
const keriNoti = await this.getNotificationRecordById(notificationId);
const msgSaid = keriNoti.a.d as string;
const msg = await this.signifyClient.exchanges().get(msgSaid);
let holderSignifyName;
try {
holderSignifyName = (
await this.identifierStorage.getIdentifierMetadata(msg.exn.a.i)
).signifyName;
} catch (error) {
const identifierHolder = await this.getIdentifierById(msg.exn.a.i);
holderSignifyName = identifierHolder?.name;
}

if (!holderSignifyName) {
throw new Error(IpexCommunicationService.AID_NOT_FOUND);
}
const holderSignifyName = (
await this.identifierStorage.getIdentifierMetadata(msg.exn.a.i)
).signifyName;

const [offer, sigs, gend] = await this.signifyClient.ipex().offer({
senderName: holderSignifyName,
Expand All @@ -151,18 +141,9 @@ class IpexCommunicationService extends AgentService {
if (!pickedCred) {
throw new Error(IpexCommunicationService.CREDENTIAL_NOT_FOUND);
}
let holderSignifyName;
try {
holderSignifyName = (
await this.identifierStorage.getIdentifierMetadata(exnMessage.i)
).signifyName;
} catch (error) {
const identifierHolder = await this.getIdentifierById(msg.exn.a.i);
holderSignifyName = identifierHolder?.name;
}
if (!holderSignifyName) {
throw new Error(IpexCommunicationService.AID_NOT_FOUND);
}
const holderSignifyName = (
await this.identifierStorage.getIdentifierMetadata(exnMessage.i)
).signifyName;

const [offer, sigs, gend] = await this.signifyClient.ipex().grant({
senderName: holderSignifyName,
Expand Down Expand Up @@ -328,16 +309,6 @@ class IpexCommunicationService extends AgentService {
};
}
}

private async getIdentifierById(
id: string
): Promise<IdentifierResult | undefined> {
const allIdentifiers = await this.signifyClient.identifiers().list();
const identifier = allIdentifiers.aids.find(
(identifier: IdentifierResult) => identifier.prefix === id
);
return identifier;
}
}

export { IpexCommunicationService };

0 comments on commit cea2a1f

Please sign in to comment.