Skip to content

Commit 729a6f5

Browse files
bewestCopilot
andcommitted
Add single object and empty array tests for entries API
- Add test for single entry returns array with one item - Add test for empty array returns empty result - Validates response format consistency for entries API Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent eacb6fc commit 729a6f5

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/api.entries.test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,62 @@ describe('Entries REST api', function ( ) {
414414
});
415415
});
416416

417+
// ============================================================
418+
// Single object input tests - validates response format
419+
// ============================================================
420+
421+
it('post single entry returns array with one item', function (done) {
422+
var now = Date.now();
423+
var dateString = new Date(now).toISOString();
424+
425+
request(self.app)
426+
.post('/entries/')
427+
.set('api-secret', known || '')
428+
.send({
429+
type: 'sgv',
430+
sgv: 142,
431+
date: now,
432+
dateString: dateString,
433+
device: 'test-device',
434+
direction: 'Flat'
435+
})
436+
.expect(200)
437+
.end(function (err, res) {
438+
if (err) {
439+
return done(err);
440+
}
441+
// Response should be an array even for single object input
442+
res.body.should.be.instanceof(Array);
443+
res.body.length.should.be.above(0);
444+
res.body[0].should.have.property('_id');
445+
res.body[0].sgv.should.equal(142);
446+
res.body[0].type.should.equal('sgv');
447+
res.body[0].direction.should.equal('Flat');
448+
449+
// Clean up
450+
request(self.app)
451+
.delete('/entries.json?find[date]=' + now)
452+
.set('api-secret', known || '')
453+
.expect(200)
454+
.end(done);
455+
});
456+
});
457+
458+
it('post empty array returns empty result', function (done) {
459+
request(self.app)
460+
.post('/entries/')
461+
.set('api-secret', known || '')
462+
.send([])
463+
.expect(200)
464+
.end(function (err, res) {
465+
if (err) {
466+
return done(err);
467+
}
468+
// Empty input should return success with empty or minimal response
469+
res.body.should.be.instanceof(Array);
470+
res.body.length.should.equal(0);
471+
done();
472+
});
473+
});
474+
417475
});

0 commit comments

Comments
 (0)