mirror of
https://github.com/Ravinou/borgwarehouse
synced 2026-03-14 14:25:46 +01:00
test: ✅ add test to lanCommandOption util
This commit is contained in:
parent
4de1884de8
commit
fb61846bbb
2 changed files with 76 additions and 1 deletions
75
helpers/functions/lanCommandOption.test.ts
Normal file
75
helpers/functions/lanCommandOption.test.ts
Normal file
|
|
@ -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<WizardEnvType> = {
|
||||
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<WizardEnvType> = {
|
||||
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<WizardEnvType> = {
|
||||
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<WizardEnvType> = {
|
||||
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<WizardEnvType> = {
|
||||
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 });
|
||||
});
|
||||
});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { Optional, WizardEnvType } from '~/types';
|
||||
|
||||
export default function lanCommandOption(
|
||||
wizardEnv?: WizardEnvType,
|
||||
wizardEnv?: Partial<WizardEnvType>,
|
||||
lanCommand?: boolean
|
||||
): { FQDN: Optional<string>; SSH_SERVER_PORT: Optional<string> } {
|
||||
if (!wizardEnv) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue