Skip to content

Commit 4edbc07

Browse files
Merge pull request #93 from aquality-automation/feature/public_api_tests
Feature/public api tests
2 parents 1acc3e7 + 5c6e8b0 commit 4edbc07

File tree

12 files changed

+482
-67
lines changed

12 files changed

+482
-67
lines changed

e2e/api/base.api.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Project } from '../../src/app/shared/models/project';
2+
import { ATError } from '../../src/app/shared/models/error';
3+
import { ApiAssertMessages } from '../specs/api/api.constants';
4+
5+
export class BaseAPI {
6+
project: Project;
7+
token: string;
8+
9+
constructor(project: Project, token: string) {
10+
this.project = project;
11+
this.token = token;
12+
}
13+
14+
public async assertNegativeresponse(promise: Promise<object>, expectedError: string): Promise<void> {
15+
let atError: ATError;
16+
try {
17+
await promise;
18+
} catch (error) {
19+
atError = error;
20+
}
21+
22+
expect(atError).toBeDefined(ApiAssertMessages.errorNotRaised);
23+
expect(atError.message).toBe(expectedError, ApiAssertMessages.errorIsWrong);
24+
}
25+
}

e2e/api/editor.api.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TestRun } from '../../src/app/shared/models/testRun';
55
import { Milestone } from '../../src/app/shared/models/milestone';
66
import { sendPost, sendGet, sendDelete } from '../utils/aqualityTrackingAPI.util';
77
import { TestResult } from '../../src/app/shared/models/test-result';
8-
import { Project } from '../../src/app/shared/models/project';
8+
import { BaseAPI } from './base.api';
99

