File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,7 +115,11 @@ Function Get-BloggerPost {
115115 $title = $result.title
116116 $frontMatter = [ordered ]@ {
117117 postId = $result.id
118- tags = $result.labels
118+ }
119+ if ($result [' labels' ]) {
120+ $frontMatter [' tags' ] = $result.labels
121+ } else {
122+ $frontMatter [' tags' ] = @ ()
119123 }
120124 $file = " $title .md"
121125 $filePath = Join-Path - Path $OutDirectory - ChildPath $file
Original file line number Diff line number Diff line change @@ -221,6 +221,33 @@ Describe "Get-BloggerPost" {
221221 $frontMatter.tags [0 ] | Should - Be " Azure DevOps"
222222 $frontMatter.tags [1 ] | Should - Be " Azure Pipelines"
223223 }
224+
225+ It " Should include empty tags in frontmatter if labels are not present" {
226+ # arrange
227+ InModuleScope PSBlogger {
228+ # Mock the session to return a test blog ID
229+ $BloggerSession.BlogId = " test-blog-id"
230+
231+ $postId = " 123"
232+
233+ # mock post retrieval
234+ Mock Invoke-GApi {
235+ return @ {
236+ id = $postId
237+ title = " Test Post"
238+ published = [datetime ]" 2023-10-01T17:30:00-04:00"
239+ content = " <h1>Hello World</h1><p>This is a post.</p>"
240+ }
241+ }
242+ }
243+ # act
244+ Get-BloggerPost - PostId $postId - Format Markdown - OutDirectory " TestDrive:\"
245+
246+ # assert
247+ $frontMatter = Get-MarkdownFrontMatter - File $outFile
248+ $frontMatter [' tags' ] -eq $null | Should - BeFalse
249+ $frontMatter [' tags' ] | Should - Be @ ()
250+ }
224251 }
225252
226253 Context " As Json" {
@@ -292,6 +319,7 @@ Describe "Get-BloggerPost" {
292319 It " Should write file to specified formatted directory - <dateformat> - <format>" - TestCases @ (
293320 @ { DateFormat = " yyyy\\MM" ; ExpectedPath = " TestDrive:\2023\10\Test Post.md" ; Format = " Markdown" }
294321 @ { DateFormat = " yyyy\\MM\\dd" ; ExpectedPath = " TestDrive:\2023\10\01\123.html" ; Format = " HTML" }
322+ @ { DateFormat = " yyyy" ; ExpectedPath = " TestDrive:\2023\123.json" ; Format = " JSON" }
295323 ) {
296324 # arrange
297325 $invokeArgs = @ {
You can’t perform that action at this time.
0 commit comments