Skip to content

Commit

Permalink
Merge pull request #34 from juni-b-queer/add-generate-uri
Browse files Browse the repository at this point in the history
fix: Add URI generation method in HandlerAgent class
  • Loading branch information
juni-b-queer authored May 6, 2024
2 parents d883121 + a345def commit 45c850c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/agent/HandlerAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ export class HandlerAgent {
return message.did === this.getDid; //TODO Test

Check warning on line 265 in src/agent/HandlerAgent.ts

View check run for this annotation

Codecov / codecov/patch

src/agent/HandlerAgent.ts#L264-L265

Added lines #L264 - L265 were not covered by tests
}

/**
*
*/
generateURIFromCreateMessage(message: CreateSkeetMessage){
return `at://${message.did}/app.bsky.feed.post/${message.rkey}`
}

/**
*
*/
Expand Down
48 changes: 48 additions & 0 deletions tests/agent/HandlerAgentUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});

});

0 comments on commit 45c850c

Please sign in to comment.