|
| 1 | +import { isAuto, isAutoVpcConfig, getTimeZone, sleep } from '../../src/utils/index'; |
| 2 | +import log from '../../src/logger'; |
| 3 | +log._set(console); |
| 4 | + |
| 5 | +describe('Utils functions', () => { |
| 6 | + describe('isAuto', () => { |
| 7 | + it('should return true for "AUTO" string', () => { |
| 8 | + expect(isAuto('AUTO')).toBe(true); |
| 9 | + expect(isAuto('auto')).toBe(true); |
| 10 | + expect(isAuto('Auto')).toBe(true); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should return false for non-"AUTO" strings', () => { |
| 14 | + expect(isAuto('manual')).toBe(false); |
| 15 | + expect(isAuto('other')).toBe(false); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should return false for non-string values', () => { |
| 19 | + expect(isAuto(123)).toBe(false); |
| 20 | + expect(isAuto(null)).toBe(false); |
| 21 | + expect(isAuto(undefined)).toBe(false); |
| 22 | + expect(isAuto({})).toBe(false); |
| 23 | + expect(isAuto([])).toBe(false); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('isAutoVpcConfig', () => { |
| 28 | + it('should return true for "AUTO" string', () => { |
| 29 | + expect(isAutoVpcConfig('AUTO')).toBe(true); |
| 30 | + expect(isAutoVpcConfig('auto')).toBe(true); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should return true for object with AUTO vSwitchIds', () => { |
| 34 | + const config = { |
| 35 | + vpcId: 'vpc-123', |
| 36 | + vSwitchIds: 'auto', |
| 37 | + }; |
| 38 | + expect(isAutoVpcConfig(config)).toBe(true); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should return true for object with AUTO securityGroupId', () => { |
| 42 | + const config = { |
| 43 | + vpcId: 'vpc-123', |
| 44 | + securityGroupId: 'auto', |
| 45 | + }; |
| 46 | + expect(isAutoVpcConfig(config)).toBe(true); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should return false for object without vpcId', () => { |
| 50 | + const config = { |
| 51 | + vSwitchIds: 'auto', |
| 52 | + }; |
| 53 | + expect(isAutoVpcConfig(config)).toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should return false for non-auto configs', () => { |
| 57 | + const config = { |
| 58 | + vpcId: 'vpc-123', |
| 59 | + vSwitchIds: 'vsw-123', |
| 60 | + }; |
| 61 | + expect(isAutoVpcConfig(config)).toBe(false); |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + describe('getTimeZone', () => { |
| 66 | + it('should return a valid timezone string', () => { |
| 67 | + const tz = getTimeZone(); |
| 68 | + expect(tz).toMatch(/^UTC[+-]\d+$/); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('sleep', () => { |
| 73 | + it('should resolve after specified time', async () => { |
| 74 | + const start = Date.now(); |
| 75 | + await sleep(0.01); // 10ms |
| 76 | + const end = Date.now(); |
| 77 | + expect(end - start).toBeGreaterThanOrEqual(10); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments