From 5e7a50c77d46f0360770ecfb25099e4da4829c79 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Wed, 23 Jul 2025 10:35:59 -0400 Subject: [PATCH 1/3] Get-BloggerPost supports -Format JSON --- src/public/Get-BloggerPost.ps1 | 9 +++++- src/tests/Get-BloggerPost.Tests.ps1 | 47 ++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/public/Get-BloggerPost.ps1 b/src/public/Get-BloggerPost.ps1 index da19289..7994b94 100644 --- a/src/public/Get-BloggerPost.ps1 +++ b/src/public/Get-BloggerPost.ps1 @@ -39,7 +39,7 @@ Function Get-BloggerPost { [string]$PostId, [Parameter(Mandatory, ParameterSetName = "Persist")] - [ValidateSet("HTML", "Markdown")] + [ValidateSet("HTML", "Markdown", "JSON")] [string]$Format, [Parameter(ParameterSetName ="Persist")] @@ -122,6 +122,13 @@ Function Get-BloggerPost { Set-MarkdownFrontMatter -File $filePath -Replace $frontMatter Write-Verbose "Post content saved to: $filePath" } + + "JSON" { + $fileName = "$PostId.json" + $filePath = Join-Path -Path $OutDirectory -ChildPath $fileName + $result | ConvertTo-Json | Out-File -FilePath $filePath -Encoding UTF8 + Write-Verbose "Post content saved to: $filePath" + } } # Return the post object for further processing if needed diff --git a/src/tests/Get-BloggerPost.Tests.ps1 b/src/tests/Get-BloggerPost.Tests.ps1 index c5abc49..ea4b5fb 100644 --- a/src/tests/Get-BloggerPost.Tests.ps1 +++ b/src/tests/Get-BloggerPost.Tests.ps1 @@ -182,7 +182,7 @@ Describe "Get-BloggerPost" { return @{ id = $postId title = "Test Post" - published = "10/01/2023 12:00:00" + published = [datetime]"10/01/2023 12:00:00" content = "
This is a post.
" } } @@ -211,6 +211,51 @@ Describe "Get-BloggerPost" { } } + Context "As Json" { +BeforeEach { + InModuleScope PSBlogger { + # Mock the session to return a test blog ID + $BloggerSession.BlogId = "test-blog-id" + + $postId = "123" + + # mock post retrieval + Mock Invoke-GApi { + return @{ + id = $postId + title = "Test Post" + published = [datetime]"10/01/2023 12:00:00" + content = "This is a post.
" + } + } + } + + $postId = "123" + $title = "Test Post" + $outFile = "TestDrive:\$postId.json" + + } + + AfterEach { + if (Test-Path $outFile) { + Remove-Item $outFile -Force + } + } + + It "Should write json response to file" { + + # act + Get-BloggerPost -PostId $postId -Format JSON -OutDirectory "TestDrive:\" + + # assert + $jsonContent = Get-Content -Path $outFile -Raw | ConvertFrom-Json + $jsonContent.id | Should -Be "123" + $jsonContent.title | Should -Be "Test Post" + $jsonContent.content | Should -Not -BeNullOrEmpty + $jsonContent.published | Should -Not -BeNullOrEmpty + } + } + Context "Using FolderDateFormat" { BeforeEach { From 49f110680ca1749a9f71fd7448d4086fcde5e5c9 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Wed, 23 Jul 2025 10:59:00 -0400 Subject: [PATCH 2/3] updated tests and readme --- README.md | 3 +++ src/public/Get-BloggerPost.ps1 | 2 +- src/tests/Get-BloggerPost.Tests.ps1 | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 47e5d91..ff15082 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,12 @@ A PowerShell library for publishing markdown files authored in markdown to Blogg When using `Markdown` format, files are saved as `This is a post.
" } } @@ -224,7 +224,7 @@ BeforeEach { return @{ id = $postId title = "Test Post" - published = [datetime]"10/01/2023 12:00:00" + published = [datetime]"2023-10-01T17:30:00-04:00" content = "This is a post.
" } } @@ -270,7 +270,7 @@ BeforeEach { return @{ id = $postId title = "Test Post" - published = [datetime]"10/01/2023 12:00:00" + published = [datetime]"2023-10-01T17:30:00-04:00" content = "This is a post.
" } } From 5b380855ad77e5939385cb763777d733897ca3db Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:00:48 -0400 Subject: [PATCH 3/3] fixed indentation for tests --- src/tests/Get-BloggerPost.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/Get-BloggerPost.Tests.ps1 b/src/tests/Get-BloggerPost.Tests.ps1 index d790ea2..84ad198 100644 --- a/src/tests/Get-BloggerPost.Tests.ps1 +++ b/src/tests/Get-BloggerPost.Tests.ps1 @@ -212,7 +212,7 @@ Describe "Get-BloggerPost" { } Context "As Json" { -BeforeEach { + BeforeEach { InModuleScope PSBlogger { # Mock the session to return a test blog ID $BloggerSession.BlogId = "test-blog-id"