Skip to content

Commit a80b77c

Browse files
committed
Tests refactoring & fixes
1 parent 2cf815e commit a80b77c

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

Tests/Initialize-Parameters.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
$configPath = Join-Path -Path $PSScriptRoot -ChildPath "..\config.json"
2+
3+
if (Test-Path -Path $configPath) {
4+
$config = Get-Content -Path $configPath | ConvertFrom-Json
5+
$apiToken = $config.apiToken
6+
$workspaceId = $config.workspaceId
7+
}
8+
else {
9+
if ($env:TOGGL_API_TOKEN -eq $null) {
10+
.\scripts\load-env.ps1
11+
}
12+
$apiToken = $env:TOGGL_API_TOKEN
13+
$workspaceId = $env:TOGGL_WORKSPACE_ID
14+
}

Tests/Integration/Projects.Tests.ps1

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ Import-Module .\Toggl.API\Toggl.API.psm1 -Force
55

66
Describe 'Toggl Projects Integration Tests' {
77
BeforeAll {
8-
$configPath = Join-Path -Path $PSScriptRoot -ChildPath "..\config.json"
9-
$config = Get-Content -Path $configPath | ConvertFrom-Json
10-
11-
$apiToken = $config.apiToken
12-
$workspaceId = $config.workspaceId
13-
8+
. "$PSScriptRoot\..\Initialize-Parameters.ps1"
149
$projectName = "TestProjectToRemove"
1510
$projectId = $null
1611
}
@@ -45,7 +40,7 @@ Describe 'Toggl Projects Integration Tests' {
4540
}
4641

4742
Context "Remove-TogglProject" {
48-
It "should delete the project from the workspace" -Skip:($Script:projectId -eq $null) {
43+
It "should delete the project from the workspace" {
4944
Remove-TogglProject `
5045
-ApiToken $apiToken `
5146
-WorkspaceId $workspaceId `
@@ -61,7 +56,7 @@ Describe 'Toggl Projects Integration Tests' {
6156
-SortField "name" `
6257
-SortOrder "asc" `
6358
-OnlyTemplates $false
64-
$projects | Where-Object { $_.id -eq $Script:projectId } | Should BeNullOrEmpty
59+
$projects | Where-Object { $_.id -eq $Script:projectId } | Should -BeNullOrEmpty
6560
}
6661
}
6762
}

Tests/Integration/Reports.Detailed.Tests.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ Import-Module .\Toggl.API\Toggl.API.psm1 -Force
55

66
Describe 'Reports.Detailed Integration Tests' {
77
BeforeAll {
8-
$configPath = Join-Path -Path $PSScriptRoot -ChildPath "..\config.json"
9-
$config = Get-Content -Path $configPath | ConvertFrom-Json
10-
11-
$apiToken = $config.apiToken
12-
$workspaceId = $config.workspaceId
8+
. "$PSScriptRoot\..\Initialize-Parameters.ps1"
139

1410
$startDate = "2023-01-01"
1511
$endDate = "2023-12-31"
@@ -61,6 +57,13 @@ Describe 'Reports.Detailed Integration Tests' {
6157
-WorkspaceId $workspaceId `
6258
-TimeEntryId $timeEntryId
6359
}
60+
61+
foreach ($tagId in $tagIds) {
62+
Remove-TogglTag `
63+
-ApiToken $apiToken `
64+
-WorkspaceId $workspaceId `
65+
-TagId $tagId
66+
}
6467
}
6568

6669
Context "Search-TogglTimeEntries" {

Tests/Integration/Tags.Tests.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ Import-Module .\Toggl.API\Toggl.API.psm1 -Force
55

66
Describe 'Toggl Tag Integration Tests' {
77
BeforeAll {
8-
$configPath = Join-Path -Path $PSScriptRoot -ChildPath "..\config.json"
9-
$config = Get-Content -Path $configPath | ConvertFrom-Json
10-
11-
$apiToken = $config.apiToken
12-
$workspaceId = $config.workspaceId
8+
. "$PSScriptRoot\..\Initialize-Parameters.ps1"
139

1410
$tagName = "TestTagToRemove"
1511
}
@@ -24,20 +20,20 @@ Describe 'Toggl Tag Integration Tests' {
2420
}
2521

2622
Context "Get-TogglTags" {
27-
It "should retrieve the list of tags for the workspace" -Skip:($Script:tagId -eq $null) {
23+
It "should retrieve the list of tags for the workspace" {
2824
$tags = Get-TogglTags -ApiToken $apiToken -WorkspaceId $workspaceId
2925
$tags | Should -Not -BeNullOrEmpty
3026
$tags | Where-Object { $_.name -eq $tagName } | Should -Not -BeNullOrEmpty
3127
}
3228
}
3329

3430
Context "Remove-TogglTag" {
35-
It "should delete the tag from the workspace" -Skip:($Script:tagId -eq $null) {
31+
It "should delete the tag from the workspace" {
3632
Remove-TogglTag -ApiToken $apiToken -WorkspaceId $workspaceId -TagId $Script:tagId
3733

3834
# Verify the tag was deleted
3935
$tags = Get-TogglTags -ApiToken $apiToken -WorkspaceId $workspaceId
40-
$tags | Where-Object { $_.id -eq $Script:tagId } | Should BeNullOrEmpty
36+
$tags | Where-Object { $_.id -eq $Script:tagId } | Should -BeNullOrEmpty
4137
}
4238
}
4339
}

Tests/Integration/TimeEntries.Tests.ps1

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ Import-Module .\Toggl.API\Toggl.API.psm1 -Force
55

66
Describe 'TimeEntries Integration Tests' {
77
BeforeAll {
8-
$configPath = Join-Path -Path $PSScriptRoot -ChildPath "..\config.json"
9-
$config = Get-Content -Path $configPath | ConvertFrom-Json
10-
11-
$apiToken = $config.apiToken
12-
$workspaceId = $config.workspaceId
13-
8+
. "$PSScriptRoot\..\Initialize-Parameters.ps1"
149
$timeEntryId = $null
1510
}
1611

@@ -34,7 +29,7 @@ Describe 'TimeEntries Integration Tests' {
3429
}
3530

3631
Context "Get-TogglTimeEntryById" {
37-
It "should retrieve the created time entry by ID" -Skip:($Script:timeEntryId -eq $null) {
32+
It "should retrieve the created time entry by ID" {
3833
$response = Get-TogglTimeEntryById `
3934
-ApiToken $apiToken `
4035
-TimeEntryId $Script:timeEntryId
@@ -55,7 +50,7 @@ Describe 'TimeEntries Integration Tests' {
5550
}
5651

5752
Context "Update-TogglTimeEntry" {
58-
It "should update the time entry" -Skip:($Script:timeEntryId -eq $null) {
53+
It "should update the time entry" {
5954
$newDescription = "Updated Test Time Entry"
6055

6156
$response = Update-TogglTimeEntry `
@@ -64,7 +59,7 @@ Describe 'TimeEntries Integration Tests' {
6459
-TimeEntryId $Script:timeEntryId `
6560
-Description $newDescription
6661

67-
$response | Should Not BeNullOrEmpty
62+
$response | Should -Not -BeNullOrEmpty
6863
$response.description | Should -BeExactly $newDescription
6964
}
7065
}
@@ -85,7 +80,7 @@ Describe 'TimeEntries Integration Tests' {
8580
}
8681

8782
Context "Remove-TogglTimeEntry" {
88-
It "should delete the time entry" -Skip:($Script:timeEntryId -eq $null) {
83+
It "should delete the time entry" {
8984
Remove-TogglTimeEntry `
9085
-ApiToken $apiToken `
9186
-WorkspaceId $workspaceId `

0 commit comments

Comments
 (0)