Major refactoring and fixes.
* Split Node into multiple types and make sure fields are actually set when type says so. * Refactor request handling. * Start getting rid of moment as a dependency by using UnixTimestampSeconds instead.
This commit is contained in:
parent
cfa784dfe2
commit
250353edbf
16 changed files with 676 additions and 455 deletions
server/utils
53
server/utils/time.test.ts
Normal file
53
server/utils/time.test.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import {parseTimestamp} from "./time";
|
||||
import moment from "moment";
|
||||
|
||||
const TIMESTAMP_INVALID_STRING = "2020-01-02T42:99:23.000Z";
|
||||
const TIMESTAMP_VALID_STRING = "2020-01-02T12:34:56.000Z";
|
||||
|
||||
test('parseTimestamp() should fail parsing non-string timestamp', () => {
|
||||
// given
|
||||
const timestamp = {};
|
||||
|
||||
// when
|
||||
const parsedTimestamp = parseTimestamp(timestamp);
|
||||
|
||||
// then
|
||||
expect(parsedTimestamp).toEqual(null);
|
||||
});
|
||||
|
||||
test('parseTimestamp() should fail parsing empty timestamp string', () => {
|
||||
// given
|
||||
const timestamp = "";
|
||||
|
||||
// when
|
||||
const parsedTimestamp = parseTimestamp(timestamp);
|
||||
|
||||
// then
|
||||
expect(parsedTimestamp).toEqual(null);
|
||||
});
|
||||
|
||||
test('parseTimestamp() should fail parsing invalid timestamp string', () => {
|
||||
// given
|
||||
// noinspection UnnecessaryLocalVariableJS
|
||||
const timestamp = TIMESTAMP_INVALID_STRING;
|
||||
|
||||
// when
|
||||
const parsedTimestamp = parseTimestamp(timestamp);
|
||||
|
||||
// then
|
||||
expect(parsedTimestamp).toEqual(null);
|
||||
});
|
||||
|
||||
test('parseTimestamp() should succeed parsing valid timestamp string', () => {
|
||||
// given
|
||||
const timestamp = TIMESTAMP_VALID_STRING;
|
||||
|
||||
// when
|
||||
const parsedTimestamp = parseTimestamp(timestamp);
|
||||
|
||||
// then
|
||||
if (parsedTimestamp === null) {
|
||||
fail('timestamp should not be null');
|
||||
}
|
||||
expect(moment.unix(parsedTimestamp).toISOString()).toEqual(timestamp);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue