fix: legacy UUID treatments findable via $or fallback (#6923)

updateIdQuery() and upsertQueryFor() now use
  {$or: [{identifier: UUID}, {_id: UUID}]}
instead of only {identifier: UUID}. This matches both:
- New documents (UUID in identifier field, ObjectId in _id)
- Legacy documents (UUID directly in _id, no identifier field)

Gated behind env.uuidHandling (UUID_HANDLING env var, default true).

All 30 treatment tests pass:
- 3 legacy UUID tests (issue-6923): DELETE, PUT, GET all work
- 12 gap-treat-012 tests: new data paths unaffected
- 15 uuid-handling tests: edge cases, UUID_HANDLING=false still works

Fixes #6923 (unable to edit/save/delete overrides for legacy data)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Ben West
2026-03-25 15:20:51 -07:00
co-authored by Copilot
parent 98ee2bcb3e
commit 246e46adb3
3 changed files with 14 additions and 7 deletions
+5 -4
View File
@@ -1,7 +1,7 @@
'use strict';
/**
* Legacy UUID Data Test: Issue #6923 Reproduction
* Legacy UUID Data Test: Issue #6923 Regression
*
* ISSUE: https://github.com/nightscout/cgm-remote-monitor/issues/6923
*
@@ -11,10 +11,11 @@
*
* The test inserts a legacy-shaped document directly into MongoDB
* (bypassing normalizeTreatmentId) and then exercises the API
* DELETE and PUT paths that a user would trigger from Reports > Treatments.
* DELETE, PUT, and GET paths that a user would trigger from Reports > Treatments.
*
* EXPECTED RESULT: These tests FAIL, proving the legacy data bug.
* When all tests pass, the bug is fixed.
* FIX: updateIdQuery() and upsertQueryFor() now use $or to match both
* {identifier: UUID} (new docs) and {_id: UUID} (legacy docs).
* All 3 tests pass, confirming Loop can manage pre-existing overrides.
*/
const request = require('supertest');