-
Notifications
You must be signed in to change notification settings - Fork 10
/
l0g-101086.Tests.ps1
276 lines (245 loc) · 12.6 KB
/
l0g-101086.Tests.ps1
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018 Jacob Keller. All rights reserved.
# vim: et:ts=4:sw=4
# Terminate on all errors...
$ErrorActionPreference = "Stop"
# Load the shared module
Import-Module -Force -DisableNameChecking (Join-Path $PSScriptRoot "l0g-101086.psm1")
Describe 'Load-Configuration' {
# Prevent the "Read-Host" prompts from being displayed during tests
Mock Read-Host {}
Context 'Verify configuration files are valid' {
It 'l0g-101086-config.sample.json is loadable' {
$config = Load-Configuration 'l0g-101086-config.sample.json' 2
$config | Should -Not -BeNullOrEmpty
}
It 'l0g-101086-config.multipleguilds.json is loadable' {
$config = Load-Configuration 'l0g-101086-config.multipleguilds.json' 2
$config | Should -Not -BeNullOrEmpty
}
# Also verify that the l0g-101086-config.json is loadable if it exists
if (Test-Path "l0g-101086-config.json" ) {
It 'l0g-101086-config.json is loadable' {
$config = Load-Configuration 'l0g-101086-config.json' 2
$config | Should -Not -BeNullOrEmpty
}
}
}
$testConfig = "TestDrive:\config.json"
Context 'Basic configuration file' {
Set-Content $testConfig -Value @"
{
"config_version": 2,
"debug_mode": false,
"experimental_arcdps": false,
"arcdps_logs": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\arcdps.cbtlogs",
"discord_json_data": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\arcdps.webhook_posts",
"extra_upload_data": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\arcdps.uploadextras",
"last_format_file": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\format_encounters_time.json",
"last_upload_file": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\upload_logs_time.json",
"simple_arc_parse_path": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\simpleArcParse\\bin\\Release\\simpleArcParse.exe",
"upload_log_file": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\upload_log.txt",
"format_encounters_log": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\format_encounters_log.txt",
"guildwars2_path": "C:\\Program Files (x86)\\Guild Wars 2",
"launchbuddy_path": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\gw2launchbuddy\\Gw2.Launchbuddy.exe",
"dll_backup_path": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\arcdps.dllbackups",
"restsharp_path": "%UserProfile%\\Documents\\Guild Wars 2\\addons\\arcdps\\RestSharp.dll",
"dps_report_token": "",
"dps_report_generator": "ei",
"upload_dps_report": "successful",
"guilds": [
{
"name": "[guild]",
"priority": 1,
"webhook_url": "",
"threshold": 0,
"thumbnail": "",
"raids": true,
"fractals": false,
"discord_map": {
"Serena Sedai.3064": "@119167866103791621"
},
"show_players": "discord_if_possible",
"prefix_players_text": "",
"emoji_map": {
"Mursaat Overseer": ":mo:311579053486243841",
"Samarog": ":sam:311578871214637057",
"Slothasor": ":sloth:311578871206117376",
"Sabetha": ":sab:311578871122231296",
"Dhuum": ":dhuum:399610319464431627",
"Gorseval": ":gors:311578871013310474",
"Xera": ":xera:311578871277289472",
"Soulless Horror": ":horror:386645168289480715",
"Cairn": ":cairn:311578870954590208",
"Keep Construct": ":kc:311578870686023682",
"Matthias": ":matt:311578871105454080",
"Deimos": ":deimos:311578870761652225",
"Vale Guardian": ":vg:311578870933356545",
"Conjured Amalgamate": ":ca:",
"Largos Twins": ":twins:",
"Qadim": ":qadim:"
}
}
]
}
"@
It 'loads the basic config file properly' {
$config = Load-Configuration $testConfig 2
$config | Should -Not -BeNullOrEmpty
}
}
Context 'config_version 2 sets default values' {
Set-Content -Force $testConfig -Value @"
{ "config_version": 2 }
"@
It 'loads config version 2, and sets defaults for optional/default fields' {
$config = Load-Configuration $testConfig 2
$config | Should -Not -BeNullOrEmpty
$config.config_version | Should -BeExactly 2
$config.upload_dps_report | Should -BeExactly "successful"
}
}
}
Describe 'Get-Discord-Players' {
Context "show_players set to 'none'" {
$guild = [PSCustomObject]@{
show_players = "none"
prefix_players_text = ""
discord_map = @{
"Serena Sedai.3064" = "Jake"
"Player1.0001" = "Player One"
"Player2.0002" = "Player Two"
}
}
It 'returns nothing when no prefix is set' {
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @()
}
It 'returns the prefix' {
$guild.prefix_players_text = "@here"
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("@here")
}
It 'returns nothing when show_players is set to a garbage value' {
$guild.prefix_players_text = ""
$guild.show_players = "garbage"
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @()
}
}
Context "show_players set to 'discord_only'" {
$guild = [PSCustomObject]@{
show_players = "discord_only"
prefix_players_text = ""
discord_map = @{
"Serena Sedai.3064" = "Jake"
"Player1.0001" = "Player One"
"Player2.0002" = "Player Two"
}
}
It 'returns only discord names' {
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("Player One", "Player Two", "Jake")
}
It 'returns discord names sorted by the gw2 account name' {
$guild.discord_map = @{
"Z.0001" = "A"
"H.0005" = "B"
"A.0006" = "C"
}
$participants = Get-Discord-Players $guild @("Z.0001", "H.0005", "A.0006")
$participants | Should -BeExactly @("C", "B", "A")
}
It 'returns the prefix if it is set' {
$guild.prefix_players_text = "@everyone"
$participants = Get-Discord-Players $guild @("Z.0001", "H.0005", "A.0006")
$participants | Should -BeExactly @("@everyone", "C", "B", "A")
}
}
Context "show_players set to 'accounts_only'" {
$guild = [PSCustomObject]@{
show_players = "accounts_only"
prefix_players_text = ""
discord_map = @{
"Serena Sedai.3064" = "Jake"
"Player1.0001" = "Player One"
"Player2.0002" = "Player Two"
}
}
It 'returns all the account names' {
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("_A Pug.0003_", "_Another Pug.0004_", "_Player1.0001_", "_Player2.0002_", "_Serena Sedai.3064_")
}
It 'returns account names even if the discord map is unset' {
$guild.discord_map = $null
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("_A Pug.0003_", "_Another Pug.0004_", "_Player1.0001_", "_Player2.0002_", "_Serena Sedai.3064_")
}
It 'other account names in the discord map dont impact output' {
$guild.discord_map = @{
"Serena Sedai.3064" = "Jake"
"Player1.0001" = "Player One"
"Player2.0002" = "Player Two"
"Player3.0003" = "Player Three"
}
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("_A Pug.0003_", "_Another Pug.0004_", "_Player1.0001_", "_Player2.0002_", "_Serena Sedai.3064_")
}
It 'returns the prefix if it is set' {
$guild.prefix_players_text = "@everyone"
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("@everyone", "_A Pug.0003_", "_Another Pug.0004_", "_Player1.0001_", "_Player2.0002_", "_Serena Sedai.3064_")
}
}
Context "show players set to 'discord_if_possible'" {
$guild = [PSCustomObject]@{
show_players = "discord_if_possible"
prefix_players_text = ""
discord_map = @{
"Serena Sedai.3064" = "Jake"
"Player1.0001" = "Player One"
"Player2.0002" = "Player Two"
}
}
It 'returns a mix of discord and account name' {
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("_A Pug.0003_", "_Another Pug.0004_", "Player One", "Player Two", "Jake")
}
It 'returns account names even if the discord map is unset' {
$guild.discord_map = $null
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("_A Pug.0003_", "_Another Pug.0004_", "_Player1.0001_", "_Player2.0002_", "_Serena Sedai.3064_")
}
It 'other account names in the discord map dont impact output' {
$guild.discord_map = @{
"Serena Sedai.3064" = "Jake"
"Player1.0001" = "Player One"
"Player2.0002" = "Player Two"
"Player3.0003" = "Player Three"
}
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("_A Pug.0003_", "_Another Pug.0004_", "Player One", "Player Two", "Jake")
}
It 'returns the prefix if set' {
$guild.discord_map = @{
"Serena Sedai.3064" = "Jake"
"Player1.0001" = "Player One"
"Player2.0002" = "Player Two"
"Player3.0003" = "Player Three"
}
$guild.prefix_players_text = "A Prefix"
$participants = Get-Discord-Players $guild @("Serena Sedai.3064", "Player1.0001", "Player2.0002", "A Pug.0003", "Another Pug.0004")
$participants | Should -BeExactly @("A Prefix", "_A Pug.0003_", "_Another Pug.0004_", "Player One", "Player Two", "Jake")
}
}
}
Describe 'Split-Bosses' {
$bosses = @( @{ a=1; b=1 }, @{ a=1; b=2; }, @{ a=2; b=3 }, @{ a=3; b=4; }, @{ a=1; b=5 } )
It 'correctly splits bosses into sections' {
$split = Split-Bosses $bosses "a"
$split.Keys | sort | Should -BeExactly @( 1, 2, 3 )
$split[1] | Should -BeExactly @( $bosses[0], $bosses[1], $bosses[4] )
$split[2] | Should -BeExactly @( $bosses[2] )
$split[3] | Should -BeExactly @( $bosses[3] )
}
}