1+ Import-Module - Name Pester - Force
2+ Import-Module .\Toggl.API\Toggl.API.psm1 - Force
3+
4+ $configPath = Join-Path - Path $PSScriptRoot - ChildPath " ..\config.json"
5+ $config = Get-Content - Path $configPath | ConvertFrom-Json
6+
7+ $apiToken = $config.apiToken
8+ $workspaceId = $config.workspaceId
9+
10+ Describe ' TimeEntries Integration Tests' {
11+ $timeEntryId = $null
12+
13+ Context " New-TogglTimeEntry" {
14+ It " should create a new time entry" {
15+ $start = [datetime ]::UtcNow
16+ $description = " Test Time Entry"
17+ $createdWith = " PesterTest"
18+
19+ $response = New-TogglTimeEntry `
20+ - ApiToken $apiToken `
21+ - WorkspaceId $workspaceId `
22+ - CreatedWith $createdWith `
23+ - Start $start `
24+ - Description $description
25+
26+ $response | Should Not BeNullOrEmpty
27+ $response.description | Should - BeExactly $description
28+ $Script :timeEntryId = $response.id
29+ }
30+ }
31+
32+ Context " Get-TogglTimeEntryById" {
33+ It " should retrieve the created time entry by ID" - Skip:($Script :timeEntryId -eq $null ) {
34+ $response = Get-TogglTimeEntryById `
35+ - ApiToken $apiToken `
36+ - TimeEntryId $Script :timeEntryId
37+
38+ $response | Should Not BeNullOrEmpty
39+ $response.id | Should - BeExactly $Script :timeEntryId
40+ }
41+
42+ It " should return null for a non-existing time entry ID" {
43+ $nonExistingTimeEntryId = 999999999
44+
45+ $response = Get-TogglTimeEntryById `
46+ - ApiToken $apiToken `
47+ - TimeEntryId $nonExistingTimeEntryId
48+
49+ $response | Should BeNullOrEmpty
50+ }
51+ }
52+
53+ Context " Update-TogglTimeEntry" {
54+ It " should update the time entry" - Skip:($Script :timeEntryId -eq $null ) {
55+ $newDescription = " Updated Test Time Entry"
56+
57+ $response = Update-TogglTimeEntry `
58+ - ApiToken $apiToken `
59+ - WorkspaceId $workspaceId `
60+ - TimeEntryId $Script :timeEntryId `
61+ - Description $newDescription
62+
63+ $response | Should Not BeNullOrEmpty
64+ $response.description | Should - BeExactly $newDescription
65+ }
66+ }
67+
68+ Context " Get-TogglTimeEntries" {
69+ It " should retrieve the list of time entries" {
70+ $response = Get-TogglTimeEntries `
71+ - ApiToken $apiToken `
72+ - Since ([int ][double ]::Parse((Get-Date ).AddDays(-7 ).ToUniversalTime().Subtract([datetime ]' 1970-01-01' ).TotalSeconds))
73+
74+ $response | Should Not BeNullOrEmpty
75+ $response.GetType ().Name | Should - Be " Object[]"
76+
77+ $filteredResponse = $response | Where-Object { $_.server_deleted_at -ne $null }
78+ $filteredResponse | Should Not BeNullOrEmpty
79+ $filteredResponse.Count | Should - BeGreaterThan 0
80+ }
81+ }
82+
83+ Context " Remove-TogglTimeEntry" {
84+ It " should delete the time entry" - Skip:($Script :timeEntryId -eq $null ) {
85+ Remove-TogglTimeEntry `
86+ - ApiToken $apiToken `
87+ - WorkspaceId $workspaceId `
88+ - TimeEntryId $Script :timeEntryId
89+
90+ $response = Get-TogglTimeEntryById `
91+ - ApiToken $apiToken `
92+ - TimeEntryId $Script :timeEntryId
93+
94+ $response | Should BeNullOrEmpty
95+ }
96+ }
97+ }
0 commit comments