@adobe/spacecat-shared-data-access 1.20.3 → 1.20.4
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.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/models/audit.js +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v1.20.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.20.3...@adobe/spacecat-shared-data-access-v1.20.4) (2024-03-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* audit result can be an array ([#189](https://github.com/adobe/spacecat-shared/issues/189)) ([6982907](https://github.com/adobe/spacecat-shared/commit/698290744cf15758f0d27c900484ac4949d42224))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-data-access-v1.20.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.20.2...@adobe/spacecat-shared-data-access-v1.20.3) (2024-03-18)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/models/audit.js
CHANGED
|
@@ -46,9 +46,7 @@ const validateScores = (auditResult, auditType) => {
|
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
if ((auditType === AUDIT_TYPE_LHS_DESKTOP
|
|
50
|
-
|| auditType === AUDIT_TYPE_LHS_MOBILE
|
|
51
|
-
|| auditType === AUDIT_TYPE_CWV)
|
|
49
|
+
if ((auditType === AUDIT_TYPE_LHS_DESKTOP || auditType === AUDIT_TYPE_LHS_MOBILE)
|
|
52
50
|
&& !isObject(auditResult.scores)) {
|
|
53
51
|
throw new Error(`Missing scores property for audit type '${auditType}'`);
|
|
54
52
|
}
|
|
@@ -93,6 +91,10 @@ const Audit = (data = {}) => {
|
|
|
93
91
|
return Object.freeze(self);
|
|
94
92
|
};
|
|
95
93
|
|
|
94
|
+
function isValidAuditResult(auditResult) {
|
|
95
|
+
return isObject(auditResult) || Array.isArray(auditResult);
|
|
96
|
+
}
|
|
97
|
+
|
|
96
98
|
/**
|
|
97
99
|
* Creates a new Audit.
|
|
98
100
|
*
|
|
@@ -114,8 +116,8 @@ export const createAudit = (data) => {
|
|
|
114
116
|
throw new Error('Audit type must be provided');
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
if (!
|
|
118
|
-
throw new Error('Audit result must be an object');
|
|
119
|
+
if (!isValidAuditResult(newState.auditResult)) {
|
|
120
|
+
throw new Error('Audit result must be an object or an array');
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
if (!newState.auditResult.scores) {
|
|
@@ -123,8 +125,8 @@ export const createAudit = (data) => {
|
|
|
123
125
|
}
|
|
124
126
|
validateScores(data.auditResult, data.auditType);
|
|
125
127
|
|
|
126
|
-
if (data.previousAuditResult && !
|
|
127
|
-
throw new Error('Previous audit result must be an object');
|
|
128
|
+
if (data.previousAuditResult && !isValidAuditResult(data.previousAuditResult)) {
|
|
129
|
+
throw new Error('Previous audit result must be an object or an array');
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
if (data.previousAuditResult) {
|