Tests/Integration/SpotifyPlaylists.Tests.ps1

InModuleScope SpotifyControls {
    BeforeAll {
        Import-Module "$PSScriptRoot\..\SUCommonTestFuncs.psm1"
        Mock Invoke-WebRequest { Invoke-MockWebRequest @PesterBoundParameters }
        Mock Start-Process     { Start-MockProcess @PesterBoundParameters }
        Mock Get-Content       { Get-MockContent @PesterBoundParameters }
        $script:TOKENS = [System.Collections.ArrayList]::New()
    }
    Describe "SpotifyPlaylists" {
        It "returns all playlists as Name and Id objects" {
            $playlists = Get-SpotifyPlaylists
            [string] $playlists.GetType() | Should -Be 'System.Object[]'
            [string] $playlists[0].GetType() | Should -Match 'PSCustomObject'
            $playlists[0].Name | Should -Be 'playlist name'
            $playlists[0].Id   | Should -Be 'string'
            $jsonResult = $playlists | ConvertTo-Json -Depth 10 -Compress
            $jsonResult | Should -Be (Get-PlaylistOutput)
            $script:TOKENS.Count | Should -Be 1
            $expectedScopes = @(
                'playlist-read-private', 'playlist-read-collaborative'
            )
            $script:TOKENS[0].scopes | Should -Be $expectedScopes
        }
        It "filters by name when -Name is provided" {
            $match = Get-SpotifyPlaylists -Name "playlist"
            $match | Should -Not -BeNullOrEmpty
            $match[0].Name | Should -BeLike '*playlist*'
        }
        It "returns warning when -Name has no match" {
            { Get-SpotifyPlaylists -Name "zzz-no-match-zzz" } | Should -Not -Throw
        }
    }
}