-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert event date fields from integer to date objects (#354)
* convert event date fields from integer to date objects * chore: bump fix version
- Loading branch information
1 parent
9ac7903
commit 107fedb
Showing
4 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { CogniteEvent } from 'cdf/types'; | ||
import { convertEventsDateFields } from './EventsDatasource'; | ||
|
||
describe('convertEventsDateFields', () => { | ||
it('should convert date fields to Date objects when start time is available', () => { | ||
const events: CogniteEvent[] = [ | ||
{ | ||
id: 1, | ||
createdTime: 1708415906649, | ||
lastUpdatedTime: 1708415906786, | ||
startTime: 1708415893288, | ||
}, | ||
]; | ||
const result = convertEventsDateFields(events as CogniteEvent[]); | ||
expect(result[0].createdTime).toBeInstanceOf(Date); | ||
expect(result[0].lastUpdatedTime).toBeInstanceOf(Date); | ||
expect(result[0].startTime).toBeInstanceOf(Date); | ||
}); | ||
|
||
it('should convert date fields to Date objects when end time is available', () => { | ||
const events: CogniteEvent[] = [ | ||
{ | ||
id: 1, | ||
createdTime: 1708415906649, | ||
lastUpdatedTime: 1708415906786, | ||
endTime: 1708415893288, | ||
}, | ||
]; | ||
const result = convertEventsDateFields(events as CogniteEvent[]); | ||
expect(result[0].createdTime).toBeInstanceOf(Date); | ||
expect(result[0].lastUpdatedTime).toBeInstanceOf(Date); | ||
expect(result[0].endTime).toBeInstanceOf(Date); | ||
}); | ||
|
||
it('should convert date fields to Date objects when both start and end time are available', () => { | ||
const events: CogniteEvent[] = [ | ||
{ | ||
id: 1, | ||
createdTime: 1708415906649, | ||
lastUpdatedTime: 1708415906786, | ||
startTime: 1708415893288, | ||
endTime: 1708415893288, | ||
}, | ||
]; | ||
const result = convertEventsDateFields(events as CogniteEvent[]); | ||
expect(result[0].createdTime).toBeInstanceOf(Date); | ||
expect(result[0].lastUpdatedTime).toBeInstanceOf(Date); | ||
expect(result[0].startTime).toBeInstanceOf(Date); | ||
expect(result[0].endTime).toBeInstanceOf(Date); | ||
}); | ||
|
||
it('should not convert date fields to Date objects when they are not available', () => { | ||
const events: CogniteEvent[] = [ | ||
{ | ||
id: 1, | ||
createdTime: 1708415906649, | ||
lastUpdatedTime: 1708415906786, | ||
}, | ||
]; | ||
const result = convertEventsDateFields(events as CogniteEvent[]); | ||
expect(result[0].createdTime).toBeInstanceOf(Date); | ||
expect(result[0].lastUpdatedTime).toBeInstanceOf(Date); | ||
expect(result[0].startTime).toBeUndefined(); | ||
expect(result[0].endTime).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters