Skip to content

Commit d9532e0

Browse files
Merge pull request #108 from aquality-automation/develop
Develop
2 parents 6585e86 + 97dabce commit d9532e0

File tree

91 files changed

+2179
-859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+2179
-859
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# CHANGELOG
22

3+
## 0.3.10 (unreleased)
4+
5+
Features:
6+
- Update Tests to use Admin API to create preconditions -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/100)
7+
- Dashboard: My open Issues -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/74)
8+
- Cannot open external issue from Modal and View of Issue -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/96)
9+
- Test run Bulk Delete -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/91)
10+
11+
Bugfixes:
12+
- Test run View Page performance is bad -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/99)
13+
- API Token page: Link to Aquality Tracking API leads to null -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/84)
14+
- External Link does not work on Issues List -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/97)
15+
- Test page design is broken if steps are empty -> [View Issue](https://github.com/aquality-automation/aquality-tracking/issues/94)
16+
317
## 0.3.9 (2020-04-21)
418

519
Features:

e2e/api/base.api.ts

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import { Project } from '../../src/app/shared/models/project';
22
import { ATError } from '../../src/app/shared/models/error';
33
import { ApiAssertMessages } from '../specs/api/api.constants';
4+
import superagent, { SuperAgentRequest } from 'superagent';
5+
import { environment } from '../../src/environments/environment';
6+
import { logger } from '../utils/log.util';
7+
8+
enum RequestType {
9+
post = 'post',
10+
get = 'get',
11+
delete = 'delete'
12+
}
413

514
export class BaseAPI {
615
project: Project;
716
token: string;
17+
protected cookie: string;
818

9-
constructor(project: Project, token: string) {
19+
constructor(project: Project, token: string, cookie: string = undefined) {
1020
this.project = project;
1121
this.token = token;
22+
this.cookie = cookie;
1223
}
1324

1425
public async assertNegativeResponse(promise: Promise<object>, expectedError: string): Promise<void> {
@@ -22,4 +33,87 @@ export class BaseAPI {
2233
expect(atError).toBeDefined(ApiAssertMessages.errorNotRaised);
2334
expect(atError).toBe(expectedError, ApiAssertMessages.errorIsWrong);
2435
}
36+
37+
protected sendGet = async (endpoint: string, params: object = undefined) => {
38+
try {
39+
const resp = await this.send(this.getFullURL(endpoint, params), RequestType.get);
40+
return resp.body;
41+
} catch (error) {
42+
logger.error(`Was not able to get ${this.getFullURL(endpoint, params)}:\n${error.response.body.message}`);
43+
throw error.response.body.message;
44+
}
45+
};
46+
47+
protected sendPost = async (endpoint: string, params: object, body: any) => {
48+
try {
49+
const resp = await this.send(this.getFullURL(endpoint, params), RequestType.post, body);
50+
return resp.body;
51+
} catch (error) {
52+
logger.error(`Was not able to post ${this.getFullURL(endpoint, params)}`);
53+
throw error.response.body.message;
54+
}
55+
};
56+
57+
protected sendDelete = async (endpoint: string, params: object, body: any = undefined) => {
58+
try {
59+
const resp = await this.send(this.getFullURL(endpoint, params), RequestType.delete, body);
60+
return resp.body;
61+
} catch (error) {
62+
logger.error(`Was not able to delete ${this.getFullURL(endpoint, params)}`);
63+
throw error.response.body.message;
64+
}
65+
};
66+
67+
protected sendPostFiles = (endpoint: string, params: object, filesAsString: string[], filenames: string[],
68+
token: string, projectId: number) => {
69+
const req = this.send(this.getFullURL(endpoint, params), RequestType.post);
70+
for (let i = 0; i < filesAsString.length; i++) {
71+
const file = filesAsString[i];
72+
const filename = filenames[i];
73+
req.attach('file', new Buffer(file), { filename });
74+
}
75+
76+
return req;
77+
};
78+
79+
private createAuthHeaderValue = () => {
80+
if (this.cookie) {
81+
return `Basic ${this.cookie}`;
82+
}
83+
84+
if (this.project && this.token) {
85+
return `Basic ${Buffer.from(`project:${this.project.id}:${this.token}`).toString('base64')}`;
86+
}
87+
88+
throw ('You are trying to make wrong authorization: you should specify project and token, or cookie!')
89+
};
90+
91+
private send = (fullUrl: string, type: RequestType, body?: object): SuperAgentRequest => {
92+
const request = superagent[type](fullUrl)
93+
.set('Authorization', this.createAuthHeaderValue())
94+
.set('Accept', 'application/json');
95+
96+
if (body) {
97+
request.send(body);
98+
}
99+
100+
return request;
101+
};
102+
103+
private serializeToQueryString = (object: object) => {
104+
if (!object) {
105+
return '';
106+
}
107+
const str = [];
108+
for (const property in object) {
109+
if (object.hasOwnProperty(property) && object[property] !== undefined) {
110+
str.push(`${encodeURIComponent(property)}=${encodeURIComponent(object[property])}`);
111+
}
112+
}
113+
return `?${str.join('&')}`;
114+
};
115+
116+
private getFullURL = (endpoint: string, params: object) => {
117+
return `${environment.host}${endpoint}${this.serializeToQueryString(params)}`;
118+
};
25119
}

e2e/api/editor.api.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Test } from '../../src/app/shared/models/test';
33
import { Step, StepToTest } from '../../src/app/shared/models/steps';
44
import { TestRun } from '../../src/app/shared/models/testRun';
55
import { Milestone } from '../../src/app/shared/models/milestone';
6-
import { sendPost, sendGet, sendDelete } from '../utils/aqualityTrackingAPI.util';
76
import { TestResult } from '../../src/app/shared/models/test-result';
87
import { BaseAPI } from './base.api';
98
import { Issue } from '../../src/app/shared/models/issue';
@@ -24,74 +23,70 @@ export class EditorAPI extends BaseAPI {
2423

2524
public async createSuite(suite: TestSuite): Promise<TestSuite> {
2625
suite.project_id = this.project.id;
27-
return sendPost(Endpoints.suite, undefined, suite, this.token, this.project.id);
26+
return this.sendPost(Endpoints.suite, undefined, suite);
2827
}
2928

3029
public async createTest(test: Test): Promise<Test> {
3130
test.project_id = this.project.id;
32-
return sendPost(Endpoints.test, undefined, test, this.token, this.project.id);
31+
return this.sendPost(Endpoints.test, undefined, test);
3332
}
3433

3534
public async createStep(step: Step): Promise<Step> {
3635
step.project_id = this.project.id;
37-
return sendPost(Endpoints.steps, undefined, step, this.token, this.project.id);
36+
return this.sendPost(Endpoints.steps, undefined, step);
3837
}
3938

4039
public async createTestRun(testrun: TestRun) {
4140
testrun.project_id = this.project.id;
42-
return sendPost(Endpoints.testrun, undefined, testrun, this.token, this.project.id);
41+
return this.sendPost(Endpoints.testrun, undefined, testrun);
4342
}
4443

4544
public async createMilestone(milestone: Milestone) {
4645
milestone.project_id = this.project.id;
47-
return sendPost(Endpoints.milestone, undefined, milestone, this.token, this.project.id);
46+
return this.sendPost(Endpoints.milestone, undefined, milestone);
4847
}
4948

5049
public async createResult(testResult: TestResult): Promise<TestResult> {
5150
testResult.project_id = this.project.id;
52-
return sendPost(Endpoints.testresult, undefined, testResult, this.token, this.project.id);
51+
return this.sendPost(Endpoints.testresult, undefined, testResult);
5352
}
5453

5554
public async addStepToTest(stepToTest: StepToTest): Promise<Step> {
5655
stepToTest.project_id = this.project.id;
57-
return sendPost(Endpoints.testSteps, undefined, stepToTest, this.token, this.project.id);
56+
return this.sendPost(Endpoints.testSteps, undefined, stepToTest);
5857
}
5958

6059
public async addTestToSuite(testId: number, suiteId: number) {
61-
return sendPost(Endpoints.testToSuite, { testId, suiteId, project_id: this.project.id }, {}, this.token, this.project.id);
60+
return this.sendPost(Endpoints.testToSuite, { testId, suiteId, project_id: this.project.id }, {});
6261
}
6362

6463
public async getSuites(testSuite: TestSuite): Promise<TestSuite[]> {
6564
testSuite.project_id = this.project.id;
66-
return sendGet(Endpoints.suite, testSuite, this.token, this.project.id);
65+
return this.sendGet(Endpoints.suite, testSuite);
6766
}
6867

6968
public async getTests(test: Test): Promise<Test[]> {
70-
return sendGet(Endpoints.test, test, this.token, this.project.id);
69+
return this.sendGet(Endpoints.test, test);
7170
}
7271

7372
public async getResults(testResult: TestResult): Promise<TestResult[]> {
7473
testResult.project_id = this.project.id;
75-
return sendGet(Endpoints.testresult, testResult, this.token, this.project.id);
74+
return this.sendGet(Endpoints.testresult, testResult);
7675
}
7776

7877
public async getTestRuns(testrun: TestRun): Promise<TestRun[]> {
79-
return sendGet(Endpoints.testrun, testrun, this.token, this.project.id);
78+
return this.sendGet(Endpoints.testrun, testrun);
8079
}
8180

8281
public async getMilestones(milestone: Milestone): Promise<Milestone[]> {
8382
milestone.project_id = this.project.id;
84-
return sendGet(Endpoints.milestone, milestone, this.token, this.project.id);
85-
}
86-
87-
public async removeTestRun(testRunId: number) {
88-
return sendDelete(Endpoints.testrun, { id: testRunId, project_id: this.project.id }, null, this.token, this.project.id);
83+
return this.sendGet(Endpoints.milestone, milestone);
8984
}
9085

9186
public async createIssue(issue: Issue): Promise<Issue> {
9287
issue.project_id = this.project.id;
9388
issue.creator_id = 1;
94-
return sendPost(Endpoints.issue, undefined, issue, this.token, this.project.id);
89+
return this.sendPost(Endpoints.issue, undefined, issue);
9590
}
9691

9792
public async addSuiteToMilestone(milestoneName: string, suiteName: string) {

e2e/api/importer.api.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { sendPostFiles } from '../utils/aqualityTrackingAPI.util';
21
import { logger } from '../utils/log.util';
32
import { Project } from '../../src/app/shared/models/project';
43
import { EditorAPI } from './editor.api';
@@ -21,13 +20,7 @@ export enum ImportFormats {
2120

2221
const CHECK_IMPORTED_DELAY = 2000;
2322

24-
export class Importer extends BaseAPI {
25-
editorAPI: EditorAPI;
26-
27-
constructor(project: Project, token: string) {
28-
super(project, token);
29-
this.editorAPI = new EditorAPI(this.project, this.token);
30-
}
23+
export class Importer extends EditorAPI {
3124

3225
public async executeImport(importParameters: ImportParams, files: string[], fileNames: string[]): Promise<TestRun[]> {
3326
importParameters.projectId = this.project.id;
@@ -84,7 +77,7 @@ export class Importer extends BaseAPI {
8477
}
8578

8679
private async isAllBuildsAreImported(buildNames: string[]): Promise<TestRun[]> {
87-
const testRuns = await this.editorAPI.getTestRuns({ project_id: this.project.id });
80+
const testRuns = await this.getTestRuns({ project_id: this.project.id });
8881
let imported = true;
8982
const importedTestRuns: TestRun[] = [];
9083
buildNames.forEach(buildName => {
@@ -102,7 +95,7 @@ export class Importer extends BaseAPI {
10295
logger.info(`Start API import with params: ${JSON.stringify(params)}`);
10396
logger.info(`Files count: ${filesAsString.length}`);
10497
logger.info(`File Names count: ${filesAsString.length}`);
105-
await sendPostFiles('/import', params, filesAsString, fileNames, this.token, this.project.id);
98+
await this.sendPostFiles('/import', params, filesAsString, fileNames, this.token, this.project.id);
10699
return true;
107100
} catch (err) {
108101
logger.error(`Import was failed: ${err.message}`);

e2e/api/public.api.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { TestSuite } from '../../src/app/shared/models/testSuite';
22
import { Test } from '../../src/app/shared/models/test';
33
import { TestRun } from '../../src/app/shared/models/testRun';
4-
import { sendPost, sendGet } from '../utils/aqualityTrackingAPI.util';
54
import { TestResult } from '../../src/app/shared/models/test-result';
6-
import { Project } from '../../src/app/shared/models/project';
75
import { BaseAPI } from './base.api';
86

97
enum Endpoints {
@@ -18,26 +16,26 @@ enum Endpoints {
1816
export class PublicAPI extends BaseAPI {
1917

2018
public createOrUpdateSuite(suite: TestSuite): Promise<TestSuite> {
21-
return sendPost(Endpoints.suite_create_or_update, undefined, suite, this.token, this.project.id);
19+
return this.sendPost(Endpoints.suite_create_or_update, undefined, suite);
2220
}
2321

2422
public createOrUpdateTest(test: Test): Promise<Test> {
25-
return sendPost(Endpoints.test_create_or_update, undefined, test, this.token, this.project.id);
23+
return this.sendPost(Endpoints.test_create_or_update, undefined, test);
2624
}
2725

2826
public startTestrun(testrun: TestRun): Promise<TestRun> {
29-
return sendPost(Endpoints.testrun_start, undefined, testrun, this.token, this.project.id);
27+
return this.sendPost(Endpoints.testrun_start, undefined, testrun);
3028
}
3129

3230
public finishTestRun(project_id: number, id: number) {
33-
return sendGet(Endpoints.testrun_finish, { project_id, id }, this.token, this.project.id);
31+
return this.sendGet(Endpoints.testrun_finish, { project_id, id });
3432
}
3533

3634
public testResultStart(test_id: number, test_run_id: number, project_id: number) {
37-
return sendGet(Endpoints.test_result_start, { test_id, test_run_id, project_id }, this.token, this.project.id);
35+
return this.sendGet(Endpoints.test_result_start, { test_id, test_run_id, project_id });
3836
}
3937

4038
public testResultFinish(testResult: TestResult): Promise<TestResult> {
41-
return sendPost(Endpoints.test_result_finish, undefined, testResult, this.token, this.project.id);
39+
return this.sendPost(Endpoints.test_result_finish, undefined, testResult);
4240
}
4341
}

0 commit comments

Comments
 (0)