Skip to content

Commit

Permalink
fix(arcgis-rest-places): update pagination values for latest API (#1109)
Browse files Browse the repository at this point in the history
* fix(arcgis-rest-places): update pagination values for latest API

* chore: Apply suggestions from code review

Co-authored-by: Gavin Rehkemper <gavinr@users.noreply.github.com>

---------

Co-authored-by: Gavin Rehkemper <gavinr@users.noreply.github.com>
  • Loading branch information
patrickarlt and gavinr authored Jun 27, 2023
1 parent 649f7e7 commit ea5370c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/arcgis-rest-places/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/arcgis-rest-places/test/findPlacesNearPoint.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions packages/arcgis-rest-places/test/mocks/nearPoint.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
};
7 changes: 3 additions & 4 deletions packages/arcgis-rest-places/test/mocks/withinExtent.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
};
17 changes: 12 additions & 5 deletions packages/arcgis-rest-places/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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();
});
});

0 comments on commit ea5370c

Please sign in to comment.