-
Notifications
You must be signed in to change notification settings - Fork 1
Add unit tests for Notion block creation commands #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fasteiner
merged 1 commit into
feature/36-pester-tests-for-block-functions
from
codex/add-pester-tests-for-new-commands
Sep 25, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
tests/Unit/Public/Block/Bookmark/New-NotionBookmarkBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
tests/Unit/Public/Block/Breadcrumb/New-NotionBreadcrumbBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
tests/Unit/Public/Block/BulletedListItem/New-NotionBulletedListItemBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
tests/Unit/Public/Block/Callout/New-NotionCalloutBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
tests/Unit/Public/Block/ChildDatabase/ChildPage/New-NotionChildPageBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
tests/Unit/Public/Block/ChildDatabase/New-NotionChildDatabaseBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
tests/Unit/Public/Block/Code/New-NotionCodeBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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' | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
tests/Unit/Public/Block/Column/New-NotionColumnBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
tests/Unit/Public/Block/ColumnList/New-NotionColumnListBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
tests/Unit/Public/Block/Divider/New-NotionDividerBlock.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Avoid null dereference when asserting empty bookmark block
The new test dereferences
bookmark.urlon a bookmark block created without parameters.New-NotionBookmarkBlockreturns[notion_bookmark_block]::new()in this case and the class’s default constructor leaves thebookmarkmember uninitialized, so$result.bookmarkis$null. Accessing.urlwill raise anInvokeMethodOnNullerror before theShould -BeNullOrEmptyassertion is evaluated, causing the suite to fail even when the command behaves correctly. Consider asserting on$result.bookmarkitself or initializing the bookmark structure in the cmdlet instead of dereferencing a possibly-null property.Useful? React with 👍 / 👎.