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

opengovsg / formsg-javascript-sdk / 13652601401

04 Mar 2025 11:24AM UTC coverage: 97.495%. First build
13652601401

Pull #115

github

GitHub
Merge 8fbb6680c into 2c59c0547
Pull Request #115:

104 of 114 branches covered (91.23%)

Branch coverage included in aggregate %.

363 of 365 relevant lines covered (99.45%)

6.57 hits per line

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

95.24
/src/util/validate.ts
1
import { FormField, FormFieldsV3 } from '../types'
2

3
function determineIsFormFields(tbd: any): tbd is FormField[] {
4
  if (!Array.isArray(tbd)) {
16✔
5
    return false
1✔
6
  }
7

8
  // If there exists even a single internal response that does not fit the
9
  // shape, the object is not created properly.
10
  const filter = tbd.filter(
15✔
11
    (internal) =>
12
      // Have either answer or answerArray or is isHeader
13
      // Since empty strings are allowed, check using typeof.
14
      (typeof internal.answer === 'string' ||
161!
15
        Array.isArray(internal.answerArray) ||
16
        internal.isHeader) &&
17
      internal._id &&
18
      internal.fieldType &&
19
      // The field is still valid even when the question title is empty string
20
      // (even though it is not intended behavior).
21
      typeof internal.question === 'string'
22
  )
23

24
  return filter.length === tbd.length
15✔
25
}
26

27
// TODO(MRF): This is currently very rudimentary, we should look at making this more specific where required.
28
function determineIsFormFieldsV3(tbd: any): tbd is FormFieldsV3 {
29
  for (const id of Object.keys(tbd)) {
11✔
30
    const value = tbd[id]
11✔
31
    const hasCorrectShape = value.fieldType && value.answer !== undefined
11✔
32
    if (!hasCorrectShape) return false
11✔
33
  }
34
  return true
4✔
35
}
36

37
export { determineIsFormFields, determineIsFormFieldsV3 }
3✔
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

© 2026 Coveralls, Inc