From 4e8f2c4a5c50eef915ae3dc4430e455dc49dfe9c Mon Sep 17 00:00:00 2001 From: Heron Q Date: Wed, 16 Jul 2025 00:29:43 +0200 Subject: [PATCH] relax date constrain on map control --- src/models/TerritoryControl.js | 4 ++- src/tests/models/territoryControl.test.js | 38 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/models/TerritoryControl.js b/src/models/TerritoryControl.js index 761fdf6..e804dd3 100644 --- a/src/models/TerritoryControl.js +++ b/src/models/TerritoryControl.js @@ -138,7 +138,9 @@ const TerritoryControlSchema = new mongoose.Schema({ required: [true, 'Territory control date is required'], validate: { validator: function(value) { - return value <= new Date(); + const today = new Date(); + today.setHours(23, 59, 59, 999); // Set to end of current day + return value <= today; }, message: 'Territory control date cannot be in the future' } diff --git a/src/tests/models/territoryControl.test.js b/src/tests/models/territoryControl.test.js index 3cc77b3..e17aa39 100644 --- a/src/tests/models/territoryControl.test.js +++ b/src/tests/models/territoryControl.test.js @@ -293,6 +293,44 @@ describe('TerritoryControl Model', () => { await expect(territoryControl.save()).rejects.toThrow(); }); + + it('should allow same-day dates', async () => { + const today = new Date(); + today.setHours(0, 0, 0, 0); // Set to start of today + + const territoryControlData = { + type: 'FeatureCollection', + date: today, + features: [ + { + type: 'Feature', + properties: { + name: 'Test Territory Today', + controlledBy: 'sdf', + color: '#ffff00', + controlledSince: '2020-01-01' + }, + geometry: { + type: 'Polygon', + coordinates: [ + [ + [35.0, 36.0], + [36.0, 36.0], + [36.0, 37.0], + [35.0, 37.0], + [35.0, 36.0] + ] + ] + } + } + ] + }; + + const territoryControl = new TerritoryControl(territoryControlData); + + // This should not throw an error + await expect(territoryControl.save()).resolves.toBeDefined(); + }); }); describe('Static Methods', () => {