mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-12 16:02:57 +00:00
ace642ea0f
isOlderThan -> isValidDateAndOlderThan See: https://github.com/balena-os/balena-supervisor/pull/2170#discussion_r1226809686 Signed-off-by: Christina Ying Wang <christina@balena.io>
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { expect } from 'chai';
|
|
import * as ComposeUtils from '~/src/compose/utils';
|
|
|
|
describe('compose/utils', () => {
|
|
it('should correctly camel case the configuration', () => {
|
|
const config = {
|
|
networks: ['test', 'test2'],
|
|
};
|
|
|
|
expect(ComposeUtils.camelCaseConfig(config)).to.deep.equal({
|
|
networks: ['test', 'test2'],
|
|
});
|
|
});
|
|
|
|
it('should return whether a date is valid and older than an interval of seconds', () => {
|
|
const now = new Date(Date.now());
|
|
expect(ComposeUtils.isValidDateAndOlderThan(now, 60)).to.equal(false);
|
|
const time59SecondsAgo = new Date(Date.now() - 59 * 1000);
|
|
expect(ComposeUtils.isValidDateAndOlderThan(time59SecondsAgo, 60)).to.equal(
|
|
false,
|
|
);
|
|
const time61SecondsAgo = new Date(Date.now() - 61 * 1000);
|
|
expect(ComposeUtils.isValidDateAndOlderThan(time61SecondsAgo, 60)).to.equal(
|
|
true,
|
|
);
|
|
|
|
const notDates = [
|
|
null,
|
|
undefined,
|
|
'',
|
|
'test',
|
|
123,
|
|
0,
|
|
-1,
|
|
Infinity,
|
|
NaN,
|
|
{},
|
|
];
|
|
notDates.forEach((n) => {
|
|
expect(ComposeUtils.isValidDateAndOlderThan(n, 0)).to.equal(false);
|
|
});
|
|
});
|
|
});
|