mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-05-18 07:16:17 +02:00
Remove some unneeded duplication and fix up reconnection management
This commit is contained in:
@@ -4,13 +4,12 @@ import {
|
||||
findContactsByPrefix,
|
||||
calculateDistance,
|
||||
sortContactsByDistance,
|
||||
getHopCount,
|
||||
resolvePath,
|
||||
formatDistance,
|
||||
formatHopCounts,
|
||||
} from '../utils/pathUtils';
|
||||
import type { Contact, RadioConfig } from '../types';
|
||||
import { CONTACT_TYPE_REPEATER, CONTACT_TYPE_CLIENT } from '../types';
|
||||
import { CONTACT_TYPE_REPEATER } from '../types';
|
||||
|
||||
// Helper to create mock contacts
|
||||
function createContact(overrides: Partial<Contact> = {}): Contact {
|
||||
@@ -90,7 +89,7 @@ describe('findContactsByPrefix', () => {
|
||||
createContact({
|
||||
public_key: '1ACCCC' + 'C'.repeat(52),
|
||||
name: 'Client1',
|
||||
type: CONTACT_TYPE_CLIENT,
|
||||
type: 1, // client
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -195,20 +194,6 @@ describe('sortContactsByDistance', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getHopCount', () => {
|
||||
it('returns 0 for null/empty', () => {
|
||||
expect(getHopCount(null)).toBe(0);
|
||||
expect(getHopCount(undefined)).toBe(0);
|
||||
expect(getHopCount('')).toBe(0);
|
||||
});
|
||||
|
||||
it('counts hops correctly', () => {
|
||||
expect(getHopCount('1A')).toBe(1);
|
||||
expect(getHopCount('1A2B')).toBe(2);
|
||||
expect(getHopCount('1A2B3C')).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolvePath', () => {
|
||||
const repeater1 = createContact({
|
||||
public_key: '1A' + 'A'.repeat(62),
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { parseSenderFromText } from '../utils/messageParser';
|
||||
import { CONTACT_TYPE_REPEATER, CONTACT_TYPE_CLIENT } from '../types';
|
||||
import { CONTACT_TYPE_REPEATER } from '../types';
|
||||
|
||||
describe('Repeater message sender parsing', () => {
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ describe('Repeater message sender parsing', () => {
|
||||
|
||||
it('non-repeater messages still get sender parsed', () => {
|
||||
const channelMessage = 'Alice: Hello everyone!';
|
||||
const contactType: number = CONTACT_TYPE_CLIENT;
|
||||
const contactType: number = 1; // client
|
||||
|
||||
const isRepeater = contactType === CONTACT_TYPE_REPEATER;
|
||||
const { sender, content } = isRepeater
|
||||
|
||||
@@ -164,7 +164,6 @@ export interface MigratePreferencesResponse {
|
||||
}
|
||||
|
||||
/** Contact type constants */
|
||||
export const CONTACT_TYPE_CLIENT = 1;
|
||||
export const CONTACT_TYPE_REPEATER = 2;
|
||||
|
||||
export interface NeighborInfo {
|
||||
|
||||
@@ -148,7 +148,7 @@ export function sortContactsByDistance(
|
||||
/**
|
||||
* Get simple hop count from path string
|
||||
*/
|
||||
export function getHopCount(path: string | null | undefined): number {
|
||||
function getHopCount(path: string | null | undefined): number {
|
||||
if (!path || path.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user