validation.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Report, SchedulingFrequency } from '../../types';
  2. import { getMissingFields } from './validation';
  3. const testReport: Report = {
  4. id: 0,
  5. name: 'Test report',
  6. recipients: 'test@example.com',
  7. replyTo: '',
  8. message: 'Hi, \nPlease find attached a PDF status report. If you have any questions, feel free to contact me!\nBest,',
  9. dashboardName: '',
  10. dashboards: [
  11. {
  12. dashboard: {
  13. uid: '7MeksYbmk',
  14. id: 20,
  15. name: 'gdev dashboards/Alerting with TestData',
  16. },
  17. timeRange: {
  18. from: '',
  19. to: '',
  20. },
  21. reportVariables: {
  22. namefilter: 'TestData',
  23. },
  24. },
  25. ],
  26. schedule: {
  27. frequency: SchedulingFrequency.Never,
  28. timeZone: 'Europe/Helsinki',
  29. },
  30. formats: ['pdf'],
  31. options: {
  32. orientation: 'landscape',
  33. layout: 'grid',
  34. timeRange: {
  35. from: '',
  36. to: '',
  37. },
  38. },
  39. enableDashboardUrl: true,
  40. };
  41. describe('Report validation', () => {
  42. it('should correctly show that report is valid', () => {
  43. expect(getMissingFields(testReport)).toBe(false);
  44. });
  45. it('should validate missing report name', () => {
  46. expect(getMissingFields({ ...testReport, name: '' })).toBe(true);
  47. });
  48. it('should validate missing report recipients', () => {
  49. expect(getMissingFields({ ...testReport, recipients: '' })).toBe(true);
  50. });
  51. it('should validate missing report dashboard', () => {
  52. expect(
  53. getMissingFields({
  54. ...testReport,
  55. dashboards: [
  56. {
  57. dashboard: undefined,
  58. timeRange: {
  59. from: '',
  60. to: '',
  61. },
  62. },
  63. ],
  64. })
  65. ).toBe(true);
  66. });
  67. it('should validate empty report formats', () => {
  68. expect(
  69. getMissingFields({
  70. ...testReport,
  71. formats: [],
  72. })
  73. ).toBe(true);
  74. });
  75. });