From 141fa6e8478eae5b064825b6d666bed4e3079494 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Thu, 22 Jun 2023 10:43:12 -0700 Subject: [PATCH 1/2] fix(arcgis-rest-places): update pagination values for latest API --- packages/arcgis-rest-places/src/utils.ts | 2 +- .../test/findPlacesNearPoint.test.ts | 4 ++-- .../test/mocks/nearPoint.mock.ts | 7 +++---- .../test/mocks/withinExtent.mock.ts | 7 +++---- packages/arcgis-rest-places/test/utils.test.ts | 17 ++++++++++++----- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/arcgis-rest-places/src/utils.ts b/packages/arcgis-rest-places/src/utils.ts index 576719ad5..7f21aa81e 100644 --- a/packages/arcgis-rest-places/src/utils.ts +++ b/packages/arcgis-rest-places/src/utils.ts @@ -2,7 +2,7 @@ export const baseUrl = "https://places-api.arcgis.com/arcgis/rest/services/places-service/v1"; export function hasNextPage(response: any) { - return !!response?.links?.next; + return !!response?.links?.next || !!response?.pagination?.nextUrl; } export function getNextPageParams(currentOffset = 0, currentPageSize = 10) { diff --git a/packages/arcgis-rest-places/test/findPlacesNearPoint.test.ts b/packages/arcgis-rest-places/test/findPlacesNearPoint.test.ts index b03e0f264..d8d1d9399 100644 --- a/packages/arcgis-rest-places/test/findPlacesNearPoint.test.ts +++ b/packages/arcgis-rest-places/test/findPlacesNearPoint.test.ts @@ -1,5 +1,5 @@ import { ApiKeyManager } from "@esri/arcgis-rest-request"; -import fetchMock from "fetch-mock"; +import fetchMock, { MockCall } from "fetch-mock"; import { findPlacesNearPoint } from "../src/index.js"; import { placeNearPointMockNoMoreResults, @@ -21,7 +21,7 @@ describe("findPlacesNearPoint()", () => { authentication: ApiKeyManager.fromKey("MOCK_KEY") }); - const [url, options] = fetchMock.lastCall("*"); + const [url, options] = fetchMock.lastCall("*") as MockCall; expect(response.results).toEqual( placeNearPointMockNoMoreResults.results as any diff --git a/packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts b/packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts index 245f09cc3..3fc56ccc5 100644 --- a/packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts +++ b/packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts @@ -177,9 +177,8 @@ export const placeNearPointMockNoMoreResults = { } ], maxResultsExceeded: false, - links: { - base: "https://placesdev-api.arcgis.com/", - previous: - "/arcgis/rest/services/places-service/v1/places/near-point?x=-3.18830000&y=55.95330000&radius=100.00000000&f=json&offset=0&pageSize=10" + pagination: { + previousUrl: + "https://placesdev-api.arcgis.com//arcgis/rest/services/places-service/v1/places/near-point?x=-3.18830000&y=55.95330000&radius=100.00000000&f=json&offset=0&pageSize=10" } }; diff --git a/packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts b/packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts index a9249dfc1..db7d18bb5 100644 --- a/packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts +++ b/packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts @@ -146,9 +146,8 @@ export const placesWithinExtentMockNoMoreResults = { } ], maxResultsExceeded: false, - links: { - base: "https://places-service.esri.com/", - previous: - "/rest/v1/world/places/within-extent?xmin=-118.01333400&ymin=33.78193000&xmax=-117.79575300&ymax=33.87333700&categoryIds=13002&f=json&offset=0&pageSize=5&token=AAPK7d4bf083681e434b8d7593a08954e918ro7MqS9xFOIaAk7StSGVbajdmn5IDn1upbdHw9OiZbNx5YaeP51obAVmMVcmHuZ4" + pagination: { + previousUrl: + "https://places-service.esri.com//rest/v1/world/places/within-extent?xmin=-118.01333400&ymin=33.78193000&xmax=-117.79575300&ymax=33.87333700&categoryIds=13002&f=json&offset=0&pageSize=5&token=AAPK7d4bf083681e434b8d7593a08954e918ro7MqS9xFOIaAk7StSGVbajdmn5IDn1upbdHw9OiZbNx5YaeP51obAVmMVcmHuZ4" } }; diff --git a/packages/arcgis-rest-places/test/utils.test.ts b/packages/arcgis-rest-places/test/utils.test.ts index 2170f7ca5..c6783267e 100644 --- a/packages/arcgis-rest-places/test/utils.test.ts +++ b/packages/arcgis-rest-places/test/utils.test.ts @@ -6,7 +6,6 @@ describe("hasNextPage()", () => { it("should return if a response has a next page of results", async () => { expect( hasNextPage({ - maxResultsExceeded: true, links: { next: "next" } @@ -15,17 +14,25 @@ describe("hasNextPage()", () => { expect( hasNextPage({ - maxResultsExceeded: false + pagination: { + nextUrl: "next" + } }) - ).toBeFalsy(); + ).toBeTruthy(); + + expect(hasNextPage({})).toBeFalsy(); + expect(hasNextPage(undefined)).toBeFalsy(); expect( hasNextPage({ - maxResultsExceeded: true, links: {} }) ).toBeFalsy(); - expect(hasNextPage(undefined)).toBeFalsy(); + expect( + hasNextPage({ + pagination: {} + }) + ).toBeFalsy(); }); }); From d41e50d6f62bbe13f8f22f610df8d941902ab0b2 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 27 Jun 2023 08:42:47 -0700 Subject: [PATCH 2/2] chore: Apply suggestions from code review Co-authored-by: Gavin Rehkemper --- packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts | 2 +- packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts b/packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts index 3fc56ccc5..01de9730e 100644 --- a/packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts +++ b/packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts @@ -179,6 +179,6 @@ export const placeNearPointMockNoMoreResults = { maxResultsExceeded: false, pagination: { previousUrl: - "https://placesdev-api.arcgis.com//arcgis/rest/services/places-service/v1/places/near-point?x=-3.18830000&y=55.95330000&radius=100.00000000&f=json&offset=0&pageSize=10" + "https://placesdev-api.arcgis.com/arcgis/rest/services/places-service/v1/places/near-point?x=-3.18830000&y=55.95330000&radius=100.00000000&f=json&offset=0&pageSize=10" } }; diff --git a/packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts b/packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts index db7d18bb5..c9bfbbfca 100644 --- a/packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts +++ b/packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts @@ -148,6 +148,6 @@ export const placesWithinExtentMockNoMoreResults = { maxResultsExceeded: false, pagination: { previousUrl: - "https://places-service.esri.com//rest/v1/world/places/within-extent?xmin=-118.01333400&ymin=33.78193000&xmax=-117.79575300&ymax=33.87333700&categoryIds=13002&f=json&offset=0&pageSize=5&token=AAPK7d4bf083681e434b8d7593a08954e918ro7MqS9xFOIaAk7StSGVbajdmn5IDn1upbdHw9OiZbNx5YaeP51obAVmMVcmHuZ4" + "https://places-service.esri.com/rest/v1/world/places/within-extent?xmin=-118.01333400&ymin=33.78193000&xmax=-117.79575300&ymax=33.87333700&categoryIds=13002&f=json&offset=0&pageSize=5&token=AAPK7d4bf083681e434b8d7593a08954e918ro7MqS9xFOIaAk7StSGVbajdmn5IDn1upbdHw9OiZbNx5YaeP51obAVmMVcmHuZ4" } };