utils.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {shouldUse24Hours} from 'sentry/utils/dates';
  2. import type {MonitorConfig} from './types';
  3. import {ScheduleType} from './types';
  4. import {crontabAsText, scheduleAsText} from './utils';
  5. jest.mock('sentry/utils/dates');
  6. describe('crontabAsText', function () {
  7. beforeEach(() => {
  8. jest.mocked(shouldUse24Hours).mockReturnValue(false);
  9. });
  10. it('translates simple crontab', function () {
  11. expect(crontabAsText('* * * * *')).toBe('Every minute');
  12. expect(crontabAsText('10 * * * *')).toBe('At 10 minutes past the hour');
  13. });
  14. it('handles 24 hour clock', function () {
  15. expect(crontabAsText('0 5/* * 1-5 *')).toBe(
  16. 'At 0 minutes past the hour, every * hours, starting at 05:00 AM, January through May'
  17. );
  18. jest.mocked(shouldUse24Hours).mockReturnValue(true);
  19. expect(crontabAsText('0 5/* * 1-5 *')).toBe(
  20. 'At 0 minutes past the hour, every * hours, starting at 05:00, January through May'
  21. );
  22. });
  23. });
  24. describe('scheduleAsText', function () {
  25. it('uses crontabAsText', function () {
  26. const config: MonitorConfig = {
  27. checkin_margin: 0,
  28. max_runtime: 0,
  29. timezone: 'utc',
  30. schedule_type: ScheduleType.CRONTAB,
  31. schedule: '10 * * * *',
  32. };
  33. expect(scheduleAsText(config)).toBe('At 10 minutes past the hour');
  34. });
  35. it('translates interval conigs', function () {
  36. const config: MonitorConfig = {
  37. checkin_margin: 0,
  38. max_runtime: 0,
  39. timezone: 'utc',
  40. schedule_type: ScheduleType.INTERVAL,
  41. schedule: [1, 'minute'],
  42. };
  43. expect(scheduleAsText({...config, schedule: [1, 'minute']})).toBe('Every minute');
  44. expect(scheduleAsText({...config, schedule: [1, 'hour']})).toBe('Every hour');
  45. expect(scheduleAsText({...config, schedule: [1, 'day']})).toBe('Every day');
  46. expect(scheduleAsText({...config, schedule: [1, 'week']})).toBe('Every week');
  47. expect(scheduleAsText({...config, schedule: [1, 'month']})).toBe('Every month');
  48. expect(scheduleAsText({...config, schedule: [1, 'year']})).toBe('Every year');
  49. expect(scheduleAsText({...config, schedule: [5, 'minute']})).toBe('Every 5 minutes');
  50. expect(scheduleAsText({...config, schedule: [5, 'hour']})).toBe('Every 5 hours');
  51. expect(scheduleAsText({...config, schedule: [5, 'day']})).toBe('Every 5 days');
  52. expect(scheduleAsText({...config, schedule: [5, 'week']})).toBe('Every 5 weeks');
  53. expect(scheduleAsText({...config, schedule: [5, 'month']})).toBe('Every 5 months');
  54. expect(scheduleAsText({...config, schedule: [5, 'year']})).toBe('Every 5 years');
  55. });
  56. });