Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/Unit/Public/Block/Bookmark/New-NotionBookmarkBlock.Tests.ps1
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
Comment on lines +22 to +27
Copy link
Copy Markdown

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.url on a bookmark block created without parameters. New-NotionBookmarkBlock returns [notion_bookmark_block]::new() in this case and the class’s default constructor leaves the bookmark member uninitialized, so $result.bookmark is $null. Accessing .url will raise an InvokeMethodOnNull error before the Should -BeNullOrEmpty assertion is evaluated, causing the suite to fail even when the command behaves correctly. Consider asserting on $result.bookmark itself or initializing the bookmark structure in the cmdlet instead of dereferencing a possibly-null property.

Useful? React with 👍 / 👎.

}

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"
}
}
}
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)
}
}
}
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 tests/Unit/Public/Block/Callout/New-NotionCalloutBlock.Tests.ps1
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)
}
}
}
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"
}
}
}
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 tests/Unit/Public/Block/Code/New-NotionCodeBlock.Tests.ps1
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 tests/Unit/Public/Block/Column/New-NotionColumnBlock.Tests.ps1
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)
}
}
}
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 tests/Unit/Public/Block/Divider/New-NotionDividerBlock.Tests.ps1
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)
}
}
}
Loading
Loading