@seniorsistemas/hcm-clocking-event-rule-nodejs 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/.github/copilot-instructions.md +11 -0
  2. package/.github/workflows/release.yaml +10 -0
  3. package/.gitlab-ci.yml +68 -0
  4. package/CHANGELOG.md +274 -0
  5. package/README.doc.md +658 -0
  6. package/README.md +117 -0
  7. package/assets/favicon.ico +0 -0
  8. package/catalog-info.yaml +19 -0
  9. package/jest.config.js +17 -0
  10. package/package.json +48 -0
  11. package/prompt.md +15 -0
  12. package/run_build_win.bat +1 -0
  13. package/run_link.bat +3 -0
  14. package/run_test.bat +1 -0
  15. package/sonar-project.properties +21 -0
  16. package/src/data/changes/changes.ts +92 -0
  17. package/src/data/context/context.ts +251 -0
  18. package/src/data/context/contextReference.ts +376 -0
  19. package/src/data/contract/contract.ts +272 -0
  20. package/src/data/dataset/database.ts +130 -0
  21. package/src/data/dataset/dataset.ts +275 -0
  22. package/src/data/definition/timeEvaluationSituationDefinitionHistory.ts +1425 -0
  23. package/src/data/employee/employee.ts +434 -0
  24. package/src/data/foundation/companyBranch.ts +66 -0
  25. package/src/data/foundation/costCenter.ts +47 -0
  26. package/src/data/foundation/employer.ts +35 -0
  27. package/src/data/foundation/employmentRelationship.ts +63 -0
  28. package/src/data/foundation/holiday.ts +84 -0
  29. package/src/data/foundation/holidayGroup.ts +47 -0
  30. package/src/data/foundation/jobPosition.ts +73 -0
  31. package/src/data/foundation/person.ts +35 -0
  32. package/src/data/foundation/situation.ts +301 -0
  33. package/src/data/foundation/syndicate.ts +244 -0
  34. package/src/data/foundation/workschedule.ts +688 -0
  35. package/src/data/foundation/workshift.ts +647 -0
  36. package/src/data/foundation/workshiftBase.ts +113 -0
  37. package/src/data/histories/companyBranchHistory.ts +128 -0
  38. package/src/data/histories/costCenterHistory.ts +114 -0
  39. package/src/data/histories/employmentRelationshipHistory.ts +116 -0
  40. package/src/data/histories/histories.ts +419 -0
  41. package/src/data/histories/jobPositionHistory.ts +117 -0
  42. package/src/data/histories/leaveHistory.ts +227 -0
  43. package/src/data/histories/timeEvaluationHistory.ts +191 -0
  44. package/src/data/histories/workshiftHistory.ts +66 -0
  45. package/src/data/hourBank/hourBank.ts +43 -0
  46. package/src/data/hourBank/hourBankAccount.ts +77 -0
  47. package/src/data/log/log.ts +38 -0
  48. package/src/data/schedules/bridge.ts +84 -0
  49. package/src/data/schedules/compensation.ts +332 -0
  50. package/src/data/schedules/overtimeAuthorization.ts +174 -0
  51. package/src/data/schedules/readiness.ts +150 -0
  52. package/src/data/schedules/schedules.ts +398 -0
  53. package/src/data/schedules/workscheduleChange.ts +91 -0
  54. package/src/data/schedules/workshiftChange.ts +76 -0
  55. package/src/data/timeEvaluation/adjustmentReason.ts +46 -0
  56. package/src/data/timeEvaluation/clockingEvent.ts +198 -0
  57. package/src/data/timeEvaluation/estimatedHours.ts +245 -0
  58. package/src/data/timeEvaluation/interval.ts +568 -0
  59. package/src/data/timeEvaluation/separatedHours.ts +134 -0
  60. package/src/data/timeEvaluation/timeEvaluation.ts +1540 -0
  61. package/src/data/timeEvaluation/timeEvaluationSituation.ts +154 -0
  62. package/src/data/user/user.ts +44 -0
  63. package/src/index.ts +60 -0
  64. package/src/test/builder/bridgeBuilder.builder.ts +28 -0
  65. package/src/test/builder/clockingEvent.builder.ts +49 -0
  66. package/src/test/builder/companyBranchHistoryBuilder.ts +29 -0
  67. package/src/test/builder/compensation.builder.ts +84 -0
  68. package/src/test/builder/contextReference.builder.ts +69 -0
  69. package/src/test/builder/costCenterHistoryBuilder.ts +29 -0
  70. package/src/test/builder/database.builder.ts +21 -0
  71. package/src/test/builder/datasetBuilder.ts +111 -0
  72. package/src/test/builder/dateIntervalBuilder.ts +25 -0
  73. package/src/test/builder/employee.builder.ts +91 -0
  74. package/src/test/builder/employmentRelationshipBuilder.ts +35 -0
  75. package/src/test/builder/employmentRelationshipHistoryBuilder.ts +29 -0
  76. package/src/test/builder/historiesBuilder.ts +56 -0
  77. package/src/test/builder/holiday.builder.ts +44 -0
  78. package/src/test/builder/hourBankAccountBuilder.ts +77 -0
  79. package/src/test/builder/hourBankBuilder.ts +32 -0
  80. package/src/test/builder/interval.builder.ts +113 -0
  81. package/src/test/builder/jobPositionHistoryBuilder.ts +29 -0
  82. package/src/test/builder/overtimeAuthorization.builder.ts +42 -0
  83. package/src/test/builder/readinessBuilder.builder.ts +57 -0
  84. package/src/test/builder/schedules.builder.ts +126 -0
  85. package/src/test/builder/situation.builder.ts +59 -0
  86. package/src/test/builder/syndicate.builder.ts +96 -0
  87. package/src/test/builder/syndicateHistoryBuilder.ts +33 -0
  88. package/src/test/builder/timeEvaluation.builder.ts +138 -0
  89. package/src/test/builder/timeEvaluationHistory.builder.ts +49 -0
  90. package/src/test/builder/timeEvaluationSituation.builder.ts +34 -0
  91. package/src/test/builder/workschedule.builder.ts +96 -0
  92. package/src/test/builder/workshift.builder.ts +179 -0
  93. package/src/test/builder/workshiftBuilder.ts +55 -0
  94. package/src/test/data/clockingEvent.spec.ts +56 -0
  95. package/src/test/data/context.spec.ts +176 -0
  96. package/src/test/data/currentUser.spec.ts +11 -0
  97. package/src/test/data/dataset.spec.ts +144 -0
  98. package/src/test/data/employee/employee.spec.ts +20 -0
  99. package/src/test/data/employmentRelationship/employmentRelationship.spec.ts +48 -0
  100. package/src/test/data/estimatedHours/estimatedHours.spec.ts +96 -0
  101. package/src/test/data/histories/costCenterHistory.spec.ts +32 -0
  102. package/src/test/data/histories/histories.spec.ts +306 -0
  103. package/src/test/data/holyday.spec.ts +89 -0
  104. package/src/test/data/hourBank/hourBank.spec.ts +48 -0
  105. package/src/test/data/hourBank/hourBankAccount.spec.ts +32 -0
  106. package/src/test/data/schedules/bridge.spec.ts +13 -0
  107. package/src/test/data/schedules/compesation.spect.ts +89 -0
  108. package/src/test/data/schedules/overtimeAuthorization.spec.ts +52 -0
  109. package/src/test/data/schedules/readiness.spec.ts +64 -0
  110. package/src/test/data/schedules/schedules.spec.ts +134 -0
  111. package/src/test/data/schedules/workscheduleChange.spec.ts +21 -0
  112. package/src/test/data/syndicate/syndicate.spec.ts +51 -0
  113. package/src/test/data/timeEvaluation.spec.ts +1057 -0
  114. package/src/test/data/timeEvaluationDefinition.spec.ts +144 -0
  115. package/src/test/data/workschedule/workschedule.spec.ts +194 -0
  116. package/src/test/data/workshift/workshift.spec.ts +79 -0
  117. package/src/test/utils/date.utils.spec.ts +198 -0
  118. package/src/test/utils/dateIntervalUtils.spec.ts +210 -0
  119. package/src/test/utils/object.utils.spec.ts +83 -0
  120. package/src/utils/dateIntervalUtils.ts +284 -0
  121. package/src/utils/dateUtils.ts +456 -0
  122. package/src/utils/decompressGzipLambda.ts +15 -0
  123. package/src/utils/object.utils.ts +156 -0
  124. package/trivy/vulnerabilities_scan.json +1160 -0
  125. package/tsconfig.json +32 -0
  126. package/tsconfig.spec.json +21 -0
  127. package/tslint.json +92 -0
  128. package/typedoc.json +22 -0
