tests/Get-SkylineCustomAction.Tests.ps1

$BootstrapJsUrl = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
$jQueryUrl = "https://code.jquery.com/jquery-3.2.1.min.js"
$SiteCustomActionName = "CustomActionTestSite"
$WebCustomActionName = "CustomActionTestWeb"

Describe "Get-SkylineCustomAction - Root Web" {
    BeforeAll {
        Add-PnPJavaScriptLink -Name $SiteCustomActionName -Url $jQueryUrl -Scope Site
        Add-PnPJavaScriptLink -Name $WebCustomActionName -Url $BootstrapJsUrl -Scope Web
    }
    Context "get all site and web scoped custom actions on the root web" {
        It "should have a site and web scope custom action" {
            $script:SiteCustomAction = Get-PnPCustomAction -Scope Site | Where-Object {$_.Name -eq $SiteCustomActionName}
            $script:SiteCustomAction | Should Not BeNullOrEmpty

            $script:WebCustomAction = Get-PnPCustomAction -Scope Web | Where-Object {$_.Name -eq $WebCustomActionName}
            $script:WebCustomAction | Should Not BeNullOrEmpty
        }
        It "should find the site custom action" {
            Get-SkylineCustomAction -Name $SiteCustomActionName | Should Not BeNullOrEmpty
        }
        It "should find the web custom action" {
            Get-SkylineCustomAction -Name $WebCustomActionName | Should Not BeNullOrEmpty
        }
        It "should find both custom actions" {
            $CustomActions = Get-SkylineCustomAction
            $CustomActions | Where-Object {$_.Name -eq $SiteCustomActionName} | Should Not BeNullOrEmpty
            $CustomActions | Where-Object {$_.Name -eq $WebCustomActionName} | Should Not BeNullOrEmpty
        }
    }
    AfterAll {
        Remove-PnPCustomAction -Identity $script:SiteCustomAction.Id -Scope Site -Force
        Remove-PnPCustomAction -Identity $script:WebCustomAction.Id -Scope Web -Force        
    }
}

Describe "Get-SkylineCustomAction - Subsite" {
    BeforeAll {
        $Subsite = @(Get-PnPSubWebs)[0]
        Add-PnPJavaScriptLink -Name $SiteCustomActionName -Url $jQueryUrl -Scope Site -Web $Subsite
        Add-PnPJavaScriptLink -Name $WebCustomActionName -Url $BootstrapJsUrl -Scope Web -Web $Subsite
    }
    Context "get all site and web scoped custom actions on the subsite" {
        It "should have a site and web scope custom action" {
            $script:SiteCustomAction = Get-PnPCustomAction -Scope Site -Web $Subsite | Where-Object {$_.Name -eq $SiteCustomActionName}
            $script:SiteCustomAction | Should Not BeNullOrEmpty

            $script:WebCustomAction = Get-PnPCustomAction -Scope Web -Web $Subsite | Where-Object {$_.Name -eq $WebCustomActionName}
            $script:WebCustomAction | Should Not BeNullOrEmpty
        }
        It "should find the site custom action" {
            Get-SkylineCustomAction -Name $SiteCustomActionName -Web $Subsite | Should Not BeNullOrEmpty
        }
        It "should find the web custom action" {
            Get-SkylineCustomAction -Name $WebCustomActionName -Web $Subsite | Should Not BeNullOrEmpty
        }
        It "should find both custom actions" {
            $CustomActions = Get-SkylineCustomAction -Web $Subsite
            $CustomActions | Where-Object {$_.Name -eq $SiteCustomActionName} | Should Not BeNullOrEmpty
            $CustomActions | Where-Object {$_.Name -eq $WebCustomActionName} | Should Not BeNullOrEmpty
        }
    }
    AfterAll {
        Remove-PnPCustomAction -Identity $script:SiteCustomAction.Id -Scope Site -Force -Web $Subsite
        Remove-PnPCustomAction -Identity $script:WebCustomAction.Id -Scope Web -Force -Web $Subsite    
    }
}