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
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions source/Classes/03_File/01_file.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
{
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions source/Classes/Block/24_PDF.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions source/Classes/Block/27.99_Table.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
11 changes: 0 additions & 11 deletions source/Public/Block/Cmds/Pdf/New-NotionPdfBlock.ps1

This file was deleted.

11 changes: 0 additions & 11 deletions source/Public/Block/Cmds/Video/New-NotionVideoBlock.ps1

This file was deleted.

63 changes: 63 additions & 0 deletions source/Public/Block/Pdf/New-NotionPdfBlock.ps1
Original file line number Diff line number Diff line change
@@ -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
}
63 changes: 63 additions & 0 deletions source/Public/Block/Video/New-NotionVideoBlock.ps1
Original file line number Diff line number Diff line change
@@ -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
}
44 changes: 3 additions & 41 deletions tests/Unit/Classes/Block/27.99_Table.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions tests/Unit/Public/Block/New-NotionPdfBlock.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
}

}
}
Loading
Loading