Skip to content

new api #38

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@octomind/octomind",
"version": "1.0.4",
"version": "1.0.5",
"description": "a command line client for octomind apis",
"main": "./dist/index.js",
"packageManager": "[email protected]+sha512.139cab068fdf0b751268179ac5f909b5be72afb4a75c513d1905d151befc8977b593d3cf8671ed83d4d6637c5c94b98ffbce108125de4a5a27a31233601a99de",
Expand Down
136 changes: 136 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import {
SuccessResponse,
Environment,
TestReport,
GetNotificationsOptions,
Notification,
GetTestCaseOptions,
TestCase,
CreateDiscoveryOptions,
DiscoveryResponse,
} from "./types";

const BASE_URL = "https://app.octomind.dev/api";
Expand Down Expand Up @@ -354,3 +360,133 @@ export const deleteEnvironment = async (

console.log("Environment deleted successfully!");
};

export const getNotifications = async (
options: GetNotificationsOptions,
): Promise<void> => {
if (!options.apiKey) {
console.error("API key is required");
process.exit(1);
}

const response = await apiCall<Notification[]>(
"get",
`/apiKey/v2/test-targets/${options.testTargetId}/notifications`,
options.apiKey,
);

if (options.json) {
outputResult(response);
return;
}

console.log("Notifications:");
response.forEach((notification) => {
console.log(`\nID: ${notification.id}`);
console.log(`Type: ${notification.type}`);
console.log(`Created At: ${notification.createdAt}`);
if (notification.payload.testReportId) {
console.log(`Test Report ID: ${notification.payload.testReportId}`);
}
if (notification.payload.testCaseId) {
console.log(`Test Case ID: ${notification.payload.testCaseId}`);
}
if (notification.payload.failed !== undefined) {
console.log(`Failed: ${notification.payload.failed}`);
}
if (notification.ack) {
console.log(`Acknowledged: ${notification.ack}`);
}
});
};

export const getTestCase = async (
options: GetTestCaseOptions,
): Promise<void> => {
if (!options.apiKey) {
console.error("API key is required");
process.exit(1);
}

const response = await apiCall<TestCase>(
"get",
`/apiKey/v2/test-targets/${options.testTargetId}/test-cases/${options.testCaseId}`,
options.apiKey,
);

if (options.json) {
outputResult(response);
return;
}

console.log("Test Case Details:");
console.log(`ID: ${response.id}`);
console.log(`Description: ${response.description}`);
console.log(`Status: ${response.status}`);
console.log(`Run Status: ${response.runStatus}`);
console.log(`Created At: ${response.createdAt}`);
console.log(`Updated At: ${response.updatedAt}`);

if (response.elements.length > 0) {
console.log("\nElements:");
response.elements.forEach((element, index) => {
console.log(`\nElement ${index + 1}:`);
if (element.interaction) {
console.log(` Action: ${element.interaction.action}`);
if (element.interaction.calledWith) {
console.log(` Called With: ${element.interaction.calledWith}`);
}
}
if (element.assertion) {
console.log(` Expectation: ${element.assertion.expectation}`);
if (element.assertion.calledWith) {
console.log(` Called With: ${element.assertion.calledWith}`);
}
}
console.log(" Selectors:");
element.selectors.forEach((selector) => {
console.log(` - ${selector.selectorType}: ${selector.selector}`);
if (selector.options?.name) {
console.log(` Name: ${selector.options.name}`);
}
});
});
}
};

export const createDiscovery = async (
options: CreateDiscoveryOptions,
): Promise<void> => {
if (!options.apiKey) {
console.error("API key is required");
process.exit(1);
}

const requestBody = {
name: options.name,
prompt: options.prompt,
...(options.entryPointUrlPath && {
entryPointUrlPath: options.entryPointUrlPath,
}),
...(options.prerequisiteId && { prerequisiteId: options.prerequisiteId }),
...(options.externalId && { externalId: options.externalId }),
...(options.assignedTagIds && { assignedTagIds: options.assignedTagIds }),
...(options.folderId && { folderId: options.folderId }),
};

const response = await apiCall<DiscoveryResponse>(
"post",
`/apiKey/v2/test-targets/${options.testTargetId}/discoveries`,
options.apiKey,
requestBody,
);

if (options.json) {
outputResult(response);
return;
}

console.log("Discovery created successfully!");
console.log(`Discovery ID: ${response.discoveryId}`);
console.log(`Test Case ID: ${response.testCaseId}`);
};
31 changes: 31 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
registerLocation,
unregisterLocation,
updateEnvironment,
getNotifications,
getTestCase,
createDiscovery,
} from "./api";

