@@ -7,6 +7,7 @@ import {
|
||||
arrayMove,
|
||||
aspectRatioToStyle,
|
||||
contentsChanged,
|
||||
convertHTTPAdressToWebsocket,
|
||||
dayToDate,
|
||||
desparsifyArrays,
|
||||
errorToConsole,
|
||||
@@ -514,3 +515,23 @@ describe('generateFloatApproximatelyEqualsCustomizer', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertHTTPAdressToWebsocket', () => {
|
||||
it('should convert http to ws', () => {
|
||||
expect(convertHTTPAdressToWebsocket('http://example.com')).toBe('ws://example.com');
|
||||
});
|
||||
it('should convert https to ws', () => {
|
||||
expect(convertHTTPAdressToWebsocket('https://example.com')).toBe(
|
||||
'wss://example.com',
|
||||
);
|
||||
});
|
||||
it('should not change ws url', () => {
|
||||
expect(convertHTTPAdressToWebsocket('ws://example.com')).toBe('ws://example.com');
|
||||
});
|
||||
it('should not change wss url', () => {
|
||||
expect(convertHTTPAdressToWebsocket('wss://example.com')).toBe('wss://example.com');
|
||||
});
|
||||
it('should handle mixed case', () => {
|
||||
expect(convertHTTPAdressToWebsocket('HtTp://example.com')).toBe('ws://example.com');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { homeAssistantSignPath } from '../../src/ha/sign-path.js';
|
||||
import { convertEndpointAddressToSignedWebsocket } from '../../src/utils/endpoint';
|
||||
import { createHASS } from '../test-utils';
|
||||
|
||||
vi.mock('../../src/ha/sign-path.js');
|
||||
|
||||
describe('convertEndpointAddressToSignedWebsocket', () => {
|
||||
it('without signing', async () => {
|
||||
expect(
|
||||
await convertEndpointAddressToSignedWebsocket(createHASS(), {
|
||||
endpoint: 'http://example.com',
|
||||
sign: false,
|
||||
}),
|
||||
).toBe('http://example.com');
|
||||
});
|
||||
|
||||
describe('with signing', () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('successful', async () => {
|
||||
vi.mocked(homeAssistantSignPath).mockResolvedValue('http://signed.com');
|
||||
|
||||
expect(
|
||||
await convertEndpointAddressToSignedWebsocket(createHASS(), {
|
||||
endpoint: 'http://example.com',
|
||||
sign: true,
|
||||
}),
|
||||
).toBe('ws://signed.com');
|
||||
});
|
||||
|
||||
it('with null response', async () => {
|
||||
vi.mocked(homeAssistantSignPath).mockResolvedValue(null);
|
||||
|
||||
expect(
|
||||
await convertEndpointAddressToSignedWebsocket(createHASS(), {
|
||||
endpoint: 'http://example.com',
|
||||
sign: true,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('with exception on signing', async () => {
|
||||
const consoleSpy = vi.spyOn(global.console, 'warn').mockReturnValue(undefined);
|
||||
|
||||
vi.mocked(homeAssistantSignPath).mockRejectedValue(new Error());
|
||||
|
||||
expect(
|
||||
await convertEndpointAddressToSignedWebsocket(createHASS(), {
|
||||
endpoint: 'http://example.com',
|
||||
sign: true,
|
||||
}),
|
||||
).toBeNull();
|
||||
|
||||
expect(consoleSpy).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user