Functions/Compare-MSPCompleteUsers.Tests.ps1

describe "BitTitan.Runbooks.MSPComplete/Compare-MSPCompleteUsers" -Tag "module", "unit" {

    # Import the function to test
    . "$($PSScriptRoot)\Compare-MSPCompleteUsers.ps1"

    # Declare external functions and mocks
    function Compare-MSPCompleteUser {
        return $true
    }

    it "returns true for identical lists of users" {
        # Declare the function inputs
        $referenceUsers = @(
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress1"
            },
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress2"
            }
        )

        # Call the function
        $output = Compare-MSPCompleteUsers -ReferenceUsers $referenceUsers -ComparisonUsers $referenceUsers `
            -ErrorAction SilentlyContinue -ErrorVariable errorVariable

        # Verify the output
        $errorVariable | Should BeNullOrEmpty
        $output | Should Be $true
    }

    it "returns false for two lists of users with different lengths" {
        # Declare the function inputs
        $referenceUsers = @(
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress1"
            },
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress2"
            }
        )
        $comparisonUsers = @(
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress1"
            }
        )

        # Call the function
        $output = Compare-MSPCompleteUsers -ReferenceUsers $referenceUsers -ComparisonUsers $comparisonUsers `
            -ErrorAction SilentlyContinue -ErrorVariable errorVariable

        # Verify the output
        $errorVariable | Should Not BeNullOrEmpty
        $output | Should Be $false
    }

    # Declare mocks
    mock Compare-MSPCompleteUser {
        return $false
    }

    it "returns false for two lists of users with different properties" {
        # Declare the function inputs
        $referenceUsers = @(
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress1"
            },
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress2"
            }
        )
        $comparisonUsers = @(
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress2"
            },
            [PSCustomObject]@{
                PrimaryEmailAddress = "primaryEmailAddress3"
            }
        )

        # Call the function
        $output = Compare-MSPCompleteUsers -ReferenceUsers $referenceUsers -ComparisonUsers $comparisonUsers `
            -ErrorAction SilentlyContinue -ErrorVariable errorVariable

        # Verify the output
        $errorVariable | Should BeNullOrEmpty
        $output | Should Be $false
    }
}