const apiKeyOption = new Option(
Expand Down Expand Up @@ -119,5 +122,33 @@ export const buildCmd = (): Command => {
.requiredOption("-t, --test-target-id <id>", "Test target ID")
.requiredOption("-e, --environment-id <id>", "Environment ID")
.action(deleteEnvironment);

createCommandWithCommonOptions("notifications")
.description("Get notifications for a test target")
.requiredOption("-t, --test-target-id <id>", "Test target ID")
.action(getNotifications);

createCommandWithCommonOptions("test-case")
.description("Get details of a specific test case")
.requiredOption("-t, --test-target-id <id>", "Test target ID")
.requiredOption("-c, --test-case-id <id>", "Test case ID")
.action(getTestCase);

createCommandWithCommonOptions("create-discovery")
.description("Create a new test case discovery")
.requiredOption("-t, --test-target-id <id>", "Test target ID")
.requiredOption("-n, --name <name>", "Discovery name")
.requiredOption("-p, --prompt <prompt>", "Discovery prompt")
.option("-e, --entry-point-url-path <path>", "Entry point URL path")
.option("--prerequisite-id <id>", "Prerequisite test case ID")
.option("--external-id <id>", "External identifier")
.option(
"--assigned-tag-ids <ids>",
"Comma-separated list of tag IDs",
splitter,
)
.option("--folder-id <id>", "Folder ID")
.action(createDiscovery);

return program;
};
152 changes: 152 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,155 @@ export interface DeleteEnvironmentOptions {
environmentId: string;
json?: boolean;
}

export interface Notification {
id: string;
testTargetId: string;
createdAt: string;
updatedAt: string;
payload: {
failed?: boolean;
context?: ExecutionContext;
testReportId?: string;
testCaseId?: string;
};
type: "REPORT_EXECUTION_FINISHED" | "VALIDATION_PASSED";
ack?: "IN_WEB_APP" | null;
}

export interface TestCase {
id: string;
testTargetId: string;
type: string | null;
elements: Array<{
id: string;
index: number;
interaction?: {
id: string;
action:
| "EXTRACT"
| "ENTER_TEXT"
| "CLICK"
| "SELECT_OPTION"
| "TYPE_TEXT"
| "KEY_PRESS"
| "HOVER"
| "UPLOAD"
| "GO_TO"
| "DRAG_AND_DROP"
| "CLOSE_PAGE"
| "OPEN_EMAIL";
calledWith?: string | null;
testCaseElementId: string;
} | null;
assertion?: {
id: string;
expectation:
| "VISIBLE"
| "NOT_VISIBLE"
| "TO_BE_CHECKED"
| "NOT_TO_BE_CHECKED"
| "TO_HAVE_VALUE"
| "TO_CONTAIN_TEXT"
| "TO_HAVE_STYLE";
calledWith?: string | null;
testCaseElementId: string;
} | null;
scrollState: null;
selectors: Array<{
id: string;
index: number;
selector: string;
selectorType: "TEXT" | "LABEL" | "PLACEHOLDER" | "ROLE";
options?: { name?: string } | null;
testCaseElementId: string;
scrollStateId: string | null;
}>;
testCaseId: string;
ignoreFailure: boolean;
}>;
createdAt: string;
updatedAt: string;
description: string;
status: "ENABLED" | "DRAFT";
externalId: string | null;
entryPointUrlPath: string | null;
tags: string[];
createdBy: "EDIT";
runStatus: "ON" | "OFF";
prerequisiteId: string | null;
proposalRunId: string | null;
folderId: string | null;
discovery?: {
id: string;
freePrompt: string;
traceUrl: string | null;
traceJsonManifestUrl: string | null;
status: "OUTDATED";
abortCause: string | null;
message: string | null;
testCaseId: string;
lastJobExecutionName: string | null;
createdAt: string;
updatedAt: string;
executedTestCaseElements: string[];
testCase: {
id: string;
testTargetId: string;
description: string;
createdAt: string;
updatedAt: string;
entryPointUrlPath: string | null;
type: string | null;
status: "ENABLED";
runStatus: "ON";
interactionStatus: "NEW";
createdBy: "EDIT";
proposalRunId: string | null;
externalId: string | null;
folderId: string | null;
prerequisiteId: string | null;
predecessorId: string;
testTarget: {
id: string;
app: string;
createdAt: string;
updatedAt: string;
orgId: string;
testIdAttribute: string | null;
timeoutPerStep: number;
};
};
};
}

export interface GetNotificationsOptions {
apiKey: string;
testTargetId: string;
json?: boolean;
}

export interface GetTestCaseOptions {
apiKey: string;
testTargetId: string;
testCaseId: string;
json?: boolean;
}

export interface CreateDiscoveryOptions {
apiKey: string;
testTargetId: string;
name: string;
prompt: string;
entryPointUrlPath?: string;
prerequisiteId?: string;
externalId?: string;
assignedTagIds?: string[];
folderId?: string;
json?: boolean;
}

export interface DiscoveryResponse {
discoveryId: string;
testCaseId: string;
}
Loading