Skip to content

Commit fed537e

Browse files
committed
Submit Defect + reusing field methods for requirements
1 parent cd78dcc commit fed537e

File tree

4 files changed

+75
-13
lines changed

4 files changed

+75
-13
lines changed

components/tricentis_qtest/actions/create-requirement/create-requirement.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
getRequirementFieldProps as additionalProps, getProperties,
2+
getFieldProps as additionalProps, getProperties,
33
} from "../../common/utils.mjs";
44
import tricentisQtest from "../../tricentis_qtest.app.mjs";
55

@@ -40,11 +40,14 @@ export default {
4040
},
4141
additionalProps,
4242
methods: {
43+
getDataFields() {
44+
return this.tricentisQtest.getRequirementFields(this.projectId);
45+
},
4346
getProperties,
4447
},
4548
async run({ $ }) {
4649
const { // eslint-disable-next-line no-unused-vars
47-
tricentisQtest, projectId, parentId, useFields, name, getProperties, ...fields
50+
tricentisQtest, projectId, parentId, useFields, name, getProperties, getDataFields, ...fields
4851
} = this;
4952
const response = await tricentisQtest.createRequirement({
5053
$,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
getFieldProps as additionalProps, getProperties,
3+
} from "../../common/utils.mjs";
4+
import tricentisQtest from "../../tricentis_qtest.app.mjs";
5+
6+
export default {
7+
key: "tricentis_qtest-submit-defect",
8+
name: "Submit Defect",
9+
description: "Submit a new defect. [See the documentation](https://documentation.tricentis.com/qtest/od/en/content/apis/apis/defect_apis.htm#SubmitaDefect)",
10+
version: "0.0.{{ts}}",
11+
type: "action",
12+
props: {
13+
tricentisQtest,
14+
projectId: {
15+
propDefinition: [
16+
tricentisQtest,
17+
"projectId",
18+
],
19+
reloadProps: true,
20+
},
21+
},
22+
additionalProps,
23+
methods: {
24+
getDataFields() {
25+
return this.tricentisQtest.getDefectFields(this.projectId);
26+
},
27+
getProperties,
28+
},
29+
async run({ $ }) {
30+
const { // eslint-disable-next-line no-unused-vars
31+
tricentisQtest, projectId, getProperties, getDataFields, ...fields
32+
} = this;
33+
const response = await tricentisQtest.createDefect({
34+
$,
35+
projectId,
36+
data: {
37+
properties: getProperties(fields),
38+
},
39+
});
40+
$.export("$summary", `Successfully submitted defect (ID: ${response.id})`);
41+
return response;
42+
},
43+
};

components/tricentis_qtest/actions/update-requirement/update-requirement.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
getRequirementFieldProps as additionalProps, getProperties,
2+
getFieldProps as additionalProps, getProperties,
33
} from "../../common/utils.mjs";
44
import tricentisQtest from "../../tricentis_qtest.app.mjs";
55

@@ -40,12 +40,22 @@ export default {
4040
},
4141
additionalProps,
4242
methods: {
43+
getDataFields() {
44+
return this.tricentisQtest.getRequirementFields(this.projectId);
45+
},
4346
getProperties,
4447
},
4548
async run({ $ }) {
46-
const { // eslint-disable-next-line no-unused-vars
47-
tricentisQtest, projectId, requirementId, useFields, name, getProperties, ...fields
48-
} = this;
49+
const { /* eslint-disable no-unused-vars */
50+
tricentisQtest,
51+
projectId,
52+
requirementId,
53+
useFields,
54+
name,
55+
getProperties,
56+
getDataFields,
57+
...fields
58+
} = this; /* eslint-enable no-unused-vars */
4959
const response = await tricentisQtest.updateRequirement({
5060
$,
5161
projectId,

components/tricentis_qtest/common/utils.mjs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export async function getRequirementFieldProps() {
2-
if (!this.useFields) return {};
1+
export async function getFieldProps() {
2+
if (this.useFields === false) return {};
33

4-
const fields = await this.tricentisQtest.getRequirementFields(this.projectId);
4+
const fields = await this.getDataFields();
55

66
function getFieldType(type) {
77
switch (type) {
@@ -15,22 +15,28 @@ export async function getRequirementFieldProps() {
1515
}
1616
}
1717

18+
console.log(fields);
19+
1820
const result = {};
21+
const isUpdate = this.requirementId || this.defectId;
1922

2023
fields?.forEach(({
21-
id, label, attribute_type: type, allowed_values: options,
24+
id, label, attribute_type: fieldType, allowed_values: options, required,
2225
}) => {
26+
const type = getFieldType(fieldType);
2327
result[`field_${id}`] = {
2428
label,
25-
type: getFieldType(type),
29+
type,
2630
description: `Field ID: ${id}`,
27-
optional: true,
31+
optional: isUpdate || !required,
2832
...(options && {
2933
options: options.map(({
3034
label, value,
3135
}) => ({
3236
label,
33-
value,
37+
value: (type === "string" && typeof value !== "string")
38+
? value.toString()
39+
: value,
3440
})),
3541
}),
3642
};

0 commit comments

Comments
 (0)