|
| 1 | +Import-Module .\Fake-UserAgent\Fake-UserAgent.psm1 -Force |
| 2 | + |
| 3 | +Describe 'Fake-UserAgent.Tests' { |
| 4 | + Context "Get-UserAgentData Tests" { |
| 5 | + |
| 6 | + BeforeAll { |
| 7 | + $datPath = '.\Fake-UserAgent\data\user-agents.dat' |
| 8 | + } |
| 9 | + |
| 10 | + It "should have initialized state" { |
| 11 | + Test-Path $datPath | Should -Be $true |
| 12 | + } |
| 13 | + |
| 14 | + It "should have user agents" { |
| 15 | + $agents = Get-UserAgent |
| 16 | + $agents | Should -Not -BeNullOrEmpty |
| 17 | + $agents.Count | Should -BeGreaterThan 0 |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + Context "UA file update Tests" { |
| 22 | + |
| 23 | + BeforeAll { |
| 24 | + $datPath = '.\Fake-UserAgent\data\user-agents.dat' |
| 25 | + Remove-Item -Path $datPath -ErrorAction SilentlyContinue |
| 26 | + } |
| 27 | + |
| 28 | + It "should have broken state" { |
| 29 | + Test-Path $datPath | Should -Be $false |
| 30 | + { Get-UserAgent -ErrorAction SilentlyContinue } | Should -Throw |
| 31 | + } |
| 32 | + |
| 33 | + It "should download and update user agents" { |
| 34 | + { .\update-data.ps1 6>$null } | Should -Not -Throw |
| 35 | + } |
| 36 | + |
| 37 | + It "should have initialized state" { |
| 38 | + Test-Path $datPath | Should -Be $true |
| 39 | + } |
| 40 | + |
| 41 | + It "should have the same number of user agents" { |
| 42 | + $raw = Get-Content .\temp\user-agents.json -Raw | ConvertFrom-Json |
| 43 | + $processed = Get-UserAgent |
| 44 | + $processed.Count | Should -Be $raw.Count |
| 45 | + } |
| 46 | + |
| 47 | + It "should have the same user agent values" { |
| 48 | + $raw = Get-Content .\temp\user-agents.json -Raw | ConvertFrom-Json |
| 49 | + $processed = Get-UserAgent |
| 50 | + |
| 51 | + for ($i = 0; $i -lt 200; $i++) { |
| 52 | + $processed[$i].ua | Should -Be $raw[$i].userAgent |
| 53 | + $processed[$i].type | Should -Be $raw[$i].deviceCategory |
| 54 | + $processed[$i].platform | Should -Be $raw[$i].platform |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments