-
Notifications
You must be signed in to change notification settings - Fork 1
relax date constrain on map control #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
| }); | ||
|
Comment on lines
+297
to
+333
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test relies on the actual system time via To make this test deterministic and reliable, it's best practice to mock the system clock using Jest's fake timers. This ensures it('should allow same-day dates', async () => {
// Mock the system time to ensure the test is deterministic and not affected by the actual time it's run.
const mockDate = new Date('2024-05-20T12:00:00.000Z');
jest.useFakeTimers().setSystemTime(mockDate);
const territoryControlData = {
type: 'FeatureCollection',
date: new Date(), // This will use the mocked date, which is valid.
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 because the mocked date is not in the future.
await expect(territoryControl.save()).resolves.toBeDefined();
// It's important to restore the real timers after the test.
jest.useRealTimers();
}); |
||
| }); | ||
|
|
||
| describe('Static Methods', () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
todayis a bit misleading as it's immediately mutated to represent the end of the current day. Using a more descriptive variable name would improve code clarity and make the validator's logic easier to understand at a glance.