Skip to content

Commit baf8c4a

Browse files
authored
Merging pull request #14803
* [Action] TestMonitor - Create a new Test Result #13990 Actions - Create New Test Result * update pnpm * some adjusts * pnpm update * soem adjusts
1 parent 80fa385 commit baf8c4a

File tree

11 files changed

+385
-18
lines changed

11 files changed

+385
-18
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
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";
7+
import testmonitor from "../../testmonitor.app.mjs";
8+
9+
export default {
10+
key: "testmonitor-create-test-result",
11+
name: "Create Test Result",
12+
description: "Create a new test result. [See the docs here](https://docs.testmonitor.com/#tag/Test-Results/operation/PostTestResult)",
13+
version: "0.0.1",
14+
type: "action",
15+
props: {
16+
testmonitor,
17+
projectId: {
18+
propDefinition: [
19+
testmonitor,
20+
"projectId",
21+
],
22+
},
23+
testCaseId: {
24+
propDefinition: [
25+
testmonitor,
26+
"testCaseId",
27+
({ projectId }) => ({
28+
projectId,
29+
}),
30+
],
31+
},
32+
testRunId: {
33+
propDefinition: [
34+
testmonitor,
35+
"testRunId",
36+
({ projectId }) => ({
37+
projectId,
38+
}),
39+
],
40+
},
41+
draft: {
42+
type: "boolean",
43+
label: "Draft",
44+
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,
63+
},
64+
description: {
65+
type: "string",
66+
label: "Description",
67+
description: "The description of the test result.",
68+
optional: true,
69+
},
70+
},
71+
async additionalProps(props) {
72+
if (!this.draft) {
73+
props.attachments.hidden = false;
74+
props.testResultStatusId.hidden = false;
75+
}
76+
return {};
77+
},
78+
async run({ $ }) {
79+
let testResultId;
80+
let summary = "";
81+
try {
82+
const response = await this.testmonitor.createTestResult({
83+
$,
84+
data: {
85+
test_case_id: this.testCaseId,
86+
test_run_id: this.testRunId,
87+
description: this.description,
88+
draft: true,
89+
},
90+
});
91+
testResultId = response.data.id;
92+
93+
if (this.attachments) {
94+
try {
95+
for (const file of parseObject(this.attachments)) {
96+
const data = new FormData();
97+
data.append("file", fs.createReadStream(checkTmp(file)));
98+
await this.testmonitor.uploadAttachment({
99+
$,
100+
testResultId,
101+
data,
102+
headers: data.getHeaders(),
103+
});
104+
}
105+
} catch (e) {
106+
summary = ", but the attachments could not be loaded.";
107+
}
108+
}
109+
110+
const updateResponse = await this.testmonitor.updateTestResult({
111+
$,
112+
testResultId,
113+
data: {
114+
draft: this.draft,
115+
test_result_status_id: this.testResultStatusId,
116+
},
117+
});
118+
119+
$.export("$summary", `Successfully created test result with Id: ${testResultId}${summary}`);
120+
return updateResponse;
121+
} catch (e) {
122+
throw new ConfigurationError((e.response.status === 400)
123+
? "It seems that there is already a test with this configuration!"
124+
: e.response.data.message);
125+
}
126+
},
127+
};

components/testmonitor/actions/find-issue/find-issue.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "testmonitor-find-issue",
77
name: "Find an Issue",
88
description: "Retrieve a list of issues. [See the docs here](https://docs.testmonitor.com/#tag/Issues/operation/GetIssueCollection)",
9-
version: "0.0.2",
9+
version: "0.0.3",
1010
type: "action",
1111
props: {
1212
...common.props,

components/testmonitor/actions/find-project/find-project.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "testmonitor-find-project",
77
name: "Find a Project",
88
description: "Retrieve a list of projects. [See the docs here](https://docs.testmonitor.com/#tag/Projects/operation/GetProjectCollection)",
9-
version: "0.0.2",
9+
version: "0.0.3",
1010
type: "action",
1111
props: {
1212
...common.props,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "testmonitor-find-test-result",
77
name: "Find a Test Result",
88
description: "Retrieve a list of test results. [See the docs here](https://docs.testmonitor.com/#tag/Test-Results/operation/GetTestResultCollection)",
9-
version: "0.0.2",
9+
version: "0.0.3",
1010
type: "action",
1111
props: {
1212
...common.props,
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/testmonitor",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Pipedream Testmonitor Components",
55
"main": "testmonitor.app.mjs",
66
"keywords": [
@@ -10,7 +10,8 @@
1010
"homepage": "https://pipedream.com/apps/testmonitor",
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^1.2.1",
13+
"@pipedream/platform": "^3.0.3",
14+
"fs": "^0.0.1-security",
1415
"moment": "^2.29.4"
1516
},
1617
"publishConfig": {

components/testmonitor/sources/new-issue/new-issue.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "testmonitor-new-issue",
66
name: "New Issue",
77
description: "Emit new event when a new issue is created.",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {

components/testmonitor/sources/new-test-result/new-test-result.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "testmonitor-new-test-result",
66
name: "New Test Result",
77
description: "Emit new event when a new test result is created.",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {

0 commit comments

Comments
 (0)