Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
66 lines
2.8 KiB
TypeScript
66 lines
2.8 KiB
TypeScript
import { TIMEUNIT, timeUnitToMs, msToTimeUnit } from './convertTimeUnit';
|
|
|
|
describe('timeUnitToMs function', () => {
|
|
it('should correctly convert days to milliseconds', () => {
|
|
expect(timeUnitToMs(TIMEUNIT.days, 1)).toBe(86400000);
|
|
expect(timeUnitToMs(TIMEUNIT.days, 2)).toBe(172800000);
|
|
expect(timeUnitToMs(TIMEUNIT.days, 0.5)).toBe(43200000);
|
|
});
|
|
|
|
it('should correctly convert hours to milliseconds', () => {
|
|
expect(timeUnitToMs(TIMEUNIT.hours, 1)).toBe(3600000);
|
|
expect(timeUnitToMs(TIMEUNIT.hours, 2)).toBe(7200000);
|
|
expect(timeUnitToMs(TIMEUNIT.hours, 0.5)).toBe(1800000);
|
|
});
|
|
|
|
it('should correctly convert minutes to milliseconds', () => {
|
|
expect(timeUnitToMs(TIMEUNIT.minutes, 1)).toBe(60000);
|
|
expect(timeUnitToMs(TIMEUNIT.minutes, 2)).toBe(120000);
|
|
expect(timeUnitToMs(TIMEUNIT.minutes, 0.5)).toBe(30000);
|
|
});
|
|
|
|
it('should throw an error for invalid time units', () => {
|
|
expect(() => timeUnitToMs('invalidUnit' as TIMEUNIT, 1)).toThrow('timeUnitToMs - invalid time unit');
|
|
});
|
|
|
|
it('should throw an error for invalid timespan', () => {
|
|
const errorMessage = 'timeUnitToMs - invalid timespan';
|
|
expect(() => timeUnitToMs(TIMEUNIT.days, NaN)).toThrow(errorMessage);
|
|
expect(() => timeUnitToMs(TIMEUNIT.days, Infinity)).toThrow(errorMessage);
|
|
expect(() => timeUnitToMs(TIMEUNIT.days, -Infinity)).toThrow(errorMessage);
|
|
expect(() => timeUnitToMs(TIMEUNIT.days, -1)).toThrow(errorMessage);
|
|
});
|
|
});
|
|
|
|
describe('msToTimeUnit function', () => {
|
|
it('should correctly convert milliseconds to days', () => {
|
|
expect(msToTimeUnit(TIMEUNIT.days, 86400000)).toBe(1); // 1 day
|
|
expect(msToTimeUnit(TIMEUNIT.days, 172800000)).toBe(2); // 2 days
|
|
expect(msToTimeUnit(TIMEUNIT.days, 43200000)).toBe(0.5); // .5 days
|
|
});
|
|
|
|
it('should correctly convert milliseconds to hours', () => {
|
|
expect(msToTimeUnit(TIMEUNIT.hours, 3600000)).toBe(1); // 1 hour
|
|
expect(msToTimeUnit(TIMEUNIT.hours, 7200000)).toBe(2); // 2 hours
|
|
expect(msToTimeUnit(TIMEUNIT.hours, 1800000)).toBe(0.5); // .5 hours
|
|
});
|
|
|
|
it('should correctly convert milliseconds to minutes', () => {
|
|
expect(msToTimeUnit(TIMEUNIT.minutes, 60000)).toBe(1); // 1 min
|
|
expect(msToTimeUnit(TIMEUNIT.minutes, 120000)).toBe(2); // 2 min
|
|
expect(msToTimeUnit(TIMEUNIT.minutes, 30000)).toBe(0.5); // .5 min
|
|
});
|
|
|
|
it('should throw an error for invalid time units', () => {
|
|
expect(() => msToTimeUnit('invalidUnit' as TIMEUNIT, 1)).toThrow('msToTimeUnit - invalid time unit');
|
|
});
|
|
|
|
it('should throw an error for invalid timespan', () => {
|
|
const errorMessage = 'msToTimeUnit - invalid timespan';
|
|
expect(() => msToTimeUnit(TIMEUNIT.days, NaN)).toThrow(errorMessage);
|
|
expect(() => msToTimeUnit(TIMEUNIT.days, Infinity)).toThrow(errorMessage);
|
|
expect(() => msToTimeUnit(TIMEUNIT.days, -Infinity)).toThrow(errorMessage);
|
|
expect(() => msToTimeUnit(TIMEUNIT.days, -1)).toThrow(errorMessage);
|
|
});
|
|
});
|