diff --git a/helpers/functions/lanCommandOption.test.ts b/helpers/functions/lanCommandOption.test.ts new file mode 100644 index 0000000..d4dbdd3 --- /dev/null +++ b/helpers/functions/lanCommandOption.test.ts @@ -0,0 +1,75 @@ +import { describe, it, expect } from 'vitest'; +import lanCommandOption from './lanCommandOption'; +import { WizardEnvType } from '~/types'; + +describe('lanCommandOption', () => { + it('should return undefined values when wizardEnv is not provided', () => { + const result = lanCommandOption(); + expect(result).toEqual({ FQDN: undefined, SSH_SERVER_PORT: undefined }); + }); + + it('should return FQDN and SSH_SERVER_PORT from wizardEnv when lanCommand is false', () => { + const wizardEnv: Partial = { + FQDN: 'example.com', + FQDN_LAN: 'lan.example.com', + SSH_SERVER_PORT: '22', + SSH_SERVER_PORT_LAN: '2222', + HIDE_SSH_PORT: 'false', + }; + + const result = lanCommandOption(wizardEnv, false); + expect(result).toEqual({ FQDN: 'example.com', SSH_SERVER_PORT: ':22' }); + }); + + it('should return FQDN_LAN and SSH_SERVER_PORT_LAN from wizardEnv when lanCommand is true', () => { + const wizardEnv: Partial = { + FQDN: 'example.com', + FQDN_LAN: 'lan.example.com', + SSH_SERVER_PORT: '22', + SSH_SERVER_PORT_LAN: '2222', + HIDE_SSH_PORT: 'false', + }; + + const result = lanCommandOption(wizardEnv, true); + expect(result).toEqual({ FQDN: 'lan.example.com', SSH_SERVER_PORT: ':2222' }); + }); + + it('should return undefined for SSH_SERVER_PORT when HIDE_SSH_PORT is true', () => { + const wizardEnv: Partial = { + FQDN: 'example.com', + FQDN_LAN: 'lan.example.com', + SSH_SERVER_PORT: '22', + SSH_SERVER_PORT_LAN: '2222', + HIDE_SSH_PORT: 'true', + }; + + const result = lanCommandOption(wizardEnv, false); + expect(result).toEqual({ FQDN: 'example.com', SSH_SERVER_PORT: undefined }); + }); + + it('should fallback to FQDN and should leave ssh server port to undefined for some usages', () => { + const wizardEnv: Partial = { + FQDN: 'example.com', + FQDN_LAN: undefined, + SSH_SERVER_PORT: '22', + SSH_SERVER_PORT_LAN: undefined, + HIDE_SSH_PORT: 'false', + }; + + const result = lanCommandOption(wizardEnv, true); + expect(result).toEqual({ FQDN: 'example.com', SSH_SERVER_PORT: undefined }); + }); + + it('should handle missing FQDN and SSH_SERVER_PORT gracefully', () => { + const wizardEnv: Partial = { + FQDN: undefined, + FQDN_LAN: 'lan.example.com', + SSH_SERVER_PORT: undefined, + SSH_SERVER_PORT_LAN: '2222', + HIDE_SSH_PORT: 'false', + }; + + const result = lanCommandOption(wizardEnv, false); + expect(result).toEqual({ FQDN: undefined, SSH_SERVER_PORT: undefined }); + }); +}); diff --git a/helpers/functions/lanCommandOption.ts b/helpers/functions/lanCommandOption.ts index 2f1f001..43b1424 100644 --- a/helpers/functions/lanCommandOption.ts +++ b/helpers/functions/lanCommandOption.ts @@ -1,7 +1,7 @@ import { Optional, WizardEnvType } from '~/types'; export default function lanCommandOption( - wizardEnv?: WizardEnvType, + wizardEnv?: Partial, lanCommand?: boolean ): { FQDN: Optional; SSH_SERVER_PORT: Optional } { if (!wizardEnv) {