Skip to content

Commit

Permalink
exporting twitter action and schema and adding twitter tool test
Browse files Browse the repository at this point in the history
  • Loading branch information
stat committed Dec 6, 2024
1 parent eaa71c4 commit 181c2e5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cdp-agentkit-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ export { CdpAction } from "./actions/cdp/cdp_action";
// Export CDP AgentKit
export { CdpAgentkit } from "./cdp_agentkit";

// Export Twitter Action
export { TwitterAction, TwitterActionSchemaAny } from "./actions/cdp/social/twitter/twitter_action";

// Export Twitter AgentKit
export { TwitterAgentkit } from "./twitter_agentkit";
58 changes: 58 additions & 0 deletions twitter-langchain/src/tests/twitter_tool_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
TwitterAction,
TwitterActionSchemaAny,
TwitterAgentkit,
} from "@coinbase/cdp-agentkit-core";
import { TwitterTool } from "../twitter_tool";
import { z } from "zod";

const MOCK_DESCRIPTION = "Twitter Test Action";
const MOCK_NAME = "test_action";

describe("TwitterTool", () => {
let mockAgentkit: jest.Mocked<TwitterAgentkit>;
let mockAction: jest.Mocked<TwitterAction<TwitterActionSchemaAny>>;
let twitterTool: TwitterTool<any>;

Check failure on line 15 in twitter-langchain/src/tests/twitter_tool_test.ts

View workflow job for this annotation

GitHub Actions / lint-twitter-langchain

Unexpected any. Specify a different type

beforeEach(() => {
mockAgentkit = {
run: jest.fn((action, args) => action.func(mockAgentkit, args)),
} as unknown as jest.Mocked<TwitterAgentkit>;

mockAction = {
name: MOCK_NAME,
description: MOCK_DESCRIPTION,
argsSchema: z.object({ test_param: z.string() }),
func: jest.fn().mockResolvedValue("success"),
} as unknown as jest.Mocked<TwitterAction<TwitterActionSchemaAny>>;

twitterTool = new TwitterTool(mockAction, mockAgentkit);
});

test("should initialize with correct properties", () => {
expect(twitterTool.name).toBe(MOCK_NAME);
expect(twitterTool.description).toBe(MOCK_DESCRIPTION);
expect(twitterTool.schema).toEqual(mockAction.argsSchema);
});

test("should execute action with valid args", async () => {
const args = { test_param: "test" };
const response = await twitterTool.call(args);

expect(mockAction.func).toHaveBeenCalledWith(mockAgentkit, args);
expect(response).toBe("success");
});

test("should handle schema validation errors", async () => {
const invalidargs = { invalid_param: "test" };
await expect(twitterTool.call(invalidargs)).rejects.toThrow();
expect(mockAction.func).not.toHaveBeenCalled();
});

test("should return error message on action execution failure", async () => {
mockAction.func.mockRejectedValue(new Error("Execution failed"));
const args = { test_param: "test" };
const response = await twitterTool.call(args);
expect(response).toContain("Error executing test_action: Execution failed");
});
});

0 comments on commit 181c2e5

Please sign in to comment.