• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / crdc-datahub-ui / 17132131774

21 Aug 2025 03:52PM UTC coverage: 77.592% (+1.7%) from 75.941%
17132131774

Pull #806

github

web-flow
Merge 6b88b37d9 into c10ceac73
Pull Request #806: Submission Request Excel Import & Export CRDCDH-3033, CRDCDH-3045, CRDCDH-3063

4841 of 5322 branches covered (90.96%)

Branch coverage included in aggregate %.

3122 of 3394 new or added lines in 32 files covered. (91.99%)

7 existing lines in 3 files now uncovered.

28996 of 38287 relevant lines covered (75.73%)

1856.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.5
/src/utils/zodUtils.ts
1
import { cloneDeep, has, unset } from "lodash";
1✔
2
import z from "zod";
3

4
import { Logger } from "./logger";
1✔
5

6
/**
7
 * This function will remove the fields that are not valid according to the schema
8
 *
9
 * @template S
10
 * @param {S} schema - The Zod schema to validate against.
11
 * @param {object} data - The object to parse against the schema.
12
 * @returns {Partial<z.infer<S>>} - The parsed and validated object with all fields optional.
13
 */
14
export const parseSchemaObject = <S extends z.ZodObject>(
1✔
15
  schema: S,
30✔
16
  data: object
30✔
17
): Partial<z.infer<S>> => {
30✔
18
  const result = schema.safeParse(data);
30✔
19
  if (result.success) {
30✔
20
    return result.data;
10✔
21
  }
10✔
22

23
  Logger.error(
20✔
24
    `parseSchemaObject: Failed schema validation. Will try to extract invalid fields.`,
20✔
25
    data
20✔
26
  );
20✔
27

28
  const issues = result?.error?.issues;
20✔
29
  const errorFields = issues.map((issue) => issue.path).filter((path) => path?.length > 0);
30✔
30

31
  const clonedData = cloneDeep(data);
30✔
32
  for (const path of errorFields) {
30✔
33
    if (!has(clonedData, path)) {
100!
NEW
34
      break;
×
NEW
35
    }
×
36
    const success = unset(clonedData, path);
100✔
37

38
    if (!success) {
100!
NEW
39
      Logger.error(
×
NEW
40
        `parseSchemaObject: Failed to unset path ${JSON.stringify(path)} in object.`,
×
NEW
41
        data
×
NEW
42
      );
×
NEW
43
    }
×
44
  }
100✔
45

46
  return clonedData;
20✔
47
};
20✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc