· 6 years ago · Dec 02, 2019, 03:10 PM
1Import-Module $ENV:BHPSModuleManifest -Force
2InModuleScope 'PSITSPortal' {
3 Describe 'Get-Token' {
4 BeforeAll {
5 Mock Import-Clixml {
6 $Password = ConvertTo-SecureString "password" -AsPlainText -Force
7 [Management.Automation.PSCredential]::new("username", $Password)
8 }
9 Mock ConvertTo-Json {
10 $true
11 }
12 Mock Invoke-WebRequest {
13 [PSCustomObject]@{
14 Content = "asdf2123dfasdfw2erasdxcDSAfas"
15 }
16 }
17 }
18 Context 'Output' {
19 It 'outputs the API key in the form of a authorization header' {
20 $Token = Get-Token
21 $Token | Should -Not -BeNullOrEmpty
22 $Token['Authorization'] | Should -Be 'Token asdf2123dfasdfw2erasdxcDSAfas'
23 }
24 }
25 }
26}