Skip to content

Commit 6570c28

Browse files
committed
refactoring
1 parent 95d6a26 commit 6570c28

File tree

5 files changed

+52
-63
lines changed

5 files changed

+52
-63
lines changed

src/components/TestDetailsModal.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import {
1212
} from "@material-ui/core";
1313
import { TestRun } from "../types";
1414
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles";
15-
import {
16-
testsService,
17-
testRunService,
18-
testVariationService,
19-
} from "../services";
15+
import { testRunService, testVariationService } from "../services";
2016
import DrawArea from "./DrawArea";
2117
import { TestStatus } from "../types/testStatus";
2218
import { useHistory, Prompt } from "react-router-dom";
@@ -106,7 +102,7 @@ const TestDetailsModal: React.FunctionComponent<{
106102
<Button
107103
color="inherit"
108104
onClick={() =>
109-
testsService.approve(testRun.id).then((testRun) => {
105+
testRunService.approve(testRun.id).then((testRun) => {
110106
updateTestRun(testRun);
111107
})
112108
}
@@ -116,7 +112,7 @@ const TestDetailsModal: React.FunctionComponent<{
116112
<Button
117113
color="secondary"
118114
onClick={() =>
119-
testsService
115+
testRunService
120116
.reject(testRun.id)
121117
.then((testRun) => updateTestRun(testRun))
122118
}

src/pages/ProjectPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
22
import { Grid, Dialog, IconButton, Box, Typography } from "@material-ui/core";
33
import { useParams, useLocation, useHistory } from "react-router-dom";
44
import { Build, TestRun } from "../types";
5-
import { projectsService, buildsService, testsService } from "../services";
5+
import { projectsService, buildsService, testRunService } from "../services";
66
import BuildList from "../components/BuildList";
77
import ProjectSelect from "../components/ProjectSelect";
88
import qs from "qs";
@@ -150,7 +150,7 @@ const ProjectPage = () => {
150150
items={filteredTestRuns}
151151
selectedId={selectedTestdId}
152152
handleRemove={(id: string) =>
153-
testsService.remove(id).then((isRemoved) => {
153+
testRunService.remove(id).then((isRemoved) => {
154154
if (isRemoved) {
155155
setTestRuns(testRuns.filter((item) => item.id !== id));
156156
}

src/services/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export * from './users.service';
22
export * from './projects.service'
33
export * from './builds.service'
4-
export * from './tests.service'
54
export * from './static.service'
65
export * from './testVariation.service'
76
export * from './testRun.service'

src/services/testRun.service.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,55 @@ import { IgnoreArea } from "../types/ignoreArea";
66
const ENDPOINT_URL = "/test-runs"
77

88
export const testRunService = {
9-
setIgnoreAreas
9+
get,
10+
remove,
11+
approve,
12+
reject,
13+
setIgnoreAreas,
1014
};
1115

16+
function get(testId: string): Promise<TestRun> {
17+
const requestOptions = {
18+
method: "GET",
19+
headers: authHeader(),
20+
};
21+
22+
return fetch(`${API_URL}${ENDPOINT_URL}/${testId}`, requestOptions).then(
23+
handleResponse
24+
);
25+
}
26+
27+
function remove(id: string): Promise<Number> {
28+
const requestOptions = {
29+
method: "DELETE",
30+
headers: authHeader(),
31+
};
32+
33+
return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(handleResponse);
34+
}
35+
36+
function approve(id: string): Promise<TestRun> {
37+
const requestOptions = {
38+
method: "GET",
39+
headers: authHeader(),
40+
};
41+
42+
return fetch(`${API_URL}${ENDPOINT_URL}/approve/${id}`, requestOptions).then(
43+
handleResponse
44+
);
45+
}
46+
47+
function reject(id: string): Promise<TestRun> {
48+
const requestOptions = {
49+
method: "GET",
50+
headers: authHeader(),
51+
};
52+
53+
return fetch(`${API_URL}${ENDPOINT_URL}/reject/${id}`, requestOptions).then(
54+
handleResponse
55+
);
56+
}
57+
1258
function setIgnoreAreas(
1359
id: string,
1460
ignoreAreas: IgnoreArea[]

src/services/tests.service.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)