Skip to content

Commit

Permalink
feat: setup app integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniAkash committed Mar 13, 2024
1 parent 9fd1a9a commit f0f99ee
Show file tree
Hide file tree
Showing 9 changed files with 422 additions and 3,156 deletions.
3,251 changes: 114 additions & 3,137 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"types": "dist/types.d.ts",
"scripts": {
"test": "vitest",
"test:unit": "vitest unit.test",
"test:integration": "vitest run integration.test",
"lint:fix": "eslint . --fix --ignore-path .gitignore",
"lint": "tsc --noEmit --pretty && eslint . --ignore-path .gitignore",
"watch": "parcel watch",
Expand Down
123 changes: 112 additions & 11 deletions src/client/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {
GetDatasetRequest,
GetModelRequest,
GetWorkflowRequest,
ListConceptsRequest,
ListDatasetsRequest,
ListInstalledModuleVersionsRequest,
Expand All @@ -8,6 +11,10 @@ import {
MultiDatasetResponse,
PostDatasetsRequest,
PostModelsRequest,
SingleModelResponse,
SingleWorkflowResponse,
SingleDatasetResponse,
PostModulesRequest,
} from "clarifai-nodejs-grpc/proto/clarifai/api/service_pb";
import { UserError } from "../errors";
import { ClarifaiUrlHelper } from "../urls/helper";
Expand Down Expand Up @@ -85,7 +92,7 @@ export class App extends Lister {
onlyInApp?: boolean;
pageNo?: number;
perPage?: number;
}): AsyncGenerator<Model.AsObject[], void, unknown> {
} = {}): AsyncGenerator<Model.AsObject[], void, unknown> {
const listModels = promisifyGrpcCall(
this.STUB.client.listModels,
this.STUB.client,
Expand Down Expand Up @@ -129,7 +136,7 @@ export class App extends Lister {
onlyInApp?: boolean;
pageNo?: number;
perPage?: number;
}): AsyncGenerator<Workflow.AsObject[], void, unknown> {
} = {}): AsyncGenerator<Workflow.AsObject[], void, unknown> {
const request = new ListWorkflowsRequest();
mapParamsToRequest(params, request);

Expand Down Expand Up @@ -168,7 +175,7 @@ export class App extends Lister {
onlyInApp?: boolean;
pageNo?: number;
perPage?: number;
}): AsyncGenerator<Module.AsObject[], void, unknown> {
} = {}): AsyncGenerator<Module.AsObject[], void, unknown> {
const listModules = promisifyGrpcCall(
this.STUB.client.listModules,
this.STUB.client,
Expand Down Expand Up @@ -259,10 +266,13 @@ export class App extends Lister {
return TRAINABLE_MODEL_TYPES;
}

async createDataset(
datasetId: string,
params: Omit<Partial<Dataset.AsObject>, "id">,
): Promise<Dataset.AsObject> {
async createDataset({
datasetId,
params = {},
}: {
datasetId: string;
params?: Omit<Partial<Dataset.AsObject>, "id">;
}): Promise<Dataset.AsObject> {
const request = new PostDatasetsRequest();
request.setUserAppId(this.userAppId);

Expand All @@ -289,10 +299,13 @@ export class App extends Lister {
return responseObject.datasetsList?.[0];
}

async createModel(
modelId: string,
params: Omit<Partial<Model.AsObject>, "id">,
): Promise<Model.AsObject> {
async createModel({
modelId,
params = {},
}: {
modelId: string;
params?: Omit<Partial<Model.AsObject>, "id">;
}): Promise<Model.AsObject> {
const request = new PostModelsRequest();
request.setUserAppId(this.userAppId);
const newModel = new Model();
Expand All @@ -314,4 +327,92 @@ export class App extends Lister {
console.info("\nModel created\n%s", responseObject.status.description);
return responseObject.model;
}

async createModule({
moduleId,
description,
}: {
moduleId: string;
description: string;
}): Promise<Module.AsObject> {
const request = new PostModulesRequest();
request.setUserAppId(this.userAppId);
const newModule = new Module();
newModule.setId(moduleId);
newModule.setDescription(description);
request.setModulesList([newModule]);
const postModules = promisifyGrpcCall(
this.STUB.client.postModules,
this.STUB.client,
);
const response = await this.grpcRequest(postModules, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
console.info("\nModule created\n%s", responseObject.status.description);
return responseObject.modulesList?.[0];
}

async model({
modelId,
modelVersionId,
}: {
modelId: string;
modelVersionId: string;
}): Promise<SingleModelResponse.AsObject["model"]> {
const request = new GetModelRequest();
request.setUserAppId(this.userAppId);
request.setModelId(modelId);
request.setVersionId(modelVersionId);

const getModel = promisifyGrpcCall(
this.STUB.client.getModel,
this.STUB.client,
);

const response = await this.grpcRequest(getModel, request);
const responseObject = response.toObject();
return responseObject.model;
}

async workflow({
workflowId,
}: {
workflowId: string;
}): Promise<SingleWorkflowResponse.AsObject["workflow"]> {
const request = new GetWorkflowRequest();
request.setUserAppId(this.userAppId);
request.setWorkflowId(workflowId);
const getWorkflow = promisifyGrpcCall(
this.STUB.client.getWorkflow,
this.STUB.client,
);
const response = await this.grpcRequest(getWorkflow, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
return responseObject.workflow;
}

async dataset({
datasetId,
}: {
datasetId: string;
}): Promise<SingleDatasetResponse.AsObject["dataset"]> {
const request = new GetDatasetRequest();
request.setUserAppId(this.userAppId);
request.setDatasetId(datasetId);
const getDataset = promisifyGrpcCall(
this.STUB.client.getDataset,
this.STUB.client,
);
const response = await this.grpcRequest(getDataset, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
return responseObject.dataset;
}
}
18 changes: 11 additions & 7 deletions src/client/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export class User extends Lister {
params?: PaginationRequestParams<ListAppsRequest.AsObject>;
pageNo?: number;
perPage?: number;
}): AsyncGenerator<MultiAppResponse.AsObject, void, unknown> {
} = {}): AsyncGenerator<
MultiAppResponse.AsObject["appsList"],
void,
unknown
> {
const listApps = promisifyGrpcCall(
this.STUB.client.listApps,
this.STUB.client,
Expand All @@ -91,7 +95,7 @@ export class User extends Lister {
pageNo,
perPage,
)) {
yield item.toObject();
yield item.toObject()?.appsList;
}
}

Expand Down Expand Up @@ -168,8 +172,8 @@ export class User extends Lister {
baseWorkflow = "Empty",
}: {
appId: string;
baseWorkflow: string;
}): Promise<MultiAppResponse.AsObject> {
baseWorkflow?: string;
}): Promise<App.AsObject> {
const workflow = new Workflow();
workflow.setId(baseWorkflow);
workflow.setAppId("main");
Expand Down Expand Up @@ -198,7 +202,7 @@ export class User extends Lister {
);
}

return responseObject;
return responseObject.appsList?.[0];
}

/**
Expand Down Expand Up @@ -228,7 +232,7 @@ export class User extends Lister {
runnerId: string;
labels: string[];
description: string;
}): Promise<MultiRunnerResponse.AsObject> {
}): Promise<MultiRunnerResponse.AsObject["runnersList"][0]> {
if (!Array.isArray(labels)) {
throw new Error("Labels must be an array of strings");
}
Expand All @@ -254,7 +258,7 @@ export class User extends Lister {
}
console.info("\nRunner created\n%s", responseObject.status.description);

return responseObject;
return responseObject.runnersList?.[0];
}

/**
Expand Down
Loading

0 comments on commit f0f99ee

Please sign in to comment.