Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): resolve linting issues in test files #1210

Closed
1,867 changes: 1,796 additions & 71 deletions js/src/sdk/base.toolset.spec.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/src/sdk/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
BASE_ERROR_CODE_INFO,
COMPOSIO_SDK_ERROR_CODES,
} from "./utils/errors/src/constants";
const { COMPOSIO_API_KEY, BACKEND_HERMES_URL } = getTestConfig();
const { COMPOSIO_API_KEY, _BACKEND_HERMES_URL } = getTestConfig();

describe("Basic SDK spec suite", () => {
const mock = new AxiosMockAdapter(axiosClient.instance);
Expand Down
10 changes: 5 additions & 5 deletions js/src/sdk/models/Entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ describe("Entity class tests", () => {
});

it("should have an Id of a connected account with label - primary", async () => {
const entityW2Connection = new Entity(backendClient, "ckemvy");
const _entityW2Connection = new Entity(backendClient, "ckemvy");

const entity = new Entity(backendClient, "ckemvy");
const _entity = new Entity(backendClient, "ckemvy");

// Remove test with normal app where reinitiate connection is not needed
// await entity.initiateConnection({
Expand All @@ -78,11 +78,11 @@ describe("Entity class tests", () => {
});

it("should have an Id of a connected account with default - primary", async () => {
const entityW2Connection = new Entity(backendClient, "default");
const _entityW2Connection = new Entity(backendClient, "default");

const entity = new Entity(backendClient, "default");
const _entity = new Entity(backendClient, "default");

const getConnection = await entity.getConnection({
const getConnection = await _entity.getConnection({
app: "github",
});
expect(getConnection).toHaveProperty("id");
Expand Down
10 changes: 5 additions & 5 deletions js/src/sdk/models/connectedAccounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ describe("ConnectedAccounts class tests", () => {

it("should create a ConnectedAccounts instance and retrieve connections list", async () => {
// @ts-ignore
const connectionsData: TConnectionData = {
const _connectionsData: TConnectionData = {
appNames: "github",
};
const connectionsList = await connectedAccounts.list(connectionsData);
const connectionsList = await connectedAccounts.list(_connectionsData);
expect(connectionsList.items).toBeInstanceOf(Array);
expect(connectionsList.items).not.toHaveLength(0);

Expand All @@ -30,7 +30,7 @@ describe("ConnectedAccounts class tests", () => {

it("should retrieve a specific connection", async () => {
// @ts-ignore
const connectionsData: TConnectionData = {
const _connectionsData: TConnectionData = {
appNames: "github",
};
const connectionsList = await connectedAccounts.list({
Expand All @@ -48,10 +48,10 @@ describe("ConnectedAccounts class tests", () => {

it("should retrieve a specific connection for entity", async () => {
// @ts-ignore
const connectionsData: TConnectionData = {
const _connectionsData: TConnectionData = {
user_uuid: "default",
};
const connectionsList = await connectedAccounts.list(connectionsData);
const connectionsList = await connectedAccounts.list(_connectionsData);

const connectionId = connectionsList.items[0].id;

Expand Down
4 changes: 2 additions & 2 deletions js/src/sdk/models/connectedAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class ConnectedAccounts {
});
try {
ZSingleConnectionParams.parse(data);
const res = await apiClient.connections.disableConnection({
await apiClient.connections.disableConnection({
path: data,
throwOnError: true,
});
Expand Down Expand Up @@ -332,7 +332,7 @@ export class ConnectionRequest {
.getConnection({
path: { connectedAccountId: this.connectedAccountId },
})
.then((res) => res.data);
.then((response: { data: unknown }) => response.data);
if (!connection) throw new Error("Connected account not found");
if (connection.status === "ACTIVE") {
return connection;
Expand Down
89 changes: 89 additions & 0 deletions js/src/sdk/tests/base.toolset.actions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// @ts-ignore - Jest globals are provided by the test environment
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import { getTestConfig } from "../../../config/getTestConfig";
import { ComposioToolSet } from "../base.toolset";

describe("ComposioToolSet - Actions Schema", () => {
let toolset: ComposioToolSet;
const testConfig = getTestConfig();

beforeEach(() => {
toolset = new ComposioToolSet({
apiKey: testConfig.COMPOSIO_API_KEY,
baseUrl: testConfig.BACKEND_HERMES_URL,
runtime: "composio-ai",
});
});

it("should get actions with valid action names", async () => {
const tools = await toolset.getActionsSchema({
actions: ["github_issues_create"],
});
expect(tools).toBeInstanceOf(Array);
expect(tools.length).toBeGreaterThan(0);
expect(tools[0].name).toBe("github_issues_create");
});

it("should handle empty filters", async () => {
const tools = await toolset.getActionsSchema();
expect(tools).toBeInstanceOf(Array);
});

it("should handle non-existent action names", async () => {
const tools = await toolset.getActionsSchema({
actions: ["non_existent_action"],
});
expect(tools).toBeInstanceOf(Array);
expect(tools).toHaveLength(0);
});

it("should handle mixed valid/invalid action names", async () => {
const tools = await toolset.getActionsSchema({
actions: ["github_issues_create", "non_existent_action"],
});
expect(tools).toBeInstanceOf(Array);
expect(tools.length).toBe(1);
expect(tools[0].name).toBe("github_issues_create");
});

it("should get actions with custom entity ID", async () => {
const customEntityId = "custom-entity";
const tools = await toolset.getActionsSchema({
actions: ["github_issues_create"],
}, customEntityId);
expect(tools).toBeInstanceOf(Array);
expect(tools.length).toBeGreaterThan(0);
});

it("should handle API errors gracefully", async () => {
const invalidToolset = new ComposioToolSet({
apiKey: "invalid-api-key",
baseUrl: testConfig.BACKEND_HERMES_URL,
});

await expect(invalidToolset.getActionsSchema({
actions: ["github_issues_create"],
})).rejects.toThrow();
});

it("should pass filters correctly to getToolsSchema", async () => {
const spy = jest.spyOn(toolset, 'getToolsSchema');
const actions = ["github_issues_create"];

await toolset.getActionsSchema({ actions });

expect(spy).toHaveBeenCalledWith({ actions }, undefined);
spy.mockRestore();
});

it("should handle undefined filters", async () => {
const tools = await toolset.getActionsSchema(undefined);
expect(tools).toBeInstanceOf(Array);
});

it("should handle null filters", async () => {
// @ts-ignore - Testing invalid input
const tools = await toolset.getActionsSchema(null);
expect(tools).toBeInstanceOf(Array);
});
});
101 changes: 101 additions & 0 deletions js/src/sdk/tests/base.toolset.constructor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// @ts-ignore - Jest globals are provided by the test environment
import { beforeEach, describe, expect, it } from "@jest/globals";
import { getTestConfig } from "../../../config/getTestConfig";
import { ComposioToolSet } from "../base.toolset";
import {
fileInputProcessor,
fileResponseProcessor,
fileSchemaProcessor,
} from "../utils/processor/file";

describe("ComposioToolSet - Constructor", () => {
let toolset: ComposioToolSet;
const testConfig = getTestConfig();

beforeEach(() => {
process.env.COMPOSIO_API_KEY = undefined;
});

it("should create instance with valid API key and base URL", async () => {
toolset = new ComposioToolSet({
apiKey: testConfig.COMPOSIO_API_KEY,
baseUrl: testConfig.BACKEND_HERMES_URL,
runtime: "composio-ai",
entityId: "default",
});

expect(toolset.apiKey).toBe(testConfig.COMPOSIO_API_KEY);
expect(toolset.runtime).toBe("composio-ai");
expect(toolset.entityId).toBe("default");
expect(toolset.client).toBeDefined();

const tools = await toolset.getToolsSchema({ apps: ["github"] });
expect(tools).toBeInstanceOf(Array);
expect(tools).not.toHaveLength(0);
});

it("should fall back to environment variable for API key", () => {
const envApiKey = "test-env-api-key";
process.env.COMPOSIO_API_KEY = envApiKey;

toolset = new ComposioToolSet();
expect(toolset.apiKey).toBe(envApiKey);
});

it("should use default entityId when not provided", () => {
toolset = new ComposioToolSet({
apiKey: testConfig.COMPOSIO_API_KEY,
});
expect(toolset.entityId).toBe("default");
});

it("should initialize with custom entityId", () => {
const customEntityId = "custom-entity";
toolset = new ComposioToolSet({
apiKey: testConfig.COMPOSIO_API_KEY,
entityId: customEntityId,
});
expect(toolset.entityId).toBe(customEntityId);
});

it("should initialize with different runtime values", () => {
const customRuntime = "custom-runtime";
toolset = new ComposioToolSet({
apiKey: testConfig.COMPOSIO_API_KEY,
runtime: customRuntime,
});
expect(toolset.runtime).toBe(customRuntime);
});

it("should initialize internal processors", () => {
toolset = new ComposioToolSet({
apiKey: testConfig.COMPOSIO_API_KEY,
});

// @ts-expect-error - accessing private property for testing
expect(toolset.internalProcessors.pre).toContain(fileInputProcessor);
// @ts-expect-error - accessing private property for testing
expect(toolset.internalProcessors.post).toContain(fileResponseProcessor);
// @ts-expect-error - accessing private property for testing
expect(toolset.internalProcessors.schema).toContain(fileSchemaProcessor);
});

it("should throw error when no API key is provided", () => {
expect(() => new ComposioToolSet()).toThrow();
});

it("should initialize all client properties", () => {
toolset = new ComposioToolSet({
apiKey: testConfig.COMPOSIO_API_KEY,
});

expect(toolset.backendClient).toBeDefined();
expect(toolset.connectedAccounts).toBeDefined();
expect(toolset.apps).toBeDefined();
expect(toolset.actions).toBeDefined();
expect(toolset.triggers).toBeDefined();
expect(toolset.integrations).toBeDefined();
expect(toolset.activeTriggers).toBeDefined();
expect(toolset.userActionRegistry).toBeDefined();
});
});
Loading
Loading