# TestIt SDK

API SDK for TestIt according to [api-doc](https://drive.google.com/file/d/1z2Qf01REKroryIOYGBRZEm5En6PR7zYP/view )



## Installation

- put this dependency in your project package.json

```shell
npm install
# ssh
npm install -verbose git+ssh://git@git.ringcentral.com:coding-now/testit-sdk.git
# https
npm install -verbose git+https://git.ringcentral.com/coding-now/testit-sdk.git
```



## APIs

### Login

```typescript
import TestItSDK from 'testIt-sdk';
const TESTIT_ENDPOINT = 'https://testit.ringcentral.com';
const testItSdk = new TestItSDK(TESTIT_ENDPOINT);
await testItSdk.login('username','password');
```

### Logout

```typescript
testItSdk.logout();
```



### Project API

#### Get all projects

```typescript
const projects = await testItSdk.getProjects();
```

#### Get project by id

```typescript
const project = await testItSdk.getProjectById(projectId); 
```

#### Get project by name

```typescript
const project = await testItSdk.getProjectByName(projectName);
```

#### Get project id by name

```typescript
const projectId = await testItSdk.getProjectIdByName(projectName);
```

#### Get project tree by project id

```typescript
const projectTree = await testIdSdk.getProjectTreeById(projectId);
```



### Test Case API

#### Get test case by id

```typescript
const testCase = await testItSdk.getTestCaseById(caseId);
```

#### Get test case by key

```typescript
const testCase = await testItSdk.getTestCaseByKey(caseKey);
```

#### Get test cases by id array

```typescript
const caseIds = [...];
const testCases = await testItSdk.getTestCasesByIds(caseIds);
```

#### Get test plans by case id

```typescript
const testPlans = await testItSdk.getTestPlansByTestCaseId(caseId);
```

#### Get execution history by case id

```typescript
const executionHistory = await testItSdk.getExecutionHistoryByTestCaseId(caseId);
```



### Test Suite API

#### Get test suite by id

```typescript
const testSuite = await testItSdk.getTestSuiteById(suiteId);
```

#### Get suite tree by id

```typescript
const suiteTree = await testItSdk.getSuiteTreeById(suiteId);
```

### Test Plan API

#### Get test plan by id

```typescript
const testPlan = await testItSdk.getTestPlanById(testPlanId);
```

#### Get test plan tree by id

```typescript
const planTree = await testItSdk.getTreeByTestPlanId(testPlanId);
```

#### Get builds by test plan id

```typescript
const builds = await testItSdk.getBuildsByTestPlanId(testPlanId);
```

#### Get execution progress by plan id

```typescript
const executionProgress = await testItSdk.getExecutionProgressByTestPlanId(testPlanId);
```



### Test Builds API

#### Get build by build id

```typescript
const build = await testItSdk.getBuildById(buildId);
```



### Search API

- Search options include
  - ProjectName
  - Keywords
  - Subtype
  - SuiteName（only the lowest level of suite name）
  - Automated by
  - Priority

#### Search test cases by search options

```typescript
const projectName = "...";
const keywords = ['...','...'];
const subtype = ['...','...'];
const suiteName = '...';
const searchOption : SearchOptions = {
    projectName : projectName,
    subtype : subtype,
    keywords : keywords,
  	suiteName : suiteName,
}
const testCases = await testItSdk.searchCasesBySearchOptions(searchOption);
```

#### Search test cases by suite name

- Because of the insufficient of rich search tools（only the lowest level of suite name）
- Search using any level of suite name

```typescript
const suiteName = '...';
const projectName = '...';
await testItSdk.searchCasesBySuiteName(suiteName,projectName)
```



### Store template info API

#### Store file by case key

```typescript
const caseKey = '...';
const filePath = "...";
const templatePath = "..."
await testItSdk.storeFileByCaseKey(caseKey,filePath,templatePath);
```

#### Store files by search options

```typescript
const projectName = "...";
const keywords = ['...','...'];
const subtype = ['...','...'];
const suiteName = '...';
const filePath = '...';
const templatePath = '...';
const searchOption : SearchOptions = {
    projectName : projectName,
    subtype : subtype,
    keywords : keywords,
  	suiteName : suiteName,
}
await testItSdk.storeFilesBySearchOptions(searchOption,filePath,templatePath);
```

#### Store files by suite name

```typescript
const suiteName = '...';
const projectName = '...';
const filePath = '...';
await testItSdk.storeCasesBySuiteName(suiteName,projectName,filePath);
```



### [Interface]Search Options

```typescript
export interface SearchOptions{
  projectName : string;
  keywords ?: string[];
  subtype ?: string[];
  suiteName ?: string;
}
```

### More Information

