From ae96d8cb646ec7e103e0b9cfbc1d0e31db46899f Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sun, 12 Jul 2020 20:08:46 -0700 Subject: [PATCH] Adding Copy-GitHubGist tests --- Tests/GitHubGists.tests.ps1 | 138 +++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 48 deletions(-) diff --git a/Tests/GitHubGists.tests.ps1 b/Tests/GitHubGists.tests.ps1 index beea1e0d..852152e3 100644 --- a/Tests/GitHubGists.tests.ps1 +++ b/Tests/GitHubGists.tests.ps1 @@ -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 } } }