-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathUsers.Tests.ps1
More file actions
86 lines (80 loc) · 3.87 KB
/
Users.Tests.ps1
File metadata and controls
86 lines (80 loc) · 3.87 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
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' }
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseDeclaredVarsMoreThanAssignments', '',
Justification = 'Pester grouping syntax: known issue.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingConvertToSecureStringWithPlainText', '',
Justification = 'Used to create a secure string for testing.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '',
Justification = 'Log outputs to GitHub Actions logs.'
)]
[CmdletBinding()]
param()
Describe 'Users' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"
Context 'As <Type> using <Case> on <Target>' -ForEach $authCases {
BeforeAll {
$context = Connect-GitHubAccount @connectParams -PassThru -Silent
LogGroup 'Context' {
Write-Host ($context | Format-List | Out-String)
}
if ($AuthType -eq 'APP') {
$context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent
LogGroup 'Context' {
Write-Host ($context | Format-List | Out-String)
}
}
}
AfterAll {
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}
It 'Get-GitHubUser - Get the specified user' {
{ Get-GitHubUser -Name 'Octocat' } | Should -Not -Throw
}
if ($OwnerType -eq 'user') {
It 'Get-GitHubUser - Gets the authenticated user' {
{ Get-GitHubUser } | Should -Not -Throw
}
It 'Update-GitHubUser - Can set configuration on a user' {
$guid = (New-Guid).Guid
$user = Get-GitHubUser
{ Update-GitHubUser -DisplayName 'Octocat' } | Should -Not -Throw
{ Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw
{ Update-GitHubUser -Website 'https://psmodule.io' } | Should -Not -Throw
{ Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw
{ Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw
{ Update-GitHubUser -Location 'USA' } | Should -Not -Throw
{ Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw
{ Update-GitHubUser -Description 'I love programming' } | Should -Not -Throw
$tmpUser = Get-GitHubUser
$tmpUser.DisplayName | Should -Be 'Octocat'
$tmpUser.Blog | Should -Be 'https://psmodule.io'
$tmpUser.Website | Should -Be 'https://psmodule.io'
$tmpUser.TwitterUsername | Should -Be 'PSModule'
$tmpUser.Company | Should -Be 'PSModule'
$tmpUser.Location | Should -Be 'USA'
$tmpUser.Bio | Should -Be 'I love programming'
$tmpUser.Description | Should -Be 'I love programming'
# Flaky tests
# { Update-GitHubUser -Hireable $true } | Should -Not -Throw
# $tmpUser.Hireable | Should -Be $true
}
Context 'Email' {
It 'Get-GitHubUserEmail - Gets all email addresses for the authenticated user' {
{ Get-GitHubUserEmail } | Should -Not -Throw
}
It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user' {
$email = (New-Guid).Guid + '@psmodule.io'
{ Add-GitHubUserEmail -Email $email } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Contain $email
{ Remove-GitHubUserEmail -Email $email } | Should -Not -Throw
(Get-GitHubUserEmail).email | Should -Not -Contain $email
}
}
}
}
}