Skip to content

Commit efb4d96

Browse files
committed
chore: migrate elevation tests to ArcGIS REST JS
1 parent d2170ee commit efb4d96

7 files changed

Lines changed: 37 additions & 29 deletions

File tree

karma.conf.cjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = function (config) {
1515
files: [
1616
"packages/arcgis-rest-demographics/{src,test}/**/!(*.test.live).ts",
1717
"packages/arcgis-rest-developer-credentials/{src,test}/**/!(*.test.live).ts",
18-
"packages/arcgis-rest-elevation/{src,test}/**/!(*.test.live).ts",
1918
"packages/arcgis-rest-feature-service/{src,test}/**/!(*.test.live).ts",
2019
"packages/arcgis-rest-geocoding/{src,test}/**/!(*.test.live).ts",
2120
"packages/arcgis-rest-places/{src,test}/**/!(*.test.live).ts",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/arcgis-rest-basemap-sessions/test/BasemapStyleSession.test.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
} from "../src/index.js";
99
import { MOCK_START_TIME, MOCK_END_TIME, TWELVE_HOURS } from "./test-utils.js";
1010
import fetchMock from "fetch-mock";
11-
import { Emitter } from "mitt";
11+
import { ApiKeyManager } from "@esri/arcgis-rest-request";
12+
13+
const MOCK_AUTH = ApiKeyManager.fromKey("fake-token");
1214

1315
function createMockSession() {
1416
return new BasemapStyleSession({
@@ -18,7 +20,7 @@ function createMockSession() {
1820
startTime: MOCK_START_TIME,
1921
endTime: MOCK_END_TIME,
2022
expires: new Date(MOCK_END_TIME.getTime() - DEFAULT_SAFETY_MARGIN * 1000),
21-
authentication: "token"
23+
authentication: MOCK_AUTH
2224
});
2325
}
2426

@@ -41,7 +43,7 @@ async function startMockSession(
4143
const session = await BasemapStyleSession.start({
4244
...{
4345
styleFamily: "arcgis",
44-
authentication: "token"
46+
authentication: MOCK_AUTH
4547
},
4648
...sessionParams
4749
});
@@ -83,7 +85,7 @@ describe("BasemapStyleSession", () => {
8385
startTime: MOCK_START_TIME,
8486
endTime: MOCK_END_TIME,
8587
expires: new Date(MOCK_END_TIME.getTime() - DEFAULT_SAFETY_MARGIN * 1000),
86-
authentication: "token"
88+
authentication: MOCK_AUTH
8789
});
8890

8991
expect(session).toBeDefined();
@@ -94,7 +96,7 @@ describe("BasemapStyleSession", () => {
9496
try {
9597
await BasemapStyleSession.start({
9698
duration: 9,
97-
authentication: "token"
99+
authentication: MOCK_AUTH
98100
});
99101
} catch (error) {
100102
expect(error).toEqual(
@@ -107,7 +109,7 @@ describe("BasemapStyleSession", () => {
107109
try {
108110
await BasemapStyleSession.start({
109111
duration: 43201,
110-
authentication: "token"
112+
authentication: MOCK_AUTH
111113
});
112114
} catch (error) {
113115
expect(error).toEqual(
@@ -157,7 +159,7 @@ describe("BasemapStyleSession", () => {
157159
expect(session.safetyMargin).toBe(DEFAULT_SAFETY_MARGIN);
158160
expect((session as any).expirationCheckInterval).toBe(10000); // 10 seconds
159161
expect(session.styleFamily).toBe("arcgis");
160-
expect(session.authentication).toBe("token");
162+
expect(session.authentication).toBe(MOCK_AUTH);
161163
expect(session.canRefresh).toBe(true);
162164
expect(await session.getToken()).toBe("fake-token");
163165
expect(session.autoRefresh).toBe(false);
@@ -170,15 +172,15 @@ describe("BasemapStyleSession", () => {
170172

171173
expect(url.startsWith(DEFAULT_START_BASEMAP_STYLE_SESSION_URL)).toBe(true);
172174
expect(url).toContain("styleFamily=arcgis");
173-
expect(url).toContain("token=token");
175+
expect(url).toContain("token=fake-token");
174176
expect(url).toContain("durationSeconds=43200");
175177
expect(url).toContain("f=json");
176178
});
177179

178180
test("should start a new BasemapStyleSession with a custom duration", async () => {
179181
const session = await startMockSession({
180182
duration: 60,
181-
authentication: "token"
183+
authentication: MOCK_AUTH
182184
});
183185

184186
// Validate the session object
@@ -198,7 +200,7 @@ describe("BasemapStyleSession", () => {
198200
);
199201
expect((session as any).expirationCheckInterval).toBe(600);
200202
expect(session.styleFamily).toBe("arcgis");
201-
expect(session.authentication).toBe("token");
203+
expect(session.authentication).toBe(MOCK_AUTH);
202204
expect(session.canRefresh).toBe(true);
203205
expect(await session.getToken()).toBe("fake-token");
204206
expect(session.autoRefresh).toBe(false);
@@ -211,14 +213,14 @@ describe("BasemapStyleSession", () => {
211213

212214
expect(url.startsWith(DEFAULT_START_BASEMAP_STYLE_SESSION_URL)).toBe(true);
213215
expect(url).toContain("styleFamily=arcgis");
214-
expect(url).toContain("token=token");
216+
expect(url).toContain("token=fake-token");
215217
expect(url).toContain("durationSeconds=60");
216218
expect(url).toContain("f=json");
217219
});
218220

219221
test("should start a new BasemapStyleSession with a custom safetyMargin", async () => {
220222
const session = await startMockSession({
221-
authentication: "token",
223+
authentication: MOCK_AUTH,
222224
safetyMargin: 600
223225
});
224226

@@ -239,7 +241,7 @@ describe("BasemapStyleSession", () => {
239241
);
240242
expect((session as any).expirationCheckInterval).toBe(10000);
241243
expect(session.styleFamily).toBe("arcgis");
242-
expect(session.authentication).toBe("token");
244+
expect(session.authentication).toBe(MOCK_AUTH);
243245
expect(session.canRefresh).toBe(true);
244246
expect(await session.getToken()).toBe("fake-token");
245247
expect(session.autoRefresh).toBe(false);
@@ -252,7 +254,7 @@ describe("BasemapStyleSession", () => {
252254

253255
expect(url.startsWith(DEFAULT_START_BASEMAP_STYLE_SESSION_URL)).toBe(true);
254256
expect(url).toContain("styleFamily=arcgis");
255-
expect(url).toContain("token=token");
257+
expect(url).toContain("token=fake-token");
256258
expect(url).toContain("durationSeconds=43200");
257259
expect(url).toContain("f=json");
258260
});
@@ -266,7 +268,7 @@ describe("BasemapStyleSession", () => {
266268
});
267269

268270
const session = await BasemapStyleSession.start({
269-
authentication: "token"
271+
authentication: MOCK_AUTH
270272
});
271273

272274
// Validate the session object
@@ -281,7 +283,7 @@ describe("BasemapStyleSession", () => {
281283
DEFAULT_START_BASEMAP_STYLE_SESSION_URL
282284
);
283285
expect(session.styleFamily).toBe("arcgis");
284-
expect(session.authentication).toBe("token");
286+
expect(session.authentication).toBe(MOCK_AUTH);
285287
expect(session.canRefresh).toBe(true);
286288
expect(await session.getToken()).toBe("fake-token");
287289
expect(session.autoRefresh).toBe(false);
@@ -294,7 +296,7 @@ describe("BasemapStyleSession", () => {
294296

295297
expect(url.startsWith(DEFAULT_START_BASEMAP_STYLE_SESSION_URL)).toBe(true);
296298
expect(url).toContain("styleFamily=arcgis");
297-
expect(url).toContain("token=token");
299+
expect(url).toContain("token=fake-token");
298300
expect(url).toContain("durationSeconds=43200");
299301
expect(url).toContain("f=json");
300302
});

packages/arcgis-rest-basemap-sessions/test/utils/startNewSession.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import {
55
IStartSessionResponse
66
} from "../../src/utils/startNewSession.js";
77
import { MOCK_START_TIME, MOCK_END_TIME } from "../test-utils.js";
8+
import { ApiKeyManager } from "@esri/arcgis-rest-request";
89

910
const MOCK_URL = "https://example.com/startSession";
10-
const MOCK_AUTH = "fake-token";
11+
const MOCK_AUTH = ApiKeyManager.fromKey("fake-token");
1112

1213
describe("startNewSession", () => {
1314
afterEach(() => {
@@ -24,7 +25,7 @@ describe("startNewSession", () => {
2425

2526
fetchMock.getOnce(
2627
{
27-
url: `${MOCK_URL}?f=json&styleFamily=arcgis&durationSeconds=43200&token=${MOCK_AUTH}`
28+
url: `${MOCK_URL}?f=json&styleFamily=arcgis&durationSeconds=43200&token=fake-token`
2829
},
2930
{
3031
status: 200,
@@ -50,7 +51,7 @@ describe("startNewSession", () => {
5051

5152
fetchMock.getOnce(
5253
{
53-
url: `${MOCK_URL}?f=json&styleFamily=open&durationSeconds=3600&token=${MOCK_AUTH}`
54+
url: `${MOCK_URL}?f=json&styleFamily=open&durationSeconds=3600&token=fake-token`
5455
},
5556
{
5657
status: 200,

packages/arcgis-rest-elevation/test/findElevationAtManyPoints.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expect, test, describe, afterEach } from "vitest";
12
import { ApiKeyManager } from "@esri/arcgis-rest-request";
23
import fetchMock from "fetch-mock";
34
import { findElevationAtManyPoints } from "../src/index.js";
@@ -9,7 +10,7 @@ describe("findElevationAtManyPoints()", () => {
910
fetchMock.restore();
1011
});
1112

12-
it("should return elevation at points with mean sea level as the reference", async () => {
13+
test("should return elevation at points with mean sea level as the reference", async () => {
1314
fetchMock.mock("*", atManyPointsDefaultResult);
1415

1516
let response = await findElevationAtManyPoints({
@@ -25,7 +26,7 @@ describe("findElevationAtManyPoints()", () => {
2526
expect(response.result).toEqual(atManyPointsDefaultResult.result);
2627
});
2728

28-
it("should return elevation at points with ellipsoid as the reference", async () => {
29+
test("should return elevation at points with ellipsoid as the reference", async () => {
2930
fetchMock.mock("*", atManyPointsEllipsoidResult);
3031

3132
const response = await findElevationAtManyPoints({

packages/arcgis-rest-elevation/test/findElevationAtPoint.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expect, test, describe, afterEach } from "vitest";
12
import { ApiKeyManager } from "@esri/arcgis-rest-request";
23
import fetchMock from "fetch-mock";
34
import { findElevationAtPoint } from "../src/index.js";
@@ -9,7 +10,7 @@ describe("findElevationAtPoint()", () => {
910
fetchMock.restore();
1011
});
1112

12-
it("should return elevation at a point with mean sea level as the reference", async () => {
13+
test("should return elevation at a point with mean sea level as the reference", async () => {
1314
fetchMock.mock("*", atPointDefaultResult);
1415

1516
const response = await findElevationAtPoint({
@@ -26,7 +27,7 @@ describe("findElevationAtPoint()", () => {
2627
expect(url).toContain("token=MOCK_KEY");
2728
});
2829

29-
it("should return elevation at a point with ellipsoid as the reference", async () => {
30+
test("should return elevation at a point with ellipsoid as the reference", async () => {
3031
fetchMock.mock("*", atPointEllipsoidResult);
3132

3233
const response = await findElevationAtPoint({

vitest.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { defineConfig } from "vite";
33
export default defineConfig({
44
test: {
55
include: [
6-
"packages/arcgis-rest-basemap-sessions/**/*.{test,spec}.?(c|m)[jt]s?(x)"
6+
"packages/arcgis-rest-basemap-sessions/**/*.{test,spec}.?(c|m)[jt]s?(x)",
7+
"packages/arcgis-rest-elevation/**/*.{test,spec}.?(c|m)[jt]s?(x)"
78
],
89
coverage: {
910
enabled: true,
10-
include: ["packages/arcgis-rest-basemap-sessions/src/**/*.{ts,js}"],
11+
include: [
12+
"packages/arcgis-rest-basemap-sessions/src/**/*.{ts,js}",
13+
"packages/arcgis-rest-elevation/src/**/*.{ts,js}"
14+
],
1115
provider: "istanbul",
1216
reporter: ["json", "html", "cobertura"],
1317
reportsDirectory: "./coverage/vitest",

0 commit comments

Comments
 (0)