Public/Connect-Connector.tests.ps1

BeforeAll {
    $Script:Module = Import-Module "$($PSScriptRoot)/.." -Force -PassThru
    $Script:ATP = "connector-$(New-Guid)"
    Add-EntraIDExternalAccessTokenProfile -Name $Script:ATP -AccessToken (New-DummyJWT)
}

Describe "Connect-Connector" {
    It "Should throw when there is no access token profile" {
        {
            Connect-Connector -ConnectorId (New-Guid).ToString() -AccessTokenProfile (New-Guid).ToString()
        } | Should -Throw
    }

    It "Should call the get connector configuraiton endpoint when an access token is available" {
        Mock -ModuleName $Script:Module.Name -CommandName Invoke-RestMethod -ParameterFilter { $Uri -like "http*://*.*fortytwo.*/connectors/*-*-*-*-*/configuration" } -MockWith {
            @{
                IsSuccess = $true
                Data      = @{
                    Id = (New-Guid).ToString()
                }
            }
        }
        
        {
            Connect-Connector -ConnectorId (New-Guid).ToString() -AccessTokenProfile $Script:ATP
        } | Should -Not -Throw
    }
}