@apistudio/apim-cli
Version:
CLI for API Management Products
58 lines (46 loc) • 2.19 kB
text/typescript
/**
* Copyright Super iPaaS Integration LLC, an IBM Company 2024
*/
import {checkForNullOrUndefined, isNullOrUndefined, equalsIgnoreCase} from './data-helper';
describe('Data helper test suite', () => {
it('should return false on valid value', () => {
const isUndefined = isNullOrUndefined('test');
expect(isUndefined).toBeFalsy();
});
it('should return true if null or undefined provided', () => {
const isUndefined = isNullOrUndefined(null);
expect(isUndefined).toBeTruthy();
});
it('should return value on valid value', () => {
const value = 'testValue';
const checkForNullOrUndefined1 = checkForNullOrUndefined(value, 'value is not defined');
expect(checkForNullOrUndefined1).toBe(value);
});
it('should throw error on null', () => {
const errorMessage= 'value is not defined';
expect(() => checkForNullOrUndefined(null, errorMessage)).toThrow(errorMessage);
});
it('should return true when both inputs are null', () => {
expect(equalsIgnoreCase(null as unknown as string, null as unknown as string)).toBe(true);
});
it('should return true when both inputs are undefined', () => {
expect(equalsIgnoreCase(undefined as unknown as string, undefined as unknown as string)).toBe(true);
});
it('should return false when one input is null and the other is a non-empty string', () => {
expect(equalsIgnoreCase(null as unknown as string, 'test')).toBe(false);
expect(equalsIgnoreCase('test', null as unknown as string)).toBe(false);
});
it('should return false when one input is undefined and the other is a non-empty string', () => {
expect(equalsIgnoreCase(undefined as unknown as string, 'test')).toBe(false);
expect(equalsIgnoreCase('test', undefined as unknown as string)).toBe(false);
});
it('should return true for equal strings in different cases', () => {
expect(equalsIgnoreCase('Test', 'test')).toBe(true);
expect(equalsIgnoreCase('TEST', 'test')).toBe(true);
expect(equalsIgnoreCase('Test', 'TEST')).toBe(true);
});
it('should return false for strings that are not equal', () => {
expect(equalsIgnoreCase('Test', 'different')).toBe(false);
expect(equalsIgnoreCase('TEST', 'DIFFERENT')).toBe(false);
});
});