Functions/New-GSuiteEndpointConfiguration.Tests.ps1

Describe "GSuite/New-GSuiteEndpointConfiguration" -Tag "task", "unit" {

    # Import the function to test
    . "$($PSScriptRoot)\New-GSuiteEndpointConfiguration.ps1"

    # Declare external functions
    function New-Object {
        param($typeName, $property)
    }

    context "when there are no issues" {
        # Declare mocks
        mock New-Object {
            param($typeName, $property)
        }

        # Declare the function inputs
        $endpointParams = @{
            GSuiteApplicationID = "id"
            GSuiteClientSecret = "secret"
            UserRefreshToken = "user"
            GroupRefreshToken = "group"
            OrganizationalUnitRefreshToken = "organizationalUnit"
            UserSchemaRefreshToken = "userSchema"
            MobileDeviceRefreshToken = "mobileDevice"
            SecurityRefreshToken = "security"
            CustomerRefreshToken = "customer"
            DomainRefreshToken = "domain"
        }

        # Declare the expected password
        $expectedPassword = "ClientSecret:secret User:user Group:group OrganizationalUnit:organizationalUnit UserSchema:userSchema MobileDevice:mobileDevice Security:security Customer:customer Domain:domain"

        it "creates a configuration object" {
            # Call the function
            $output = New-GSuiteEndpointConfiguration @endpointParams

            Assert-MockCalled New-Object -Times 1 -Exactly -ParameterFilter {
                $TypeName -eq "ManagementProxy.ManagementService.GenericConfiguration" -and
                $Property.Username -eq "id" -and
                $Property.Password -eq $expectedPassword -and
                $Property.Url -eq "https://admin.google.com" -and
                $Property.UseAdministrativeCredentials -eq $true
            } -Scope it
        }
    }
}