From fb61846bbbe88f3ee3ff79c3182dd1382ac163bd Mon Sep 17 00:00:00 2001 From: Ravinou Date: Sat, 19 Apr 2025 21:09:55 +0200 Subject: [PATCH] =?UTF-8?q?test:=20=E2=9C=85=20add=20test=20to=20lanComman?= =?UTF-8?q?dOption=20util?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helpers/functions/lanCommandOption.test.ts | 75 ++++++++++++++++++++++ helpers/functions/lanCommandOption.ts | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 helpers/functions/lanCommandOption.test.ts 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) {