test: remove completed MongoDB 5.x array investigation tests

The 'WebSocket dbAdd Array Handling Investigation' block was R&D to
understand insertOne behavior with arrays. The investigation concluded:
- MongoDB's insertOne([a,b]) creates single doc (not multiple)
- Fix: sequential processing via processNextItem() in websocket.js

Production tests now cover this behavior:
- 'dbAdd with array input for treatments - current behavior test'
- 'dbAdd with array input for devicestatus - current behavior test'
- 'dbAdd with array input for entries - current behavior test'

Removes 2 flaky investigative tests, keeps 729 production tests passing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Ben West
2026-03-12 14:09:36 -07:00
co-authored by Copilot
parent ee3e6af76e
commit b76fb3e18a
-153
View File
@@ -488,156 +488,3 @@ describe('WebSocket Shape Handling - dbAdd Single vs Array Input', function () {
});
});
});
describe('WebSocket dbAdd Array Handling Investigation', function () {
this.timeout(15000);
var self = this;
var http = require('http');
var io = require('socket.io-client');
beforeEach(function (done) {
process.env.API_SECRET = 'this is my long pass phrase';
self.env = require('../lib/server/env')();
self.env.settings.authDefaultRoles = 'readable';
self.env.settings.enable = ['careportal', 'api'];
require('../lib/server/bootevent')(self.env, language).boot(function booted(ctx) {
self.ctx = ctx;
self.ctx.ddata = require('../lib/data/ddata')();
var app = require('express')();
app.enable('api');
var server = http.createServer(app);
require('../lib/server/websocket')(self.env, ctx, server);
server.listen(0, function () {
self.port = server.address().port;
self.server = server;
done();
});
});
});
afterEach(function (done) {
if (self.socket) {
self.socket.disconnect();
}
if (self.server) {
self.server.close(done);
} else {
done();
}
});
function connectAndAuthorize(callback) {
var socket = io('http://localhost:' + self.port, {
transports: ['websocket'],
reconnection: false
});
socket.on('connect', function () {
socket.emit('authorize', {
client: 'test',
secret: 'b723e97aa97846eb92d5264f084b2823f57c4aa1'
}, function (authResult) {
self.socket = socket;
callback(null, socket, authResult);
});
});
socket.on('connect_error', function (err) {
callback(err);
});
}
describe('Array input behavior with insertOne (MongoDB 5.x migration)', function () {
beforeEach(function (done) {
self.ctx.treatments.remove({ find: { created_at: { '$gte': '1999-01-01T00:00:00.000Z' } } }, function () {
done();
});
});
it('verify insertOne behavior when array is passed - EXPECTED TO DEMONSTRATE ISSUE', function (done) {
connectAndAuthorize(function (err, socket, authResult) {
if (err) return done(err);
var now = Date.now();
var testArray = [
{ eventType: 'Note', created_at: new Date(now).toISOString(), notes: 'array item 1' },
{ eventType: 'Note', created_at: new Date(now + 1000).toISOString(), notes: 'array item 2' },
{ eventType: 'Note', created_at: new Date(now + 2000).toISOString(), notes: 'array item 3' }
];
socket.emit('dbAdd', {
collection: 'treatments',
data: testArray
}, function (result) {
console.log('Array input result type:', typeof result);
console.log('Array input result:', JSON.stringify(result, null, 2));
waitForConditionWithWarning({
condition: function(cb) {
self.ctx.treatments.list({}, cb);
},
assertion: function(list) {
console.log('Total treatments in DB after array dbAdd:', list.length);
console.log('Treatments:', JSON.stringify(list, null, 2));
list.length.should.be.greaterThanOrEqual(1);
},
done: done,
operationName: 'dbAdd array treatments verification',
warningThreshold: 200,
maxTimeout: 5000
});
});
});
});
it('compare single dbAdd calls vs one array dbAdd call', function (done) {
connectAndAuthorize(function (err, socket, authResult) {
if (err) return done(err);
var now = Date.now();
var count = 0;
var results = [];
function addTreatment(index) {
socket.emit('dbAdd', {
collection: 'treatments',
data: {
eventType: 'Note',
created_at: new Date(now + index * 1000).toISOString(),
notes: 'individual item ' + index
}
}, function (result) {
results.push(result);
count++;
if (count === 3) {
waitForConditionWithWarning({
condition: function(cb) {
self.ctx.treatments.list({}, cb);
},
assertion: function(list) {
console.log('Total treatments after 3 individual dbAdd calls:', list.length);
list.length.should.be.greaterThanOrEqual(3);
},
done: done,
operationName: 'individual dbAdd calls verification',
warningThreshold: 200,
maxTimeout: 5000
});
}
});
}
addTreatment(0);
addTreatment(1);
addTreatment(2);
});
});
});
});