Improve Utils unit tests
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 1 Nov 2022 10:07:52 +0000 (11:07 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 1 Nov 2022 10:07:52 +0000 (11:07 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
test/utils/UtilsTest.ts

index 1607cf53967e96be7b0821edfb4b8d9d5f59f252..7eb6aeb240363db2924eb1c2fbcf7e9764fe9036 100644 (file)
@@ -23,6 +23,9 @@ describe('Utils test suite', () => {
   });
 
   it('Verify convertToDate()', () => {
+    expect(Utils.convertToDate(undefined)).toBe(undefined);
+    expect(Utils.convertToDate(null)).toBe(null);
+    expect(Utils.convertToDate(0)).toBe(0);
     const dateStr = '2020-01-01T00:00:00.000Z';
     let date = Utils.convertToDate(dateStr);
     expect(date).toBeInstanceOf(Date);
@@ -45,8 +48,11 @@ describe('Utils test suite', () => {
   });
 
   it('Verify convertToInt()', () => {
-    const random = Utils.getRandomInteger();
-    expect(Utils.convertToInt(random)).toEqual(random);
+    expect(Utils.convertToInt(undefined)).toBe(0);
+    expect(Utils.convertToInt(null)).toBe(0);
+    expect(Utils.convertToInt(0)).toBe(0);
+    const randomInteger = Utils.getRandomInteger();
+    expect(Utils.convertToInt(randomInteger)).toEqual(randomInteger);
     expect(Utils.convertToInt('1')).toBe(1);
     expect(Utils.convertToInt('1.1')).toBe(1);
     expect(Utils.convertToInt('1.9')).toBe(1);
@@ -58,8 +64,11 @@ describe('Utils test suite', () => {
   });
 
   it('Verify convertToFloat()', () => {
-    const random = Utils.getRandomFloat();
-    expect(Utils.convertToFloat(random)).toEqual(random);
+    expect(Utils.convertToFloat(undefined)).toBe(0);
+    expect(Utils.convertToFloat(null)).toBe(0);
+    expect(Utils.convertToFloat(0)).toBe(0);
+    const randomFloat = Utils.getRandomFloat();
+    expect(Utils.convertToFloat(randomFloat)).toEqual(randomFloat);
     expect(Utils.convertToFloat('1')).toBe(1);
     expect(Utils.convertToFloat('1.1')).toBe(1.1);
     expect(Utils.convertToFloat('1.9')).toBe(1.9);
@@ -71,6 +80,8 @@ describe('Utils test suite', () => {
   });
 
   it('Verify convertToBoolean()', () => {
+    expect(Utils.convertToBoolean(undefined)).toBe(false);
+    expect(Utils.convertToBoolean(null)).toBe(false);
     expect(Utils.convertToBoolean('true')).toBe(true);
     expect(Utils.convertToBoolean('false')).toBe(false);
     expect(Utils.convertToBoolean('TRUE')).toBe(true);