|
| 1 | +import { TestSuite } from '../../src/app/shared/models/testSuite'; |
| 2 | +import { Test } from '../../src/app/shared/models/test'; |
| 3 | +import { Step, StepToTest } from '../../src/app/shared/models/steps'; |
| 4 | +import { TestRun } from '../../src/app/shared/models/testRun'; |
| 5 | +import { Milestone } from '../../src/app/shared/models/milestone'; |
| 6 | +import { sendPost, sendGet, sendDelete } from '../utils/aqualityTrackingAPI.util'; |
| 7 | +import { TestResult } from '../../src/app/shared/models/test-result'; |
| 8 | +import { Project } from '../../src/app/shared/models/project'; |
| 9 | + |
| 10 | +enum Endpoints { |
| 11 | + suite = '/suite', |
| 12 | + test = '/test', |
| 13 | + steps = '/steps', |
| 14 | + testrun = '/testrun', |
| 15 | + milestone = '/milestone', |
| 16 | + testresult = '/testresult', |
| 17 | + testSteps = '/test/steps', |
| 18 | + testToSuite = '/testToSuite' |
| 19 | +} |
| 20 | + |
| 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 | + } |
| 29 | + |
| 30 | + public async createSuite(suite: TestSuite): Promise<TestSuite> { |
| 31 | + suite.project_id = this.project.id; |
| 32 | + return sendPost(Endpoints.suite, undefined, suite, this.token, this.project.id); |
| 33 | + } |
| 34 | + |
| 35 | + public async createTest(test: Test): Promise<Test> { |
| 36 | + test.project_id = this.project.id; |
| 37 | + return sendPost(Endpoints.test, undefined, test, this.token, this.project.id); |
| 38 | + } |
| 39 | + |
| 40 | + public async createStep(step: Step): Promise<Step> { |
| 41 | + step.project_id = this.project.id; |
| 42 | + return sendPost(Endpoints.steps, undefined, step, this.token, this.project.id); |
| 43 | + } |
| 44 | + |
| 45 | + public async createTestRun(testrun: TestRun) { |
| 46 | + testrun.project_id = this.project.id; |
| 47 | + return sendPost(Endpoints.testrun, undefined, testrun, this.token, this.project.id); |
| 48 | + } |
| 49 | + |
| 50 | + public async createMilestone(milestone: Milestone) { |
| 51 | + milestone.project_id = this.project.id; |
| 52 | + return sendPost(Endpoints.milestone, undefined, milestone, this.token, this.project.id); |
| 53 | + } |
| 54 | + |
| 55 | + public async createResult(testResult: TestResult): Promise<TestResult> { |
| 56 | + return sendPost(Endpoints.testresult, undefined, testResult, this.token, this.project.id); |
| 57 | + } |
| 58 | + |
| 59 | + public async addStepToTest(stepToTest: StepToTest): Promise<Step> { |
| 60 | + stepToTest.project_id = this.project.id; |
| 61 | + return sendPost(Endpoints.testSteps, undefined, stepToTest, this.token, this.project.id); |
| 62 | + } |
| 63 | + |
| 64 | + public async addTestToSuite(testId: number, suiteId: number) { |
| 65 | + return sendPost(Endpoints.testToSuite, { testId, suiteId, projectId: this.project.id }, {}, this.token, this.project.id); |
| 66 | + } |
| 67 | + |
| 68 | + public async getSuites(testSuite: TestSuite): Promise<TestSuite[]> { |
| 69 | + return sendGet(Endpoints.suite, testSuite, this.token, this.project.id); |
| 70 | + } |
| 71 | + |
| 72 | + public async getTests(test: Test): Promise<Test[]> { |
| 73 | + return sendGet(Endpoints.test, test, this.token, this.project.id); |
| 74 | + } |
| 75 | + |
| 76 | + public async getResults(testResult: TestResult): Promise<TestResult[]> { |
| 77 | + return sendGet(Endpoints.testresult, testResult, this.token, this.project.id); |
| 78 | + } |
| 79 | + |
| 80 | + public async getTestRuns(testrun: TestRun): Promise<TestRun[]> { |
| 81 | + return sendGet(Endpoints.testrun, testrun, this.token, this.project.id); |
| 82 | + } |
| 83 | + |
| 84 | + public async removeTestRun(testRunId: number) { |
| 85 | + return sendDelete(Endpoints.testrun, { id: testRunId, projectId: this.project.id}, null, this.token, this.project.id); |
| 86 | + } |
| 87 | +} |
0 commit comments