Skip to content

Commit 930a43c

Browse files
committed
Added unit tests
1 parent b32da21 commit 930a43c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ok": false,
3+
"error": "invalid_auth"
4+
}

Tests/MockData/auth.test.ok.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"ok": true,
3+
"url": "https://subarachnoid.slack.com/",
4+
"team": "Subarachnoid Workspace",
5+
"user": "grace",
6+
"team_id": "T12345678",
7+
"user_id": "W12345678"
8+
}

Tests/Slack.Backup.Tests.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Clear-Host
2+
if (-not $PSScriptRoot) {
3+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
4+
}
5+
Import-Module -Name Pester -Force
6+
Import-Module .\Slack.Backup\Slack.Backup.psm1 -Force
7+
8+
Describe 'Test-Auth' {
9+
Context "Check token" {
10+
Mock Invoke-SlackAPI -ModuleName Slack.Backup {
11+
if ($Method -eq 'auth.test') {
12+
$file = "auth.test.error.json"
13+
if ($Token -eq "valid") {
14+
$file = "auth.test.ok.json"
15+
}
16+
Get-Content ".\Tests\MockData\$file" | ConvertFrom-Json
17+
}
18+
}
19+
20+
It "Given -Token '<Token>', it returns '<Expected>'" -TestCases @(
21+
@{ Token = "invalid"; Expected = $false }
22+
@{ Token = "valid"; Expected = $true }
23+
) {
24+
param ($Token, $Expected)
25+
Test-Auth -Token $Token -ErrorAction SilentlyContinue | Should -Be $Expected
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)