Repository navigation
Expand file tree
/
Copy pathPSTelegramAPI.Tests.ps1
More file actions
90 lines (72 loc) · 4.24 KB
/
Copy pathPSTelegramAPI.Tests.ps1
File metadata and controls
90 lines (72 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Try { Set-BuildEnvironment -Path "${PSScriptRoot}\.." -ErrorAction SilentlyContinue -Force } Catch { }
If (-Not $ENV:TLApiId) { $ENV:TLApiId = [Environment]::GetEnvironmentVariable("TLApiId", "User") }
If (-Not $ENV:TLApiHash) { $ENV:TLApiHash = [Environment]::GetEnvironmentVariable("TLApiHash", "User") }
If (-Not $ENV:TLPhoneNumber) { $ENV:TLPhoneNumber = [Environment]::GetEnvironmentVariable("TLPhoneNumber", "User") }
Remove-Module $ENV:BHProjectName -ErrorAction SilentlyContinue -Force -Confirm:$False
$Script:Module = Import-Module $ENV:BHPSModuleManifest -Force -PassThru
Describe 'Get-Module -Name PSTelegramAPI' {
Context 'Strict mode' {
Set-StrictMode -Version Latest
It 'Should Import' {
$Script:Module.Name | Should be $ENV:BHProjectName
}
It 'Should have ExportedFunctions' {
$Script:Module.ExportedFunctions.Keys -contains 'Get-TLContacts' | Should be $True
$Script:Module.ExportedFunctions.Keys -contains 'Get-TLHistory' | Should be $True
$Script:Module.ExportedFunctions.Keys -contains 'Get-TLUserDialogs' | Should be $True
$Script:Module.ExportedFunctions.Keys -contains 'Invoke-TLSendMessage' | Should be $True
$Script:Module.ExportedFunctions.Keys -contains 'New-TLClient' | Should be $True
}
}
}
Describe 'Execute Function tests' {
Context 'Strict mode' {
Set-StrictMode -Version Latest
$Invalid_ApiId = Get-Random -Minimum 100000 -Maximum 999999
$Invalid_ApiHash = [guid]::NewGuid().Guid.Replace('-','')
$Invalid_PhoneNumber = '15550000000'
It 'New-TLClient: Should fail with invalid ApiId' {
{ New-TLClient -ApiId $Invalid_ApiId -ApiHash $Invalid_ApiHash -PhoneNumber $Invalid_PhoneNumber } | Should -Throw "API_ID_INVALID"
}
It 'New-TLClient: Should fail with invalid ApiHash' {
{ New-TLClient -ApiId $ENV:TLApiId -ApiHash $Invalid_ApiHash -PhoneNumber $Invalid_PhoneNumber } | Should -Throw "API_ID_INVALID"
}
It 'New-TLClient: Should prompt for Code' {
Mock 'Read-Host' { 11111 } -ModuleName PSTelegramAPI
{ New-TLClient -ApiId $ENV:TLApiId -ApiHash $ENV:TLApiHash -PhoneNumber $Invalid_PhoneNumber } | Should -Throw "The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram"
Assert-MockCalled -CommandName Read-Host -ModuleName PSTelegramAPI -Exactly 1
}
}
}
Describe 'Execution End-to-End tests' {
Context 'Strict mode' {
Set-StrictMode -Version Latest
It 'New-TLClient: Should be IsConnected' -Skip {
$Script:TLClient = New-TLClient -ApiId $ENV:TLApiId -ApiHash $ENV:TLApiHash -PhoneNumber $ENV:TLPhoneNumber
$Script:TLClient.IsUserAuthorized() | Should -Be $true
}
It 'Get-TLContacts: Should be TLContacts' -Skip {
$Script:TLContacts = Get-TLContacts -TLClient $Script:TLClient
$Script:TLContacts.GetType().Name | Should -Be 'TLContacts'
}
It 'Get-TLUserDialogs: Should contain TLUserDialog' -Skip {
$Script:TLUserDialogs = Get-TLUserDialogs -TLClient $Script:TLClient
$Script:TLUserDialogs.Constructor | Should -Contain '1728035348'
}
It 'Get-TLUserDialogs: Should contain TLUser' -Skip {
$Script:TLPeer = $Script:TLUserDialogs.Where({$_.Peer.username -eq 'mkellerman'}).Peer
$Script:TLPeer.GetType().Name | Should -Be 'TLUser'
}
It 'Get-TLUserDialogs: Should contain TLMessage' -Skip {
$Script:TLMessage = $Script:TLUserDialogs.Where({$_.Peer.username -eq 'mkellerman'}).Message
$Script:TLMessage.GetType().Name | Should -Be 'TLMessage'
}
It 'Get-TLHistory: Should contain TLMessage' -Skip {
$Script:TLHistory = Get-TLHistory -TLClient $Script:TLClient -TLPeer $Script:TLPeer -Limit 1
$Script:TLHistory.Messages[0].GetType().Name | Should -Be 'TLMessage'
}
It 'Invoke-TLSendMessage: Should contain TLUpdateShortSentMessage' -Skip {
$Script:TLSendMessage = Invoke-TLSendMessage -TLClient $Script:TLClient -TLPeer $Script:TLPeer -Message "Pester Test ${ENV:BHBuildNumber}"
}
}
}