|
| 1 | +import configMeta from '../../src/shared/configMeta.js'; |
| 2 | +import { CONFIG_SHOULD_LOG_KEY } from '../../src/shared/constants.js'; |
| 3 | + |
| 4 | +describe('configMeta (shared/configMeta)', () => { |
| 5 | + it('exports a single config entry', () => { |
| 6 | + expect(configMeta).toHaveLength(1); |
| 7 | + }); |
| 8 | + |
| 9 | + describe('config entry', () => { |
| 10 | + const entry = configMeta[0]; |
| 11 | + |
| 12 | + it('uses CONFIG_SHOULD_LOG_KEY as key', () => { |
| 13 | + expect(entry.key).toBe(CONFIG_SHOULD_LOG_KEY); |
| 14 | + expect(entry.key).toBe('should-log-env'); |
| 15 | + }); |
| 16 | + |
| 17 | + it('has description about printing loaded env variables', () => { |
| 18 | + expect(entry.description).toContain('loaded env variables'); |
| 19 | + expect(entry.description).toContain('SF CLI command'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('has failedMessage for invalid input', () => { |
| 23 | + expect(entry.input.failedMessage).toBe('must provide either "true" or "false"'); |
| 24 | + }); |
| 25 | + |
| 26 | + describe('input.validator', () => { |
| 27 | + const validator = entry.input.validator; |
| 28 | + |
| 29 | + it('accepts string "true"', () => { |
| 30 | + expect(validator('true')).toBe(true); |
| 31 | + }); |
| 32 | + |
| 33 | + it('accepts string "false"', () => { |
| 34 | + expect(validator('false')).toBe(true); |
| 35 | + }); |
| 36 | + |
| 37 | + it('accepts boolean true (toString "true")', () => { |
| 38 | + expect(validator(true)).toBe(true); |
| 39 | + }); |
| 40 | + |
| 41 | + it('accepts boolean false (toString "false")', () => { |
| 42 | + expect(validator(false)).toBe(true); |
| 43 | + }); |
| 44 | + |
| 45 | + it('rejects null', () => { |
| 46 | + expect(validator(null)).toBe(false); |
| 47 | + }); |
| 48 | + |
| 49 | + it('rejects undefined', () => { |
| 50 | + expect(validator(undefined as unknown as string)).toBe(false); |
| 51 | + }); |
| 52 | + |
| 53 | + it('rejects other strings', () => { |
| 54 | + expect(validator('yes')).toBe(false); |
| 55 | + expect(validator('no')).toBe(false); |
| 56 | + expect(validator('')).toBe(false); |
| 57 | + expect(validator('1')).toBe(false); |
| 58 | + expect(validator('0')).toBe(false); |
| 59 | + }); |
| 60 | + |
| 61 | + it('rejects numbers', () => { |
| 62 | + expect(validator(1)).toBe(false); |
| 63 | + expect(validator(0)).toBe(false); |
| 64 | + }); |
| 65 | + }); |
| 66 | + }); |
| 67 | +}); |
0 commit comments