@@ -0,0 +1,198 @@
1
+ import { DateUtils, WeekDay } from '../../utils/dateUtils';
2
+
3
+ const DATE_2025_03_04 = new Date('2025-03-04T00:00:00Z');
4
+
5
+ describe('DateUtils', () => {
6
+ it('should return the correct difference in minutes between two dates', () => {
7
+ const start = DATE_2025_03_04;
8
+ const end = new Date('2025-03-04T01:00:00Z');
9
+ expect(DateUtils.getDateInMinutes(start, end)).toBe(60);
10
+ });
11
+
12
+ it('should create a date from year, month, and day', () => {
13
+ const date = DateUtils.of(2025, 3, 4);
14
+ expect(date.toISOString()).toBe('2025-03-04T00:00:00.000Z');
15
+ });
16
+
17
+ it('should format a date string to a Date object', () => {
18
+ const date = DateUtils.strIsoDateToDate('2025-03-04');
19
+ expect(date.toISOString()).toBe('2025-03-04T00:00:00.000Z');
20
+ });
21
+
22
+ it('should format a date string to a Date object', () => {
23
+ const date = DateUtils.dateToIsoDateStr(DateUtils.of(2025, 3, 4));
24
+ expect(date).toBe('2025-03-04');
25
+ });
26
+
27
+ it('should return true if one date is before another', () => {
28
+ const oneDate = new Date('2025-03-03T00:00:00Z');
29
+ const otherDate = DATE_2025_03_04;
30
+ expect(DateUtils.isBefore(oneDate, otherDate)).toBe(true);
31
+ });
32
+
33
+ it('should return true if one date is before or equal to another', () => {
34
+ const oneDate = DATE_2025_03_04;
35
+ const otherDate = DATE_2025_03_04;
36
+ expect(DateUtils.isBeforeOrEquals(oneDate, otherDate)).toBe(true);
37
+ });
38
+
39
+ it('should return true if one date is after another', () => {
40
+ const oneDate = new Date('2025-03-07T00:00:00Z');
41
+ const otherDate = DATE_2025_03_04;
42
+ expect(DateUtils.isAfter(oneDate, otherDate)).toBe(true);
43
+ });
44
+
45
+ it('should return true if one date is after or equal to another', () => {
46
+ const oneDate = DATE_2025_03_04;
47
+ const otherDate = DATE_2025_03_04;
48
+ expect(DateUtils.isAfterOrEquals(oneDate, otherDate)).toBe(true);
49
+ });
50
+
51
+ it('should compare two dates correctly', () => {
52
+ const oneDate = new Date('2025-03-03T00:00:00Z');
53
+ const otherDate = new Date('2025-03-06T00:00:00Z');
54
+ expect(DateUtils.compareTo(oneDate, otherDate)).toBeLessThan(0);
55
+ });
56
+
57
+ it('should return true if a date is between two other dates', () => {
58
+ const date = new Date('2025-03-04T12:00:00Z');
59
+ const start = DATE_2025_03_04;
60
+ const end = new Date('2025-03-05T00:00:00Z');
61
+ expect(DateUtils.between(date, start, end)).toBe(true);
62
+ });
63
+
64
+ it('should return true if two dates are equal', () => {
65
+ const oneDate = DATE_2025_03_04;
66
+ const otherDate = DATE_2025_03_04;
67
+ expect(DateUtils.equals(oneDate, otherDate)).toBe(true);
68
+ });
69
+
70
+ it('should return 30 minutos os diff', () => {
71
+ const date1 = new Date("2024-04-01T10:00:00Z");
72
+ const date2 = new Date("2024-04-01T10:30:00Z");
73
+ expect(DateUtils.getDateInMinutes(date1, date2)).toBe(30);
74
+ });
75
+
76
+ it("of should create correct date", () => {
77
+ const date = DateUtils.of(2024, 4, 1);
78
+ expect(date.toISOString()).toBe("2024-04-01T00:00:00.000Z");
79
+ });
80
+
81
+ it("isoDate should parse date correctly", () => {
82
+ const date = DateUtils.strIsoDateToDate("2024-04-01");
83
+ expect(date.toISOString()).toBe("2024-04-01T00:00:00.000Z");
84
+ });
85
+
86
+ it("isBefore should return true if first date is before second", () => {
87
+ expect(DateUtils.isBefore(new Date("2024-04-01"), new Date("2024-04-02"))).toBe(true);
88
+ });
89
+
90
+ it("getWeekDay should return correct weekday", () => {
91
+ const date = new Date("2025-04-01"); // TUESDAY
92
+ expect(DateUtils.getWeekDay(date)).toBe(WeekDay.TUESDAY);
93
+ });
94
+
95
+ it("getNumberOfDaysInMonth should return correct days count Fev", () => {
96
+ expect(DateUtils.getNumberOfDaysInMonth(new Date("2024-02-01"))).toBe(29); // Leap year
97
+ });
98
+
99
+ it("getNumberOfDaysInMonth should return correct days count", () => {
100
+ expect(DateUtils.getNumberOfDaysInMonth(new Date("2024-01-09"))).toBe(31); // Leap year
101
+ });
102
+
103
+ it("addMinutes should add correct minutes", () => {
104
+ const date = new Date("2024-04-01T10:00:00Z");
105
+ expect(DateUtils.addMinutes(date, 30).toISOString()).toBe("2024-04-01T10:30:00.000Z");
106
+ });
107
+
108
+ it("addMinutes should add correct minutes - next day", () => {
109
+ const date = new Date("2024-04-01T23:59:00Z");
110
+ expect(DateUtils.addMinutes(date, 30).toISOString()).toBe("2024-04-02T00:29:00.000Z");
111
+ });
112
+
113
+ it("subMinutes should subtract correct minutes", () => {
114
+ const date = new Date("2024-04-01T10:00:00Z");
115
+ expect(DateUtils.subMinutes(date, 30).toISOString()).toBe("2024-04-01T09:30:00.000Z");
116
+ });
117
+
118
+ it("subMinutes should subtract correct minutes - previews day", () => {
119
+ const date = new Date("2024-04-03T00:10:00Z");
120
+ expect(DateUtils.subMinutes(date, 30).toISOString()).toBe("2024-04-02T23:40:00.000Z");
121
+ });
122
+
123
+ it("days should return correct difference in days", () => {
124
+ const date1 = new Date("2024-04-01");
125
+ const date2 = new Date("2024-04-11");
126
+ expect(DateUtils.days(date1, date2)).toBe(10);
127
+ });
128
+
129
+ it("days should return correct difference in days- same day", () => {
130
+ const date1 = new Date("2024-04-01");
131
+ const date2 = new Date("2024-04-01");
132
+ expect(DateUtils.days(date1, date2)).toBe(0);
133
+ });
134
+
135
+
136
+ it("days should return correct difference in days- same day", () => {
137
+ const date1 = new Date("2024-04-02");
138
+ const date2 = new Date("2024-04-01");
139
+ expect(DateUtils.days(date1, date2)).toBe(-1);
140
+ });
141
+
142
+
143
+ it("days should return correct day of month", () => {
144
+ const date1 = new Date("2024-04-02");
145
+ expect(DateUtils.getDay(date1)).toBe(2);
146
+ });
147
+
148
+ it("days should return correct day of month - 31", () => {
149
+ const date1 = new Date("2024-01-31");
150
+ expect(DateUtils.getDay(date1)).toBe(31);
151
+ });
152
+
153
+ it("Month should return correct day of month - Janeiro = 1", () => {
154
+ const date1 = new Date("2024-01-31");
155
+ expect(DateUtils.getMonth(date1)).toBe(1);
156
+ });
157
+
158
+ it("Month should return correct day of month - Dezembro = 12", () => {
159
+ const date1 = new Date("2024-12-31");
160
+ expect(DateUtils.getMonth(date1)).toBe(12);
161
+ });
162
+
163
+ it("Year should return correct year ", () => {
164
+ const date1 = new Date("2024-12-31");
165
+ expect(DateUtils.getYear(date1)).toBe(2024);
166
+ });
167
+
168
+
169
+ it("should return last day 29 ", () => {
170
+ const date1 = new Date("2024-02-10");
171
+ expect(DateUtils.getLastDayOfMonth(date1).toISOString()).toBe("2024-02-29T00:00:00.000Z");
172
+ });
173
+
174
+ it("should return last day 30 ", () => {
175
+ const date1 = new Date("2025-07-10");
176
+ expect(DateUtils.getLastDayOfMonth(date1).toISOString()).toBe("2025-07-31T00:00:00.000Z");
177
+ });
178
+ });
179
+
180
+ describe('DateUtils.format', () => {
181
+ it('deve formatar a data no formato dd/MM/yyyy', () => {
182
+ const date = new Date('2025-04-08T00:00:00Z');
183
+ const formattedDate = DateUtils.format(date);
184
+ expect(formattedDate).toBe('08/04/2025');
185
+ });
186
+
187
+ it('deve formatar corretamente uma data com dia e mês de um dígito', () => {
188
+ const date = new Date('2025-01-05T00:00:00Z');
189
+ const formattedDate = DateUtils.format(date);
190
+ expect(formattedDate).toBe('05/01/2025');
191
+ });
192
+
193
+ it('deve formatar corretamente uma data no final do ano', () => {
194
+ const date = new Date('2025-12-31T00:00:00Z');
195
+ const formattedDate = DateUtils.format(date);
196
+ expect(formattedDate).toBe('31/12/2025');
197
+ });
198
+ });
@@ -0,0 +1,210 @@
1
+ import { DateInterval, DateIntervalUtils } from "../../utils/dateIntervalUtils";
2
+
3
+ describe("DateIntervalsUtils", () => {
4
+ describe("isBeforeOrEquals", () => {
5
+ it("should return true if interval ends before comparedInterval starts", () => {
6
+ const a = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-02T00:00:00.000Z"));
7
+ const b = new DateInterval(new Date("2023-01-03T00:00:00.000Z"), new Date("2023-01-04T00:00:00.000Z"));
8
+ expect(DateIntervalUtils.isBeforeOrEquals(a, b)).toBe(true);
9
+ });
10
+ it("should return false if interval ends after comparedInterval starts", () => {
11
+ const a = new DateInterval(new Date("2023-01-03T00:00:00.000Z"), new Date("2023-01-05T00:00:00.000Z"));
12
+ const b = new DateInterval(new Date("2023-01-02T00:00:00.000Z"), new Date("2023-01-04T00:00:00.000Z"));
13
+ expect(DateIntervalUtils.isBeforeOrEquals(a, b)).toBe(false);
14
+ });
15
+ it("should return true if interval ends before comparedInterval starts with Time equals", () => {
16
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
17
+ const b = new DateInterval(new Date("2023-01-01T12:00:00.000Z"), new Date("2023-01-04T13:30:00.000Z"));
18
+ expect(DateIntervalUtils.isBeforeOrEquals(a, b)).toBe(true);
19
+ });
20
+
21
+ it("should return true if interval ends before comparedInterval starts with Time", () => {
22
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
23
+ const b = new DateInterval(new Date("2023-01-01T12:01:00.000Z"), new Date("2023-01-04T13:30:00.000Z"));
24
+ expect(DateIntervalUtils.isBeforeOrEquals(a, b)).toBe(true);
25
+ });
26
+
27
+ it("should return false if interval ends after comparedInterval starts with time", () => {
28
+ const a = new DateInterval(new Date("2023-01-01T12:00:00.000Z"), new Date("2023-01-01T13:00:00.000Z"));
29
+ const b = new DateInterval(new Date("2023-01-01T11:00:00.000Z"), new Date("2023-01-01T11:59:00.000Z"));
30
+ expect(DateIntervalUtils.isBeforeOrEquals(a, b)).toBe(false);
31
+ });
32
+ });
33
+
34
+ describe("isAfterOrEquals", () => {
35
+ it("should return true if interval starts after comparedInterval ends", () => {
36
+ const a = new DateInterval(new Date("2023-01-05T00:00:00.000Z"), new Date("2023-01-06T00:00:00.000Z"));
37
+ const b = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-04T00:00:00.000Z"));
38
+ expect(DateIntervalUtils.isAfterOrEquals(a, b)).toBe(true);
39
+ });
40
+ it("should return false if interval starts before comparedInterval ends", () => {
41
+ const a = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-03T00:00:00.000Z"));
42
+ const b = new DateInterval(new Date("2023-01-02T00:00:00.000Z"), new Date("2023-01-04T00:00:00.000Z"));
43
+ expect(DateIntervalUtils.isAfterOrEquals(a, b)).toBe(false);
44
+ });
45
+
46
+ it("should return true if interval starts after comparedInterval ends With time", () => {
47
+ const a = new DateInterval(new Date("2023-01-01T18:00:00.000Z"), new Date("2023-01-01T20:00:00.000Z"));
48
+ const b = new DateInterval(new Date("2023-01-01T13:30:00.000Z"), new Date("2023-01-01T18:00:00.000Z"));
49
+ expect(DateIntervalUtils.isAfterOrEquals(a, b)).toBe(true);
50
+ });
51
+ it("should return false if interval starts before comparedInterval ends with time", () => {
52
+ const a = new DateInterval(new Date("2023-01-01T13:30:00.000Z"), new Date("2023-01-01T18:00:00.000Z"));
53
+ const b = new DateInterval(new Date("2023-01-01T18:01:00.000Z"), new Date("2023-01-01T20:00:00.000Z"));
54
+ expect(DateIntervalUtils.isAfterOrEquals(a, b)).toBe(false);
55
+ });
56
+ });
57
+
58
+ describe("overlaps", () => {
59
+ it("should return true if interval overlaps compareInterval", () => {
60
+ const a = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-10T00:00:00.000Z"));
61
+ const b = new DateInterval(new Date("2023-01-03T00:00:00.000Z"), new Date("2023-01-05T00:00:00.000Z"));
62
+ expect(DateIntervalUtils.overlaps(a, b)).toBe(true);
63
+ });
64
+ it("should return false if interval does not overlap compareInterval", () => {
65
+ const a = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-02T00:00:00.000Z"));
66
+ const b = new DateInterval(new Date("2023-01-03T00:00:00.000Z"), new Date("2023-01-04T00:00:00.000Z"));
67
+ expect(DateIntervalUtils.overlaps(a, b)).toBe(false);
68
+ });
69
+
70
+ it("should return false if interval does not overlap compareInterval with time", () => {
71
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
72
+ const b = new DateInterval(new Date("2023-01-01T09:00:00.000Z"), new Date("2023-01-01T11:00:00.000Z"));
73
+ expect(DateIntervalUtils.overlaps(a, b)).toBe(true);
74
+ });
75
+
76
+ it("should return false if interval does not overlap compareInterval with time", () => {
77
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
78
+ const b = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
79
+ expect(DateIntervalUtils.overlaps(a, b)).toBe(true);
80
+ });
81
+
82
+ it("should return false if interval does not overlap compareInterval with time", () => {
83
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
84
+ const b = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:01.000Z"));
85
+ expect(DateIntervalUtils.overlaps(a, b)).toBe(false);
86
+ });
87
+ });
88
+
89
+ describe("into", () => {
90
+ it("should return true if interval is completely inside compareInterval", () => {
91
+ const a = new DateInterval(new Date("2023-01-03T00:00:00.000Z"), new Date("2023-01-05T00:00:00.000Z"));
92
+ const b = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-10T00:00:00.000Z"));
93
+ expect(DateIntervalUtils.into(a, b)).toBe(true);
94
+ });
95
+ it("should return false if interval is not inside compareInterval", () => {
96
+ const a = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-11T00:00:00.000Z"));
97
+ const b = new DateInterval(new Date("2023-01-03T00:00:00.000Z"), new Date("2023-01-10T00:00:00.000Z"));
98
+ expect(DateIntervalUtils.into(a, b)).toBe(false);
99
+ });
100
+
101
+
102
+ it("should return true if interval is completely inside compareInterval with timer", () => {
103
+ const a = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-01T00:00:00.000Z"));
104
+ const b = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-01T00:00:00.000Z"));
105
+ expect(DateIntervalUtils.into(a, b)).toBe(true);
106
+ });
107
+
108
+
109
+ it("should return true if interval is completely inside compareInterval", () => {
110
+ const a = new DateInterval(new Date("2023-01-01T12:00:00.000Z"), new Date("2023-01-01T13:30:00.000Z"));
111
+ const b = new DateInterval(new Date("2023-01-01T12:00:00.000Z"), new Date("2023-01-01T14:00:00.000Z"));
112
+ expect(DateIntervalUtils.into(a, b)).toBe(true);
113
+ });
114
+
115
+ it("should return true if interval is completely inside compareInterval", () => {
116
+ const a = new DateInterval(new Date("2023-01-01T12:00:00.000Z"), new Date("2023-01-01T13:30:00.000Z"));
117
+ const b = new DateInterval(new Date("2023-01-01T11:59:00.000Z"), new Date("2023-01-01T13:30:00.000Z"));
118
+ expect(DateIntervalUtils.into(a, b)).toBe(true);
119
+ });
120
+
121
+ it("should return true if interval is completely inside compareInterval", () => {
122
+ const a = new DateInterval(new Date("2023-01-01T13:00:00.000Z"), new Date("2023-01-01T13:00:00.000Z"));
123
+ const b = new DateInterval(new Date("2023-01-01T11:59:00.000Z"), new Date("2023-01-01T13:30:00.000Z"));
124
+ expect(DateIntervalUtils.into(a, b)).toBe(true);
125
+ });
126
+
127
+ it("should return true if interval is completely inside compareInterval", () => {
128
+ const a = new DateInterval(new Date("2023-01-01T11:59:00.000Z"), new Date("2023-01-01T13:30:00.000Z"));
129
+ const b = new DateInterval(new Date("2023-01-01T13:00:00.000Z"), new Date("2023-01-01T13:00:00.000Z"));
130
+ expect(DateIntervalUtils.into(a, b)).toBe(false);
131
+ });
132
+
133
+
134
+ });
135
+
136
+ describe("isOverStart", () => {
137
+ it("should return true if interval is over the start of compareInterval", () => {
138
+ const a = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-10T00:00:00.000Z"));
139
+ const b = new DateInterval(new Date("2023-01-05T00:00:00.000Z"), new Date("2023-01-12T00:00:00.000Z"));
140
+ expect(DateIntervalUtils.isOverStart(a, b)).toBe(true);
141
+ });
142
+ it("should return false if interval is not over the start of compareInterval", () => {
143
+ const a = new DateInterval(new Date("2023-01-10T00:00:00.000Z"), new Date("2023-01-12T00:00:00.000Z"));
144
+ const b = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-08T00:00:00.000Z"));
145
+ expect(DateIntervalUtils.isOverStart(a, b)).toBe(false);
146
+ });
147
+
148
+
149
+ it("should return true if interval is over the start of compareInterval with Time", () => {
150
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-10T12:00:00.000Z"));
151
+ const b = new DateInterval(new Date("2023-01-10T11:59:00.000Z"), new Date("2023-01-12T13:00:00.000Z"));
152
+ expect(DateIntervalUtils.isOverStart(a, b)).toBe(true);
153
+ });
154
+
155
+ it("should return true if interval is over the start of compareInterval with Time", () => {
156
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-10T12:00:00.000Z"));
157
+ const b = new DateInterval(new Date("2023-01-05T10:00:00.000Z"), new Date("2023-01-08T10:00:00.000Z"));
158
+ expect(DateIntervalUtils.isOverStart(a, b)).toBe(false);
159
+ });
160
+
161
+ it("should return true if interval is over the start of compareInterval with Time", () => {
162
+ const a = new DateInterval(new Date("2023-01-09T00:00:00.000Z"), new Date("2023-01-10T00:00:00.000Z"));
163
+ const b = new DateInterval(new Date("2023-01-05T00:00:00.000Z"), new Date("2023-01-08T00:00:00.000Z"));
164
+ expect(DateIntervalUtils.isOverStart(a, b)).toBe(false);
165
+ });
166
+
167
+ it("should return true if interval is over the start of compareInterval with Time", () => {
168
+ const a = new DateInterval(new Date("2023-01-01T10:00:00.000Z"), new Date("2023-01-01T11:00:00.000Z"));
169
+ const b = new DateInterval(new Date("2023-01-01T11:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
170
+ expect(DateIntervalUtils.isOverStart(a, b)).toBe(false);
171
+ });
172
+
173
+ it("should return true if interval is over the start of compareInterval with Time", () => {
174
+ const a = new DateInterval(new Date("2023-01-01T11:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
175
+ const b = new DateInterval(new Date("2023-01-01T11:00:00.000Z"), new Date("2023-01-01T13:00:00.000Z"));
176
+ expect(DateIntervalUtils.isOverStart(a, b)).toBe(true);
177
+ });
178
+ });
179
+
180
+ describe("isOverEnd", () => {
181
+ it("should return true if interval is over the end of compareInterval", () => {
182
+ const a = new DateInterval(new Date("2023-01-05"), new Date("2023-01-12"));
183
+ const b = new DateInterval(new Date("2023-01-01"), new Date("2023-01-08"));
184
+ expect(DateIntervalUtils.isOverEnd(a, b)).toBe(true);
185
+ });
186
+ it("should return false if interval is not over the end of compareInterval", () => {
187
+ const a = new DateInterval(new Date("2023-01-01"), new Date("2023-01-05"));
188
+ const b = new DateInterval(new Date("2023-01-06"), new Date("2023-01-08"));
189
+ expect(DateIntervalUtils.isOverEnd(a, b)).toBe(false);
190
+ });
191
+
192
+ it("should return true if interval is over the end of compareInterval with time", () => {
193
+ const a = new DateInterval(new Date("2023-01-05T00:00:00.000Z"), new Date("2023-01-12T00:00:00.000Z"));
194
+ const b = new DateInterval(new Date("2023-01-01T00:00:00.000Z"), new Date("2023-01-08T00:00:00.000Z"));
195
+ expect(DateIntervalUtils.isOverEnd(a, b)).toBe(true);
196
+ });
197
+
198
+ it("should return true if interval is over the end of compareInterval with time", () => {
199
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
200
+ const b = new DateInterval(new Date("2023-01-01T08:01:00.000Z"), new Date("2023-01-01T09:00:00.000Z"));
201
+ expect(DateIntervalUtils.isOverEnd(a, b)).toBe(false);
202
+ });
203
+
204
+ it("should return true if interval is over the end of compareInterval with time", () => {
205
+ const a = new DateInterval(new Date("2023-01-01T08:00:00.000Z"), new Date("2023-01-01T12:00:00.000Z"));
206
+ const b = new DateInterval(new Date("2023-01-01T07:59:00.000Z"), new Date("2023-01-01T09:00:00.000Z"));
207
+ expect(DateIntervalUtils.isOverEnd(a, b)).toBe(true);
208
+ });
209
+ });
210
+ });
@@ -0,0 +1,83 @@
1
+ import { ObjectUtils } from "../../utils/object.utils";
2
+
3
+ describe("ObjectUtils", () => {
4
+ describe("isObjectEmpty", () => {
5
+ it("deve retornar true para objeto vazio", () => {
6
+ expect(ObjectUtils.isObjectEmpty({})).toBe(true);
7
+ });
8
+
9
+ it("deve retornar false para objeto com propriedades", () => {
10
+ expect(ObjectUtils.isObjectEmpty({ key: "value" })).toBe(false);
11
+ });
12
+
13
+ });
14
+
15
+ describe("isDateInstance", () => {
16
+ it("deve retornar true para instância válida de Date", () => {
17
+ expect(ObjectUtils.isDateInstance(new Date())).toBe(true);
18
+ });
19
+
20
+ it("deve retornar false para data inválida", () => {
21
+ expect(ObjectUtils.isDateInstance(new Date("invalid-date"))).toBe(false);
22
+ });
23
+
24
+ it("deve retornar false para string", () => {
25
+ expect(ObjectUtils.isDateInstance("2025-04-01")).toBe(false);
26
+ });
27
+ });
28
+
29
+ describe("toDateOrThrow", () => {
30
+ it("deve retornar a data se for uma instância válida de Date", () => {
31
+ const date = new Date("2025-04-02");
32
+ expect(ObjectUtils.toDateOrThrow(date)).toEqual(date);
33
+ });
34
+
35
+ it("deve converter string de data válida para Date", () => {
36
+ const date = ObjectUtils.toDateOrThrow("2025-04-02");
37
+ expect(date).toBeInstanceOf(Date);
38
+ expect(date.toISOString().startsWith("2025-04-02")).toBe(true);
39
+ });
40
+
41
+ it("deve lançar erro se valor for null", () => {
42
+ expect(() => ObjectUtils.toDateOrThrow(null)).toThrow(
43
+ 'O campo "date" não é uma data válida: null'
44
+ );
45
+ });
46
+
47
+ it("deve lançar erro se string for inválida", () => {
48
+ expect(() => ObjectUtils.toDateOrThrow("data inválida")).toThrow();
49
+ });
50
+
51
+ it("deve lançar erro com nome de campo personalizado", () => {
52
+ expect(() => ObjectUtils.toDateOrThrow("abc", "nascimento")).toThrow(
53
+ 'O campo "nascimento" não é uma data válida: abc'
54
+ );
55
+ });
56
+ });
57
+
58
+ describe("toDateOrNull", () => {
59
+ it("deve retornar a própria instância de Date válida", () => {
60
+ const date = new Date();
61
+ expect(ObjectUtils.toDateOrNull(date)).toEqual(date);
62
+ });
63
+
64
+ it("deve converter string de data válida para Date", () => {
65
+ const result = ObjectUtils.toDateOrNull("2025-04-02");
66
+ expect(result).toBeInstanceOf(Date);
67
+ expect(result!.toISOString().startsWith("2025-04-02")).toBe(true);
68
+ });
69
+
70
+ it("deve retornar null para string inválida", () => {
71
+ expect(ObjectUtils.toDateOrNull("abc")).toBeNull();
72
+ });
73
+
74
+ it("deve retornar null para null", () => {
75
+ expect(ObjectUtils.toDateOrNull(null)).toBeNull();
76
+ });
77
+
78
+ it("deve retornar null para tipos não suportados", () => {
79
+ expect(ObjectUtils.toDateOrNull({})).toBeNull();
80
+ expect(ObjectUtils.toDateOrNull(123)).toBeNull();
81
+ });
82
+ });
83
+ });