From af53c66cd5391e93afb0f33cd3c91f4607d919ce Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sat, 4 Oct 2025 16:13:11 -0700 Subject: [PATCH] fix: Folders should be overrideable (#2198) - Closes #2196 --- src/config/schema/folders.ts | 7 +++++- tests/config/schema/folders.test.ts | 36 ++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/config/schema/folders.ts b/src/config/schema/folders.ts index 7023d432..68c434aa 100644 --- a/src/config/schema/folders.ts +++ b/src/config/schema/folders.ts @@ -119,7 +119,12 @@ export const transformPathURLToPathArray = ( }; const haFolderConfigSchema = z.object({ - url: z.string().transform(transformPathURLToPathArray).optional(), + url: z + .string() + .transform(transformPathURLToPathArray) + // See: https://github.com/dermotduffy/advanced-camera-card/issues/2196 + .or(haFolderPathComponentSchema.array().min(1)) + .optional(), path: haFolderPathComponentSchema.array().nonempty().optional(), }); export type HAFolderConfig = z.infer; diff --git a/tests/config/schema/folders.test.ts b/tests/config/schema/folders.test.ts index b53130e2..9c6e6d47 100644 --- a/tests/config/schema/folders.test.ts +++ b/tests/config/schema/folders.test.ts @@ -1,11 +1,13 @@ import { NonEmptyTuple } from 'type-fest'; import { describe, expect, it } from 'vitest'; import { + FolderConfigWithoutID, + foldersConfigSchema, matcherSchema, transformPathURLToPathArray, } from '../../../src/config/schema/folders'; -describe('transformURLToMediaSourceRoot', () => { +describe('transformPathURLToPathArray', () => { const prefixes: NonEmptyTuple[] = [ ['http://card.camera/' as const], ['/' as const], @@ -92,3 +94,35 @@ describe('should lazy evaluate schemas', () => { }); }); }); + +// See: https://github.com/dermotduffy/advanced-camera-card/issues/2196 +describe('should be able to re-parse a folder', () => { + it('should be able to re-parse a folder', () => { + const inputFolder = { + type: 'ha', + ha: { + url: 'media-browser/browser/app%2Cmedia-source%3A%2F%2Fcamera' as const, + }, + }; + + const expectedFolder: FolderConfigWithoutID = { + type: 'ha', + ha: { + url: [ + { + id: 'media-source://', + }, + { + id: 'media-source://camera', + }, + ], + }, + }; + + const parsedFolders = foldersConfigSchema.parse([inputFolder]); + expect(parsedFolders).toEqual([expectedFolder]); + + const parsedFolder_2 = foldersConfigSchema.parse(parsedFolders); + expect(parsedFolder_2).toEqual([expectedFolder]); + }); +});