1010
enum Endpoints {
1111
suite = '/suite',
@@ -18,14 +18,7 @@ enum Endpoints {
1818
testToSuite = '/testToSuite'
1919
}
2020

21-
export class EditorAPI {
22-
project: Project;
23-
token: string;
24-
25-
constructor(project: Project, token: string) {
26-
this.project = project;
27-
this.token = token;
28-
}
21+
export class EditorAPI extends BaseAPI {
2922

3023
public async createSuite(suite: TestSuite): Promise<TestSuite> {
3124
suite.project_id = this.project.id;

e2e/api/importer.api.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { logger } from '../utils/log.util';
33
import { Project } from '../../src/app/shared/models/project';
44
import { EditorAPI } from './editor.api';
55
import { TestRun } from '../../src/app/shared/models/testRun';
6+
import { BaseAPI } from './base.api';
67

78
export class ImportParams {
89
projectId?: number;
@@ -20,14 +21,11 @@ export enum ImportFormats {
2021

2122
const CHECK_IMPORTED_DELAY = 2000;
2223

23-
export class Importer {
24-
project: Project;
25-
token: string;
24+
export class Importer extends BaseAPI {
2625
editorAPI: EditorAPI;
2726

2827
constructor(project: Project, token: string) {
29-
this.project = project;
30-
this.token = token;
28+
super(project, token);
3129
this.editorAPI = new EditorAPI(this.project, this.token);
3230
}
3331

e2e/api/public.api.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { TestSuite } from '../../src/app/shared/models/testSuite';
2+
import { Test } from '../../src/app/shared/models/test';
3+
import { TestRun } from '../../src/app/shared/models/testRun';
4+
import { sendPost, sendGet } from '../utils/aqualityTrackingAPI.util';
5+
import { TestResult } from '../../src/app/shared/models/test-result';
6+
import { Project } from '../../src/app/shared/models/project';
7+
import { BaseAPI } from './base.api';
8+
9+
enum Endpoints {
10+
suite_create_or_update = '/public/suite/create-or-update',
11+
testrun_start = '/public/testrun/start',
12+
testrun_finish = '/public/testrun/finish',
13+
test_result_start = '/public/test/result/start',
14+
test_result_finish = '/public/test/result/finish',
15+
test_create_or_update = '/public/test/create-or-update'
16+
}
17+
18+
export class PublicAPI extends BaseAPI {
19+
20+
public createOrUpdateSuite(suite: TestSuite): Promise<TestSuite> {
21+
return sendPost(Endpoints.suite_create_or_update, undefined, suite, this.token, this.project.id);
22+
}
23+
24+
public createOrUpdateTest(test: Test): Promise<Test> {
25+
return sendPost(Endpoints.test_create_or_update, undefined, test, this.token, this.project.id);
26+
}
27+
28+
public startTestrun(testrun: TestRun): Promise<TestRun> {
29+
return sendPost(Endpoints.testrun_start, undefined, testrun, this.token, this.project.id);
30+
}
31+
32+
public finishTestRun(project_id: number, id: number) {
33+
return sendGet(Endpoints.testrun_finish, { project_id, id }, this.token, this.project.id);
34+
}
35+
36+
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);
38+
}
39+
40+
public testResultFinish(testResult: TestResult): Promise<TestResult> {
41+
return sendPost(Endpoints.test_result_finish, undefined, testResult, this.token, this.project.id);
42+
}
43+
}

e2e/helpers/project.helper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Importer } from '../api/importer.api';
1212
import { EditorAPI } from '../api/editor.api';
1313
import projects from '../data/projects.json';
1414
import usersTestData from '../data/users.json';
15+
import { PublicAPI } from '../api/public.api';
1516

1617

1718
export enum PermissionType {
@@ -28,6 +29,7 @@ export class ProjectHelper {
2829
public project: Project = projects.customerOnly;
2930
public importer: Importer;
3031
public editorAPI: EditorAPI;
32+
public publicAPI: PublicAPI;
3133
private admin = usersTestData.admin;
3234

3335
constructor(name?: string) {
@@ -52,6 +54,7 @@ export class ProjectHelper {
5254

5355
this.importer = new Importer(this.project, token);
5456
this.editorAPI = new EditorAPI(this.project, token);
57+
this.publicAPI = new PublicAPI(this.project, token);
5558
return projectView.menuBar.clickLogOut();
5659
} catch (err) {
5760
logger.error(err.message);

e2e/specs/api/api.constants.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
export enum ApiAssertMessages {
2+
errorNotRaised = 'Error was not raised!',
3+
errorIsWrong = 'Error message is wrong!',
4+
idMissed = 'id is missed!',
5+
nameWrong = 'name is wrong!',
6+
projecIdWrong = 'project_id is wrong!',
7+
suiteMissed = 'suite is missed!',
8+
idWrong = 'id is wrong!',
9+
startTimeMissed = 'start_time is missed!',
10+
startTimeWrong = 'start_time is wrong!',
11+
finishTimeWrong = 'finish_time is wrong!',
12+
startDateMissed = 'start_date is missed!',
13+
finalResultIdWrong = 'final_result_id is wrong!',
14+
testIdWrong = 'test_id is wrong!',
15+
}
16+
17+
class ApiResponseErrors {
18+
public missedId = `You should specify 'id'!`;
19+
public missedIdOrName = `You should specify 'id' or/and 'name' suite parameters!`;
20+
public missedProjectId = `You should specify 'project_id'!`;
21+
public missedBuildName = `You should specify 'build_name'!`;
22+
public missedSuiteId = `You should specify 'test_suite_id'`;
23+
public missedTestId = `You should specify 'test_id'`;
24+
public missedTestRunId = `You should specify 'test_run_id'`;
25+
public missedFinalResultId = `You should specify 'final_result_id' - Failed: 1, Passed: 2, Not Executed: 3, Pending: 5.`;
26+
// tslint:disable-next-line: quotemark
27+
public missedSuites = "You should specify 'suites' array with single suite like `[{id: test_suite_id}]`";
28+
public anonymousNotAllowedToViewTestSuites = this.anonymousNotAllowedToView('Test Suites');
29+
public anonymousNotAllowedToViewTests = this.anonymousNotAllowedToView('Tests');
30+
public anonymousNotAllowedToViewTestResults = this.anonymousNotAllowedToView('Test Results');
31+
public anonymousNotAllowedToCreateTestRun = this.anonymousNotAllowedToCreate('Test Run');
32+
public entityWithIdDoesNotExist = (id: number) => `Entity with specified '${id}' id does not exist!`;
33+
34+
private anonymousNotAllowedToView(entity: string) {
35+
return `[Permissions anonymous]: Account is not allowed to view ${entity}`;
36+
}
37+
38+
private anonymousNotAllowedToCreate(entity: string) {
39+
return `[Permissions anonymous]: Account is not allowed to create ${entity}`;
40+
}
41+
}
42+
export const apiResponseErrors = new ApiResponseErrors();

e2e/specs/api/publicApi.spec.ts renamed to e2e/specs/api/application.api.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { TestRun } from '../../../src/app/shared/models/testRun';
66
import { Test } from '../../../src/app/shared/models/test';
77
import { TestResult } from '../../../src/app/shared/models/test-result';
88

9-
describe('Public API tests', () => {
9+
describe('Application API:', () => {
1010
const projectHelper: ProjectHelper = new ProjectHelper();
1111
const builds = { build_1: 'Build_1' };
1212
let suite: TestSuite = suites.suiteCreation;

0 commit comments

Comments
 (0)