Improve compatibility for max long values in backups

This commit is contained in:
ayumi-signal
2024-12-09 07:30:45 -08:00
committed by GitHub
parent 8b1ceaa1d7
commit 0f66bb13b9
4 changed files with 52 additions and 14 deletions

View File

@@ -7,6 +7,7 @@ import Long from 'long';
import {
getSafeLongFromTimestamp,
getTimestampFromLong,
getTimestampOrUndefinedFromLong,
} from '../../util/timestampLongUtils';
describe('getSafeLongFromTimestamp', () => {
@@ -46,3 +47,27 @@ describe('getTimestampFromLong', () => {
assert.equal(getTimestampFromLong(null), 0);
});
});
describe('getTimestampOrUndefinedFromLong', () => {
it('returns undefined when passed 0 Long', () => {
assert.equal(
getTimestampOrUndefinedFromLong(Long.fromNumber(0)),
undefined
);
});
it('returns Number.MAX_SAFE_INTEGER when passed Long.MAX_VALUE', () => {
assert.equal(
getTimestampOrUndefinedFromLong(Long.MAX_VALUE),
Number.MAX_SAFE_INTEGER
);
});
it('returns a normal number', () => {
assert.equal(getTimestampOrUndefinedFromLong(Long.fromNumber(16)), 16);
});
it('returns undefined for null value', () => {
assert.equal(getTimestampOrUndefinedFromLong(null), undefined);
});
});