diff --git a/functions/core.ps1 b/functions/core.ps1 index e60f92a..0b8faad 100644 --- a/functions/core.ps1 +++ b/functions/core.ps1 @@ -57,7 +57,10 @@ function CallRestUri { if ($null -eq $params.TimeoutSec) { $paramInvokeRestMethod.TimeoutSec = 300 } - $result = Invoke-WebRequest @paramInvokeRestMethod @params + $result = Invoke-WebRequest @paramInvokeRestMethod @params -UseBasicParsing + if ($result.Headers -and $result.Headers['Content-Type'] -like 'application/json;*') { + $result = $result.Content | ConvertFrom-Json + } } else { $result = Invoke-RestMethod @paramInvokeRestMethod @params diff --git a/tests/core.tests.ps1 b/tests/core.tests.ps1 index 681be9e..c7d85c0 100644 --- a/tests/core.tests.ps1 +++ b/tests/core.tests.ps1 @@ -3,20 +3,28 @@ Import-Module (Resolve-Path "$PSScriptRoot\..\Qlik-Cli.psd1").Path Describe 'CallRestUri' { InModuleScope Qlik-Cli { - Context 'when uploading or downloading files' { + Describe 'when uploading or downloading files' { BeforeAll { - Mock Invoke-WebRequest -Verifiable { } + Mock Invoke-WebRequest -Verifiable { return $UseBasicParsing } Mock Invoke-RestMethod { throw 'Invoke-RestMethod should not be used for file transfers' } $script:prefix = 'https://localhost' $script:api_params = @{ } $script:rawOutput = $true } - it 'should use Invoke-WebRequest' { + It 'should use Invoke-WebRequest' { CallRestUri GET /qrs/download/scriptlog @{ OutFile = 'TestDrive:\script.log' } Assert-VerifiableMock } + + It 'should use basic parsing' { + $result = CallRestUri GET /qrs/app/upload @{ InFile = 'TestDrive:\app.qvf' } + + $result | Should -BeTrue + + Assert-VerifiableMock + } } } }