Skip to content

Commit

Permalink
Adding Copy-GitHubGist tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardWolosky committed Jul 14, 2020
1 parent 521c39c commit ae96d8c
Showing 1 changed file with 90 additions and 48 deletions.
138 changes: 90 additions & 48 deletions Tests/GitHubGists.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,71 +95,113 @@ try
}

Describe 'Copy-GitHubGist' {
Context 'By files' {
BeforeAll {
BeforeAll {
$originalGist = Get-GitHubGist -Gist '1169852' # octocat/test.cs
}

Context 'By parameters' {
$gist = Copy-GitHubGist -Gist $originalGist.id
It 'Should have been forked' {
$gist.files.Count | Should -Be $originalGist.files.Count
foreach ($file in $gist.files)
{
$originalFile = $originalGist.files |
Where-Object { $_.filename -eq $file.filename }
$file.filename | Should -Be $originalFile.filename
$file.size | Should -Be $originalFile.size
}
}

AfterAll {
It 'Should have the expected additional type and properties' {
$gist.PSObject.TypeNames[0] | Should -Be 'GitHub.Gist'
$gist.GistId | Should -Be $gist.id
$gist.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User'
}

It 'Should be removed' {
{ Remove-GitHubGist -Gist $gist.id -Force } | Should -Not -Throw
}
}
}

Describe 'Add/Remove/Test-GitHubGistStar' {
Context 'By files' {
BeforeAll {
$gist = New-GitHubGist -Content 'Sample text' -Filename 'sample.txt'
Context 'Gist on the pipeline' {
$gist = $originalGist | Copy-GitHubGist
It 'Should have been forked' {
$gist.files.Count | Should -Be $originalGist.files.Count
foreach ($file in $gist.files)
{
$originalFile = $originalGist.files |
Where-Object { $_.filename -eq $file.filename }
$file.filename | Should -Be $originalFile.filename
$file.size | Should -Be $originalFile.size
}
}

AfterAll {
$gist | Remove-GitHubGist -Force
It 'Should have the expected additional type and properties' {
$gist.PSObject.TypeNames[0] | Should -Be 'GitHub.Gist'
$gist.GistId | Should -Be $gist.id
$gist.owner.PSObject.TypeNames[0] | Should -Be 'GitHub.User'
}

Context 'With parameters' {
$starred = Test-GitHubGistStar -Gist $gist.id
It 'Should not be starred yet' {
$starred | Should -BeFalse
}
It 'Should be removed' {
{ $gist | Remove-GitHubGist -Force } | Should -Not -Throw
}
}
}

Add-GitHubGistStar -Gist $gist.id
$starred = Test-GitHubGistStar -Gist $gist.id
It 'Should now be starred yet' {
$starred | Should -BeTrue
}
Describe 'Add/Remove/Test-GitHubGistStar' {
BeforeAll {
$gist = New-GitHubGist -Content 'Sample text' -Filename 'sample.txt'
}

$starred = Test-GitHubGistStar -Gist $gist.id
It 'Should not be starred yet' {
$starred | Should -BeTrue
}
AfterAll {
$gist | Remove-GitHubGist -Force
}

Remove-GitHubGistStar -Gist $gist.id
$starred = Test-GitHubGistStar -Gist $gist.id
It 'Should no longer be starred yet' {
$starred | Should -BeFalse
}
Context 'With parameters' {
$starred = Test-GitHubGistStar -Gist $gist.id
It 'Should not be starred yet' {
$starred | Should -BeFalse
}

Context 'With the gist on the pipeline' {
$starred = $gist | Test-GitHubGistStar
It 'Should not be starred yet' {
$starred | Should -BeFalse
}
Add-GitHubGistStar -Gist $gist.id
$starred = Test-GitHubGistStar -Gist $gist.id
It 'Should now be starred yet' {
$starred | Should -BeTrue
}

$gist | Add-GitHubGistStar
$starred = $gist | Test-GitHubGistStar
It 'Should now be starred yet' {
$starred | Should -BeTrue
}
$starred = Test-GitHubGistStar -Gist $gist.id
It 'Should not be starred yet' {
$starred | Should -BeTrue
}

$starred = $gist | Test-GitHubGistStar
It 'Should not be starred yet' {
$starred | Should -BeTrue
}
Remove-GitHubGistStar -Gist $gist.id
$starred = Test-GitHubGistStar -Gist $gist.id
It 'Should no longer be starred yet' {
$starred | Should -BeFalse
}
}

$gist | Remove-GitHubGistStar
$starred = $gist | Test-GitHubGistStar
It 'Should no longer be starred yet' {
$starred | Should -BeFalse
}
Context 'With the gist on the pipeline' {
$starred = $gist | Test-GitHubGistStar
It 'Should not be starred yet' {
$starred | Should -BeFalse
}

$gist | Add-GitHubGistStar
$starred = $gist | Test-GitHubGistStar
It 'Should now be starred yet' {
$starred | Should -BeTrue
}

$starred = $gist | Test-GitHubGistStar
It 'Should not be starred yet' {
$starred | Should -BeTrue
}

$gist | Remove-GitHubGistStar
$starred = $gist | Test-GitHubGistStar
It 'Should no longer be starred yet' {
$starred | Should -BeFalse
}
}
}
Expand Down

0 comments on commit ae96d8c

Please sign in to comment.