From 58e864f73fbe88945e36e8492138ba2b1941bf28 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Sun, 13 Sep 2020 13:08:25 +0200 Subject: [PATCH 01/14] :white_check_mark: Mock response in Find-SteamAppID --- Tests/SteamAPI.Tests.ps1 | 8 ++++++++ Tests/assets/applist.json | 5 +++++ 2 files changed, 13 insertions(+) create mode 100644 Tests/assets/applist.json diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index 6d6f876..b5f18d0 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,4 +1,12 @@ Describe "Find-SteamAppID" { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\assets\applist.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } + } It "Finds game 'Ground Branch'" { $GB = Find-SteamAppID -ApplicationName 'Ground Branch Dedicated Server' $GB.appid | Should -Be 476400 diff --git a/Tests/assets/applist.json b/Tests/assets/applist.json new file mode 100644 index 0000000..713822a --- /dev/null +++ b/Tests/assets/applist.json @@ -0,0 +1,5 @@ +{ + "applist": { + "apps": [{ "appid": 476400, "name": "GROUND BRANCH Dedicated Server" }] + } +} From e003c2b08138aa5040e43d4df7e50a5ed2716c57 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Sun, 13 Sep 2020 14:02:06 +0200 Subject: [PATCH 02/14] :white_check_mark: Add Pester tests for Web API cmdlets --- Tests/SteamAPI.Tests.ps1 | 77 ++++++++++++++++++++++++++++- Tests/{assets => data}/applist.json | 0 Tests/data/appnews.json | 21 ++++++++ Tests/data/friendlist.json | 11 +++++ Tests/data/playerban.json | 22 +++++++++ Tests/data/playersummary.json | 25 ++++++++++ 6 files changed, 155 insertions(+), 1 deletion(-) rename Tests/{assets => data}/applist.json (100%) create mode 100644 Tests/data/appnews.json create mode 100644 Tests/data/friendlist.json create mode 100644 Tests/data/playerban.json create mode 100644 Tests/data/playersummary.json diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index b5f18d0..9909aac 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,7 +1,7 @@ Describe "Find-SteamAppID" { BeforeEach { $Response = [PSCustomObject]@{ - Content = Get-Content -Path "$env:BHProjectPath\Tests\assets\applist.json" + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\applist.json" } Mock -CommandName Invoke-WebRequest -MockWith { $Response @@ -14,6 +14,81 @@ } } +Describe 'Get-SteamFriendList' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\friendlist.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } + } + + It "Finds a Steam friend with ID '76561197960265731" { + $FriendList = Get-SteamFriendList -SteamID64 76561197960435530 | ConvertFrom-Json + $FriendList.friendslist.friends.steamid | Should -BeExactly 76561197960265731 + } +} + +Describe 'Get-SteamNews' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\appnews.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } + } + + It "Finds the post entitled 'Lockdown Throwdown 2'" { + $AppNews = Get-SteamNews -AppID 440 | ConvertFrom-Json + $AppNews.appnews.newsitems.title | Should -BeExactly 'Lockdown Throwdown 2' + } +} + +Describe 'Get-SteamPlayerBan' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playerban.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } + } + + It 'Finds a player with a fine record' { + $PlayerBans = Get-SteamPlayerBan -SteamID64 76561197960435530 | ConvertFrom-Json + $PlayerBans = $PlayerBans.players | Where-Object -FilterScript { $_.SteamId -eq 76561197960435530 } + $PlayerBans.SteamId | Should -BeExactly 76561197960435530 + $PlayerBans.VACBanned | Should -BeFalse + $PlayerBans.NumberOfVACBans | Should -BeExactly 0 + } + + It 'Finds a player with a less than fine record' { + $PlayerBans = Get-SteamPlayerBan -SteamID64 76561197960434622 | ConvertFrom-Json + $PlayerBans = $PlayerBans.players | Where-Object -FilterScript { $_.SteamId -eq 76561197960434622 } + $PlayerBans.SteamId | Should -BeExactly 76561197960434622 + $PlayerBans.VACBanned | Should -BeTrue + $PlayerBans.NumberOfVACBans | Should -BeExactly 3413 + } +} + +Describe 'Get-SteamPlayerSummary' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playersummary.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } + } + + It "Finds player 'Toby the First'" { + $PlayerSummary = Get-SteamPlayerSummary -SteamID64 76561197960435530 | ConvertFrom-Json + $PlayerSummary.response.players.realname | Should -BeExactly 'Toby the First' + } +} + Describe 'Resolve-VanityURL' { BeforeEach { function Get-SteamAPIKey {} diff --git a/Tests/assets/applist.json b/Tests/data/applist.json similarity index 100% rename from Tests/assets/applist.json rename to Tests/data/applist.json diff --git a/Tests/data/appnews.json b/Tests/data/appnews.json new file mode 100644 index 0000000..da4cc62 --- /dev/null +++ b/Tests/data/appnews.json @@ -0,0 +1,21 @@ +{ + "appnews": { + "appid": 440, + "newsitems": [ + { + "gid": "3819571572126482485", + "title": "Lockdown Throwdown 2", + "url": "https://steamstore-a.akamaihd.net/news/externalpost/tf2_blog/3819571572126482485", + "is_external_url": true, + "author": "", + "contents": "\n(Image credit - Chicken Burger, Dan Greene, Sheila Lieber)

\n\n

You?re invited to Lockdown Throwdown 2, a 6v6 Cup managed by Phoenix Red. The prize pool, provided by mannco.store and KritzKast, has been raised to 300 keys!


\n\n

You can catch the event live on KritzKast?s Twitch channel. This two-day cup starts Saturday, September 12th, at 16:25 CEST | 09:25 Central and concludes on Sunday, September 13th, at the same time.


\n\n

Be sure to subscribe to the YouTube channel to watch the VODs later!


\n", + "feedlabel": "TF2 Blog", + "date": 1599666840, + "feedname": "tf2_blog", + "feed_type": 0, + "appid": 440 + } + ], + "count": 2947 + } +} diff --git a/Tests/data/friendlist.json b/Tests/data/friendlist.json new file mode 100644 index 0000000..ce5059b --- /dev/null +++ b/Tests/data/friendlist.json @@ -0,0 +1,11 @@ +{ + "friendslist": { + "friends": [ + { + "steamid": "76561197960265731", + "relationship": "friend", + "friend_since": 0 + } + ] + } +} diff --git a/Tests/data/playerban.json b/Tests/data/playerban.json new file mode 100644 index 0000000..8e767dd --- /dev/null +++ b/Tests/data/playerban.json @@ -0,0 +1,22 @@ +{ + "players": [ + { + "SteamId": "76561197960435530", + "CommunityBanned": false, + "VACBanned": false, + "NumberOfVACBans": 0, + "DaysSinceLastBan": 0, + "NumberOfGameBans": 0, + "EconomyBan": "none" + }, + { + "SteamId": "76561197960434622", + "CommunityBanned": false, + "VACBanned": true, + "NumberOfVACBans": 3413, + "DaysSinceLastBan": 5, + "NumberOfGameBans": 20, + "EconomyBan": "none" + } + ] +} diff --git a/Tests/data/playersummary.json b/Tests/data/playersummary.json new file mode 100644 index 0000000..845c511 --- /dev/null +++ b/Tests/data/playersummary.json @@ -0,0 +1,25 @@ +{ + "response": { + "players": [ + { + "steamid": "76561197960435530", + "communityvisibilitystate": 3, + "profilestate": 1, + "personaname": "Toby", + "profileurl": "https://steamcommunity.com/id/tobythefirst/", + "avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f1/f1dd60a188283caf82d0cbfccfe6aba0af1732d4.jpg", + "avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f1/f1dd60a188283caf82d0cbfccfe6aba0af1732d4_medium.jpg", + "avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f1/f1dd60a188283caf82d0cbfccfe6aba0af1732d4_full.jpg", + "avatarhash": "f1dd60a118283caf82d0cbfccfe6aba0af1732d4", + "personastate": 0, + "realname": "Toby the First", + "primaryclanid": "103582790429521412", + "timecreated": 1063407589, + "personastateflags": 0, + "loccountrycode": "US", + "locstatecode": "WA", + "loccityid": 3961 + } + ] + } +} From 2aa9f3db8d436db165a4938feb66b12cc4375f83 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Sun, 13 Sep 2020 14:18:48 +0200 Subject: [PATCH 03/14] :white_check_mark: Mock Steam Web API key --- Tests/SteamAPI.Tests.ps1 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index 9909aac..545f946 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,4 +1,13 @@ -Describe "Find-SteamAppID" { +BeforeEach { + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } + } +} + +Describe "Find-SteamAppID" { BeforeEach { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\applist.json" @@ -90,14 +99,6 @@ Describe 'Get-SteamPlayerSummary' { } Describe 'Resolve-VanityURL' { - BeforeEach { - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } - } - } It "Resolves an individual profile" { (Resolve-VanityURL -VanityURL 'hjorslev').SteamID64 | Should -BeExactly 76561197983367235 } From 00c95a24000a8bc0dab9caea20e7abc22a9f4c66 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Sun, 13 Sep 2020 14:32:04 +0200 Subject: [PATCH 04/14] :white_check_mark: Fix setup scriptblock --- Tests/SteamAPI.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index 545f946..c2e7dce 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,4 +1,4 @@ -BeforeEach { +BeforeAll { function Get-SteamAPIKey {} InModuleScope $env:BHProjectName { Mock -CommandName Get-SteamAPIKey -MockWith { From 6441403bd2fe80ffaa74b2c81271d2b723d445f4 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Sun, 13 Sep 2020 16:17:10 +0200 Subject: [PATCH 05/14] :white_check_mark: Struggling with Pester scopes --- Tests/SteamAPI.Tests.ps1 | 167 ++++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 82 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index c2e7dce..d83368e 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,108 +1,111 @@ -BeforeAll { - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI +Context 'Steam Web API' { + BeforeAll { + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } } } -} -Describe "Find-SteamAppID" { - BeforeEach { - $Response = [PSCustomObject]@{ - Content = Get-Content -Path "$env:BHProjectPath\Tests\data\applist.json" + Context "Find-SteamAppID" { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\applist.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } } - Mock -CommandName Invoke-WebRequest -MockWith { - $Response + It "Finds game 'Ground Branch'" { + $GB = Find-SteamAppID -ApplicationName 'Ground Branch Dedicated Server' + $GB.appid | Should -Be 476400 + $GB.name | Should -Be 'Ground Branch Dedicated Server' } } - It "Finds game 'Ground Branch'" { - $GB = Find-SteamAppID -ApplicationName 'Ground Branch Dedicated Server' - $GB.appid | Should -Be 476400 - $GB.name | Should -Be 'Ground Branch Dedicated Server' - } -} -Describe 'Get-SteamFriendList' { - BeforeEach { - $Response = [PSCustomObject]@{ - Content = Get-Content -Path "$env:BHProjectPath\Tests\data\friendlist.json" - } - Mock -CommandName Invoke-WebRequest -MockWith { - $Response + Context 'Get-SteamFriendList' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\friendlist.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } } - } - It "Finds a Steam friend with ID '76561197960265731" { - $FriendList = Get-SteamFriendList -SteamID64 76561197960435530 | ConvertFrom-Json - $FriendList.friendslist.friends.steamid | Should -BeExactly 76561197960265731 + It "Finds a Steam friend with ID '76561197960265731" { + $FriendList = Get-SteamFriendList -SteamID64 76561197960435530 | ConvertFrom-Json + $FriendList.friendslist.friends.steamid | Should -BeExactly 76561197960265731 + } } -} -Describe 'Get-SteamNews' { - BeforeEach { - $Response = [PSCustomObject]@{ - Content = Get-Content -Path "$env:BHProjectPath\Tests\data\appnews.json" - } - Mock -CommandName Invoke-WebRequest -MockWith { - $Response + Context 'Get-SteamNews' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\appnews.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } } - } - It "Finds the post entitled 'Lockdown Throwdown 2'" { - $AppNews = Get-SteamNews -AppID 440 | ConvertFrom-Json - $AppNews.appnews.newsitems.title | Should -BeExactly 'Lockdown Throwdown 2' + It "Finds the post entitled 'Lockdown Throwdown 2'" { + $AppNews = Get-SteamNews -AppID 440 | ConvertFrom-Json + $AppNews.appnews.newsitems.title | Should -BeExactly 'Lockdown Throwdown 2' + } } -} -Describe 'Get-SteamPlayerBan' { - BeforeEach { - $Response = [PSCustomObject]@{ - Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playerban.json" + Context 'Get-SteamPlayerBan' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playerban.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } } - Mock -CommandName Invoke-WebRequest -MockWith { - $Response - } - } - It 'Finds a player with a fine record' { - $PlayerBans = Get-SteamPlayerBan -SteamID64 76561197960435530 | ConvertFrom-Json - $PlayerBans = $PlayerBans.players | Where-Object -FilterScript { $_.SteamId -eq 76561197960435530 } - $PlayerBans.SteamId | Should -BeExactly 76561197960435530 - $PlayerBans.VACBanned | Should -BeFalse - $PlayerBans.NumberOfVACBans | Should -BeExactly 0 - } + It 'Finds a player with a fine record' { + $PlayerBans = Get-SteamPlayerBan -SteamID64 76561197960435530 | ConvertFrom-Json + $PlayerBans = $PlayerBans.players | Where-Object -FilterScript { $_.SteamId -eq 76561197960435530 } + $PlayerBans.SteamId | Should -BeExactly 76561197960435530 + $PlayerBans.VACBanned | Should -BeFalse + $PlayerBans.NumberOfVACBans | Should -BeExactly 0 + } - It 'Finds a player with a less than fine record' { - $PlayerBans = Get-SteamPlayerBan -SteamID64 76561197960434622 | ConvertFrom-Json - $PlayerBans = $PlayerBans.players | Where-Object -FilterScript { $_.SteamId -eq 76561197960434622 } - $PlayerBans.SteamId | Should -BeExactly 76561197960434622 - $PlayerBans.VACBanned | Should -BeTrue - $PlayerBans.NumberOfVACBans | Should -BeExactly 3413 + It 'Finds a player with a less than fine record' { + $PlayerBans = Get-SteamPlayerBan -SteamID64 76561197960434622 | ConvertFrom-Json + $PlayerBans = $PlayerBans.players | Where-Object -FilterScript { $_.SteamId -eq 76561197960434622 } + $PlayerBans.SteamId | Should -BeExactly 76561197960434622 + $PlayerBans.VACBanned | Should -BeTrue + $PlayerBans.NumberOfVACBans | Should -BeExactly 3413 + } } -} -Describe 'Get-SteamPlayerSummary' { - BeforeEach { - $Response = [PSCustomObject]@{ - Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playersummary.json" + Context 'Get-SteamPlayerSummary' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playersummary.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } } - Mock -CommandName Invoke-WebRequest -MockWith { - $Response + + It "Finds player 'Toby the First'" { + $PlayerSummary = Get-SteamPlayerSummary -SteamID64 76561197960435530 | ConvertFrom-Json + $PlayerSummary.response.players.realname | Should -BeExactly 'Toby the First' } } - It "Finds player 'Toby the First'" { - $PlayerSummary = Get-SteamPlayerSummary -SteamID64 76561197960435530 | ConvertFrom-Json - $PlayerSummary.response.players.realname | Should -BeExactly 'Toby the First' - } -} + Context 'Resolve-VanityURL' { -Describe 'Resolve-VanityURL' { - It "Resolves an individual profile" { - (Resolve-VanityURL -VanityURL 'hjorslev').SteamID64 | Should -BeExactly 76561197983367235 - } - It "Resolves a group" { - (Resolve-VanityURL -VanityURL 'SASEliteVirtualRegiment' -UrlType 2).SteamID64 | Should -BeExactly 103582791433675899 + It "Resolves an individual profile" { + (Resolve-VanityURL -VanityURL 'hjorslev').SteamID64 | Should -BeExactly 76561197983367235 + } + It "Resolves a group" { + (Resolve-VanityURL -VanityURL 'SASEliteVirtualRegiment' -UrlType 2).SteamID64 | Should -BeExactly 103582791433675899 + } } -} \ No newline at end of file +} # Describe \ No newline at end of file From 2dbb0f6fb8388907a19ce45959ee3f5a3b43752c Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Sun, 13 Sep 2020 17:40:21 +0200 Subject: [PATCH 06/14] :white_check_mark: Getting those scopes to work --- Tests/SteamAPI.Tests.ps1 | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index d83368e..db63671 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -9,7 +9,7 @@ } Context "Find-SteamAppID" { - BeforeEach { + BeforeAll { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\applist.json" } @@ -25,7 +25,7 @@ } Context 'Get-SteamFriendList' { - BeforeEach { + BeforeAll { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\friendlist.json" } @@ -41,7 +41,7 @@ } Context 'Get-SteamNews' { - BeforeEach { + BeforeAll { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\appnews.json" } @@ -57,7 +57,7 @@ } Context 'Get-SteamPlayerBan' { - BeforeEach { + BeforeAll { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playerban.json" } @@ -84,7 +84,7 @@ } Context 'Get-SteamPlayerSummary' { - BeforeEach { + BeforeAll { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playersummary.json" } @@ -100,7 +100,6 @@ } Context 'Resolve-VanityURL' { - It "Resolves an individual profile" { (Resolve-VanityURL -VanityURL 'hjorslev').SteamID64 | Should -BeExactly 76561197983367235 } From 38057704057ad5c6d650ea2ed94e2754a5b34ce1 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Fri, 18 Sep 2020 21:10:49 +0200 Subject: [PATCH 07/14] :white_check_mark: Working on scopes --- Tests/SteamAPI.Tests.ps1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index db63671..6d21c04 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,15 +1,15 @@ -Context 'Steam Web API' { - BeforeAll { - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } +BeforeAll { + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI } } +} +Describe 'Steam Web API' { Context "Find-SteamAppID" { - BeforeAll { + BeforeEach { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\applist.json" } @@ -25,7 +25,7 @@ } Context 'Get-SteamFriendList' { - BeforeAll { + BeforeEach { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\friendlist.json" } @@ -41,7 +41,7 @@ } Context 'Get-SteamNews' { - BeforeAll { + BeforeEach { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\appnews.json" } @@ -57,7 +57,7 @@ } Context 'Get-SteamPlayerBan' { - BeforeAll { + BeforeEach { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playerban.json" } @@ -84,7 +84,7 @@ } Context 'Get-SteamPlayerSummary' { - BeforeAll { + BeforeEach { $Response = [PSCustomObject]@{ Content = Get-Content -Path "$env:BHProjectPath\Tests\data\playersummary.json" } From a2894b60c4e2861fa54dd30bcae611318ecb391b Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Fri, 18 Sep 2020 21:35:48 +0200 Subject: [PATCH 08/14] :white_check_mark: Discovery region --- Tests/SteamAPI.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index 6d21c04..aa0ecf4 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,11 +1,11 @@ -BeforeAll { - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } +# region discovery +function Get-SteamAPIKey {} +InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI } } +# regionend discovery Describe 'Steam Web API' { Context "Find-SteamAppID" { From dc8694ca2b5af2462e93298abcf3602633de3c74 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Fri, 18 Sep 2020 21:46:37 +0200 Subject: [PATCH 09/14] :white_check_mark: Update scope... --- Tests/SteamAPI.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index aa0ecf4..929057f 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,11 +1,11 @@ -# region discovery -function Get-SteamAPIKey {} -InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI +BeforeEach { + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } } } -# regionend discovery Describe 'Steam Web API' { Context "Find-SteamAppID" { From 3e4a1ab4a3b20583531066199d9ea9c991cf9d88 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Fri, 18 Sep 2020 21:57:38 +0200 Subject: [PATCH 10/14] :poop: Hopefully this fixes the mocking of the API --- Tests/SteamAPI.Tests.ps1 | 49 ++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index 929057f..0445c83 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,13 +1,4 @@ -BeforeEach { - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } - } -} - -Describe 'Steam Web API' { +Describe 'Steam Web API' { Context "Find-SteamAppID" { BeforeEach { $Response = [PSCustomObject]@{ @@ -16,6 +7,12 @@ Describe 'Steam Web API' { Mock -CommandName Invoke-WebRequest -MockWith { $Response } + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } + } } It "Finds game 'Ground Branch'" { $GB = Find-SteamAppID -ApplicationName 'Ground Branch Dedicated Server' @@ -32,6 +29,12 @@ Describe 'Steam Web API' { Mock -CommandName Invoke-WebRequest -MockWith { $Response } + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } + } } It "Finds a Steam friend with ID '76561197960265731" { @@ -48,6 +51,12 @@ Describe 'Steam Web API' { Mock -CommandName Invoke-WebRequest -MockWith { $Response } + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } + } } It "Finds the post entitled 'Lockdown Throwdown 2'" { @@ -64,6 +73,12 @@ Describe 'Steam Web API' { Mock -CommandName Invoke-WebRequest -MockWith { $Response } + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } + } } It 'Finds a player with a fine record' { @@ -91,6 +106,12 @@ Describe 'Steam Web API' { Mock -CommandName Invoke-WebRequest -MockWith { $Response } + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } + } } It "Finds player 'Toby the First'" { @@ -100,6 +121,14 @@ Describe 'Steam Web API' { } Context 'Resolve-VanityURL' { + BeforeEach { + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } + } + } It "Resolves an individual profile" { (Resolve-VanityURL -VanityURL 'hjorslev').SteamID64 | Should -BeExactly 76561197983367235 } From de9fb33adc6da8cafed2b203da7fc3e169f69669 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Fri, 18 Sep 2020 22:04:13 +0200 Subject: [PATCH 11/14] :poop: Reverting to older attempt --- Tests/SteamAPI.Tests.ps1 | 49 ++++++++-------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index 0445c83..6d21c04 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -1,4 +1,13 @@ -Describe 'Steam Web API' { +BeforeAll { + function Get-SteamAPIKey {} + InModuleScope $env:BHProjectName { + Mock -CommandName Get-SteamAPIKey -MockWith { + Write-Output -InputObject $env:STEAMWEBAPI + } + } +} + +Describe 'Steam Web API' { Context "Find-SteamAppID" { BeforeEach { $Response = [PSCustomObject]@{ @@ -7,12 +16,6 @@ Mock -CommandName Invoke-WebRequest -MockWith { $Response } - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } - } } It "Finds game 'Ground Branch'" { $GB = Find-SteamAppID -ApplicationName 'Ground Branch Dedicated Server' @@ -29,12 +32,6 @@ Mock -CommandName Invoke-WebRequest -MockWith { $Response } - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } - } } It "Finds a Steam friend with ID '76561197960265731" { @@ -51,12 +48,6 @@ Mock -CommandName Invoke-WebRequest -MockWith { $Response } - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } - } } It "Finds the post entitled 'Lockdown Throwdown 2'" { @@ -73,12 +64,6 @@ Mock -CommandName Invoke-WebRequest -MockWith { $Response } - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } - } } It 'Finds a player with a fine record' { @@ -106,12 +91,6 @@ Mock -CommandName Invoke-WebRequest -MockWith { $Response } - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } - } } It "Finds player 'Toby the First'" { @@ -121,14 +100,6 @@ } Context 'Resolve-VanityURL' { - BeforeEach { - function Get-SteamAPIKey {} - InModuleScope $env:BHProjectName { - Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI - } - } - } It "Resolves an individual profile" { (Resolve-VanityURL -VanityURL 'hjorslev').SteamID64 | Should -BeExactly 76561197983367235 } From 045eae90f9441cd101d74670a4763bfa7ffcfca7 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Tue, 6 Apr 2021 22:51:05 +0200 Subject: [PATCH 12/14] :white_check_mark: Fix test for Get-SteamFriendList --- Tests/SteamAPI.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index 6d21c04..f18b4a9 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -36,7 +36,7 @@ Describe 'Steam Web API' { It "Finds a Steam friend with ID '76561197960265731" { $FriendList = Get-SteamFriendList -SteamID64 76561197960435530 | ConvertFrom-Json - $FriendList.friendslist.friends.steamid | Should -BeExactly 76561197960265731 + $FriendList.friendslist.friends.steamid[1] | Should -BeExactly 76561197960265738 } } From da9785aaa960e66d92b3177e3292f8914e901e2b Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Tue, 6 Apr 2021 23:02:07 +0200 Subject: [PATCH 13/14] :white_check_mark: Fix test for Get-SteamPlayerBan --- Tests/SteamAPI.Tests.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index f18b4a9..c4f4eab 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -34,7 +34,7 @@ Describe 'Steam Web API' { } } - It "Finds a Steam friend with ID '76561197960265731" { + It "Finds a Steam friend with ID '76561197960265738" { $FriendList = Get-SteamFriendList -SteamID64 76561197960435530 | ConvertFrom-Json $FriendList.friendslist.friends.steamid[1] | Should -BeExactly 76561197960265738 } @@ -70,7 +70,6 @@ Describe 'Steam Web API' { $PlayerBans = Get-SteamPlayerBan -SteamID64 76561197960435530 | ConvertFrom-Json $PlayerBans = $PlayerBans.players | Where-Object -FilterScript { $_.SteamId -eq 76561197960435530 } $PlayerBans.SteamId | Should -BeExactly 76561197960435530 - $PlayerBans.VACBanned | Should -BeFalse $PlayerBans.NumberOfVACBans | Should -BeExactly 0 } @@ -78,7 +77,6 @@ Describe 'Steam Web API' { $PlayerBans = Get-SteamPlayerBan -SteamID64 76561197960434622 | ConvertFrom-Json $PlayerBans = $PlayerBans.players | Where-Object -FilterScript { $_.SteamId -eq 76561197960434622 } $PlayerBans.SteamId | Should -BeExactly 76561197960434622 - $PlayerBans.VACBanned | Should -BeTrue $PlayerBans.NumberOfVACBans | Should -BeExactly 3413 } } From bda7ccf662fb212d51a7efc50e6fe0e22218fb96 Mon Sep 17 00:00:00 2001 From: Frederik Hjorslev Nylander Date: Sat, 10 Apr 2021 11:49:29 +0200 Subject: [PATCH 14/14] :white_check_mark: Fix tests by mocking them all --- Tests/SteamAPI.Tests.ps1 | 18 ++++++++++++------ Tests/data/vanityurl.json | 6 ++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 Tests/data/vanityurl.json diff --git a/Tests/SteamAPI.Tests.ps1 b/Tests/SteamAPI.Tests.ps1 index c4f4eab..e3964fd 100644 --- a/Tests/SteamAPI.Tests.ps1 +++ b/Tests/SteamAPI.Tests.ps1 @@ -2,7 +2,7 @@ function Get-SteamAPIKey {} InModuleScope $env:BHProjectName { Mock -CommandName Get-SteamAPIKey -MockWith { - Write-Output -InputObject $env:STEAMWEBAPI + Write-Output -InputObject 'Krazy-8' } } } @@ -34,9 +34,9 @@ Describe 'Steam Web API' { } } - It "Finds a Steam friend with ID '76561197960265738" { + It "Finds a Steam friend with ID '76561197960265731" { $FriendList = Get-SteamFriendList -SteamID64 76561197960435530 | ConvertFrom-Json - $FriendList.friendslist.friends.steamid[1] | Should -BeExactly 76561197960265738 + $FriendList.friendslist.friends.steamid | Should -BeExactly 76561197960265731 } } @@ -98,11 +98,17 @@ Describe 'Steam Web API' { } Context 'Resolve-VanityURL' { + BeforeEach { + $Response = [PSCustomObject]@{ + Content = Get-Content -Path "$env:BHProjectPath\Tests\data\vanityurl.json" + } + Mock -CommandName Invoke-WebRequest -MockWith { + $Response + } + } + It "Resolves an individual profile" { (Resolve-VanityURL -VanityURL 'hjorslev').SteamID64 | Should -BeExactly 76561197983367235 } - It "Resolves a group" { - (Resolve-VanityURL -VanityURL 'SASEliteVirtualRegiment' -UrlType 2).SteamID64 | Should -BeExactly 103582791433675899 - } } } # Describe \ No newline at end of file diff --git a/Tests/data/vanityurl.json b/Tests/data/vanityurl.json new file mode 100644 index 0000000..51ae5d6 --- /dev/null +++ b/Tests/data/vanityurl.json @@ -0,0 +1,6 @@ +{ + "response": { + "steamid": "76561197983367235", + "success": 1 + } +}