Skip to content

Commit

Permalink
add generic provider test
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 25, 2024
1 parent 9853678 commit f775394
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/lib/__tests__/providers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { type UUID } from "crypto";
import dotenv from "dotenv";
import { createRuntime } from "../../test/createRuntime";
import { BgentRuntime } from "../runtime";
import { type Message, type Provider, type State } from "../types";

dotenv.config({ path: ".dev.vars" });

const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID;

// Define a generic TestProvider that always provides "Hello Test"
const TestProvider: Provider = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
get: async (_runtime: BgentRuntime, _message: Message, _state?: State) => {
return "Hello Test";
},
};

describe("TestProvider", () => {
let runtime: BgentRuntime;
let room_id: UUID;

beforeAll(async () => {
const setup = await createRuntime({
env: process.env as Record<string, string>,
providers: [TestProvider], // Add TestProvider to the runtime
});
runtime = setup.runtime;
room_id = "some-room-id" as UUID; // Assume room_id is fetched or set up in your environment
});

test("TestProvider should return 'Hello Test'", async () => {
const message: Message = {
senderId: zeroUuid,
agentId: zeroUuid,
userIds: [zeroUuid, zeroUuid],
content: { content: "" },
room_id: room_id,
};

const testProviderResponse = await TestProvider.get(
runtime,
message,
{} as State,
);
expect(testProviderResponse).toBe("Hello Test");
});

test("TestProvider should be integrated in the runtime providers", async () => {
expect(runtime.providers).toContain(TestProvider);
});
});

0 comments on commit f775394

Please sign in to comment.