From a345def664799697849641f697e6dbd9c8d18310 Mon Sep 17 00:00:00 2001 From: Juni Date: Mon, 6 May 2024 11:12:24 -0500 Subject: [PATCH] fix: Add URI generation method in HandlerAgent class A new method, 'generateURIFromCreateMessage', was added to the HandlerAgent class for URI generation from CreateMessage. A corresponding test for this functionality was also written and added to 'HandlerAgentUtils.test.ts'. --- src/agent/HandlerAgent.ts | 7 ++++ tests/agent/HandlerAgentUtils.test.ts | 48 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/agent/HandlerAgentUtils.test.ts diff --git a/src/agent/HandlerAgent.ts b/src/agent/HandlerAgent.ts index 83fde1b..4877495 100644 --- a/src/agent/HandlerAgent.ts +++ b/src/agent/HandlerAgent.ts @@ -265,6 +265,13 @@ export class HandlerAgent { return message.did === this.getDid; //TODO Test } + /** + * + */ + generateURIFromCreateMessage(message: CreateSkeetMessage){ + return `at://${message.did}/app.bsky.feed.post/${message.rkey}` + } + /** * */ diff --git a/tests/agent/HandlerAgentUtils.test.ts b/tests/agent/HandlerAgentUtils.test.ts new file mode 100644 index 0000000..95586ab --- /dev/null +++ b/tests/agent/HandlerAgentUtils.test.ts @@ -0,0 +1,48 @@ +import { CreateSkeetMessage, HandlerAgent } from "../../src"; +import { AtpSessionData, BskyAgent } from "@atproto/api"; +import dotenv from "dotenv"; + +dotenv.config(); + +jest.mock("@atproto/api", () => jest.genMockFromModule("@atproto/api")); + +describe("HandlerAgent", () => { + let handlerAgent: HandlerAgent; + const testHandle: string = "testhandle"; + const testPassword: string = "testpassword"; + let mockedAgent: BskyAgent; + beforeEach(() => { + mockedAgent = { + session: { + did: "did:plc:2bnsooklzchcu5ao7xdjosrs", + } as AtpSessionData, + } as BskyAgent; + handlerAgent = new HandlerAgent( + "agentName", + testHandle, + testPassword, + mockedAgent, + ); + }); + + it("generateURIFromCreateMessage creates expected uri", () => { + const message: CreateSkeetMessage = { + cid: "", + collection: "", + opType: "c", + record: { + $type: "", + createdAt: "", + subject: "" + }, + seq: 0, + did: 'did:example:12345', + rkey: 'feed1' + // other necessary fields... + }; + const result = handlerAgent.generateURIFromCreateMessage(message); + + expect(result).toEqual('at://did:example:12345/app.bsky.feed.post/feed1'); + }); + +});