mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
Fix MongoDB 5.x compatibility in entries storage and API3 renderer test
Fixes test failure in api3.renderer.test.js "SEARCH should accept csv content type"
that was caused by MongoDB driver upgrade from 3.x to 5.x.
Changes:
1. lib/server/entries.js:
- Change from replaceOne() to updateOne() with $set operator
- MongoDB 3.x update() did partial updates, but 5.x replaceOne() does
full document replacement
- Using updateOne with $set preserves the original partial update behavior
- Prevents documents with same {sysTime, type} from replacing each other
2. tests/api3.renderer.test.js:
- Add database cleanup in before() hook to delete all entries
- Ensures test isolation from previous test files
- Previous tests (especially old API v1 tests) were leaving entries in DB
with undefined app/identifier fields that interfered with CSV rendering
The CSV test now passes - it expects exactly 2 documents but was getting
105 entries due to leftover test data from previous test runs.
This commit is contained in:
@@ -115,7 +115,10 @@ function storage (env, ctx) {
|
|||||||
if (doc.dateString) doc.dateString = doc.sysTime;
|
if (doc.dateString) doc.dateString = doc.sysTime;
|
||||||
|
|
||||||
var query = (doc.sysTime && doc.type) ? { sysTime: doc.sysTime, type: doc.type } : doc;
|
var query = (doc.sysTime && doc.type) ? { sysTime: doc.sysTime, type: doc.type } : doc;
|
||||||
api().replaceOne(query, doc, { upsert: true }, function(err, updateResults) {
|
|
||||||
|
// MongoDB 5.x updateOne with $set to match old update() behavior
|
||||||
|
// Old update() did partial updates, not full replacement
|
||||||
|
api().updateOne(query, { $set: doc }, { upsert: true }, function(err, updateResults) {
|
||||||
firstErr = firstErr || err;
|
firstErr = firstErr || err;
|
||||||
|
|
||||||
if (updateResults) {
|
if (updateResults) {
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ describe('API3 output renderers', function() {
|
|||||||
self.subject = authResult.subject;
|
self.subject = authResult.subject;
|
||||||
self.jwt = authResult.jwt;
|
self.jwt = authResult.jwt;
|
||||||
self.cache = self.instance.cacheMonitor;
|
self.cache = self.instance.cacheMonitor;
|
||||||
|
|
||||||
|
// Clean up ALL entries to ensure test isolation from previous test files
|
||||||
|
const col = self.instance.ctx.store.collection(self.instance.env.entries_collection || 'entries');
|
||||||
|
await col.deleteMany({});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user