From 56a597265593a7a2251d10e9ab94a2393200f394 Mon Sep 17 00:00:00 2001 From: Fabian Franz Steiner <75947402+fasteiner@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:38:40 +0200 Subject: [PATCH] test: add unit tests for block creation commands --- .../New-NotionBookmarkBlock.Tests.ps1 | 39 +++ .../New-NotionBreadcrumbBlock.Tests.ps1 | 29 ++ .../New-NotionBulletedListItemBlock.Tests.ps1 | 39 +++ .../Callout/New-NotionCalloutBlock.Tests.ps1 | 41 +++ .../New-NotionChildPageBlock.Tests.ps1 | 37 +++ .../New-NotionChildDatabaseBlock.Tests.ps1 | 37 +++ .../Block/Code/New-NotionCodeBlock.Tests.ps1 | 46 +++ .../Column/New-NotionColumnBlock.Tests.ps1 | 29 ++ .../New-NotionColumnListBlock.Tests.ps1 | 29 ++ .../Divider/New-NotionDividerBlock.Tests.ps1 | 29 ++ .../Embed/New-NotionEmbedBlock.Tests.ps1 | 38 +++ .../New-NotionEquationBlock.Tests.ps1 | 37 +++ .../Block/File/New-NotionFileBlock.Tests.ps1 | 55 ++++ .../Heading/New-NotionHeadingBlock.Tests.ps1 | 41 +++ .../Image/New-NotionImageBlock.Tests.ps1 | 31 ++ .../New-NotionLinkPreviewBlock.Tests.ps1 | 29 ++ .../Public/Block/New-NotionBlock.Tests.ps1 | 47 +++ .../Block/New-NotionCalloutBlock.Tests.ps1 | 70 ----- .../Block/New-NotionHeadingBlock.Tests.ps1 | 53 ---- .../Block/New-NotionTableBlock.Tests.ps1 | 273 ------------------ .../Block/New-NotionVideoBlock.Tests.ps1 | 51 ---- .../New-NotionNumberedListItemBlock.Tests.ps1 | 37 +++ .../New-NotionParagraphBlock.Tests.ps1 | 46 +++ .../{ => Pdf}/New-NotionPdfBlock.Tests.ps1 | 27 +- .../Quote/New-NotionQuoteBlock.Tests.ps1 | 38 +++ .../Synced/New-NotionSyncedBlock.Tests.ps1 | 29 ++ .../Table/New-NotionTableBlock.Tests.ps1 | 43 +++ .../New-NotionTableOfContentsBlock.Tests.ps1 | 36 +++ .../New-NotionTableRowBlock.Tests.ps1 | 39 +++ .../Block/ToDo/New-NotionToDoBlock.Tests.ps1 | 45 +++ .../Toggle/New-NotionToggleBlock.Tests.ps1 | 37 +++ .../Video/New-NotionVideoBlock.Tests.ps1 | 38 +++ .../_RichText/New-NotionRichText.Tests.ps1 | 46 +++ .../New-NotionRichTextAnnotation.Tests.ps1 | 47 +++ 34 files changed, 1123 insertions(+), 465 deletions(-) create mode 100644 tests/Unit/Public/Block/Bookmark/New-NotionBookmarkBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Breadcrumb/New-NotionBreadcrumbBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/BulletedListItem/New-NotionBulletedListItemBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Callout/New-NotionCalloutBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/ChildDatabase/ChildPage/New-NotionChildPageBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/ChildDatabase/New-NotionChildDatabaseBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Code/New-NotionCodeBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Column/New-NotionColumnBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/ColumnList/New-NotionColumnListBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Divider/New-NotionDividerBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Embed/New-NotionEmbedBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Equation/New-NotionEquationBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/File/New-NotionFileBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Heading/New-NotionHeadingBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Image/New-NotionImageBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/LinkPreview/New-NotionLinkPreviewBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/New-NotionBlock.Tests.ps1 delete mode 100644 tests/Unit/Public/Block/New-NotionCalloutBlock.Tests.ps1 delete mode 100644 tests/Unit/Public/Block/New-NotionHeadingBlock.Tests.ps1 delete mode 100644 tests/Unit/Public/Block/New-NotionTableBlock.Tests.ps1 delete mode 100644 tests/Unit/Public/Block/New-NotionVideoBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/NumberedListItem/New-NotionNumberedListItemBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Paragraph/New-NotionParagraphBlock.Tests.ps1 rename tests/Unit/Public/Block/{ => Pdf}/New-NotionPdfBlock.Tests.ps1 (52%) create mode 100644 tests/Unit/Public/Block/Quote/New-NotionQuoteBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Synced/New-NotionSyncedBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Table/New-NotionTableBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/TableOfContents/New-NotionTableOfContentsBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/TableRow/New-NotionTableRowBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/ToDo/New-NotionToDoBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Toggle/New-NotionToggleBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/Video/New-NotionVideoBlock.Tests.ps1 create mode 100644 tests/Unit/Public/Block/_RichText/New-NotionRichText.Tests.ps1 create mode 100644 tests/Unit/Public/Block/_RichText/New-NotionRichTextAnnotation.Tests.ps1 diff --git a/tests/Unit/Public/Block/Bookmark/New-NotionBookmarkBlock.Tests.ps1 b/tests/Unit/Public/Block/Bookmark/New-NotionBookmarkBlock.Tests.ps1 new file mode 100644 index 0000000..7512b6b --- /dev/null +++ b/tests/Unit/Public/Block/Bookmark/New-NotionBookmarkBlock.Tests.ps1 @@ -0,0 +1,39 @@ +# FILE: Bookmark/New-NotionBookmarkBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionBookmarkBlock" { + InModuleScope $moduleName { + It "Should create an empty bookmark block" { + $result = New-NotionBookmarkBlock + + $result | Should -BeOfType "notion_bookmark_block" + $result.type | Should -Be ([notion_blocktype]::bookmark) + $result.bookmark.url | Should -BeNullOrEmpty + } + + It "Should create a bookmark block with url and caption" { + $result = New-NotionBookmarkBlock -Url "https://example.com" -Caption "Example Caption" + + $result | Should -BeOfType "notion_bookmark_block" + $result.type | Should -Be ([notion_blocktype]::bookmark) + $result.bookmark.url | Should -Be "https://example.com" + $result.bookmark.caption[0].plain_text | Should -Be "Example Caption" + } + } +} diff --git a/tests/Unit/Public/Block/Breadcrumb/New-NotionBreadcrumbBlock.Tests.ps1 b/tests/Unit/Public/Block/Breadcrumb/New-NotionBreadcrumbBlock.Tests.ps1 new file mode 100644 index 0000000..cff1854 --- /dev/null +++ b/tests/Unit/Public/Block/Breadcrumb/New-NotionBreadcrumbBlock.Tests.ps1 @@ -0,0 +1,29 @@ +# FILE: Breadcrumb/New-NotionBreadcrumbBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionBreadcrumbBlock" { + InModuleScope $moduleName { + It "Should create a breadcrumb block" { + $result = New-NotionBreadcrumbBlock + + $result | Should -BeOfType "notion_breadcrumb_block" + $result.type | Should -Be ([notion_blocktype]::breadcrumb) + } + } +} diff --git a/tests/Unit/Public/Block/BulletedListItem/New-NotionBulletedListItemBlock.Tests.ps1 b/tests/Unit/Public/Block/BulletedListItem/New-NotionBulletedListItemBlock.Tests.ps1 new file mode 100644 index 0000000..616752b --- /dev/null +++ b/tests/Unit/Public/Block/BulletedListItem/New-NotionBulletedListItemBlock.Tests.ps1 @@ -0,0 +1,39 @@ +# FILE: BulletedListItem/New-NotionBulletedListItemBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionBulletedListItemBlock" { + InModuleScope $moduleName { + It "Should create an empty bulleted list item block" { + $result = New-NotionBulletedListItemBlock + + $result | Should -BeOfType "notion_bulleted_list_item_block" + $result.type | Should -Be ([notion_blocktype]::bulleted_list_item) + $result.bulleted_list_item.rich_text | Should -BeEmpty + } + + It "Should create a bulleted list item block with text and color" { + $result = New-NotionBulletedListItemBlock -RichText "Item 1" -Color "yellow" + + $result | Should -BeOfType "notion_bulleted_list_item_block" + $result.type | Should -Be ([notion_blocktype]::bulleted_list_item) + $result.bulleted_list_item.rich_text[0].plain_text | Should -Be "Item 1" + $result.bulleted_list_item.color | Should -Be ([notion_color]::yellow) + } + } +} diff --git a/tests/Unit/Public/Block/Callout/New-NotionCalloutBlock.Tests.ps1 b/tests/Unit/Public/Block/Callout/New-NotionCalloutBlock.Tests.ps1 new file mode 100644 index 0000000..b1ba94c --- /dev/null +++ b/tests/Unit/Public/Block/Callout/New-NotionCalloutBlock.Tests.ps1 @@ -0,0 +1,41 @@ +# FILE: Callout/New-NotionCalloutBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionCalloutBlock" { + InModuleScope $moduleName { + It "Should create an empty callout block" { + $result = New-NotionCalloutBlock + + $result | Should -BeOfType "notion_callout_block" + $result.type | Should -Be ([notion_blocktype]::callout) + $result.callout.rich_text | Should -BeEmpty + } + + It "Should create a callout block with rich text icon and color" { + $richText = New-NotionRichText -Text "Hello" + $result = New-NotionCalloutBlock -RichText $richText -Icon "💡" -Color blue + + $result | Should -BeOfType "notion_callout_block" + $result.type | Should -Be ([notion_blocktype]::callout) + $result.callout.rich_text[0].plain_text | Should -Be "Hello" + $result.callout.icon.emoji | Should -Be "💡" + $result.callout.color | Should -Be ([notion_color]::blue) + } + } +} diff --git a/tests/Unit/Public/Block/ChildDatabase/ChildPage/New-NotionChildPageBlock.Tests.ps1 b/tests/Unit/Public/Block/ChildDatabase/ChildPage/New-NotionChildPageBlock.Tests.ps1 new file mode 100644 index 0000000..242716a --- /dev/null +++ b/tests/Unit/Public/Block/ChildDatabase/ChildPage/New-NotionChildPageBlock.Tests.ps1 @@ -0,0 +1,37 @@ +# FILE: ChildDatabase/ChildPage/New-NotionChildPageBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../../../" | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionChildPageBlock" { + InModuleScope $moduleName { + It "Should create an empty child page block" { + $result = New-NotionChildPageBlock + + $result | Should -BeOfType "notion_child_page_block" + $result.type | Should -Be ([notion_blocktype]::child_page) + $result.child_page.title | Should -BeNullOrEmpty + } + + It "Should create a child page block with a title" { + $result = New-NotionChildPageBlock -Title "Documentation" + + $result | Should -BeOfType "notion_child_page_block" + $result.child_page.title | Should -Be "Documentation" + } + } +} diff --git a/tests/Unit/Public/Block/ChildDatabase/New-NotionChildDatabaseBlock.Tests.ps1 b/tests/Unit/Public/Block/ChildDatabase/New-NotionChildDatabaseBlock.Tests.ps1 new file mode 100644 index 0000000..cd1d26b --- /dev/null +++ b/tests/Unit/Public/Block/ChildDatabase/New-NotionChildDatabaseBlock.Tests.ps1 @@ -0,0 +1,37 @@ +# FILE: ChildDatabase/New-NotionChildDatabaseBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionChildDatabaseBlock" { + InModuleScope $moduleName { + It "Should create an empty child database block" { + $result = New-NotionChildDatabaseBlock + + $result | Should -BeOfType "notion_child_database_block" + $result.type | Should -Be ([notion_blocktype]::child_database) + $result.child_database.title | Should -BeNullOrEmpty + } + + It "Should create a child database block with title" { + $result = New-NotionChildDatabaseBlock -Title "Tasks" + + $result | Should -BeOfType "notion_child_database_block" + $result.child_database.title | Should -Be "Tasks" + } + } +} diff --git a/tests/Unit/Public/Block/Code/New-NotionCodeBlock.Tests.ps1 b/tests/Unit/Public/Block/Code/New-NotionCodeBlock.Tests.ps1 new file mode 100644 index 0000000..5cf1160 --- /dev/null +++ b/tests/Unit/Public/Block/Code/New-NotionCodeBlock.Tests.ps1 @@ -0,0 +1,46 @@ +# FILE: Code/New-NotionCodeBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionCodeBlock" { + InModuleScope $moduleName { + It "Should create an empty code block" { + $result = New-NotionCodeBlock + + $result | Should -BeOfType "notion_code_block" + $result.type | Should -Be ([notion_blocktype]::code) + $result.code.rich_text | Should -BeEmpty + } + + It "Should create a code block with text and language" { + $result = New-NotionCodeBlock -Text '$value = 1' -Language 'powershell' + + $result | Should -BeOfType "notion_code_block" + $result.code.rich_text[0].plain_text | Should -Be '$value = 1' + $result.code.language | Should -Be 'powershell' + } + + It "Should create a code block with caption" { + $caption = New-NotionRichText -Text 'Example snippet' + $result = New-NotionCodeBlock -Text 'Write-Output "Hello"' -Caption $caption -Language 'powershell' + + $result | Should -BeOfType "notion_code_block" + $result.code.caption[0].plain_text | Should -Be 'Example snippet' + } + } +} diff --git a/tests/Unit/Public/Block/Column/New-NotionColumnBlock.Tests.ps1 b/tests/Unit/Public/Block/Column/New-NotionColumnBlock.Tests.ps1 new file mode 100644 index 0000000..123d219 --- /dev/null +++ b/tests/Unit/Public/Block/Column/New-NotionColumnBlock.Tests.ps1 @@ -0,0 +1,29 @@ +# FILE: Column/New-NotionColumnBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionColumnBlock" { + InModuleScope $moduleName { + It "Should create an empty column block" { + $result = New-NotionColumnBlock + + $result | Should -BeOfType "notion_column_block" + $result.type | Should -Be ([notion_blocktype]::column) + } + } +} diff --git a/tests/Unit/Public/Block/ColumnList/New-NotionColumnListBlock.Tests.ps1 b/tests/Unit/Public/Block/ColumnList/New-NotionColumnListBlock.Tests.ps1 new file mode 100644 index 0000000..03c9be7 --- /dev/null +++ b/tests/Unit/Public/Block/ColumnList/New-NotionColumnListBlock.Tests.ps1 @@ -0,0 +1,29 @@ +# FILE: ColumnList/New-NotionColumnListBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionColumnListBlock" { + InModuleScope $moduleName { + It "Should create an empty column list block" { + $result = New-NotionColumnListBlock + + $result | Should -BeOfType "notion_column_list_block" + $result.type | Should -Be ([notion_blocktype]::column_list) + } + } +} diff --git a/tests/Unit/Public/Block/Divider/New-NotionDividerBlock.Tests.ps1 b/tests/Unit/Public/Block/Divider/New-NotionDividerBlock.Tests.ps1 new file mode 100644 index 0000000..9c59440 --- /dev/null +++ b/tests/Unit/Public/Block/Divider/New-NotionDividerBlock.Tests.ps1 @@ -0,0 +1,29 @@ +# FILE: Divider/New-NotionDividerBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionDividerBlock" { + InModuleScope $moduleName { + It "Should create a divider block" { + $result = New-NotionDividerBlock + + $result | Should -BeOfType "notion_divider_block" + $result.type | Should -Be ([notion_blocktype]::divider) + } + } +} diff --git a/tests/Unit/Public/Block/Embed/New-NotionEmbedBlock.Tests.ps1 b/tests/Unit/Public/Block/Embed/New-NotionEmbedBlock.Tests.ps1 new file mode 100644 index 0000000..a480d0c --- /dev/null +++ b/tests/Unit/Public/Block/Embed/New-NotionEmbedBlock.Tests.ps1 @@ -0,0 +1,38 @@ +# FILE: Embed/New-NotionEmbedBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionEmbedBlock" { + InModuleScope $moduleName { + It "Should create an empty embed block" { + $result = New-NotionEmbedBlock + + $result | Should -BeOfType "notion_embed_block" + $result.type | Should -Be ([notion_blocktype]::embed) + $result.embed.url | Should -BeNullOrEmpty + } + + It "Should create an embed block with url and caption" { + $result = New-NotionEmbedBlock -Url "https://example.com" -Caption "Example" + + $result | Should -BeOfType "notion_embed_block" + $result.embed.url | Should -Be "https://example.com" + $result.embed.caption[0].plain_text | Should -Be "Example" + } + } +} diff --git a/tests/Unit/Public/Block/Equation/New-NotionEquationBlock.Tests.ps1 b/tests/Unit/Public/Block/Equation/New-NotionEquationBlock.Tests.ps1 new file mode 100644 index 0000000..8b8215d --- /dev/null +++ b/tests/Unit/Public/Block/Equation/New-NotionEquationBlock.Tests.ps1 @@ -0,0 +1,37 @@ +# FILE: Equation/New-NotionEquationBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionEquationBlock" { + InModuleScope $moduleName { + It "Should create an empty equation block" { + $result = New-NotionEquationBlock + + $result | Should -BeOfType "notion_equation_block" + $result.type | Should -Be ([notion_blocktype]::equation) + $result.equation.expression | Should -BeNullOrEmpty + } + + It "Should create an equation block with expression" { + $result = New-NotionEquationBlock -Expression '\\frac{a}{b}' + + $result | Should -BeOfType "notion_equation_block" + $result.equation.expression | Should -Be "\\frac{a}{b}" + } + } +} diff --git a/tests/Unit/Public/Block/File/New-NotionFileBlock.Tests.ps1 b/tests/Unit/Public/Block/File/New-NotionFileBlock.Tests.ps1 new file mode 100644 index 0000000..7ebec4c --- /dev/null +++ b/tests/Unit/Public/Block/File/New-NotionFileBlock.Tests.ps1 @@ -0,0 +1,55 @@ +# FILE: File/New-NotionFileBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionFileBlock" { + InModuleScope $moduleName { + It "Should create an empty file block" { + $result = New-NotionFileBlock + + $result | Should -BeOfType "notion_file_block" + $result.type | Should -Be ([notion_blocktype]::file) + } + + It "Should create an external file block" { + $result = New-NotionFileBlock -Name "example.pdf" -Caption "Example" -Url "https://example.com/example.pdf" + + $result | Should -BeOfType "notion_file_block" + $result.file.external.url | Should -Be "https://example.com/example.pdf" + $result.file.caption[0].plain_text | Should -Be "Example" + } + + It "Should create a hosted file block with expiry" { + $expiry = Get-Date "2025-12-31T23:59:59Z" + $expectedExpiry = ConvertTo-NotionFormattedDateTime -InputDate $expiry + $result = New-NotionFileBlock -Name "report.pdf" -Caption "Report" -Url "https://example.com/report.pdf" -ExpiryTime $expiry + + $result | Should -BeOfType "notion_file_block" + $result.file.file.url | Should -Be "https://example.com/report.pdf" + $result.file.file.expiry_time | Should -Be $expectedExpiry + } + + It "Should create a file block from object" { + $externalFile = [notion_external_file]::new("example.pdf", "https://example.com/example.pdf") + $result = New-NotionFileBlock -File $externalFile + + $result | Should -BeOfType "notion_file_block" + $result.file.external.url | Should -Be "https://example.com/example.pdf" + } + } +} diff --git a/tests/Unit/Public/Block/Heading/New-NotionHeadingBlock.Tests.ps1 b/tests/Unit/Public/Block/Heading/New-NotionHeadingBlock.Tests.ps1 new file mode 100644 index 0000000..6f48866 --- /dev/null +++ b/tests/Unit/Public/Block/Heading/New-NotionHeadingBlock.Tests.ps1 @@ -0,0 +1,41 @@ +# FILE: Heading/New-NotionHeadingBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionHeadingBlock" { + InModuleScope $moduleName { + It "Should create a level 1 heading block" { + $result = New-NotionHeadingBlock -Text "Heading" -Level 1 + + $result | Should -BeOfType "notion_heading_1_block" + $result.type | Should -Be ([notion_blocktype]::heading_1) + $result.heading_1.rich_text[0].plain_text | Should -Be "Heading" + $result.heading_1.color | Should -Be ([notion_color]::default) + } + + It "Should create a level 2 heading block with color and toggle" { + $result = New-NotionHeadingBlock -Text "Section" -Color blue -Level 2 -is_toggleable + + $result | Should -BeOfType "notion_heading_2_block" + $result.type | Should -Be ([notion_blocktype]::heading_2) + $result.heading_2.rich_text[0].plain_text | Should -Be "Section" + $result.heading_2.color | Should -Be ([notion_color]::blue) + $result.heading_2.is_toggleable | Should -BeTrue + } + } +} diff --git a/tests/Unit/Public/Block/Image/New-NotionImageBlock.Tests.ps1 b/tests/Unit/Public/Block/Image/New-NotionImageBlock.Tests.ps1 new file mode 100644 index 0000000..04fcd87 --- /dev/null +++ b/tests/Unit/Public/Block/Image/New-NotionImageBlock.Tests.ps1 @@ -0,0 +1,31 @@ +# FILE: Image/New-NotionImageBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionImageBlock" { + InModuleScope $moduleName { + It "Should convert a notion file into an image block" { + $file = [notion_external_file]::new("Sample", "https://example.com/image.png") + $result = New-NotionImageBlock -File $file + + $result | Should -BeOfType "notion_image_block" + $result.type | Should -Be ([notion_blocktype]::image) + $result.image.external.url | Should -Be "https://example.com/image.png" + } + } +} diff --git a/tests/Unit/Public/Block/LinkPreview/New-NotionLinkPreviewBlock.Tests.ps1 b/tests/Unit/Public/Block/LinkPreview/New-NotionLinkPreviewBlock.Tests.ps1 new file mode 100644 index 0000000..a1f33c1 --- /dev/null +++ b/tests/Unit/Public/Block/LinkPreview/New-NotionLinkPreviewBlock.Tests.ps1 @@ -0,0 +1,29 @@ +# FILE: LinkPreview/New-NotionLinkPreviewBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionLinkPreviewBlock" { + InModuleScope $moduleName { + It "Should throw because link preview blocks cannot be created" { + { + $ErrorActionPreference = 'Stop' + New-NotionLinkPreviewBlock + } | Should -Throw -ErrorMessage "link_preview" + } + } +} diff --git a/tests/Unit/Public/Block/New-NotionBlock.Tests.ps1 b/tests/Unit/Public/Block/New-NotionBlock.Tests.ps1 new file mode 100644 index 0000000..88d09e6 --- /dev/null +++ b/tests/Unit/Public/Block/New-NotionBlock.Tests.ps1 @@ -0,0 +1,47 @@ +# FILE: New-NotionBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionBlock" { + InModuleScope $moduleName { + It "Should create a paragraph block" { + $result = New-NotionBlock -paragraph | Select-Object -Last 1 + + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType "notion_paragraph_block" + $result.type | Should -Be ([notion_blocktype]::paragraph) + } + + It "Should create a bookmark block when url is provided" { + $outputs = New-NotionBlock -bookmark -Url "https://example.com" -Caption "Example" + $result = $outputs | Select-Object -Last 1 + + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType "notion_bookmark_block" + $result.type | Should -Be ([notion_blocktype]::bookmark) + } + + It "Should create a to-do block when requested" { + $result = New-NotionBlock -to_do -Checked | Select-Object -Last 1 + + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType "notion_to_do_block" + $result.type | Should -Be ([notion_blocktype]::to_do) + } + } +} diff --git a/tests/Unit/Public/Block/New-NotionCalloutBlock.Tests.ps1 b/tests/Unit/Public/Block/New-NotionCalloutBlock.Tests.ps1 deleted file mode 100644 index c4f58fd..0000000 --- a/tests/Unit/Public/Block/New-NotionCalloutBlock.Tests.ps1 +++ /dev/null @@ -1,70 +0,0 @@ -# FILE: New-NotionCalloutBlock.Tests.ps1 -Import-Module Pester -DisableNameChecking - -BeforeDiscovery { - $projectPath = "$($PSScriptRoot)/../../../.." | Convert-Path - - if (-not $ProjectName) - { - $ProjectName = Get-SamplerProjectName -BuildRoot $projectPath - } - Write-Debug "ProjectName: $ProjectName" - $global:moduleName = $ProjectName - - Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue - $mut = Import-Module -Name "$projectPath/output/module/$ProjectName" -Force -ErrorAction Stop -PassThru -} - -Describe "New-NotionCalloutBlock" { - Context "When called with no parameters" { - It "Returns an empty notion_callout_block object" { - $result = New-NotionCalloutBlock - $result | Should -BeOfType "notion_callout_block" - $result.callout.rich_text | Should -BeNullOrEmpty - $result.callout.Icon | Should -BeNullOrEmpty - $result.callout.Color | Should -Be "default" - } - } - - Context "When called with RichText, Icon, and Color" { - It "Returns a notion_callout_block object with the specified properties" { - $text = "Hallo" - $richText = [rich_text]::new("text", [notion_annotation]::new(), $text) - $icon = "💡" - $color = [notion_color]::Default - - $result = New-NotionCalloutBlock -RichText @($richText) -Icon $icon -Color $color - - $result | Should -BeOfType "notion_callout_block" - $result.callout.rich_text.gettype().Name | Should -Be "rich_text[]" - $result.callout.rich_text.plain_text | Should -Be $text - $result.callout.Icon | Should -BeOfType "notion_emoji" - $result.callout.Icon.emoji | Should -Be $icon - $result.callout.Color | Should -Be $color - } - } - - Context "When called with only some parameters" { - It "Returns an empty notion_callout_block object" { - $result1 = New-NotionCalloutBlock - - $result1 | Should -BeOfType "notion_callout_block" - $result1.callout.rich_text | Should -BeNullOrEmpty - $result1.callout.Icon | Should -BeNullOrEmpty - $result1.callout.Color | Should -Be "default" - } - - It "Returns an empty notion_callout_block object with text, icon and color" { - $result2 = New-NotionCalloutBlock -RichText @("Test") -Icon "🌟" -Color ([notion_color]::green) - - $result2.callout.rich_text.gettype().Name | Should -Be "rich_text[]" - $result2.callout.rich_text.plain_text | Should -Be @("Test") - - $result2.callout.Icon | Should -BeOfType "notion_emoji" - $result2.callout.icon.emoji | Should -Be "🌟" - - $result2.callout.Color | Should -BeOfType "notion_color" - $result2.callout.Color | Should -Be "green" - } - } -} diff --git a/tests/Unit/Public/Block/New-NotionHeadingBlock.Tests.ps1 b/tests/Unit/Public/Block/New-NotionHeadingBlock.Tests.ps1 deleted file mode 100644 index cd6d18a..0000000 --- a/tests/Unit/Public/Block/New-NotionHeadingBlock.Tests.ps1 +++ /dev/null @@ -1,53 +0,0 @@ -# FILE: New-NotionHeadingBlock.Tests.ps1 -Import-Module Pester - -BeforeDiscovery { - $script:projectPath = "$($PSScriptRoot)/../../../.." | Convert-Path - - <# - If the QA tests are run outside of the build script (e.g with Invoke-Pester) - the parent scope has not set the variable $ProjectName. - #> - if (-not $ProjectName) - { - # Assuming project folder name is project name. - $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath - } - Write-Debug "ProjectName: $ProjectName" - $global:moduleName = $ProjectName - Set-Alias -Name gitversion -Value dotnet-gitversion - $script:version = (gitversion /showvariable MajorMinorPatch) - - Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue - - $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru -} - -Describe "New-NotionHeadingBlock" { - InModuleScope $moduleName { - # Test for level validation - It "Should throw an error when Level is out of range" { - { New-NotionHeadingBlock -Text "Test Header" -Level 4 } | Should -Throw - { New-NotionHeadingBlock -Text "Test Header" -Level 0 } | Should -Throw - } - - # Test for default parameters - It "Should create a Notion header with default parameters" { - $result = New-NotionHeadingBlock -Text "Test Header" -Level 1 - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType "notion_heading_block" - } - - # Test for custom color - It "Should allow setting a custom color" { - $result = New-NotionHeadingBlock -Text "Colored Header" -Color "blue" -Level 2 - $result.heading_2.Color | Should -Be "blue" - } - - # Test for toggleable property - It "Should correctly set toggleable property" { - $result = New-NotionHeadingBlock -Text "Toggleable Header" -Level 3 -is_toggleable - $result.heading_3.is_toggleable | Should -Be $true - } - } -} diff --git a/tests/Unit/Public/Block/New-NotionTableBlock.Tests.ps1 b/tests/Unit/Public/Block/New-NotionTableBlock.Tests.ps1 deleted file mode 100644 index a247184..0000000 --- a/tests/Unit/Public/Block/New-NotionTableBlock.Tests.ps1 +++ /dev/null @@ -1,273 +0,0 @@ -Import-Module Pester - -BeforeDiscovery { - $script:projectPath = "$($PSScriptRoot)/../../../.." | Convert-Path - - if (-not $ProjectName) - { - $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath - } - Write-Debug "ProjectName: $ProjectName" - $global:moduleName = $ProjectName - Set-Alias -Name gitversion -Value dotnet-gitversion - $script:version = (gitversion /showvariable MajorMinorPatch) - - Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue - - $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru -} - -Describe "New-NotionTableBlock" { - InModuleScope $moduleName { - - # Test for parameter set conflict - It "Should throw an error when both TableData and -empty_table are specified" { - { New-NotionTableBlock -TableData @( @(1,2) ) -empty_table } | Should -Throw - } - - # Test for error on invalid TableData - It "Should throw an error when TableData is empty" { - { $ErrorActionPreference = "Stop" ; New-NotionTableBlock -TableData @() } | Should -Throw - } - - It "Should throw an error when TableData is not an array" { - { $ErrorActionPreference = "Stop" ; New-NotionTableBlock -TableData $null } | Should -Throw - { $ErrorActionPreference = "Stop" ; New-NotionTableBlock -TableData 'string' } | Should -Throw - } - - # Test for valid table creation - It "Should create a Notion table block with valid data" { - $data = @( @("Cell1", "Cell2"), @("Cell3", "Cell4") ) - $result = New-NotionTableBlock -TableData $data - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [notion_table_block] - $result.table.children | Should -Not -BeNullOrEmpty - $result.table.children.Count | Should -Be 2 - $rowcount = 0 - foreach ($row in $result.table.children) { - $row | Should -BeOfType [notion_table_row_block] - $row.table_row.cells | Should -Not -BeNullOrEmpty - $row.table_row.cells.Count | Should -Be 2 - $cellcount = 0 - foreach ($cell in $row.table_row.cells) { - $cell | Should -BeOfType [rich_text_text] - $cell.plain_text | Should -Be $data[$rowcount][$cellcount] - $cellcount++ - } - $rowcount++ - } - } - - # Test for has_column_header - It "Should create a table block with column header" { - $data = @( @("Header1", "Header2"), @("Cell1", "Cell2") ) - $result = New-NotionTableBlock -TableData $data -has_column_header - $result.table.has_column_header | Should -Be $true - $result.table.has_row_header | Should -Be $false - # verify the data - $rowCount = 0 - foreach ($row in $result.table.children) { - $row | Should -BeOfType [notion_table_row_block] - $row.table_row.cells | Should -Not -BeNullOrEmpty - $row.table_row.cells.Count | Should -Be 2 - $cellCount = 0 - foreach ($cell in $row.table_row.cells) { - $cell | Should -BeOfType [rich_text_text] - $cell.plain_text | Should -Be $data[$rowCount][$cellCount] - $cellCount++ - } - $rowcount++ - } - } - - # Test for has_row_header - It "Should create a table block with row header" { - $data = @( @("Header1", "Cell1"), @("Header2", "Cell2") ) - $result = New-NotionTableBlock -TableData $data -has_row_header -NoPivot - $result.table.has_row_header | Should -Be $true - $result.table.has_column_header | Should -Be $false - # verify the data - $rowCount = 0 - foreach ($row in $result.table.children) { - $row | Should -BeOfType [notion_table_row_block] - $row.table_row.cells | Should -Not -BeNullOrEmpty - $row.table_row.cells.Count | Should -Be 2 - $cellCount = 0 - foreach ($cell in $row.table_row.cells) { - $cell | Should -BeOfType [rich_text_text] - $cell.plain_text | Should -Be $data[$rowCount][$cellCount] - $cellCount++ - } - $rowCount++ - } - } - - # Test for hashtable input - It "Should create a table block from hashtable array" { - $tabledata = @( - @{ Col1 = 'A'; Col2 = 'B' }, - @{ Col1 = 'C'; Col2 = 'D' } - ) - $result = New-NotionTableBlock -TableData $tabledata - $result | Should -BeOfType "notion_table_block" - # is automatically set by the function - $result.table.has_column_header | Should -Be $true - # should have 3 rows: 2 data rows + 1 header row - $result.table.children.Count | Should -Be 3 - $expected = @( - @($tabledata.Keys | Sort-Object -Unique ), - @("A", "B"), - @("C", "D") - ) - $rowCount = 0 - foreach ($row in $result.table.children) { - $row | Should -BeOfType [notion_table_row_block] - $row.table_row.cells | Should -Not -BeNullOrEmpty - $row.table_row.cells.Count | Should -Be 2 - $cellCount = 0 - foreach ($cell in $row.table_row.cells) { - $cell | Should -BeOfType [rich_text_text] - $cell.plain_text | Should -Be $expected[$rowCount][$cellCount] - $cellCount++ - } - $rowCount++ - } - } - - # # Test for hashtable input - It "Should create a table block from ordered hashtable array" { - $tabledata = @( - [ordered]@{ Col2 = 'A'; Col1 = 'B' }, - [ordered]@{ Col2 = 'C'; Col1 = 'D' } - ) - $result = New-NotionTableBlock -TableData $tabledata - $result | Should -BeOfType "notion_table_block" - # is automatically set by the function - $result.table.has_column_header | Should -Be $true - # should have 3 rows: 2 data rows + 1 header row - $result.table.children.Count | Should -Be 3 - $expected = @( - @($tabledata.Keys), - @("A", "B"), - @("C", "D") - ) - $rowCount = 0 - foreach ($row in $result.table.children) { - $row | Should -BeOfType [notion_table_row_block] - $row.table_row.cells | Should -Not -BeNullOrEmpty - $row.table_row.cells.Count | Should -Be 2 - $cellCount = 0 - foreach ($cell in $row.table_row.cells) { - $cell | Should -BeOfType [rich_text_text] - $cell.plain_text | Should -Be $expected[$rowCount][$cellCount] - $cellCount++ - } - $rowCount++ - } - } - - # # Test for empty table - It "Should create an empty Notion table block when -empty_table is specified" { - $result = New-NotionTableBlock -empty_table - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [notion_table_block] - } - - # Test for hashtable input with unsorted keys - It "Should create a table block from hashtable array with unsorted keys" { - $tabledata = @( - @{ ColB = '1'; ColA = '2' }, - @{ ColB = '3'; ColA = '4' } - ) - $result = New-NotionTableBlock -TableData $tabledata - $result | Should -BeOfType "notion_table_block" - $result.table.has_column_header | Should -Be $true - $result.table.children.Count | Should -Be 3 - $headers = @($tabledata[0].Keys | Sort-Object) - $expected = @( - $headers, - @($tabledata[0][$headers[0]], $tabledata[0][$headers[1]]), - @($tabledata[1][$headers[0]], $tabledata[1][$headers[1]]) - ) - $rowCount = 0 - foreach ($row in $result.table.children) { - $row | Should -BeOfType [notion_table_row_block] - $row.table_row.cells | Should -Not -BeNullOrEmpty - $row.table_row.cells.Count | Should -Be 2 - $cellCount = 0 - foreach ($cell in $row.table_row.cells) { - $cell | Should -BeOfType [rich_text_text] - $cell.plain_text | Should -Be $expected[$rowCount][$cellCount] - $cellCount++ - } - $rowCount++ - } - } - - # Test for single-row hashtable array - It "Should create a table block from single-row hashtable array" { - $tabledata = @( - @{ Col1 = 'A'; Col2 = 'B' } - ) - $result = New-NotionTableBlock -TableData $tabledata - $result | Should -BeOfType "notion_table_block" - $result.table.has_column_header | Should -Be $true - $result.table.children.Count | Should -Be 2 - $headers = @($tabledata[0].Keys | Sort-Object) - $expected = @( - $headers, - @($tabledata[0][$headers[0]], $tabledata[0][$headers[1]]) - ) - $rowCount = 0 - foreach ($row in $result.table.children) { - $row | Should -BeOfType [notion_table_row_block] - $row.table_row.cells | Should -Not -BeNullOrEmpty - $row.table_row.cells.Count | Should -Be 2 - $cellCount = 0 - foreach ($cell in $row.table_row.cells) { - $cell | Should -BeOfType [rich_text_text] - $cell.plain_text | Should -Be $expected[$rowCount][$cellCount] - $cellCount++ - } - $rowCount++ - } - } - - # Test for empty hashtable array - It "Should throw for empty hashtable array" { - $tabledata = @() - {$ErrorActionPreference = "Stop" ;New-NotionTableBlock -TableData $tabledata } | Should -Throw - } - - It "Should throw for hashtable and both headers" { - $tabledata = @( - @{ Col1 = 'A'; Col2 = 'B' } - ) - { $ErrorActionPreference = "Stop" ;New-NotionTableBlock -TableData $tabledata -has_column_header -has_row_header } | Should -Throw - } - - # Test for array of arrays with only one row - It "Should create a table block from single-row array of arrays" { - $data = @(,@("A", "B")) - $result = New-NotionTableBlock -TableData $data - $result | Should -BeOfType [notion_table_block] - $result.table.children.Count | Should -Be 1 - $row = $result.table.children[0] - $row | Should -BeOfType [notion_table_row_block] - $row.table_row.cells.Count | Should -Be 2 - $row.table_row.cells[0].plain_text | Should -Be "A" - $row.table_row.cells[1].plain_text | Should -Be "B" - } - - # Test for array of arrays with only one column - It "Should create a table block from array of arrays with one column" { - $data = @(@("A"), @("B")) - $result = New-NotionTableBlock -TableData $data - $result | Should -BeOfType [notion_table_block] - $result.table.children.Count | Should -Be 2 - $result.table.children[0].table_row.cells.Count | Should -Be 1 - $result.table.children[0].table_row.cells[0].plain_text | Should -Be "A" - $result.table.children[1].table_row.cells[0].plain_text | Should -Be "B" - } - } -} diff --git a/tests/Unit/Public/Block/New-NotionVideoBlock.Tests.ps1 b/tests/Unit/Public/Block/New-NotionVideoBlock.Tests.ps1 deleted file mode 100644 index 9f8dfc0..0000000 --- a/tests/Unit/Public/Block/New-NotionVideoBlock.Tests.ps1 +++ /dev/null @@ -1,51 +0,0 @@ -# FILE: New-NotionVideoBlock.Tests.ps1 -Import-Module Pester - -BeforeDiscovery { - $script:projectPath = "$($PSScriptRoot)/../../../.." | Convert-Path - - if (-not $ProjectName) { - $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath - } - Write-Debug "ProjectName: $ProjectName" - $global:moduleName = $ProjectName - Set-Alias -Name gitversion -Value dotnet-gitversion - $script:version = (gitversion /showvariable MajorMinorPatch) - - Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue - - $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru -} - -Describe "New-NotionVideoBlock" { - InModuleScope $moduleName { - # Test for InputObject parameter set - It "Should create a Notion Video block with InputObject" { - $fileObject = @{ video = @{ type = "external"; external = @{ url = "https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4" }; <#name = "example.mp4";#> caption = "Example Caption" } } - $result = New-NotionVideoBlock -InputObject $fileObject - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType "notion_video_block" - $result.video.type | Should -Be "external" - $result.video.external.url | Should -Be "https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4" - # $result.video.name | Should -Be "example.mp4" - $result.video.caption.plain_text | Should -Be "Example Caption" - } - - # Test for caption, name, and URL parameter set - It "Should create a Notion Video block with caption, name, and URL" { - $result = New-NotionVideoBlock -caption "My Video Caption" <#-name "example.mp4"#> -url "https://example.com/example.mp4" - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType "notion_video_block" - $result.video.type | Should -Be "external" - $result.video.external.url | Should -Be "https://example.com/example.mp4" - # $result.video.external.name | Should -Be "example.mp4" - $result.video.caption.plain_text | Should -Be "My Video Caption" - } - - # Test for invalid parameter combinations - It "Should throw an error when both InputObject and caption are specified" { - { New-NotionVideoBlock -InputObject @{ video = @{ type = "external"; external = @{ url = "https://example.com/example.mp4"; name = "example.mp4"; caption = "Example Caption" } } } -caption "My Video" -name "example.mp4" -url "https://example.com/example.mp4" } | Should -Throw - } - - } -} diff --git a/tests/Unit/Public/Block/NumberedListItem/New-NotionNumberedListItemBlock.Tests.ps1 b/tests/Unit/Public/Block/NumberedListItem/New-NotionNumberedListItemBlock.Tests.ps1 new file mode 100644 index 0000000..8bb3298 --- /dev/null +++ b/tests/Unit/Public/Block/NumberedListItem/New-NotionNumberedListItemBlock.Tests.ps1 @@ -0,0 +1,37 @@ +# FILE: NumberedListItem/New-NotionNumberedListItemBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionNumberedListItemBlock" { + InModuleScope $moduleName { + It "Should create an empty numbered list item block" { + $result = New-NotionNumberedListItemBlock + + $result | Should -BeOfType "notion_numbered_list_item_block" + $result.type | Should -Be ([notion_blocktype]::numbered_list_item) + $result.numbered_list_item.rich_text | Should -BeNullOrEmpty + } + + It "Should create a numbered list item block with text" { + $result = New-NotionNumberedListItemBlock -RichText "First" + + $result | Should -BeOfType "notion_numbered_list_item_block" + $result.numbered_list_item.rich_text[0].plain_text | Should -Be "First" + } + } +} diff --git a/tests/Unit/Public/Block/Paragraph/New-NotionParagraphBlock.Tests.ps1 b/tests/Unit/Public/Block/Paragraph/New-NotionParagraphBlock.Tests.ps1 new file mode 100644 index 0000000..0a54e4d --- /dev/null +++ b/tests/Unit/Public/Block/Paragraph/New-NotionParagraphBlock.Tests.ps1 @@ -0,0 +1,46 @@ +# FILE: Paragraph/New-NotionParagraphBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionParagraphBlock" { + InModuleScope $moduleName { + It "Should create an empty paragraph block" { + $result = New-NotionParagraphBlock + + $result | Should -BeOfType "notion_paragraph_block" + $result.type | Should -Be ([notion_blocktype]::paragraph) + $result.paragraph.rich_text | Should -BeNullOrEmpty + } + + It "Should create a paragraph block with rich text" { + $richText = New-NotionRichText -Text "Hello World" + $result = New-NotionParagraphBlock -RichText $richText + + $result.paragraph.rich_text[0].plain_text | Should -Be "Hello World" + $result.paragraph.color | Should -Be ([notion_color]::default) + } + + It "Should create a paragraph block with rich text and color" { + $richText = New-NotionRichText -Text "Colored" + $result = New-NotionParagraphBlock -RichText $richText -Color yellow + + $result.paragraph.rich_text[0].plain_text | Should -Be "Colored" + $result.paragraph.color | Should -Be ([notion_color]::yellow) + } + } +} diff --git a/tests/Unit/Public/Block/New-NotionPdfBlock.Tests.ps1 b/tests/Unit/Public/Block/Pdf/New-NotionPdfBlock.Tests.ps1 similarity index 52% rename from tests/Unit/Public/Block/New-NotionPdfBlock.Tests.ps1 rename to tests/Unit/Public/Block/Pdf/New-NotionPdfBlock.Tests.ps1 index b15cea7..1d6922a 100644 --- a/tests/Unit/Public/Block/New-NotionPdfBlock.Tests.ps1 +++ b/tests/Unit/Public/Block/Pdf/New-NotionPdfBlock.Tests.ps1 @@ -1,8 +1,8 @@ -# FILE: New-NotionPdfBlock.Tests.ps1 +# FILE: Pdf/New-NotionPdfBlock.Tests.ps1 Import-Module Pester BeforeDiscovery { - $script:projectPath = "$($PSScriptRoot)/../../../.." | Convert-Path + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path if (-not $ProjectName) { $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath @@ -19,33 +19,24 @@ BeforeDiscovery { Describe "New-NotionPdfBlock" { InModuleScope $moduleName { - # Test for InputObject parameter set - It "Should create a Notion PDF block with InputObject" { - $fileObject = @{ pdf = @{ type = "external"; external = @{ url = "https://example.com/example.pdf" }; <#name = "example.pdf";#> caption = "Example Caption" } } + It "Should create a PDF block from input object" { + $fileObject = @{ pdf = @{ type = "external"; external = @{ url = "https://example.com/example.pdf" }; caption = "Example Caption" } } $result = New-NotionPdfBlock -InputObject $fileObject + $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType "notion_PDF_block" $result.pdf.type | Should -Be "external" $result.pdf.external.url | Should -Be "https://example.com/example.pdf" - # $result.pdf.name | Should -Be "example.pdf" - $result.pdf.caption.plain_text | Should -Be "Example Caption" } - # Test for caption, name, and URL parameter set - It "Should create a Notion PDF block with caption, name, and URL" { - $result = New-NotionPdfBlock -caption "My PDF Caption" <#-name "example.pdf"#> -url "https://example.com/example.pdf" + It "Should create a PDF block with caption and url" { + $result = New-NotionPdfBlock -caption "My PDF Caption" -url "https://example.com/example.pdf" + $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType "notion_PDF_block" $result.pdf.type | Should -Be "external" $result.pdf.external.url | Should -Be "https://example.com/example.pdf" - # $result.pdf.external.name | Should -Be "example.pdf" - $result.pdf.caption.plain_text | Should -Be "My PDF Caption" + $result.pdf.caption[0].plain_text | Should -Be "My PDF Caption" } - - # Test for invalid parameter combinations - It "Should throw an error when both InputObject and caption are specified" { - { New-NotionPdfBlock -InputObject @{ pdf = @{ type = "external"; external = @{ url = "https://example.com/example.pdf"; name = "example.pdf"; caption = "Example Caption" } } } -caption "My PDF" -name "example.pdf" -url "https://example.com/example.pdf" } | Should -Throw - } - } } diff --git a/tests/Unit/Public/Block/Quote/New-NotionQuoteBlock.Tests.ps1 b/tests/Unit/Public/Block/Quote/New-NotionQuoteBlock.Tests.ps1 new file mode 100644 index 0000000..e413143 --- /dev/null +++ b/tests/Unit/Public/Block/Quote/New-NotionQuoteBlock.Tests.ps1 @@ -0,0 +1,38 @@ +# FILE: Quote/New-NotionQuoteBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionQuoteBlock" { + InModuleScope $moduleName { + It "Should create an empty quote block" { + $result = New-NotionQuoteBlock + + $result | Should -BeOfType "notion_quote_block" + $result.type | Should -Be ([notion_blocktype]::quote) + $result.quote.rich_text | Should -BeNullOrEmpty + } + + It "Should create a quote block with text and color" { + $result = New-NotionQuoteBlock -RichText "Example quote" -Color "gray" + + $result | Should -BeOfType "notion_quote_block" + $result.quote.rich_text[0].plain_text | Should -Be "Example quote" + $result.quote.color | Should -Be ([notion_color]::gray) + } + } +} diff --git a/tests/Unit/Public/Block/Synced/New-NotionSyncedBlock.Tests.ps1 b/tests/Unit/Public/Block/Synced/New-NotionSyncedBlock.Tests.ps1 new file mode 100644 index 0000000..e2c6bf7 --- /dev/null +++ b/tests/Unit/Public/Block/Synced/New-NotionSyncedBlock.Tests.ps1 @@ -0,0 +1,29 @@ +# FILE: Synced/New-NotionSyncedBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionSyncedBlock" { + InModuleScope $moduleName { + It "Should create a synced block" { + $result = New-NotionSyncedBlock + + $result | Should -BeOfType "notion_synced_block" + $result.type | Should -Be ([notion_blocktype]::synced_block) + } + } +} diff --git a/tests/Unit/Public/Block/Table/New-NotionTableBlock.Tests.ps1 b/tests/Unit/Public/Block/Table/New-NotionTableBlock.Tests.ps1 new file mode 100644 index 0000000..010c448 --- /dev/null +++ b/tests/Unit/Public/Block/Table/New-NotionTableBlock.Tests.ps1 @@ -0,0 +1,43 @@ +# FILE: Table/New-NotionTableBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionTableBlock" { + InModuleScope $moduleName { + It "Should create a table block with column headers" { + $tableData = @( + @("Header1", "Header2"), + @("Value1", "Value2") + ) + $result = New-NotionTableBlock -TableData $tableData -has_column_header + + $result | Should -BeOfType "notion_table_block" + $result.table.has_column_header | Should -BeTrue + $result.table.children.Count | Should -Be 2 + $result.table.children[0].table_row.cells[0][0].plain_text | Should -Be "Header1" + $result.table.children[1].table_row.cells[1][0].plain_text | Should -Be "Value2" + } + + It "Should create an empty table block" { + $result = New-NotionTableBlock -empty_table + + $result | Should -BeOfType "notion_table_block" + $result.table.children | Should -BeNullOrEmpty + } + } +} diff --git a/tests/Unit/Public/Block/TableOfContents/New-NotionTableOfContentsBlock.Tests.ps1 b/tests/Unit/Public/Block/TableOfContents/New-NotionTableOfContentsBlock.Tests.ps1 new file mode 100644 index 0000000..e9c897f --- /dev/null +++ b/tests/Unit/Public/Block/TableOfContents/New-NotionTableOfContentsBlock.Tests.ps1 @@ -0,0 +1,36 @@ +# FILE: TableOfContents/New-NotionTableOfContentsBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionTableOfContentsBlock" { + InModuleScope $moduleName { + It "Should create a default table of contents block" { + $result = New-NotionTableOfContentsBlock + + $result | Should -BeOfType "notion_table_of_contents_block" + $result.type | Should -Be ([notion_blocktype]::table_of_contents) + $result.table_of_contents.color | Should -Be ([notion_color]::default) + } + + It "Should create a table of contents block with custom color" { + $result = New-NotionTableOfContentsBlock -Color "gray" + + $result.table_of_contents.color | Should -Be ([notion_color]::gray) + } + } +} diff --git a/tests/Unit/Public/Block/TableRow/New-NotionTableRowBlock.Tests.ps1 b/tests/Unit/Public/Block/TableRow/New-NotionTableRowBlock.Tests.ps1 new file mode 100644 index 0000000..f2610c4 --- /dev/null +++ b/tests/Unit/Public/Block/TableRow/New-NotionTableRowBlock.Tests.ps1 @@ -0,0 +1,39 @@ +# FILE: TableRow/New-NotionTableRowBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionTableRowBlock" { + InModuleScope $moduleName { + It "Should create a table row from cell data" { + $result = New-NotionTableRowBlock -CellData @("Cell1", "Cell2") + + $result | Should -BeOfType "notion_table_row_block" + $result.type | Should -Be ([notion_blocktype]::table_row) + $result.table_row.cells[0][0].plain_text | Should -Be "Cell1" + $result.table_row.cells[1][0].plain_text | Should -Be "Cell2" + } + + It "Should convert from existing structure" { + $structure = [TableRow_structure]::new(@("A", "B")) + $result = New-NotionTableRowBlock -CellData $structure + + $result | Should -BeOfType "notion_table_row_block" + $result.table_row.cells.Count | Should -Be 2 + } + } +} diff --git a/tests/Unit/Public/Block/ToDo/New-NotionToDoBlock.Tests.ps1 b/tests/Unit/Public/Block/ToDo/New-NotionToDoBlock.Tests.ps1 new file mode 100644 index 0000000..14d3c6b --- /dev/null +++ b/tests/Unit/Public/Block/ToDo/New-NotionToDoBlock.Tests.ps1 @@ -0,0 +1,45 @@ +# FILE: ToDo/New-NotionToDoBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionToDoBlock" { + InModuleScope $moduleName { + It "Should create an empty to-do block" { + $result = New-NotionToDoBlock + + $result | Should -BeOfType "notion_to_do_block" + $result.type | Should -Be ([notion_blocktype]::to_do) + $result.to_do.rich_text | Should -BeNullOrEmpty + $result.to_do.checked | Should -BeFalse + } + + It "Should create a to-do block with text" { + $result = New-NotionToDoBlock -RichText "Buy milk" + + $result.to_do.rich_text[0].plain_text | Should -Be "Buy milk" + $result.to_do.checked | Should -BeFalse + } + + It "Should create a to-do block with checked state" { + $result = New-NotionToDoBlock -RichText "Submit report" -Checked $true + + $result.to_do.rich_text[0].plain_text | Should -Be "Submit report" + $result.to_do.checked | Should -BeTrue + } + } +} diff --git a/tests/Unit/Public/Block/Toggle/New-NotionToggleBlock.Tests.ps1 b/tests/Unit/Public/Block/Toggle/New-NotionToggleBlock.Tests.ps1 new file mode 100644 index 0000000..b42cc42 --- /dev/null +++ b/tests/Unit/Public/Block/Toggle/New-NotionToggleBlock.Tests.ps1 @@ -0,0 +1,37 @@ +# FILE: Toggle/New-NotionToggleBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionToggleBlock" { + InModuleScope $moduleName { + It "Should create an empty toggle block" { + $result = New-NotionToggleBlock + + $result | Should -BeOfType "notion_toggle_block" + $result.type | Should -Be ([notion_blocktype]::toggle) + $result.toggle.rich_text | Should -BeNullOrEmpty + } + + It "Should create a toggle block with text and color" { + $result = New-NotionToggleBlock -RichText "Details" -Color "gray" + + $result.toggle.rich_text[0].plain_text | Should -Be "Details" + $result.toggle.color | Should -Be ([notion_color]::gray) + } + } +} diff --git a/tests/Unit/Public/Block/Video/New-NotionVideoBlock.Tests.ps1 b/tests/Unit/Public/Block/Video/New-NotionVideoBlock.Tests.ps1 new file mode 100644 index 0000000..6fa0cb7 --- /dev/null +++ b/tests/Unit/Public/Block/Video/New-NotionVideoBlock.Tests.ps1 @@ -0,0 +1,38 @@ +# FILE: Video/New-NotionVideoBlock.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionVideoBlock" { + InModuleScope $moduleName { + It "Should create a video block from input object" { + $input = @{ video = @{ type = "external"; external = @{ url = "https://example.com/video.mp4" } } } + $result = New-NotionVideoBlock -InputObject $input + + $result | Should -BeOfType "notion_video_block" + $result.video.external.url | Should -Be "https://example.com/video.mp4" + } + + It "Should create a video block from caption and url" { + $result = New-NotionVideoBlock -caption "Demo video" -url "https://example.com/video.mp4" + + $result | Should -BeOfType "notion_video_block" + $result.video.caption[0].plain_text | Should -Be "Demo video" + $result.video.external.url | Should -Be "https://example.com/video.mp4" + } + } +} diff --git a/tests/Unit/Public/Block/_RichText/New-NotionRichText.Tests.ps1 b/tests/Unit/Public/Block/_RichText/New-NotionRichText.Tests.ps1 new file mode 100644 index 0000000..db6f5ca --- /dev/null +++ b/tests/Unit/Public/Block/_RichText/New-NotionRichText.Tests.ps1 @@ -0,0 +1,46 @@ +# FILE: _RichText/New-NotionRichText.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionRichText" { + InModuleScope $moduleName { + It "Should create a rich text object with text" { + $result = New-NotionRichText -Text "Hello" + + $result | Should -Not -BeNullOrEmpty + $result[0] | Should -BeOfType "rich_text_text" + $result[0].plain_text | Should -Be "Hello" + } + + It "Should create rich text with annotations and link" { + $annotations = New-NotionRichTextAnnotation -Bold + $result = New-NotionRichText -Text "Link" -Annotations $annotations -Link "https://example.com" + + $result[0].annotations.bold | Should -BeTrue + $result[0].href | Should -Be "https://example.com" + } + + It "Should convert markdown text" { + $result = New-NotionRichText -MarkdownText "**Bold**" + + $result | Should -Not -BeNullOrEmpty + $result[0].annotations.bold | Should -BeTrue + $result[0].plain_text | Should -Be "Bold" + } + } +} diff --git a/tests/Unit/Public/Block/_RichText/New-NotionRichTextAnnotation.Tests.ps1 b/tests/Unit/Public/Block/_RichText/New-NotionRichTextAnnotation.Tests.ps1 new file mode 100644 index 0000000..3c3c56d --- /dev/null +++ b/tests/Unit/Public/Block/_RichText/New-NotionRichTextAnnotation.Tests.ps1 @@ -0,0 +1,47 @@ +# FILE: _RichText/New-NotionRichTextAnnotation.Tests.ps1 +Import-Module Pester + +BeforeDiscovery { + $script:projectPath = "$($PSScriptRoot)/../../../../.." | Convert-Path + + if (-not $ProjectName) { + $ProjectName = Get-SamplerProjectName -BuildRoot $script:projectPath + } + Write-Debug "ProjectName: $ProjectName" + $global:moduleName = $ProjectName + Set-Alias -Name gitversion -Value dotnet-gitversion + $script:version = (gitversion /showvariable MajorMinorPatch) + + Remove-Module -Name $global:moduleName -Force -ErrorAction SilentlyContinue + + $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru +} + +Describe "New-NotionRichTextAnnotation" { + InModuleScope $moduleName { + It "Should create a default annotation" { + $result = New-NotionRichTextAnnotation + + $result | Should -BeOfType "notion_annotation" + $result.bold | Should -BeFalse + $result.color | Should -Be ([notion_color]::default) + } + + It "Should create an annotation from object" { + $annotations = @{ bold = $true; italic = $true; color = "red" } + $result = New-NotionRichTextAnnotation -Annotations $annotations + + $result.bold | Should -BeTrue + $result.italic | Should -BeTrue + $result.color | Should -Be ([notion_color]::red) + } + + It "Should create an annotation from switches" { + $result = New-NotionRichTextAnnotation -Bold -Underline -Color "yellow" + + $result.bold | Should -BeTrue + $result.underline | Should -BeTrue + $result.color | Should -Be ([notion_color]::yellow) + } + } +}