Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/plex/src/client.sections-rows.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { afterEach, expect, it, vi } from 'vitest'
import { PlexClient } from './client.js'

afterEach(() => {
vi.unstubAllGlobals()
})

it('skips a null entry in the library sections list instead of throwing a TypeError', async () => {
vi.stubGlobal('fetch', async (url: string) =>
new Response(
JSON.stringify(
String(url).includes('/library/sections')
? { MediaContainer: { Directory: [null, { type: 'artist', key: '1', title: 'Music' }] } }
: { MediaContainer: { machineIdentifier: 'm', version: '1' } },
),
),
)
const client = new PlexClient('http://plex.test:32400', 'tok')
const result = await client.testConnection()
expect(result.machineIdentifier).toBe('m')
})
2 changes: 1 addition & 1 deletion packages/plex/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class PlexClient {

private async librarySections(): Promise<PlexLibrarySection[]> {
const payload = await this.request<PlexSectionsResponse>('/library/sections')
return (payload.MediaContainer?.Directory ?? [])
return plexRows(payload.MediaContainer?.Directory)
.filter((section) => section.type === 'artist' && section.key !== undefined && section.title)
.map((section) => ({
id: String(section.key),
Expand Down
Loading