testit-api-client 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE.md +202 -0
  2. package/README.MD +51 -0
  3. package/dist/client.d.ts +21 -0
  4. package/dist/client.js +154 -0
  5. package/{src/index.ts → dist/index.d.ts} +0 -0
  6. package/dist/index.js +14 -0
  7. package/dist/types/attachment.d.ts +14 -0
  8. package/dist/types/attachment.js +2 -0
  9. package/dist/types/autotest.d.ts +97 -0
  10. package/dist/types/autotest.js +2 -0
  11. package/dist/types/autotestResults.d.ts +22 -0
  12. package/dist/types/autotestResults.js +2 -0
  13. package/dist/types/autotestStep.d.ts +5 -0
  14. package/dist/types/autotestStep.js +2 -0
  15. package/dist/types/capabilities.d.ts +1 -0
  16. package/dist/types/capabilities.js +2 -0
  17. package/dist/types/client.d.ts +14 -0
  18. package/dist/types/client.js +2 -0
  19. package/dist/types/config.d.ts +10 -0
  20. package/dist/types/config.js +2 -0
  21. package/dist/types/configuration.d.ts +16 -0
  22. package/dist/types/configuration.js +2 -0
  23. package/{src/types/index.ts → dist/types/index.d.ts} +0 -0
  24. package/dist/types/index.js +30 -0
  25. package/dist/types/label.d.ts +7 -0
  26. package/dist/types/label.js +2 -0
  27. package/dist/types/link.d.ts +24 -0
  28. package/dist/types/link.js +2 -0
  29. package/dist/types/outcome.d.ts +1 -0
  30. package/dist/types/outcome.js +2 -0
  31. package/dist/types/parameters.d.ts +1 -0
  32. package/dist/types/parameters.js +2 -0
  33. package/dist/types/properties.d.ts +1 -0
  34. package/dist/types/properties.js +2 -0
  35. package/dist/types/stepResults.d.ts +14 -0
  36. package/dist/types/stepResults.js +2 -0
  37. package/{src/types/tag.ts → dist/types/tag.d.ts} +1 -1
  38. package/dist/types/tag.js +2 -0
  39. package/dist/types/testPoint.d.ts +9 -0
  40. package/dist/types/testPoint.js +2 -0
  41. package/dist/types/testResult.d.ts +31 -0
  42. package/dist/types/testResult.js +2 -0
  43. package/dist/types/testRun.d.ts +20 -0
  44. package/dist/types/testRun.js +2 -0
  45. package/{src/types/workItem.ts → dist/types/workItem.d.ts} +1 -1
  46. package/dist/types/workItem.js +2 -0
  47. package/dist/validation.d.ts +2 -0
  48. package/dist/validation.js +15 -0
  49. package/package.json +10 -2
  50. package/babel.config.js +0 -6
  51. package/jest.config.ts +0 -194
  52. package/readme.md +0 -44
  53. package/src/client.ts +0 -183
  54. package/src/types/attachment.ts +0 -15
  55. package/src/types/autotest.ts +0 -102
  56. package/src/types/autotestResults.ts +0 -23
  57. package/src/types/autotestStep.ts +0 -5
  58. package/src/types/capabilities.ts +0 -1
  59. package/src/types/client.ts +0 -29
  60. package/src/types/config.ts +0 -11
  61. package/src/types/configuration.ts +0 -17
  62. package/src/types/label.ts +0 -8
  63. package/src/types/link.ts +0 -33
  64. package/src/types/outcome.ts +0 -6
  65. package/src/types/parameters.ts +0 -1
  66. package/src/types/properties.ts +0 -1
  67. package/src/types/stepResults.ts +0 -15
  68. package/src/types/testPoint.ts +0 -9
  69. package/src/types/testResult.ts +0 -32
  70. package/src/types/testRun.ts +0 -27
  71. package/src/validation.ts +0 -14
  72. package/test/client.test.ts +0 -191
  73. package/test/validation.test.ts +0 -68
  74. package/tsconfig.json +0 -102
