diff --git a/CHANGELOG.md b/CHANGELOG.md index 7523432..986ac77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- **`source/Public/Block/Pdf/New-NotionPdfBlock.ps1`** + - Implemented `New-NotionPdfBlock` to generate a Notion PDF block from provided caption and URL. + +- **`source/Public/Block/Video/New-NotionVideoBlock.ps1`** + - Implemented `New-NotionVideoBlock` to create a Notion video block with specified input. + +- **`tests/Unit/Public/Block/New-NotionPdfBlock.Tests.ps1`** + - Added unit tests for `New-NotionPdfBlock`, validating block construction from caption and URL. + +- **`tests/Unit/Public/Block/New-NotionVideoBlock.Tests.ps1`** + - Added unit tests for `New-NotionVideoBlock`, covering basic functionality and input validation. + +### Fixed + +- **`/workspaces/Notion/source/Classes/Block/27.99_Table.ps1`** + - Fixed `[Table_structure]::ConvertFromObject()` + +### Removed + +- Removed unimplemented placeholder versions of these functions from the `Cmds` folder after relocating and implementing them. + - **`source/Public/Block/Cmds/Pdf/New-NotionPdfBlock.ps1`** + - **`source/Public/Block/Cmds/Video/New-NotionVideoBlock.ps1`** + ## [0.10.0] - 2025-06-27 ### Added diff --git a/source/Classes/03_File/01_file.ps1 b/source/Classes/03_File/01_file.ps1 index 7429ab4..91b22bc 100644 --- a/source/Classes/03_File/01_file.ps1 +++ b/source/Classes/03_File/01_file.ps1 @@ -33,17 +33,15 @@ class notion_file : notion_icon static [notion_file] Create([notion_filetype] $type, [string] $name, $caption, [string] $url, $expiry_time = $null ) { - $processedCaption = [rich_text]::ConvertFromObjects($caption) - switch ($type) { "file" { - return [notion_hosted_file]::new($name, $processedCaption, $url, $expiry_time) + return [notion_hosted_file]::new($name, $caption, $url, $expiry_time) } "external" { - return [notion_external_file]::new($name, $processedCaption, $url) + return [notion_external_file]::new($name, $caption, $url) } "file_upload " { @@ -61,7 +59,7 @@ class notion_file : notion_icon static [notion_file] ConvertFromObject($Value) { - Write-Verbose "[notion_file]::ConvertFromObject($($Value | ConvertTo-Json))" + Write-Verbose "[notion_file]::ConvertFromObject($($Value | ConvertTo-Json -Depth 10))" if ($null -eq $Value) { return $null diff --git a/source/Classes/Block/24_PDF.ps1 b/source/Classes/Block/24_PDF.ps1 index 7841c2f..93d6226 100644 --- a/source/Classes/Block/24_PDF.ps1 +++ b/source/Classes/Block/24_PDF.ps1 @@ -14,6 +14,11 @@ class notion_PDF_block : notion_block $this.pdf = [notion_file]::ConvertFromObject($file) } + notion_PDF_block($caption, $url) + { + $this.pdf = [notion_file]::Create("external", $null, $caption, $url, $null) + } + notion_PDF_block($caption, $url, $name) { $this.pdf = [notion_file]::Create("external", $name, $caption, $url, $null) diff --git a/source/Classes/Block/27.99_Table.ps1 b/source/Classes/Block/27.99_Table.ps1 index 23497d5..08f4ef6 100644 --- a/source/Classes/Block/27.99_Table.ps1 +++ b/source/Classes/Block/27.99_Table.ps1 @@ -38,9 +38,9 @@ class Table_structure static [Table_structure] ConvertFromObject($Value) { $Table_structure_Obj = [Table_structure]::new() - $Table_structure_Obj.table_width = $Value.table.table_width - $Table_structure_Obj.has_column_header = $Value.table.has_column_header - $Table_structure_Obj.has_row_header = $Value.table.has_row_header + $Table_structure_Obj.table_width = $Value.table_width + $Table_structure_Obj.has_column_header = $Value.has_column_header + $Table_structure_Obj.has_row_header = $Value.has_row_header return $Table_structure_Obj } } diff --git a/source/Public/Block/Cmds/Pdf/New-NotionPdfBlock.ps1 b/source/Public/Block/Cmds/Pdf/New-NotionPdfBlock.ps1 deleted file mode 100644 index d4c03cc..0000000 --- a/source/Public/Block/Cmds/Pdf/New-NotionPdfBlock.ps1 +++ /dev/null @@ -1,11 +0,0 @@ -function New-NotionPdfBlock { -[CmdletBinding()] - [OutputType([void])] - param( - [Parameter(Mandatory = $True)] - $parameter1 - ) - -throw [System.NotImplementedException]::new("This function is not yet implemented.") - -} diff --git a/source/Public/Block/Cmds/Video/New-NotionVideoBlock.ps1 b/source/Public/Block/Cmds/Video/New-NotionVideoBlock.ps1 deleted file mode 100644 index 6016c35..0000000 --- a/source/Public/Block/Cmds/Video/New-NotionVideoBlock.ps1 +++ /dev/null @@ -1,11 +0,0 @@ -function New-NotionVideoBlock { -[CmdletBinding()] - [OutputType([void])] - param( - [Parameter(Mandatory = $True)] - $parameter1 - ) - -throw [System.NotImplementedException]::new("This function is not yet implemented.") - -} diff --git a/source/Public/Block/Pdf/New-NotionPdfBlock.ps1 b/source/Public/Block/Pdf/New-NotionPdfBlock.ps1 new file mode 100644 index 0000000..72d0c2e --- /dev/null +++ b/source/Public/Block/Pdf/New-NotionPdfBlock.ps1 @@ -0,0 +1,63 @@ +function New-NotionPdfBlock { + <# + .SYNOPSIS + Creates a new Notion PDF block. + + .DESCRIPTION + The New-NotionPdfBlock function creates a new instance of a Notion PDF block. + Users can either provide an InputObject or specify the caption, name, and URL to create the block. + + .PARAMETER InputObject + The file object to be used for creating the PDF block. This should be an object that can be converted + into a notion_PDF_block using the ConvertFromObject method. + + .PARAMETER caption + The caption for the PDF block. + + .PARAMETER url + The URL of the PDF file. + + .OUTPUTS + [notion_PDF_block] + Returns an instance of the notion_PDF_block class. + + .EXAMPLE + $pdfBlock = New-NotionPdfBlock -InputObject $fileObject + + Creates a new Notion PDF block using the specified file object. + + .EXAMPLE + $pdfBlock = New-NotionPdfBlock -caption "My PDF" -url "https://example.com/example.pdf" + + Creates a new Notion PDF block using the specified caption and URL. + + .NOTES + This function requires the notion_PDF_block class to be defined in the project. + #> + [CmdletBinding(DefaultParameterSetName = "InputObjectSet")] + [OutputType([notion_PDF_block])] + param( + [Parameter(Mandatory = $True, ParameterSetName = "InputObjectSet")] + [Alias("File")] + [object] $InputObject, + + [Parameter(Mandatory = $True, ParameterSetName = "CaptionSet")] + [object] $caption, + + # Not supported at the moment + # [Parameter(Mandatory = $True, ParameterSetName = "CaptionSet")] + # [string] $name, + + [Parameter(Mandatory = $True, ParameterSetName = "CaptionSet")] + [string] $url + ) + + if ($PSCmdlet.ParameterSetName -eq "InputObjectSet") { + # Create a new instance of notion_PDF_block using the provided InputObject + return [notion_PDF_block]::ConvertFromObject($InputObject) + } elseif ($PSCmdlet.ParameterSetName -eq "CaptionSet") { + # Create a new instance of notion_PDF_block using the caption, name, and URL + return [notion_PDF_block]::new($caption, $url<#, $name#>) + } + return $null +} diff --git a/source/Public/Block/Video/New-NotionVideoBlock.ps1 b/source/Public/Block/Video/New-NotionVideoBlock.ps1 new file mode 100644 index 0000000..0a9b2a6 --- /dev/null +++ b/source/Public/Block/Video/New-NotionVideoBlock.ps1 @@ -0,0 +1,63 @@ +function New-NotionVideoBlock { + <# + .SYNOPSIS + Creates a new Notion Video block. + + .DESCRIPTION + The New-NotionVideoBlock function creates a new instance of a Notion Video block. + Users can either provide an InputObject or specify the caption, name, and URL to create the block. + + .PARAMETER InputObject + The file object to be used for creating the Video block. This should be an object that can be converted + into a notion_video_block using the ConvertFromObject method. + + .PARAMETER caption + The caption for the Video block. + + .PARAMETER url + The URL of the Video file. + + .OUTPUTS + [notion_video_block] + Returns an instance of the notion_video_block class. + + .EXAMPLE + $videoBlock = New-NotionVideoBlock -InputObject $fileObject + + Creates a new Notion Video block using the specified file object. + + .EXAMPLE + $videoBlock = New-NotionVideoBlock -caption "My Video" -url "https://example.com/example.mp4" + + Creates a new Notion Video block using the specified caption and URL. + + .NOTES + This function requires the notion_video_block class to be defined in the project. + #> + [CmdletBinding(DefaultParameterSetName = "InputObjectSet")] + [OutputType([notion_video_block])] + param( + [Parameter(Mandatory = $True, ParameterSetName = "InputObjectSet")] + [Alias("File")] + [object] $InputObject, + + [Parameter(Mandatory = $True, ParameterSetName = "CaptionSet")] + [object] $caption, + + # Not supported at the moment + # [Parameter(Mandatory = $True, ParameterSetName = "CaptionSet")] + # [string] $name, + + [Parameter(Mandatory = $True, ParameterSetName = "CaptionSet")] + [string] $url + ) + + if ($PSCmdlet.ParameterSetName -eq "InputObjectSet") { + # Create a new instance of notion_video_block using the provided InputObject + return [notion_video_block]::ConvertFromObject($InputObject) + } elseif ($PSCmdlet.ParameterSetName -eq "CaptionSet") { + # Create a new instance of notion_video_block using the caption, name, and URL + return [notion_video_block]::new("external", $null ,$caption, $url, $null) + } + return $null +} diff --git a/tests/Unit/Classes/Block/27.99_Table.tests.ps1 b/tests/Unit/Classes/Block/27.99_Table.tests.ps1 index 1176e72..33e2086 100644 --- a/tests/Unit/Classes/Block/27.99_Table.tests.ps1 +++ b/tests/Unit/Classes/Block/27.99_Table.tests.ps1 @@ -15,49 +15,11 @@ Describe "notion_table_block Tests" { $mut = Import-Module -Name "$script:projectPath/output/module/$ProjectName/$script:version/$ProjectName.psd1" -Force -ErrorAction Stop -PassThru } - Context "Table_structure Constructors" { - It "should create default Table_structure" { - $table = [Table_structure]::new() - $table.table_width | Should -Be 0 - $table.has_column_header | Should -BeFalse - $table.has_row_header | Should -BeFalse - $table.children | Should -BeNullOrEmpty - } - - It "should create Table_structure with width" { - $table = [Table_structure]::new(3) - $table.table_width | Should -Be 3 - } - - It "should create Table_structure with width and headers" { - $table = [Table_structure]::new(4, $true, $true) - $table.table_width | Should -Be 4 - $table.has_column_header | Should -BeTrue - $table.has_row_header | Should -BeTrue - } - } - - Context "Table_structure Methods" { - It "should add a single row" { - $table = [Table_structure]::new() - $row = [notion_table_row_block]::new() - $table.addRow($row) - $table.children.Count | Should -Be 1 - } - - It "should add multiple rows" { - $table = [Table_structure]::new() - $rows = @([notion_table_row_block]::new(), [notion_table_row_block]::new()) - $table.addRows($rows) - $table.children.Count | Should -Be 2 - } - } - Context "notion_table_block Constructors" { It "should create default notion_table_block" { $block = [notion_table_block]::new() $block.type | Should -Be "table" - $block.table | Should -BeOfType "Table_structure" + $block.table.gettype().Name | Should -Be "Table_structure" } It "should create notion_table_block with rows" { @@ -86,14 +48,14 @@ Describe "notion_table_block Tests" { Context "ConvertFromObject Tests" { It "should convert from object correctly" { - $mock = [PSCustomObject]@{ + $object = [PSCustomObject]@{ table = [PSCustomObject]@{ table_width = 3 has_column_header = $true has_row_header = $false } } - $block = [notion_table_block]::ConvertFromObject($mock) + $block = [notion_table_block]::ConvertFromObject($object) $block | Should -BeOfType "notion_table_block" $block.table.table_width | Should -Be 3 $block.table.has_column_header | Should -BeTrue diff --git a/tests/Unit/Public/Block/New-NotionPdfBlock.Tests.ps1 b/tests/Unit/Public/Block/New-NotionPdfBlock.Tests.ps1 new file mode 100644 index 0000000..b15cea7 --- /dev/null +++ b/tests/Unit/Public/Block/New-NotionPdfBlock.Tests.ps1 @@ -0,0 +1,51 @@ +# FILE: New-NotionPdfBlock.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-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" } } + $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" + $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" + } + + # 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/New-NotionVideoBlock.Tests.ps1 b/tests/Unit/Public/Block/New-NotionVideoBlock.Tests.ps1 new file mode 100644 index 0000000..9f8dfc0 --- /dev/null +++ b/tests/Unit/Public/Block/New-NotionVideoBlock.Tests.ps1 @@ -0,0 +1,51 @@ +# 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 + } + + } +}