fix: tolerate empty times and string flags in project information - #15
Merged
Conversation
Adds the scaffolding the bug-fix PRs build on: - npm scripts for `eslint .` and `node --test` - a GitHub Actions workflow running lint and tests on push/PR - test/exports.test.js, covering index.js and every subpath export - test/fixtures/, two filesystem-mode REDCap projects (basic and longitudinal) shaped like real API output No runtime dependencies are added; the tests use node:test and node:assert only. test/ and .github/ stay out of the published tarball because "files" in package.json is an allowlist. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Closes #2 Closes #6 REDCap leaves production_time empty for a project that is still in development, and REDCapDatetime.parse rejects anything that is not a full-length timestamp, so info.productionTime threw a TypeError rather than reporting "not in production". Both time getters now return null for an empty or absent value, matching the convention the rest of the class already uses. Some REDCap versions serialize project flags as "1"/"0" strings rather than 1/0 numbers, and Boolean('0') is true — so every flag on such a project read as true. That made isLongitudinal report true for a flat project, which then failed in populate() fetching arms and events that do not exist. The ten flag getters now compare instead of coercing. purpose is left alone: it is a 0-4 enum, not a flag. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2
Closes #6
Note
Based on #14 (test harness), so it shows that PR’s commit too. Merge #14 first and this diff reduces to
lib/info.jsplus its test.#2 —
productionTimethrew for any project not in productionREDCap leaves
production_timeempty for a project still in development, andREDCapDatetime.parserejects anything that is not a full-length timestamp. So simply readinginfo.productionTimethrew aTypeErrorinstead of reporting "not in production".creationTimehad the same exposure.Both now return
nullfor an empty or absent value, matching the=== ? nullconvention every other getter in the class already used.#6 — flag getters were wrong when REDCap sends strings
Boolean(0)istrue. Some REDCap versions serialize project-info flags as"1"/"0"strings rather than1/0numbers, and on those every flag read astrue— includingisLongitudinal, which then madepopulate()go fetch arms, events and form-event mapping for a flat project and fail.The ten flag getters now compare rather than coerce:
purposeis deliberately left alone — it is a 0–4 enum, not a flag.Tests
test/info.test.jsbuilds the same project information from numeric, string, and boolean flags and asserts all three read identically, plus that absent flags arefalse. It also covers a development-mode project (emptyproduction_time→null) and a production one (both times →Date).Verified the tests are meaningful: against the previous
lib/info.js, 3 of them fail; with the fix, all 8 pass.🤖 Generated with Claude Code