diff --git a/src/backend/sources/PlexApiSource.ts b/src/backend/sources/PlexApiSource.ts index 570416c5..6f0fc4e0 100644 --- a/src/backend/sources/PlexApiSource.ts +++ b/src/backend/sources/PlexApiSource.ts @@ -232,22 +232,22 @@ export default class PlexApiSource extends MemoryPositionalSource { if(state.play !== undefined) { const allowedLibraries = this.getAllowedLibraries(); - if(allowedLibraries.length > 0 && !allowedLibraries.some(x => state.play.meta.library.toLocaleLowerCase().includes(x.name.toLocaleLowerCase()))) { + if(allowedLibraries.length > 0 && !allowedLibraries.some(x => state.play.meta.library.toLocaleLowerCase() === x.name.toLocaleLowerCase())) { return `media not included in librariesAllow`; } if(allowedLibraries.length === 0) { const blockedLibraries = this.getBlockedLibraries(); if(blockedLibraries.length > 0) { - const blockedLibrary = blockedLibraries.find(x => state.play.meta.library.toLocaleLowerCase().includes(x.name.toLocaleLowerCase())); + const blockedLibrary = blockedLibraries.find(x => state.play.meta.library.toLocaleLowerCase() === x.name.toLocaleLowerCase()); if(blockedLibrary !== undefined) { return `media included in librariesBlock '${blockedLibrary.name}'`; } } - - if(!this.getValidLibraries().some(x => state.play.meta.library === x.name)) { - return `media not included in a valid library`; - } + } + + if(!this.getValidLibraries().some(x => state.play.meta.library === x.name)) { + return `media not included in a valid library`; } } diff --git a/src/backend/tests/plex/plex.test.ts b/src/backend/tests/plex/plex.test.ts index 4d814f23..c26e70ce 100644 --- a/src/backend/tests/plex/plex.test.ts +++ b/src/backend/tests/plex/plex.test.ts @@ -134,18 +134,27 @@ describe("Plex API Source", function() { it('Should allow activity based on libraries allow', async function () { const s = await createSource({...defaultCreds, librariesAllow: ['music']}); + s.libraries.push({name: 'SomeOtherLibrary', collectionType: 'artist', uuid: '43543'}); + s.libraries.push({name: 'Study Music', collectionType: 'artist', uuid: '435437'}); + s.libraries.push({name: 'Music', collectionType: 'artist', uuid: '4354378'}); expect(s.isActivityValid(validPlayerState, validSession)).to.be.true; expect(s.isActivityValid(playWithMeta({library: 'SomeOtherLibrary'}), nowPlayingSession({librarySectionTitle: 'SomeOtherLibrary'}))).to.not.be.true; + expect(s.isActivityValid(playWithMeta({library: 'Study Music'}), nowPlayingSession({librarySectionTitle: 'Study Music'}))).to.not.be.true; + expect(s.isActivityValid(playWithMeta({library: 'Music'}), nowPlayingSession({librarySectionTitle: 'Music'}))).to.be.true; await s.destroy(); }); it('Should disallow activity based on libraries block', async function () { const s = await createSource({...defaultCreds, librariesBlock: ['music']}); s.libraries.push({name: 'CoolVideos', collectionType: 'artist', uuid: '43543'}); + s.libraries.push({name: 'Study Music', collectionType: 'artist', uuid: '435437'}); + s.libraries.push({name: 'Music', collectionType: 'artist', uuid: '4354378'}); expect(s.isActivityValid(validPlayerState, validSession)).to.not.be.true; expect(s.isActivityValid(playWithMeta({library: 'CoolVideos'}), nowPlayingSession({librarySectionTitle: 'CoolVideos'}))).to.be.true; + expect(s.isActivityValid(playWithMeta({library: 'Study Music'}), nowPlayingSession({librarySectionTitle: 'Study Music'}))).to.be.true; + expect(s.isActivityValid(playWithMeta({library: 'Music'}), nowPlayingSession({librarySectionTitle: 'Music'}))).to.not.be.true; await s.destroy(); });