package/src/client.ts DELETED
@@ -1,183 +0,0 @@
1
- import axios, { AxiosInstance, AxiosResponse } from 'axios';
2
- import minimist from 'minimist';
3
- import {
4
- Attachment,
5
- Autotest,
6
- AutotestPost,
7
- AutotestPut,
8
- AutotestQuery,
9
- AutotestResultsForTestRun,
10
- ClientConfig,
11
- ClientConfigWithFile,
12
- IClient,
13
- TestRunGet,
14
- TestRunPost,
15
- WorkItemId,
16
- } from './types';
17
- import { existsSync, readFileSync } from 'fs';
18
- import FormData from 'form-data';
19
- import { basename } from 'path';
20
- import { validateConfig } from './validation';
21
-
22
- export class Client implements IClient {
23
- private readonly axios: AxiosInstance;
24
- private config: ClientConfig;
25
-
26
- constructor(config: Partial<ClientConfigWithFile>) {
27
- const { configFile, ...restConfig } = config;
28
- let finalConfig = restConfig;
29
- if (configFile) {
30
- finalConfig = Client.mergeConfig(
31
- finalConfig,
32
- this.readConfigFile(configFile)
33
- );
34
- }
35
- finalConfig = Client.mergeConfig(finalConfig, this.readEnvConfig());
36
- finalConfig = Client.mergeConfig(finalConfig, this.readCliConfig());
37
- this.config = validateConfig(finalConfig);
38
- const baseURL = new URL('/api/v2', this.config.url).toString();
39
- this.axios = axios.create({
40
- baseURL,
41
- headers: {
42
- Authorization: `PrivateToken ${this.config.privateToken}`,
43
- },
44
- });
45
- }
46
-
47
- async checkConnection() {
48
- try {
49
- await axios.get(new URL('version.json', this.config.url).toString());
50
- } catch (err) {
51
- throw new Error('Cannot connect to TestIt');
52
- }
53
- }
54
-
55
- // TODO: add query object
56
- async getAutotest(query: AutotestQuery): Promise<Autotest[]> {
57
- const params = new URLSearchParams();
58
- Object.keys(query).forEach((key) => {
59
- const value = query[key as keyof AutotestQuery];
60
- if (value === undefined) {
61
- return;
62
- }
63
- if (Array.isArray(value)) {
64
- value.forEach((v) => params.append(key, v));
65
- } else {
66
- params.append(key, value.toString());
67
- }
68
- });
69
- return this.axios
70
- .get(`/autoTests?${params.toString()}`)
71
- .then((res) => res.data);
72
- }
73
-
74
- async createAutotest(autotest: AutotestPost): Promise<Autotest> {
75
- return this.axios.post('/autoTests', autotest).then((res) => res.data);
76
- }
77
-
78
- async updateAutotest(autotest: AutotestPut): Promise<void> {
79
- return this.axios.put('/autoTests', autotest);
80
- }
81
-
82
- async linkToWorkItem(
83
- autotestId: string,
84
- workItem: WorkItemId
85
- ): Promise<void> {
86
- return this.axios.post(`/autoTests/${autotestId}/workItems`, workItem);
87
- }
88
-
89
- async createTestRun(testRun: TestRunPost): Promise<TestRunGet> {
90
- return this.axios
91
- .post('/testRuns', testRun)
92
- .then((res) => res.data as TestRunGet);
93
- }
94
-
95
- async startTestRun(testRunId: string): Promise<void> {
96
- return this.axios.post(`/testRuns/${testRunId}/start`);
97
- }
98
-
99
- async loadTestRunResults(
100
- testRunId: string,
101
- results: AutotestResultsForTestRun[]
102
- ): Promise<string[]> {
103
- return await this.axios
104
- .post<AutotestResultsForTestRun[], AxiosResponse<string[]>>(
105
- `/testRuns/${testRunId}/testResults`,
106
- results
107
- )
108
- .then((res) => res.data);
109
- }
110
-
111
- async completeTestRun(testRunId: string): Promise<void> {
112
- return this.axios.post(`/testRuns/${testRunId}/complete`);
113
- }
114
-
115
- getConfig(): ClientConfig {
116
- return this.config;
117
- }
118
-
119
- async loadAttachment(filePath: string): Promise<Attachment> {
120
- const form = new FormData();
121
- form.append('file', readFileSync(filePath), basename(filePath));
122
- return this.axios
123
- .post<FormData, AxiosResponse<Attachment>>('/Attachments', form, {
124
- headers: form.getHeaders(),
125
- })
126
- .then((res) => res.data);
127
- }
128
-
129
- private readCliConfig(): Partial<ClientConfig> {
130
- const args = minimist(process.argv.slice(2));
131
- let config = {};
132
- if (args['testitConfig']) {
133
- config = this.readConfigFile(args['testitConfig']);
134
- }
135
- return Client.mergeConfig(config, {
136
- url: args['testitUrl'],
137
- privateToken: args['testitPrivateToken'],
138
- projectId: args['testitProjectId'],
139
- configurationId: args['testitConfigurationId'],
140
- testRunId: args['testitTestRunId'],
141
- });
142
- }
143
-
144
- private readEnvConfig(): Partial<ClientConfig> {
145
- let config = {};
146
- if (process.env['TESTIT_CONFIG_FILE']) {
147
- config = this.readConfigFile(process.env['TESTIT_CONFIG_FILE']);
148
- }
149
- return Client.mergeConfig(config, {
150
- url: process.env['TESTIT_URL'],
151
- privateToken: process.env['TESTIT_PRIVATE_TOKEN'],
152
- projectId: process.env['TESTIT_PROJECT_ID'],
153
- configurationId: process.env['TESTIT_CONFIGURATION_ID'],
154
- testRunId: process.env['TESTIT_TEST_RUN_ID'],
155
- });
156
- }
157
-
158
- private readConfigFile(path: string): Partial<ClientConfig> {
159
- if (!existsSync(path)) {
160
- throw new Error('Config file not found');
161
- }
162
- const config = JSON.parse(
163
- readFileSync(path, { encoding: 'utf8' })
164
- ) as Partial<ClientConfig>;
165
- if (config.privateToken) {
166
- console.warn('Private token is in config file, it is not secure');
167
- }
168
- return config;
169
- }
170
-
171
- static mergeConfig(
172
- oldConfig: Partial<ClientConfig>,
173
- newConfig: Partial<ClientConfig>
174
- ): Partial<ClientConfig> {
175
- return {
176
- url: newConfig.url ?? oldConfig.url,
177
- privateToken: newConfig.privateToken ?? oldConfig.privateToken,
178
- projectId: newConfig.projectId ?? oldConfig.projectId,
179
- configurationId: newConfig.configurationId ?? oldConfig.configurationId,
180
- testRunId: newConfig.testRunId ?? oldConfig.testRunId,
181
- };
182
- }
183
- }
@@ -1,15 +0,0 @@
1
- export interface AttachmentPut {
2
- id: string;
3
- }
4
-
5
- export interface Attachment {
6
- fileId: string;
7
- type: string;
8
- size: number;
9
- name: string;
10
- createDate?: string;
11
- modifiedDate?: string;
12
- createdById?: string;
13
- modifiedById?: string;
14
- id?: string;
15
- }
@@ -1,102 +0,0 @@
1
- import { LabelPost, LabelShort } from './label';
2
- import { Link, LinkPost, LinkPut } from './link';
3
- import { AutotestStep } from './autotestStep';
4
-
5
- export interface AutotestPost {
6
- globalId?: number;
7
- isDeleted?: boolean;
8
- id?: string;
9
- createdDate?: string;
10
- modifiedDate?: string;
11
- createdById?: string;
12
- modifiedById?: string;
13
- mustBeApproved?: boolean;
14
- externalId: string;
15
- links?: LinkPost[];
16
- projectId: string;
17
- name: string;
18
- namespace?: string;
19
- classname?: string;
20
- steps?: AutotestStep[];
21
- setup?: AutotestStep[];
22
- teardown?: AutotestStep[];
23
- title?: string;
24
- description?: string;
25
- labels?: LabelPost[];
26
- }
27
-
28
- export interface AutotestPut {
29
- id?: string;
30
- externalId: string;
31
- links?: LinkPost[];
32
- projectId: string;
33
- name: string;
34
- namespace?: string;
35
- classname?: string;
36
- steps?: AutotestStep[];
37
- setup?: AutotestStep[];
38
- teardown?: AutotestStep[];
39
- title?: string;
40
- description?: string;
41
- labels?: LabelPost[];
42
- }
43
-
44
- export interface Autotest {
45
- globalId?: number;
46
- isDeleted?: boolean;
47
- id?: string;
48
- createdDate?: string;
49
- modifiedDate?: string;
50
- createdById?: string;
51
- modifiedById?: string;
52
- mustBeApproved?: boolean;
53
- externalId: string;
54
- links?: LinkPut[];
55
- projectId: string;
56
- name: string;
57
- namespace?: string;
58
- classname?: string;
59
- steps?: AutotestStep[];
60
- setup?: AutotestStep[];
61
- teardown?: AutotestStep[];
62
- title?: string;
63
- description?: string;
64
- labels?: LabelPost[];
65
- }
66
-
67
- export interface AutotestGet {
68
- externalId?: string;
69
- links?: Link[];
70
- projectId?: string;
71
- name?: string;
72
- namespace?: string;
73
- classname?: string;
74
- steps?: AutotestStep[];
75
- setup?: AutotestStep[];
76
- teardown: AutotestStep[];
77
- global?: number;
78
- createdDate?: string;
79
- modifiedDate?: string;
80
- createdById?: string;
81
- modifiedById?: string;
82
- labels?: LabelShort[];
83
- id?: string;
84
- isDeleted?: boolean;
85
- }
86
-
87
- export interface AutotestQuery {
88
- projectId?: string;
89
- externalId?: string;
90
- globalId?: number;
91
- namespace?: string;
92
- isNamespaceNull?: boolean;
93
- classname?: string;
94
- isClassnameNull?: boolean;
95
- isDeleted?: boolean;
96
- labels?: string[];
97
- skip?: number;
98
- take?: number;
99
- orderBy?: string;
100
- searchField?: string;
101
- searchValue?: string;
102
- }
@@ -1,23 +0,0 @@
1
- import { AttachmentPut } from './attachment';
2
- import { LinkPost } from './link';
3
- import { OutcomeType } from './outcome';
4
- import { Parameters } from './parameters';
5
- import { AttachmentPutModelAutotestStepResults } from './stepResults';
6
-
7
- export interface AutotestResultsForTestRun {
8
- configurationId: string;
9
- links?: LinkPost[];
10
- failureReasonName?: string;
11
- autotestExternalId: string;
12
- outcome: OutcomeType;
13
- message?: string;
14
- traces?: string;
15
- startedOn?: string;
16
- completeOn?: string;
17
- duration?: number;
18
- attachments?: AttachmentPut[];
19
- parameters?: Parameters;
20
- stepResults?: AttachmentPutModelAutotestStepResults[];
21
- setupResults?: AttachmentPutModelAutotestStepResults[];
22
- teardownResults?: AttachmentPutModelAutotestStepResults[];
23
- }
@@ -1,5 +0,0 @@
1
- export interface AutotestStep {
2
- title: string;
3
- description?: string;
4
- steps?: AutotestStep[];
5
- }
@@ -1 +0,0 @@
1
- export type Capabilities = Record<string, string>;
@@ -1,29 +0,0 @@
1
- import {
2
- Attachment,
3
- Autotest,
4
- AutotestPost,
5
- AutotestPut,
6
- AutotestQuery,
7
- AutotestResultsForTestRun,
8
- ClientConfig,
9
- TestRunGet,
10
- TestRunPost,
11
- WorkItemId,
12
- } from '.';
13
-
14
- export interface IClient {
15
- checkConnection(): Promise<void>;
16
- getAutotest(query: AutotestQuery): Promise<Autotest[]>;
17
- createAutotest(autotest: AutotestPost): Promise<Autotest>;
18
- updateAutotest(autotest: AutotestPut): Promise<void>;
19
- linkToWorkItem(autotestId: string, workItem: WorkItemId): Promise<void>;
20
- createTestRun(testRun: TestRunPost): Promise<TestRunGet>;
21
- startTestRun(testRunId: string): Promise<void>;
22
- loadTestRunResults(
23
- testRunId: string,
24
- results: AutotestResultsForTestRun[]
25
- ): Promise<string[]>;
26
- completeTestRun(testRunId: string): Promise<void>;
27
- getConfig(): ClientConfig;
28
- loadAttachment(fileName: string): Promise<Attachment>;
29
- }
@@ -1,11 +0,0 @@
1
- export interface ClientConfig {
2
- url: string;
3
- privateToken: string;
4
- projectId: string;
5
- configurationId: string;
6
- testRunId?: string;
7
- }
8
-
9
- export interface ClientConfigWithFile extends ClientConfig {
10
- configFile?: string;
11
- }
@@ -1,17 +0,0 @@
1
- import { Capabilities } from './capabilities';
2
-
3
- export interface Configuration {
4
- description?: string;
5
- isActive?: boolean;
6
- capabilities: Capabilities;
7
- projectId?: string;
8
- isDefault?: boolean;
9
- name?: string;
10
- createdDate?: string;
11
- modifiedDate?: string;
12
- createdById?: string;
13
- modifiedById?: string;
14
- globalId?: number;
15
- id?: number;
16
- isDeleted?: boolean;
17
- }
@@ -1,8 +0,0 @@
1
- export interface LabelShort {
2
- globalId?: number;
3
- name: string;
4
- }
5
-
6
- export interface LabelPost {
7
- name: string;
8
- }
package/src/types/link.ts DELETED
@@ -1,33 +0,0 @@
1
- export type LinkType =
2
- | 'Related'
3
- | 'BlockedBy'
4
- | 'Defect'
5
- | 'Issue'
6
- | 'Requirement'
7
- | 'Repository';
8
-
9
- export interface LinkPost {
10
- title?: string;
11
- url: string;
12
- description?: string;
13
- type?: LinkType;
14
- hasInfo?: boolean;
15
- }
16
-
17
- export interface LinkPut {
18
- id?: string;
19
- title?: string;
20
- url: string;
21
- description?: string;
22
- type?: LinkType;
23
- hasInfo?: boolean;
24
- }
25
-
26
- export interface Link {
27
- id?: string;
28
- title?: string;
29
- url: string;
30
- description?: string;
31
- type?: LinkType;
32
- hasInfo?: boolean;
33
- }
@@ -1,6 +0,0 @@
1
- export type OutcomeType =
2
- | 'Passed'
3
- | 'Failed'
4
- | 'Pending'
5
- | 'Blocked'
6
- | 'Skipped';
@@ -1 +0,0 @@
1
- export type Parameters = Record<string, string>;
@@ -1 +0,0 @@
1
- export type Properties = Record<string, string>;
@@ -1,15 +0,0 @@
1
- import { AttachmentPut } from './attachment';
2
- import { OutcomeType } from './outcome';
3
- import { Parameters } from './parameters';
4
-
5
- export interface AttachmentPutModelAutotestStepResults {
6
- title?: string;
7
- description?: string;
8
- startedOn?: string;
9
- completedOn?: string;
10
- duration?: number;
11
- outcome?: OutcomeType;
12
- stepResults?: AttachmentPutModelAutotestStepResults[];
13
- attachments?: AttachmentPut[];
14
- parameters?: Parameters;
15
- }
@@ -1,9 +0,0 @@
1
- export interface TestPointShort {
2
- testSuiteId?: string;
3
- id?: string;
4
- testerId?: string;
5
- workItemId?: string;
6
- configurationId?: string;
7
- status?: string;
8
- lastTestResultId?: string;
9
- }
@@ -1,32 +0,0 @@
1
- import { Attachment } from './attachment';
2
- import { AutotestGet } from './autotest';
3
- import { Configuration } from './configuration';
4
- import { Link } from './link';
5
- import { OutcomeType } from './outcome';
6
- import { Parameters } from './parameters';
7
- import { Properties } from './properties';
8
- import { TestPointShort } from './testPoint';
9
-
10
- export interface TestResultGet {
11
- configuration?: Configuration;
12
- autotest?: AutotestGet;
13
- is?: string;
14
- configurationId?: string;
15
- workItemVersionId?: string;
16
- autotestId?: string;
17
- message?: string;
18
- traces?: string;
19
- startedOn?: string;
20
- completedOn?: string;
21
- runByUserId?: string;
22
- stoppedByUserId?: string;
23
- testPointId?: string;
24
- testPoint?: TestPointShort;
25
- testRunId?: string;
26
- outcome?: OutcomeType;
27
- comment?: string;
28
- links?: Link[];
29
- attachments?: Attachment[];
30
- parameters?: Parameters;
31
- properties?: Properties;
32
- }
@@ -1,27 +0,0 @@
1
- import { TestResultGet } from './testResult';
2
-
3
- export type TestRunStateType =
4
- | 'NotStarted'
5
- | 'InProgress'
6
- | 'Stopped'
7
- | 'Completed';
8
-
9
- export interface TestRunPost {
10
- projectId: string;
11
- name?: string;
12
- }
13
-
14
- export interface TestRunGet {
15
- startedOn?: string;
16
- completedOn?: string;
17
- stateName?: TestRunStateType;
18
- projectId?: string;
19
- testPlanId?: string;
20
- testResults?: TestResultGet[];
21
- createdDate?: string;
22
- modifiedDate?: string;
23
- createById?: string;
24
- modifiedById?: string;
25
- id: string;
26
- name: string;
27
- }
package/src/validation.ts DELETED
@@ -1,14 +0,0 @@
1
- import { z } from 'zod';
2
- import { ClientConfig } from '.';
3
-
4
- const configSchema = z.object({
5
- configurationId: z.string().uuid(),
6
- privateToken: z.string(),
7
- projectId: z.string().uuid(),
8
- url: z.string().url(),
9
- testRunId: z.string().uuid().optional(),
10
- });
11
-
12
- export function validateConfig(config: Partial<ClientConfig>): ClientConfig {
13
- return configSchema.parse(config);
14
- }