Need some help fixing - Pester Test for unregister server

#----------------------------------------------------------
# Un-register the SQL Server database instance.
#----------------------------------------------------------
if ($newDbId) {
  $registrationURL = $baseURL + "databases/unregister-monitor"
  $body = @{"databaseId" = $newDbId;
            "removeMonitoringUser" = $true;
            "removeDatabaseObjects" = $true;
            "sysAdminUser" = "sa";
            "sysAdminPassword" = "Password"} | ConvertTo-Json
  Try {
    Write-Host "Registering Database..."
    $dpaResponseJSON = Invoke-RestMethod -Uri $registrationURL -Body $body -Method POST -Headers $dpaHeader -TimeoutSec 60
    $dpaResponse = $dpaResponseJSON.data
    $dpaResponse | Format-Table -AutoSize
  }
  Catch {
    $_.Exception.ToString()
  }
}

The output of above Unregister Block is below:

Unregistering Database...

databaseId result
---------- ------
        70 SUCCESS

My Requirement is to write a unit test for the above PowerShell code , please help me fix it . So far what I tried is below:

  Context "check correct result" {
    BeforeEach {
        Mock Invoke-RestMethod { return [PSCustomObject]@{
            databaseId    = 1
            result  = "Success"

            }
        }

        Mock Write-Verbose { return $null }

        $result1 = $usage
     }
     It "Validating output from Removing Server" {
        $result1 | Should -Be 'Success'
     
     }

}

}

Couple of questions,

What is the pester version here ?
Is the above code for unregister a function ?
Why Format-Table is used ?

When you use Success , that means you are expecting a string in the assertion here $result1 | Should -Be 'Success', but your actual expression gives a formatted table as output

databaseId result
---------- ------
        70 SUCCESS
1 Like