utils.spec.tsx 2.5 KB

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