Skip to content

Commit b61691e

Browse files
committed
Check if nextPageToken exists #23
1 parent c2eef0a commit b61691e

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/public/Get-BloggerPosts.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ Function Get-BloggerPosts {
5555

5656
$result.items
5757

58-
# loop if pageToken is present and -All switch is set
59-
$pageToken = $result.nextPageToken
58+
# fetch continuation token
59+
if ($result.PSObject.Properties.name -contains "nextPageToken") {
60+
$pageToken = $result.nextPageToken
61+
}
62+
else {
63+
$pageToken = $null
64+
}
65+
# loop if pageToken is present and -All switch is set
6066
$done = ($All.IsPresent -and $All -and [string]::IsNullOrEmpty($pageToken)) -or !$All.IsPresent
6167
}
6268
}

src/tests/Get-BloggerPosts.Tests.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Describe "Get-BloggerPosts" {
1212

1313
# Setup initial get-bloggerposts
1414
Mock Invoke-GApi {
15-
return @{
15+
return [pscustomobject]@{
1616
items = @(
1717
@{ id = "1"; title = "Post 1"; published = "2023-10-01T00:00:00Z" },
1818
@{ id = "2"; title = "Post 2"; published = "2023-10-02T00:00:00Z" }
@@ -24,11 +24,10 @@ Describe "Get-BloggerPosts" {
2424

2525
# setup second call
2626
Mock Invoke-GApi {
27-
@{
27+
return [pscustomobject]@{
2828
items = @(
2929
@{ id = "3"; title = "Post 3"; published = "2023-10-03T00:00:00Z" }
3030
)
31-
nextPageToken = $null
3231
}
3332
} -ParameterFilter { $uri -like "*pageToken*" }
3433
}
@@ -48,7 +47,7 @@ Describe "Get-BloggerPosts" {
4847
InModuleScope PSBlogger {
4948
# Setup initial get-bloggerposts
5049
Mock Invoke-GApi {
51-
return @{
50+
return [pscustomobject]@{
5251
items = @(
5352
@{ id = "1"; title = "Post 1"; published = "2023-10-01T00:00:00Z" },
5453
@{ id = "2"; title = "Post 2"; published = "2023-10-02T00:00:00Z" }
@@ -80,7 +79,7 @@ Describe "Get-BloggerPosts" {
8079

8180
# Mock the API call to return posts after a specific date
8281
Mock Invoke-GApi {
83-
return @{
82+
return [pscustomobject]@{
8483
items = @(
8584
@{ id = "1"; title = "Post 1"; published = "2023-10-01T00:00:00Z" },
8685
@{ id = "2"; title = "Post 2"; published = "2023-10-02T00:00:00Z" }
@@ -105,7 +104,7 @@ Describe "Get-BloggerPosts" {
105104

106105
# Mock the API call to return all posts
107106
Mock Invoke-GApi {
108-
return @{
107+
return [pscustomobject]@{
109108
items = @(
110109
@{ id = "1"; title = "Post 1"; published = "2023-10-01T00:00:00Z" },
111110
@{ id = "2"; title = "Post 2"; published = "2023-10-02T00:00:00Z" }

0 commit comments

Comments
 (0)