Skip to content

Commit 0eee0ab

Browse files
committed
chore: clean up test/checks/build errors
1 parent 2201fd0 commit 0eee0ab

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

bc_obps/reporting/tests/models/program_configuration_tests/test_hydrogen_production_2024.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ def testCustomMethodologySchema(self):
9999
"properties": {
100100
"feedstock": {"type": "string", "title": "Feedstock"},
101101
"annualFeedstockAmount": {"type": "string", "title": "Annual Feedstock Amount"},
102-
"annualHydrogenProduction": {"type": "number", "title": "Annual Hydrogen Production"},
102+
"annualHydrogenProduction": {
103+
"type": "number",
104+
"title": "Annual Hydrogen Production",
105+
"minimum": 0,
106+
},
103107
"unitForAnnualFeedstockAmount": {
104108
"type": "string",
105109
"title": "Unit for Annual Feedstock Amount",

bc_obps/reporting/tests/models/program_configuration_tests/test_open_pit_coal_mining.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def testCustomMethodologySchema(self):
8989
# Define the expected schema for the "Feedstock Material Balance" methodology
9090
expected_schema = {
9191
"coalType": {"title": "Coal type", "type": "string", "enum": ["Bituminous coal"]},
92-
"quantityOfCoal": {"type": "number", "title": "Quantity of coal"},
92+
"quantityOfCoal": {"type": "number", "title": "Quantity of coal", "minimum": 0},
9393
"quantityOfCoalUnit": {
9494
"type": "string",
9595
"title": "Quantity of coal unit",

bciers/apps/reporting/src/app/components/activities/ActivityForm.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ export default function ActivityForm({
7373
setSelectedSourceTypeIds(initialSelectedSourceTypeIds);
7474
}, [currentActivity]);
7575

76-
const validator = customizeValidator({});
77-
const customValidate = (
78-
formData: { [key: string]: any },
79-
errors: { [key: string]: any },
80-
) => {
76+
const customValidate = (formData: { [key: string]: any }, errors: any) => {
8177
const results = findPathsWithNegativeNumbers(formData);
8278
results.forEach((result) => {
8379
setNestedErrorForCustomValidate(errors, result, "must be >= 0");

bciers/libs/utils/src/findInObject.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
export const findPathsWithNegativeNumbers = (obj: any, parentPath: string = ''): string[] => {
2-
let result: string[] = [];
1+
export const findPathsWithNegativeNumbers = (
2+
obj: any,
3+
parentPath: string = "",
4+
): string[] => {
5+
let result: string[] = [];
36

4-
// Depth first traversal through obj paths
5-
for (const key in obj) {
6-
const currPath = parentPath ? `${parentPath}.${key}` : key; // Attach key to current path
7-
const value = obj[key];
8-
9-
// Add full path if number and is negative, otherwise if there's another
10-
if (typeof(value) === 'number' && value < 0) result.push(currPath);
11-
else if (typeof(value) === 'object' && value) result = result.concat(findPathsWithNegativeNumbers(value, currPath));
12-
}
7+
// Depth first traversal through obj paths
8+
for (const key in obj) {
9+
const currPath = parentPath ? `${parentPath}.${key}` : key; // Attach key to current path
10+
const value = obj[key];
1311

14-
return result;
15-
}
12+
// Add full path if number and is negative, otherwise if there's another
13+
if (typeof value === "number" && value < 0) result.push(currPath);
14+
else if (typeof value === "object" && value)
15+
result = result.concat(findPathsWithNegativeNumbers(value, currPath));
16+
}
17+
18+
return result;
19+
};
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
const setNestedErrorForCustomValidate = (errors: any, path: string, errorMessage: string) => {
2-
const keys = path.split('.');
1+
const setNestedErrorForCustomValidate = (
2+
errors: any,
3+
path: string,
4+
errorMessage: string,
5+
) => {
6+
const keys = path.split(".");
37

4-
let curr = errors; // Initial object pointer
5-
for(const key of keys) {
6-
if (!curr[key]) return; // If doesn't exist, return
7-
curr = curr[key]; // Traverse another level deeper into the nested errorSchema
8-
}
8+
let curr = errors; // Initial object pointer
9+
for (const key of keys) {
10+
if (!curr[key]) return; // If doesn't exist, return
11+
curr = curr[key]; // Traverse another level deeper into the nested errorSchema
12+
}
913

10-
// Set error message when path is found at last object
11-
curr.addError(errorMessage);
12-
}
14+
// Set error message when path is found at last object
15+
curr.addError(errorMessage);
16+
};
1317

14-
export default setNestedErrorForCustomValidate;
18+
export default setNestedErrorForCustomValidate;

0 commit comments

Comments
 (0)