froth-webdriverio-framework 7.0.28 → 7.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
const aes = require('./aesEncryptionDecryption');
|
|
2
|
+
|
|
1
3
|
// Function to get suite details using Bearer token
|
|
2
4
|
async function getSuiteDetails(frothUrl, token, suiteId) {
|
|
3
5
|
// Default response structure
|
|
4
|
-
|
|
6
|
+
let jsonData = {
|
|
5
7
|
automation_suite_id: 0,
|
|
6
8
|
automation_suite_name: "",
|
|
7
9
|
test_data_id: 0,
|
|
@@ -16,10 +18,9 @@ async function getSuiteDetails(frothUrl, token, suiteId) {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
const url = `${frothUrl}/api/automationsuite-retrieve/${suiteId}/`;
|
|
21
|
+
console.log("Fetching Suite Details URL:", url);
|
|
19
22
|
|
|
20
23
|
try {
|
|
21
|
-
console.log("Fetching Suite Details URL:", url);
|
|
22
|
-
|
|
23
24
|
const response = await fetch(url, {
|
|
24
25
|
method: 'GET',
|
|
25
26
|
headers: {
|
|
@@ -28,26 +29,33 @@ async function getSuiteDetails(frothUrl, token, suiteId) {
|
|
|
28
29
|
}
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
console.error(
|
|
44
|
-
|
|
45
|
-
else {
|
|
46
|
-
const errorText = await response.text();
|
|
47
|
-
console.error(
|
|
48
|
-
`Failed to fetch suite details. Status: ${response.status}, Response: ${errorText}`
|
|
49
|
-
);
|
|
32
|
+
let resData = await handleResponse(response, 'getSuiteDetails');
|
|
33
|
+
if (!resData || !resData.data) return jsonData;
|
|
34
|
+
|
|
35
|
+
// Decrypt the data
|
|
36
|
+
let decryptedData = await aes.decrpytData(resData.data);
|
|
37
|
+
if (!decryptedData) return jsonData;
|
|
38
|
+
|
|
39
|
+
// Parse JSON
|
|
40
|
+
let data;
|
|
41
|
+
try {
|
|
42
|
+
data = JSON.parse(decryptedData);
|
|
43
|
+
} catch (parseError) {
|
|
44
|
+
console.error('Failed to parse decrypted data:', parseError);
|
|
45
|
+
return jsonData;
|
|
50
46
|
}
|
|
47
|
+
|
|
48
|
+
// Map data to default structure
|
|
49
|
+
jsonData = {
|
|
50
|
+
automation_suite_id: data.id ?? 0,
|
|
51
|
+
automation_suite_name: data.automation_suite_name ?? "",
|
|
52
|
+
test_data_id: data.test_data_id ?? 0,
|
|
53
|
+
script_details: data.script_details ?? [],
|
|
54
|
+
test_sequence: data.test_sequence ?? null
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
console.log("Suite JSON Data:", JSON.stringify(jsonData));
|
|
58
|
+
|
|
51
59
|
} catch (error) {
|
|
52
60
|
console.error('Error while fetching suite details:', error);
|
|
53
61
|
}
|
|
@@ -55,4 +63,20 @@ async function getSuiteDetails(frothUrl, token, suiteId) {
|
|
|
55
63
|
return jsonData;
|
|
56
64
|
}
|
|
57
65
|
|
|
66
|
+
// Helper function to handle API responses
|
|
67
|
+
async function handleResponse(response, context) {
|
|
68
|
+
if (response.ok) {
|
|
69
|
+
return response.json();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (response.status === 401) {
|
|
73
|
+
console.error(`🔒 Unauthorized (401) in ${context}`);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const errorText = await response.text();
|
|
78
|
+
console.error(`❌ ${context} failed [${response.status}]: ${errorText}`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
58
82
|
module.exports = getSuiteDetails;
|