Skip to content

Commit 0d7d40e

Browse files
committed
some adjusts
1 parent e17fdaa commit 0d7d40e

File tree

5 files changed

+245
-12
lines changed

5 files changed

+245
-12
lines changed

components/testmonitor/actions/create-test-result/create-test-result.mjs

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { ConfigurationError } from "@pipedream/platform";
2+
import FormData from "form-data";
3+
import fs from "fs";
4+
import {
5+
checkTmp, parseObject,
6+
} from "../../common/utils.mjs";
27
import testmonitor from "../../testmonitor.app.mjs";
38

49
export default {
@@ -37,6 +42,24 @@ export default {
3742
type: "boolean",
3843
label: "Draft",
3944
description: "Denotes if this test result is marked as draft.",
45+
reloadProps: true,
46+
},
47+
attachments: {
48+
type: "string[]",
49+
label: "Attachments",
50+
description: "A list of attachment files.",
51+
hidden: true,
52+
optional: true,
53+
},
54+
testResultStatusId: {
55+
propDefinition: [
56+
testmonitor,
57+
"testResultStatusId",
58+
({ projectId }) => ({
59+
projectId,
60+
}),
61+
],
62+
hidden: true,
4063
},
4164
description: {
4265
type: "string",
@@ -45,20 +68,54 @@ export default {
4568
optional: true,
4669
},
4770
},
71+
async additionalProps(props) {
72+
if (!this.draft) {
73+
props.attachments.hidden = false;
74+
props.testResultStatusId.hidden = false;
75+
}
76+
return {};
77+
},
4878
async run({ $ }) {
79+
let testResultId;
80+
let summary;
4981
try {
5082
const response = await this.testmonitor.createTestResult({
5183
$,
5284
data: {
5385
test_case_id: this.testCaseId,
5486
test_run_id: this.testRunId,
55-
draft: this.draft,
5687
description: this.description,
88+
draft: true,
89+
},
90+
});
91+
testResultId = response.data.id;
92+
93+
try {
94+
for (const file of parseObject(this.attachments)) {
95+
const data = new FormData();
96+
data.append("file", fs.createReadStream(checkTmp(file)));
97+
await this.testmonitor.uploadAttachment({
98+
$,
99+
testResultId,
100+
data,
101+
headers: data.getHeaders(),
102+
});
103+
}
104+
} catch (e) {
105+
summary = ", but the attachments could not be loaded.";
106+
}
107+
108+
const updateResponse = await this.testmonitor.updateTestResult({
109+
$,
110+
testResultId,
111+
data: {
112+
draft: this.draft,
113+
test_result_status_id: this.testResultStatusId,
57114
},
58115
});
59116

60-
$.export("$summary", `Successfully created test result with Id: ${response.data.id}`);
61-
return response;
117+
$.export("$summary", `Successfully created test result with Id: ${testResultId}${summary}`);
118+
return updateResponse;
62119
} catch (e) {
63120
throw new ConfigurationError((e.response.status === 400)
64121
? "It seems that there is already a test with this configuration!"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const checkTmp = (filename) => {
2+
if (!filename.startsWith("/tmp")) {
3+
return `/tmp/${filename}`;
4+
}
5+
return filename;
6+
};
7+
8+
export const parseObject = (obj) => {
9+
if (!obj) return undefined;
10+
11+
if (Array.isArray(obj)) {
12+
return obj.map((item) => {
13+
if (typeof item === "string") {
14+
try {
15+
return JSON.parse(item);
16+
} catch (e) {
17+
return item;
18+
}
19+
}
20+
return item;
21+
});
22+
}
23+
if (typeof obj === "string") {
24+
try {
25+
return JSON.parse(obj);
26+
} catch (e) {
27+
return obj;
28+
}
29+
}
30+
return obj;
31+
};

components/testmonitor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
1313
"@pipedream/platform": "^3.0.3",
14+
"fs": "^0.0.1-security",
1415
"moment": "^2.29.4"
1516
},
1617
"publishConfig": {

components/testmonitor/testmonitor.app.mjs

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ export default {
9696
}));
9797
},
9898
},
99+
testResultStatusId: {
100+
type: "integer",
101+
label: "Test Result Status Id",
102+
description: "The test result status identifier.",
103+
async options({
104+
page, projectId,
105+
}) {
106+
const { data } = await this.getResultStatuses({
107+
params: {
108+
page: page + 1,
109+
project_id: projectId,
110+
},
111+
});
112+
113+
return data.map(({
114+
id: value, name: label,
115+
}) => ({
116+
label,
117+
value,
118+
}));
119+
},
120+
},
99121
query: {
100122
type: "string",
101123
label: "Query",
@@ -130,20 +152,23 @@ export default {
130152
_apiUrl() {
131153
return `https://${this.$auth.domain}.testmonitor.com/api/v1`;
132154
},
133-
_getHeaders() {
155+
_getHeaders(headers = {}) {
134156
return {
157+
...headers,
135158
"Authorization": `Bearer ${this.$auth.api_token}`,
136159
};
137160
},
138161
async _makeRequest({
139-
$ = this, path, ...opts
162+
$ = this, path, headers, ...opts
140163
}) {
141164
const config = {
142165
url: `${this._apiUrl()}/${path}`,
143-
headers: this._getHeaders(),
166+
headers: this._getHeaders(headers),
144167
...opts,
145168
};
146169

170+
console.log("config: ", config);
171+
147172
return axios($, config);
148173
},
149174
createTestResult(opts = {}) {
@@ -153,6 +178,24 @@ export default {
153178
...opts,
154179
});
155180
},
181+
updateTestResult({
182+
testResultId, ...opts
183+
}) {
184+
return this._makeRequest({
185+
method: "PUT",
186+
path: `test-results/${testResultId}`,
187+
...opts,
188+
});
189+
},
190+
uploadAttachment({
191+
testResultId, ...opts
192+
}) {
193+
return this._makeRequest({
194+
method: "POST",
195+
path: `test-result/${testResultId}/attachments`,
196+
...opts,
197+
});
198+
},
156199
getTestCases(opts = {}) {
157200
return this._makeRequest({
158201
path: "test-cases",
@@ -166,11 +209,11 @@ export default {
166209
});
167210
},
168211
getIssue({
169-
$, issueId,
212+
issueId, ...opts
170213
}) {
171214
return this._makeRequest({
172-
$,
173215
path: `issues/${issueId}`,
216+
...opts,
174217
});
175218
},
176219
getIssues(params) {
@@ -180,11 +223,11 @@ export default {
180223
});
181224
},
182225
getProject({
183-
$, projectId,
226+
projectId, ...opts
184227
}) {
185228
return this._makeRequest({
186-
$,
187229
path: `projects/${projectId}`,
230+
...opts,
188231
});
189232
},
190233
getProjects(params) {
@@ -194,11 +237,17 @@ export default {
194237
});
195238
},
196239
getTestResult({
197-
$, testResultId,
240+
testResultId, ...opts
198241
}) {
199242
return this._makeRequest({
200-
$,
201243
path: `test-results/${testResultId}`,
244+
...opts,
245+
});
246+
},
247+
getResultStatuses(opts = {}) {
248+
return this._makeRequest({
249+
path: "test-result-statuses",
250+
...opts,
202251
});
203252
},
204253
getTestResults(params) {

components/testmonitor/yarn.lock

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@pipedream/platform@^3.0.3":
6+
version "3.0.3"
7+
resolved "https://registry.yarnpkg.com/@pipedream/platform/-/platform-3.0.3.tgz#b0f1d1274e061fb581635a30fabc830358975fd2"
8+
integrity sha512-7elalas41lnT8i6EAFkqB7fT/+hkLGEQ1njS6A7CVguTrEswaIYk/seKmkfkRY7+O6qncgnXswYIKCBML9Co7w==
9+
dependencies:
10+
axios "^1.7.4"
11+
fp-ts "^2.0.2"
12+
io-ts "^2.0.0"
13+
querystring "^0.2.1"
14+
15+
asynckit@^0.4.0:
16+
version "0.4.0"
17+
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
18+
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
19+
20+
axios@^1.7.4:
21+
version "1.7.9"
22+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.9.tgz#d7d071380c132a24accda1b2cfc1535b79ec650a"
23+
integrity sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==
24+
dependencies:
25+
follow-redirects "^1.15.6"
26+
form-data "^4.0.0"
27+
proxy-from-env "^1.1.0"
28+
29+
combined-stream@^1.0.8:
30+
version "1.0.8"
31+
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
32+
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
33+
dependencies:
34+
delayed-stream "~1.0.0"
35+
36+
delayed-stream@~1.0.0:
37+
version "1.0.0"
38+
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
39+
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
40+
41+
follow-redirects@^1.15.6:
42+
version "1.15.9"
43+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
44+
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==
45+
46+
form-data@^4.0.0:
47+
version "4.0.1"
48+
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.1.tgz#ba1076daaaa5bfd7e99c1a6cb02aa0a5cff90d48"
49+
integrity sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==
50+
dependencies:
51+
asynckit "^0.4.0"
52+
combined-stream "^1.0.8"
53+
mime-types "^2.1.12"
54+
55+
fp-ts@^2.0.2:
56+
version "2.16.9"
57+
resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-2.16.9.tgz#99628fc5e0bb3b432c4a16d8f4455247380bae8a"
58+
integrity sha512-+I2+FnVB+tVaxcYyQkHUq7ZdKScaBlX53A41mxQtpIccsfyv8PzdzP7fzp2AY832T4aoK6UZ5WRX/ebGd8uZuQ==
59+
60+
fs@^0.0.1-security:
61+
version "0.0.1-security"
62+
resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4"
63+
integrity sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==
64+
65+
io-ts@^2.0.0:
66+
version "2.2.21"
67+
resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.2.21.tgz#4ef754176f7082a1099d04c7d5c4ea53267c530a"
68+
integrity sha512-zz2Z69v9ZIC3mMLYWIeoUcwWD6f+O7yP92FMVVaXEOSZH1jnVBmET/urd/uoarD1WGBY4rCj8TAyMPzsGNzMFQ==
69+
70+
71+
version "1.52.0"
72+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
73+
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
74+
75+
mime-types@^2.1.12:
76+
version "2.1.35"
77+
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
78+
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
79+
dependencies:
80+
mime-db "1.52.0"
81+
82+
moment@^2.29.4:
83+
version "2.30.1"
84+
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
85+
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==
86+
87+
proxy-from-env@^1.1.0:
88+
version "1.1.0"
89+
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
90+
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
91+
92+
querystring@^0.2.1:
93+
version "0.2.1"
94+
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd"
95+
integrity sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==

0 commit comments

Comments
 (0)