feat: Implement basic general folder support (#2051)

- Related: #1748
This commit is contained in:
Dermot Duffy
2025-05-21 19:59:21 -07:00
committed by GitHub
parent 2eb0d9e35e
commit c6a4c8aea2
350 changed files with 12837 additions and 4509 deletions
+38
View File
@@ -0,0 +1,38 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { homeAssistantSignPath } from '../../src/ha/sign-path';
import { homeAssistantWSRequest } from '../../src/ha/ws-request.js';
import { signedPathSchema } from '../../src/types';
import { createHASS } from '../test-utils';
vi.mock('../../src/ha/ws-request.js');
describe('homeAssistantSignPath', () => {
afterEach(() => {
vi.clearAllMocks();
});
it('should sign path', async () => {
const hass = createHASS();
const unsignedPath = 'unsigned/path';
const expires = 42;
vi.mocked(homeAssistantWSRequest).mockResolvedValue({
path: 'signed/path',
});
vi.mocked(hass.hassUrl).mockImplementation((url) => 'hass:' + url);
expect(await homeAssistantSignPath(hass, unsignedPath, expires)).toEqual(
'hass:signed/path',
);
expect(homeAssistantWSRequest).toBeCalledWith(hass, signedPathSchema, {
type: 'auth/sign_path',
path: unsignedPath,
expires,
});
});
it('should return null for null response', async () => {
vi.mocked(homeAssistantWSRequest).mockResolvedValue(null);
expect(await homeAssistantSignPath(createHASS(), 'unsigned/path', 42)).toBeNull();
});
});