Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Pester Tests #39

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 106 additions & 16 deletions Tests/SteamAPI.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,114 @@
Describe "Find-SteamAppID" {
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'
BeforeAll {
function Get-SteamAPIKey {}
InModuleScope $env:BHProjectName {
Mock -CommandName Get-SteamAPIKey -MockWith {
Write-Output -InputObject 'Krazy-8'
}
}
}

Describe 'Resolve-VanityURL' {
BeforeEach {
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]@{
Content = Get-Content -Path "$env:BHProjectPath\Tests\data\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
$GB.name | Should -Be 'Ground Branch Dedicated Server'
}
}

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
}
}

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'
}
}

Context '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.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.NumberOfVACBans | Should -BeExactly 3413
}
}
It "Resolves an individual profile" {
(Resolve-VanityURL -VanityURL 'hjorslev').SteamID64 | Should -BeExactly 76561197983367235

Context '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'
}
}
It "Resolves a group" {
(Resolve-VanityURL -VanityURL 'SASEliteVirtualRegiment' -UrlType 2).SteamID64 | Should -BeExactly 103582791433675899

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
}
}
}
} # Describe
5 changes: 5 additions & 0 deletions Tests/data/applist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"applist": {
"apps": [{ "appid": 476400, "name": "GROUND BRANCH Dedicated Server" }]
}
}
21 changes: 21 additions & 0 deletions Tests/data/appnews.json
Original file line number Diff line number Diff line change
@@ -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": "<a href=\"https://www.twitch.tv/kritzkast\"><img src=\"https://steamcdn-a.akamaihd.net/steam/news/75361/lockdown.jpg?t=1496190900\"></a>\n(Image credit - <a href=\"https://twitter.com/chickenbruhger\">Chicken Burger</a>, <a href=\"https://twitter.com/punishedgreene\">Dan Greene</a>, <a href=\"https://twitter.com/lieber_sheila\">Sheila Lieber</a>)<br><br>\n\n<p>You?re invited to <a href=\"https://www.toornament.com/en_US/tournaments/3860652609657503744/information\">Lockdown Throwdown 2</a>, a 6v6 Cup managed by <a href=\"https://phoenixred.eu/\">Phoenix Red</a>. The prize pool, provided by mannco.store and KritzKast, has been raised to 300 keys!</p><br> \n\n<p>You can catch the event live on <a href=\"https://www.twitch.tv/kritzkast\">KritzKast?s Twitch channel</a>. 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.</p><br>\n\n<p>Be sure to subscribe to the <a href=\"https://www.youtube.com/kritzkast\">YouTube channel</a> to watch the VODs later!</p><br>\n",
"feedlabel": "TF2 Blog",
"date": 1599666840,
"feedname": "tf2_blog",
"feed_type": 0,
"appid": 440
}
],
"count": 2947
}
}
11 changes: 11 additions & 0 deletions Tests/data/friendlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"friendslist": {
"friends": [
{
"steamid": "76561197960265731",
"relationship": "friend",
"friend_since": 0
}
]
}
}
22 changes: 22 additions & 0 deletions Tests/data/playerban.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
25 changes: 25 additions & 0 deletions Tests/data/playersummary.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
}
6 changes: 6 additions & 0 deletions Tests/data/vanityurl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"response": {
"steamid": "76561197983367235",
"success": 1
}
}