ducimusipsa 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.prettierignore +2 -0
- package/.travis.yml +34 -0
- package/.vscode/launch.json +24 -0
- package/.vscode/settings.json +3 -0
- package/demos/ago-node-cli/README.md +29 -0
- package/demos/ago-node-cli/ago.js +32 -0
- package/demos/ago-node-cli/index.js +11 -0
- package/demos/ago-node-cli/lib/item-export-command.js +48 -0
- package/demos/ago-node-cli/lib/item-search-command.js +35 -0
- package/demos/ago-node-cli/package-lock.json +180 -0
- package/demos/ago-node-cli/package.json +30 -0
- package/demos/attachments/README.md +5 -0
- package/demos/attachments/index.html +164 -0
- package/demos/attachments/package-lock.json +182 -0
- package/demos/attachments/package.json +18 -0
- package/demos/batch-geocoder-node/NYC_Restaurant_Inspection_Results.csv +100 -0
- package/demos/batch-geocoder-node/README.md +15 -0
- package/demos/batch-geocoder-node/batch-geocode.js +115 -0
- package/demos/batch-geocoder-node/config-template.js +18 -0
- package/demos/batch-geocoder-node/package-lock.json +109 -0
- package/demos/batch-geocoder-node/package.json +38 -0
- package/demos/express/README.md +15 -0
- package/demos/express/config.json.template +3 -0
- package/demos/express/package-lock.json +428 -0
- package/demos/express/package.json +18 -0
- package/demos/express/server.js +33 -0
- package/demos/feature-service-browser/README.md +6 -0
- package/demos/feature-service-browser/index.html +122 -0
- package/demos/feature-service-browser/package-lock.json +182 -0
- package/demos/feature-service-browser/package.json +18 -0
- package/demos/geocoder-browser/README.md +10 -0
- package/demos/geocoder-browser/config.js.template +1 -0
- package/demos/geocoder-browser/index.html +131 -0
- package/demos/geocoder-browser/package-lock.json +182 -0
- package/demos/geocoder-browser/package.json +19 -0
- package/demos/geocoder-browser/post-sign-in.html +25 -0
- package/demos/jsapi-integration/README.md +25 -0
- package/demos/jsapi-integration/config.js +6 -0
- package/demos/jsapi-integration/index.html +85 -0
- package/demos/jsapi-integration/package-lock.json +184 -0
- package/demos/jsapi-integration/package.json +19 -0
- package/demos/oauth2-browser/README.md +14 -0
- package/demos/oauth2-browser/authenticate.html +32 -0
- package/demos/oauth2-browser/config.js.template +6 -0
- package/demos/oauth2-browser/index.html +202 -0
- package/demos/oauth2-browser/logo.svg +4 -0
- package/demos/oauth2-browser/package-lock.json +163 -0
- package/demos/oauth2-browser/package.json +18 -0
- package/demos/oauth2-browser/style.css +36 -0
- package/demos/oauth2-browser-retry/README.md +25 -0
- package/demos/oauth2-browser-retry/authenticate.html +21 -0
- package/demos/oauth2-browser-retry/index.html +116 -0
- package/demos/oauth2-browser-retry/logo.svg +4 -0
- package/demos/vue/.env.example +11 -0
- package/demos/vue/.eslintrc.js +17 -0
- package/demos/vue/.postcssrc.js +5 -0
- package/demos/vue/README.md +17 -0
- package/demos/vue/babel.config.js +3 -0
- package/demos/vue/package-lock.json +11323 -0
- package/demos/vue/package.json +33 -0
- package/demos/vue/public/favicon.ico +0 -0
- package/demos/vue/public/index.html +24 -0
- package/demos/vue/src/assets/logo.svg +29 -0
- package/demos/vue/src/components/App.vue +308 -0
- package/demos/vue/src/components/Authenticate.vue +65 -0
- package/demos/vue/src/components/Loader.vue +230 -0
- package/demos/vue/src/main.js +92 -0
- package/docs/FAQ.md +28 -0
- package/docs/HISTORY.md +62 -0
- package/docs/acetate.config.js +223 -0
- package/docs/build-typedoc.js +303 -0
- package/docs/src/_layout.html +82 -0
- package/docs/src/api/_declaration.html +496 -0
- package/docs/src/api/_layout.html +127 -0
- package/docs/src/api/_package.html +13 -0
- package/docs/src/api/index.html +23 -0
- package/docs/src/guides/_layout.html +24 -0
- package/docs/src/guides/amd-requirejs-dojo.md +40 -0
- package/docs/src/guides/babel-and-rollup.md +30 -0
- package/docs/src/guides/babel-and-webpack.md +30 -0
- package/docs/src/guides/browser-authentication.md +41 -0
- package/docs/src/guides/browserify.md +9 -0
- package/docs/src/guides/cli-authentication.md +9 -0
- package/docs/src/guides/client-server-authentication.md +9 -0
- package/docs/src/guides/from-a-cdn.md +36 -0
- package/docs/src/guides/index.md +52 -0
- package/docs/src/guides/node.md +70 -0
- package/docs/src/guides/package-overview.md +8 -0
- package/docs/src/guides/server-authentication.md +9 -0
- package/docs/src/guides/typescript-and-webpack.md +9 -0
- package/docs/src/img/icons.png +0 -0
- package/docs/src/img/icons@2x.png +0 -0
- package/docs/src/index.html +12 -0
- package/docs/src/js/api-search.js +112 -0
- package/docs/src/js/nav-toggle.js +41 -0
- package/docs/src/sass/_highlight.scss +96 -0
- package/docs/src/sass/_icons.scss +157 -0
- package/docs/src/sass/style.scss +169 -0
- package/jasmine.json +7 -0
- package/karma.conf.js +100 -0
- package/lerna.json +8 -0
- package/notes/README.md +88 -0
- package/package.json +129 -0
- package/packages/arcgis-rest-auth/README.md +67 -0
- package/packages/arcgis-rest-auth/package-lock.json +11 -0
- package/packages/arcgis-rest-auth/package.json +53 -0
- package/packages/arcgis-rest-auth/src/ApplicationSession.ts +108 -0
- package/packages/arcgis-rest-auth/src/UserSession.ts +880 -0
- package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +24 -0
- package/packages/arcgis-rest-auth/src/fetch-token.ts +52 -0
- package/packages/arcgis-rest-auth/src/generate-token.ts +39 -0
- package/packages/arcgis-rest-auth/src/index.ts +8 -0
- package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +124 -0
- package/packages/arcgis-rest-auth/test/UserSession.test.ts +1005 -0
- package/packages/arcgis-rest-auth/test/fetchToken.test.ts +112 -0
- package/packages/arcgis-rest-auth/test/generateToken.test.ts +130 -0
- package/packages/arcgis-rest-auth/test/utils.ts +14 -0
- package/packages/arcgis-rest-auth/tsconfig.json +6 -0
- package/packages/arcgis-rest-common/README.md +57 -0
- package/packages/arcgis-rest-common/package-lock.json +11 -0
- package/packages/arcgis-rest-common/package.json +41 -0
- package/packages/arcgis-rest-common/src/index.ts +10 -0
- package/packages/arcgis-rest-common/src/types/feature.ts +14 -0
- package/packages/arcgis-rest-common/src/types/geometry.ts +47 -0
- package/packages/arcgis-rest-common/src/types/symbol.ts +21 -0
- package/packages/arcgis-rest-common/src/util/location.ts +19 -0
- package/packages/arcgis-rest-common/test/location.test.ts +73 -0
- package/packages/arcgis-rest-common/tsconfig.json +6 -0
- package/packages/arcgis-rest-common-types/README.md +64 -0
- package/packages/arcgis-rest-common-types/package.json +40 -0
- package/packages/arcgis-rest-common-types/src/group.ts +54 -0
- package/packages/arcgis-rest-common-types/src/index.ts +469 -0
- package/packages/arcgis-rest-common-types/src/item.ts +47 -0
- package/packages/arcgis-rest-common-types/src/webmap.ts +1267 -0
- package/packages/arcgis-rest-common-types/tsconfig.json +11 -0
- package/packages/arcgis-rest-feature-service/README.md +73 -0
- package/packages/arcgis-rest-feature-service/package-lock.json +11 -0
- package/packages/arcgis-rest-feature-service/package.json +53 -0
- package/packages/arcgis-rest-feature-service/src/add.ts +90 -0
- package/packages/arcgis-rest-feature-service/src/addAttachment.ts +64 -0
- package/packages/arcgis-rest-feature-service/src/decodeValues.ts +129 -0
- package/packages/arcgis-rest-feature-service/src/delete.ts +97 -0
- package/packages/arcgis-rest-feature-service/src/deleteAttachments.ts +67 -0
- package/packages/arcgis-rest-feature-service/src/getAttachments.ts +64 -0
- package/packages/arcgis-rest-feature-service/src/getLayer.ts +27 -0
- package/packages/arcgis-rest-feature-service/src/helpers.ts +50 -0
- package/packages/arcgis-rest-feature-service/src/index.ts +14 -0
- package/packages/arcgis-rest-feature-service/src/query.ts +183 -0
- package/packages/arcgis-rest-feature-service/src/queryRelated.ts +94 -0
- package/packages/arcgis-rest-feature-service/src/update.ts +90 -0
- package/packages/arcgis-rest-feature-service/src/updateAttachment.ts +73 -0
- package/packages/arcgis-rest-feature-service/test/attachments.test.ts +203 -0
- package/packages/arcgis-rest-feature-service/test/crud.test.ts +263 -0
- package/packages/arcgis-rest-feature-service/test/decodeValues.test.ts +67 -0
- package/packages/arcgis-rest-feature-service/test/getLayer.test.ts +31 -0
- package/packages/arcgis-rest-feature-service/test/mocks/cvdQueryResponse.ts +225 -0
- package/packages/arcgis-rest-feature-service/test/mocks/feature.ts +281 -0
- package/packages/arcgis-rest-feature-service/test/mocks/fields.ts +779 -0
- package/packages/arcgis-rest-feature-service/test/mocks/foo.txt +1 -0
- package/packages/arcgis-rest-feature-service/test/mocks/service.ts +259 -0
- package/packages/arcgis-rest-feature-service/test/query.test.ts +140 -0
- package/packages/arcgis-rest-feature-service/tsconfig.json +6 -0
- package/packages/arcgis-rest-feature-service-admin/README.md +69 -0
- package/packages/arcgis-rest-feature-service-admin/package-lock.json +11 -0
- package/packages/arcgis-rest-feature-service-admin/package.json +56 -0
- package/packages/arcgis-rest-feature-service-admin/src/addTo.ts +74 -0
- package/packages/arcgis-rest-feature-service-admin/src/create.ts +207 -0
- package/packages/arcgis-rest-feature-service-admin/src/index.ts +2 -0
- package/packages/arcgis-rest-feature-service-admin/test/addTo.test.ts +353 -0
- package/packages/arcgis-rest-feature-service-admin/test/create.test.ts +412 -0
- package/packages/arcgis-rest-feature-service-admin/test/mocks/layerDefinition.ts +79 -0
- package/packages/arcgis-rest-feature-service-admin/test/mocks/move.ts +14 -0
- package/packages/arcgis-rest-feature-service-admin/test/mocks/service.ts +72 -0
- package/packages/arcgis-rest-feature-service-admin/tsconfig.json +6 -0
- package/packages/arcgis-rest-geocoder/README.md +83 -0
- package/packages/arcgis-rest-geocoder/package-lock.json +11 -0
- package/packages/arcgis-rest-geocoder/package.json +55 -0
- package/packages/arcgis-rest-geocoder/src/bulk.ts +102 -0
- package/packages/arcgis-rest-geocoder/src/geocode.ts +130 -0
- package/packages/arcgis-rest-geocoder/src/helpers.ts +80 -0
- package/packages/arcgis-rest-geocoder/src/index.ts +8 -0
- package/packages/arcgis-rest-geocoder/src/reverse.ts +83 -0
- package/packages/arcgis-rest-geocoder/src/suggest.ts +69 -0
- package/packages/arcgis-rest-geocoder/test/bulk.test.ts +113 -0
- package/packages/arcgis-rest-geocoder/test/geocode.test.ts +176 -0
- package/packages/arcgis-rest-geocoder/test/helpers.test.ts +111 -0
- package/packages/arcgis-rest-geocoder/test/mocks/responses.ts +629 -0
- package/packages/arcgis-rest-geocoder/test/reverse.test.ts +126 -0
- package/packages/arcgis-rest-geocoder/test/suggest.test.ts +98 -0
- package/packages/arcgis-rest-geocoder/tsconfig.json +6 -0
- package/packages/arcgis-rest-groups/README.md +67 -0
- package/packages/arcgis-rest-groups/package-lock.json +11 -0
- package/packages/arcgis-rest-groups/package.json +55 -0
- package/packages/arcgis-rest-groups/src/create.ts +34 -0
- package/packages/arcgis-rest-groups/src/get.ts +95 -0
- package/packages/arcgis-rest-groups/src/helpers.ts +27 -0
- package/packages/arcgis-rest-groups/src/index.ts +11 -0
- package/packages/arcgis-rest-groups/src/notification.ts +77 -0
- package/packages/arcgis-rest-groups/src/protect.ts +40 -0
- package/packages/arcgis-rest-groups/src/remove.ts +23 -0
- package/packages/arcgis-rest-groups/src/search.ts +64 -0
- package/packages/arcgis-rest-groups/src/update.ts +36 -0
- package/packages/arcgis-rest-groups/test/crud.test.ts +134 -0
- package/packages/arcgis-rest-groups/test/get.test.ts +101 -0
- package/packages/arcgis-rest-groups/test/mocks/responses.ts +141 -0
- package/packages/arcgis-rest-groups/test/notification.test.ts +102 -0
- package/packages/arcgis-rest-groups/test/protect.test.ts +64 -0
- package/packages/arcgis-rest-groups/test/search.test.ts +85 -0
- package/packages/arcgis-rest-groups/tsconfig.json +6 -0
- package/packages/arcgis-rest-items/README.md +69 -0
- package/packages/arcgis-rest-items/package-lock.json +11 -0
- package/packages/arcgis-rest-items/package.json +55 -0
- package/packages/arcgis-rest-items/src/add.ts +103 -0
- package/packages/arcgis-rest-items/src/create.ts +110 -0
- package/packages/arcgis-rest-items/src/get.ts +79 -0
- package/packages/arcgis-rest-items/src/helpers.ts +147 -0
- package/packages/arcgis-rest-items/src/index.ts +11 -0
- package/packages/arcgis-rest-items/src/protect.ts +38 -0
- package/packages/arcgis-rest-items/src/remove.ts +58 -0
- package/packages/arcgis-rest-items/src/search.ts +78 -0
- package/packages/arcgis-rest-items/src/update.ts +134 -0
- package/packages/arcgis-rest-items/test/add.test.ts +256 -0
- package/packages/arcgis-rest-items/test/create.test.ts +371 -0
- package/packages/arcgis-rest-items/test/get.test.ts +181 -0
- package/packages/arcgis-rest-items/test/mocks/foo.zip +0 -0
- package/packages/arcgis-rest-items/test/mocks/item.ts +35 -0
- package/packages/arcgis-rest-items/test/mocks/resources.ts +31 -0
- package/packages/arcgis-rest-items/test/mocks/search.ts +62 -0
- package/packages/arcgis-rest-items/test/protect.test.ts +122 -0
- package/packages/arcgis-rest-items/test/remove.test.ts +161 -0
- package/packages/arcgis-rest-items/test/search.test.ts +159 -0
- package/packages/arcgis-rest-items/test/update.test.ts +450 -0
- package/packages/arcgis-rest-items/tsconfig.json +6 -0
- package/packages/arcgis-rest-request/README.md +68 -0
- package/packages/arcgis-rest-request/package-lock.json +11 -0
- package/packages/arcgis-rest-request/package.json +45 -0
- package/packages/arcgis-rest-request/src/index.ts +15 -0
- package/packages/arcgis-rest-request/src/request.ts +358 -0
- package/packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts +76 -0
- package/packages/arcgis-rest-request/src/utils/ErrorTypes.ts +29 -0
- package/packages/arcgis-rest-request/src/utils/append-custom-params.ts +29 -0
- package/packages/arcgis-rest-request/src/utils/encode-form-data.ts +34 -0
- package/packages/arcgis-rest-request/src/utils/encode-query-string.ts +23 -0
- package/packages/arcgis-rest-request/src/utils/get-portal-url.ts +25 -0
- package/packages/arcgis-rest-request/src/utils/get-portal.ts +45 -0
- package/packages/arcgis-rest-request/src/utils/params.ts +52 -0
- package/packages/arcgis-rest-request/src/utils/process-params.ts +99 -0
- package/packages/arcgis-rest-request/src/utils/retryAuthError.ts +9 -0
- package/packages/arcgis-rest-request/src/utils/warn.ts +11 -0
- package/packages/arcgis-rest-request/test/mocks/errors.ts +68 -0
- package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +13 -0
- package/packages/arcgis-rest-request/test/mocks/portal.ts +112 -0
- package/packages/arcgis-rest-request/test/mocks/sharing-rest-info.ts +41 -0
- package/packages/arcgis-rest-request/test/mocks/webmap.ts +41 -0
- package/packages/arcgis-rest-request/test/request.test.ts +323 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +170 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISRequestError.test.ts +51 -0
- package/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +111 -0
- package/packages/arcgis-rest-request/test/utils/encode-form-data.test.ts +133 -0
- package/packages/arcgis-rest-request/test/utils/get-portal-url.test.ts +37 -0
- package/packages/arcgis-rest-request/test/utils/portal.test.ts +97 -0
- package/packages/arcgis-rest-request/test/utils/process-params.test.ts +193 -0
- package/packages/arcgis-rest-request/tsconfig.json +6 -0
- package/packages/arcgis-rest-routing/README.md +71 -0
- package/packages/arcgis-rest-routing/package-lock.json +11 -0
- package/packages/arcgis-rest-routing/package.json +54 -0
- package/packages/arcgis-rest-routing/src/helpers.ts +16 -0
- package/packages/arcgis-rest-routing/src/index.ts +4 -0
- package/packages/arcgis-rest-routing/src/solveRoute.ts +102 -0
- package/packages/arcgis-rest-routing/test/mocks/responses.ts +825 -0
- package/packages/arcgis-rest-routing/test/solveRoute.test.ts +267 -0
- package/packages/arcgis-rest-routing/tsconfig.json +6 -0
- package/packages/arcgis-rest-sharing/README.md +70 -0
- package/packages/arcgis-rest-sharing/package-lock.json +11 -0
- package/packages/arcgis-rest-sharing/package.json +60 -0
- package/packages/arcgis-rest-sharing/src/access.ts +85 -0
- package/packages/arcgis-rest-sharing/src/group-sharing.ts +211 -0
- package/packages/arcgis-rest-sharing/src/helpers.ts +82 -0
- package/packages/arcgis-rest-sharing/src/index.ts +5 -0
- package/packages/arcgis-rest-sharing/test/access.test.ts +154 -0
- package/packages/arcgis-rest-sharing/test/group-sharing.test.ts +566 -0
- package/packages/arcgis-rest-sharing/test/helpers.test.ts +55 -0
- package/packages/arcgis-rest-sharing/test/mocks/sharing.ts +18 -0
- package/packages/arcgis-rest-sharing/tsconfig.json +6 -0
- package/packages/arcgis-rest-users/README.md +74 -0
- package/packages/arcgis-rest-users/package-lock.json +11 -0
- package/packages/arcgis-rest-users/package.json +54 -0
- package/packages/arcgis-rest-users/src/get.ts +69 -0
- package/packages/arcgis-rest-users/src/index.ts +6 -0
- package/packages/arcgis-rest-users/src/invitation.ts +166 -0
- package/packages/arcgis-rest-users/src/notification.ts +73 -0
- package/packages/arcgis-rest-users/test/get.test.ts +99 -0
- package/packages/arcgis-rest-users/test/invitation.test.ts +169 -0
- package/packages/arcgis-rest-users/test/mocks/invitation.ts +70 -0
- package/packages/arcgis-rest-users/test/mocks/notification.ts +34 -0
- package/packages/arcgis-rest-users/test/mocks/user.ts +173 -0
- package/packages/arcgis-rest-users/test/notification.test.ts +83 -0
- package/packages/arcgis-rest-users/tsconfig.json +6 -0
- package/support/changelog.js +394 -0
- package/support/deploy-doc-site.js +16 -0
- package/support/dev.sh +6 -0
- package/support/publish.sh +43 -0
- package/support/test-helpers.js +8 -0
- package/tsconfig.json +69 -0
- package/tslint.json +16 -0
- package/umd-base-profile.js +82 -0
- package/umd-production-profile.js +13 -0
@@ -0,0 +1,323 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { request, ErrorTypes } from "../src/index";
|
5
|
+
import * as fetchMock from "fetch-mock";
|
6
|
+
import {
|
7
|
+
SharingRestInfo,
|
8
|
+
SharingRestInfoHTML
|
9
|
+
} from "./mocks/sharing-rest-info";
|
10
|
+
import { ArcGISOnlineError } from "./mocks/errors";
|
11
|
+
import { WebMapAsText, WebMapAsJSON } from "./mocks/webmap";
|
12
|
+
import { GeoJSONFeatureCollection } from "./mocks/geojson-feature-collection";
|
13
|
+
|
14
|
+
describe("request()", () => {
|
15
|
+
afterEach(fetchMock.restore);
|
16
|
+
|
17
|
+
it("should make a basic POST request", done => {
|
18
|
+
fetchMock.once("*", SharingRestInfo);
|
19
|
+
|
20
|
+
request("https://www.arcgis.com/sharing/rest/info")
|
21
|
+
.then(response => {
|
22
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
23
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info");
|
24
|
+
expect(options.method).toBe("POST");
|
25
|
+
expect(response).toEqual(SharingRestInfo);
|
26
|
+
expect(options.body).toContain("f=json");
|
27
|
+
done();
|
28
|
+
})
|
29
|
+
.catch(e => {
|
30
|
+
fail(e);
|
31
|
+
});
|
32
|
+
});
|
33
|
+
|
34
|
+
it("should make a basic GET request", done => {
|
35
|
+
fetchMock.once("*", SharingRestInfo);
|
36
|
+
|
37
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
38
|
+
httpMethod: "GET"
|
39
|
+
})
|
40
|
+
.then(response => {
|
41
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
42
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info?f=json");
|
43
|
+
expect(options.method).toBe("GET");
|
44
|
+
expect(response).toEqual(SharingRestInfo);
|
45
|
+
done();
|
46
|
+
})
|
47
|
+
.catch(e => {
|
48
|
+
fail(e);
|
49
|
+
});
|
50
|
+
});
|
51
|
+
|
52
|
+
it("should make a basic GET request for text", done => {
|
53
|
+
fetchMock.once("*", WebMapAsText);
|
54
|
+
|
55
|
+
request(
|
56
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data",
|
57
|
+
{
|
58
|
+
httpMethod: "GET",
|
59
|
+
params: { f: "text" }
|
60
|
+
}
|
61
|
+
)
|
62
|
+
.then(response => {
|
63
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
64
|
+
expect(url).toEqual(
|
65
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data?f=text"
|
66
|
+
);
|
67
|
+
expect(options.method).toBe("GET");
|
68
|
+
expect(response).toEqual(WebMapAsText);
|
69
|
+
done();
|
70
|
+
})
|
71
|
+
.catch(e => {
|
72
|
+
fail(e);
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
it("should make a basic GET request for html", done => {
|
77
|
+
fetchMock.once("*", SharingRestInfoHTML);
|
78
|
+
|
79
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
80
|
+
httpMethod: "GET",
|
81
|
+
params: { f: "html" }
|
82
|
+
})
|
83
|
+
.then(response => {
|
84
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
85
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info?f=html");
|
86
|
+
expect(options.method).toBe("GET");
|
87
|
+
expect(response).toEqual(SharingRestInfoHTML);
|
88
|
+
done();
|
89
|
+
})
|
90
|
+
.catch(e => {
|
91
|
+
fail(e);
|
92
|
+
});
|
93
|
+
});
|
94
|
+
|
95
|
+
it("should make a basic GET request for geojson", done => {
|
96
|
+
fetchMock.once("*", GeoJSONFeatureCollection);
|
97
|
+
|
98
|
+
request(
|
99
|
+
"https://services1.arcgis.com/ORG/arcgis/rest/services/FEATURE_SERVICE/FeatureServer/0/query",
|
100
|
+
{
|
101
|
+
httpMethod: "GET",
|
102
|
+
params: { where: "1=1", f: "geojson" }
|
103
|
+
}
|
104
|
+
)
|
105
|
+
.then(response => {
|
106
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
107
|
+
expect(url).toEqual(
|
108
|
+
"https://services1.arcgis.com/ORG/arcgis/rest/services/FEATURE_SERVICE/FeatureServer/0/query?f=geojson&where=1%3D1"
|
109
|
+
);
|
110
|
+
expect(options.method).toBe("GET");
|
111
|
+
expect(response).toEqual(GeoJSONFeatureCollection);
|
112
|
+
done();
|
113
|
+
})
|
114
|
+
.catch(e => {
|
115
|
+
fail(e);
|
116
|
+
});
|
117
|
+
});
|
118
|
+
|
119
|
+
it("should switch from GET to POST when url is longer than specified", done => {
|
120
|
+
fetchMock.once("*", SharingRestInfo);
|
121
|
+
const restInfoUrl = "https://www.arcgis.com/sharing/rest/info";
|
122
|
+
|
123
|
+
request(restInfoUrl, {
|
124
|
+
httpMethod: "GET",
|
125
|
+
// typically consumers would base maxUrlLength on browser/server limits
|
126
|
+
// but for testing, we use an artificially low limit
|
127
|
+
// like this one that assumes no parameters will be added
|
128
|
+
maxUrlLength: restInfoUrl.length
|
129
|
+
})
|
130
|
+
.then(response => {
|
131
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
132
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info");
|
133
|
+
expect(options.method).toBe("POST");
|
134
|
+
expect(options.body).toContain("f=json");
|
135
|
+
expect(response).toEqual(SharingRestInfo);
|
136
|
+
done();
|
137
|
+
})
|
138
|
+
.catch(e => {
|
139
|
+
fail(e);
|
140
|
+
});
|
141
|
+
});
|
142
|
+
|
143
|
+
it("should use the `authentication` option to authenticate a request", done => {
|
144
|
+
fetchMock.once("*", WebMapAsText);
|
145
|
+
|
146
|
+
const MOCK_AUTH = {
|
147
|
+
portal: "https://www.arcgis.com/sharing/rest",
|
148
|
+
getToken() {
|
149
|
+
return Promise.resolve("token");
|
150
|
+
}
|
151
|
+
};
|
152
|
+
|
153
|
+
request(
|
154
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data",
|
155
|
+
{
|
156
|
+
authentication: MOCK_AUTH
|
157
|
+
}
|
158
|
+
)
|
159
|
+
.then(response => {
|
160
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
161
|
+
expect(url).toEqual(
|
162
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
163
|
+
);
|
164
|
+
expect(options.body).toContain("token=token");
|
165
|
+
expect(response).toEqual(WebMapAsJSON);
|
166
|
+
done();
|
167
|
+
})
|
168
|
+
.catch(e => {
|
169
|
+
fail(e);
|
170
|
+
});
|
171
|
+
});
|
172
|
+
|
173
|
+
it("should re-throw HTTP errors (404, 500, etc)", done => {
|
174
|
+
fetchMock.once("*", 404);
|
175
|
+
|
176
|
+
request(
|
177
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
178
|
+
).catch(error => {
|
179
|
+
expect(error.name).toBe(ErrorTypes.ArcGISRequestError);
|
180
|
+
expect(error.message).toBe("HTTP 404: Not Found");
|
181
|
+
expect(error instanceof Error).toBeTruthy();
|
182
|
+
expect(error.url).toBe(
|
183
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
184
|
+
);
|
185
|
+
expect(error.options.params).toEqual({ f: "json" });
|
186
|
+
expect(error.options.httpMethod).toEqual("POST");
|
187
|
+
expect(typeof error.options.fetch).toEqual("function");
|
188
|
+
expect(error.options.fetch.length).toEqual(2);
|
189
|
+
done();
|
190
|
+
});
|
191
|
+
});
|
192
|
+
|
193
|
+
it("should throw errors with information about the request", done => {
|
194
|
+
fetchMock.once("*", ArcGISOnlineError);
|
195
|
+
|
196
|
+
request(
|
197
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
198
|
+
).catch(error => {
|
199
|
+
expect(error.name).toBe(ErrorTypes.ArcGISRequestError);
|
200
|
+
expect(error.message).toBe("400: 'type' and 'title' property required.");
|
201
|
+
expect(error instanceof Error).toBeTruthy();
|
202
|
+
expect(error.url).toBe(
|
203
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
204
|
+
);
|
205
|
+
expect(error.options.params).toEqual({ f: "json" });
|
206
|
+
expect(error.options.httpMethod).toEqual("POST");
|
207
|
+
expect(typeof error.options.fetch).toEqual("function");
|
208
|
+
expect(error.options.fetch.length).toEqual(2);
|
209
|
+
done();
|
210
|
+
});
|
211
|
+
});
|
212
|
+
|
213
|
+
it("should allow you to use custom implementations of `fetch`", done => {
|
214
|
+
const MockFetchResponse = {
|
215
|
+
ok: true,
|
216
|
+
json() {
|
217
|
+
return Promise.resolve(SharingRestInfo);
|
218
|
+
},
|
219
|
+
blob() {
|
220
|
+
return Promise.resolve(new Blob([JSON.stringify(SharingRestInfo)]));
|
221
|
+
},
|
222
|
+
text() {
|
223
|
+
return Promise.resolve(JSON.stringify(SharingRestInfo));
|
224
|
+
}
|
225
|
+
};
|
226
|
+
|
227
|
+
const MockFetch = function() {
|
228
|
+
return Promise.resolve(MockFetchResponse);
|
229
|
+
};
|
230
|
+
|
231
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
232
|
+
fetch: MockFetch as any
|
233
|
+
})
|
234
|
+
.then(response => {
|
235
|
+
expect(response).toEqual(SharingRestInfo);
|
236
|
+
done();
|
237
|
+
})
|
238
|
+
.catch(e => {
|
239
|
+
fail(e);
|
240
|
+
});
|
241
|
+
});
|
242
|
+
|
243
|
+
describe("should throw errors when required dependencies are missing", () => {
|
244
|
+
const oldPromise = Promise;
|
245
|
+
const oldFetch = fetch;
|
246
|
+
const oldFormData = FormData;
|
247
|
+
beforeEach(() => {
|
248
|
+
Promise = undefined;
|
249
|
+
FormData = undefined;
|
250
|
+
Function("return this")().fetch = undefined;
|
251
|
+
});
|
252
|
+
|
253
|
+
afterEach(() => {
|
254
|
+
Promise = oldPromise;
|
255
|
+
FormData = oldFormData;
|
256
|
+
Function("return this")().fetch = oldFetch;
|
257
|
+
});
|
258
|
+
it("should throw for missing dependencies", () => {
|
259
|
+
expect(() => {
|
260
|
+
request("https://www.arcgis.com/sharing/rest/info").catch();
|
261
|
+
}).toThrowError(
|
262
|
+
"`arcgis-rest-request` requires global variables for `fetch`, `Promise` and `FormData` to be present in the global scope. You are missing `fetch`, `Promise`, `FormData`. We recommend installing the `isomorphic-fetch`, `es6-promise`, `isomorphic-form-data` modules at the root of your application to add these to the global scope. See https://bit.ly/2KNwWaJ for more info."
|
263
|
+
);
|
264
|
+
});
|
265
|
+
|
266
|
+
it("should not throw if fetch is not present but a custom fetch is defined", done => {
|
267
|
+
Promise = oldPromise;
|
268
|
+
FormData = oldFormData;
|
269
|
+
|
270
|
+
const MockFetchResponse = {
|
271
|
+
ok: true,
|
272
|
+
json() {
|
273
|
+
return Promise.resolve(SharingRestInfo);
|
274
|
+
},
|
275
|
+
blob() {
|
276
|
+
return Promise.resolve(new Blob([JSON.stringify(SharingRestInfo)]));
|
277
|
+
},
|
278
|
+
text() {
|
279
|
+
return Promise.resolve(JSON.stringify(SharingRestInfo));
|
280
|
+
}
|
281
|
+
};
|
282
|
+
|
283
|
+
const MockFetch = function() {
|
284
|
+
return Promise.resolve(MockFetchResponse);
|
285
|
+
};
|
286
|
+
|
287
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
288
|
+
fetch: MockFetch as any
|
289
|
+
})
|
290
|
+
.then(response => {
|
291
|
+
expect(response).toEqual(SharingRestInfo);
|
292
|
+
done();
|
293
|
+
})
|
294
|
+
.catch(e => {
|
295
|
+
fail(e);
|
296
|
+
});
|
297
|
+
});
|
298
|
+
});
|
299
|
+
|
300
|
+
if (typeof window === "undefined") {
|
301
|
+
it("should tack on a generic referer header in Node.js only", done => {
|
302
|
+
fetchMock.once("*", WebMapAsJSON);
|
303
|
+
|
304
|
+
request("https://www.arcgis.com/sharing/rest/content/items/43a/data")
|
305
|
+
.then(() => {
|
306
|
+
expect(fetchMock.called()).toEqual(true);
|
307
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
308
|
+
expect(url).toEqual(
|
309
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a/data"
|
310
|
+
);
|
311
|
+
expect(options.method).toBe("POST");
|
312
|
+
expect(options.headers).toEqual({
|
313
|
+
referer: "@esri/arcgis-rest",
|
314
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
315
|
+
});
|
316
|
+
done();
|
317
|
+
})
|
318
|
+
.catch(e => {
|
319
|
+
fail(e);
|
320
|
+
});
|
321
|
+
});
|
322
|
+
}
|
323
|
+
});
|
@@ -0,0 +1,170 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { ArcGISAuthError, IRetryAuthError, ErrorTypes } from "../../src/index";
|
5
|
+
import { ArcGISOnlineAuthError, ArcGISOnlineError } from "./../mocks/errors";
|
6
|
+
import * as fetchMock from "fetch-mock";
|
7
|
+
|
8
|
+
describe("ArcGISRequestError", () => {
|
9
|
+
afterEach(fetchMock.restore);
|
10
|
+
|
11
|
+
it("should be an instanceof Error", () => {
|
12
|
+
expect(new ArcGISAuthError() instanceof Error).toBe(true);
|
13
|
+
});
|
14
|
+
|
15
|
+
it("should expose basic error properties", () => {
|
16
|
+
const error = new ArcGISAuthError(
|
17
|
+
ArcGISOnlineAuthError.error.message,
|
18
|
+
ArcGISOnlineAuthError.error.code,
|
19
|
+
ArcGISOnlineAuthError
|
20
|
+
);
|
21
|
+
|
22
|
+
expect(error.name).toBe("ArcGISAuthError");
|
23
|
+
expect(error.message).toBe("498: Invalid token.");
|
24
|
+
expect(error.code).toBe(498);
|
25
|
+
expect(error.originalMessage).toBe("Invalid token.");
|
26
|
+
expect(error.response).toEqual(ArcGISOnlineAuthError);
|
27
|
+
});
|
28
|
+
|
29
|
+
it("should still format without a message, code or response", () => {
|
30
|
+
const error = new ArcGISAuthError();
|
31
|
+
expect(error.message).toBe("AUTHENTICATION_ERROR");
|
32
|
+
expect(error.code).toEqual("AUTHENTICATION_ERROR_CODE");
|
33
|
+
expect(error.originalMessage).toBe("AUTHENTICATION_ERROR");
|
34
|
+
expect(error.response).toEqual(undefined);
|
35
|
+
});
|
36
|
+
|
37
|
+
describe("retry", () => {
|
38
|
+
const MockAuth: {
|
39
|
+
portal: string;
|
40
|
+
getToken: any;
|
41
|
+
retryHandler: IRetryAuthError;
|
42
|
+
} = {
|
43
|
+
portal: "https://www.arcgis.com/sharing/rest",
|
44
|
+
getToken() {
|
45
|
+
return Promise.resolve("token");
|
46
|
+
},
|
47
|
+
retryHandler(url, options) {
|
48
|
+
return Promise.resolve(MockAuth);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
it("should allow retrying a request with a new or updated session", done => {
|
53
|
+
const error = new ArcGISAuthError(
|
54
|
+
"Invalid token.",
|
55
|
+
498,
|
56
|
+
ArcGISAuthError,
|
57
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem",
|
58
|
+
{
|
59
|
+
httpMethod: "POST",
|
60
|
+
params: {
|
61
|
+
title: "Test Map",
|
62
|
+
tags: "foo",
|
63
|
+
type: "Web Map",
|
64
|
+
f: "json"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
);
|
68
|
+
|
69
|
+
fetchMock.once("*", {
|
70
|
+
success: true,
|
71
|
+
id: "abc",
|
72
|
+
folder: null
|
73
|
+
});
|
74
|
+
|
75
|
+
const retryHandlerSpy = spyOn(MockAuth, "retryHandler").and.callThrough();
|
76
|
+
|
77
|
+
error
|
78
|
+
.retry(MockAuth.retryHandler, 1)
|
79
|
+
.then((response: any) => {
|
80
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
81
|
+
expect(url).toEqual(
|
82
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem"
|
83
|
+
);
|
84
|
+
expect(options.method).toEqual("POST");
|
85
|
+
expect(retryHandlerSpy).toHaveBeenCalledTimes(1);
|
86
|
+
expect(options.body).toContain("token=token");
|
87
|
+
expect(options.body).toContain("tags=foo");
|
88
|
+
expect(options.body).toContain("f=json");
|
89
|
+
expect(response.success).toBe(true);
|
90
|
+
expect(response.id).toBe("abc");
|
91
|
+
expect(response.folder).toBe(null);
|
92
|
+
done();
|
93
|
+
})
|
94
|
+
.catch((e: any) => {
|
95
|
+
fail(e);
|
96
|
+
});
|
97
|
+
});
|
98
|
+
|
99
|
+
it("should retry a request with a new or updated session up to the limit", done => {
|
100
|
+
const error = new ArcGISAuthError(
|
101
|
+
"Invalid token.",
|
102
|
+
498,
|
103
|
+
ArcGISAuthError,
|
104
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem",
|
105
|
+
{
|
106
|
+
httpMethod: "POST",
|
107
|
+
params: {
|
108
|
+
title: "Test Map",
|
109
|
+
tags: "foo",
|
110
|
+
type: "Web Map",
|
111
|
+
f: "json"
|
112
|
+
}
|
113
|
+
}
|
114
|
+
);
|
115
|
+
|
116
|
+
fetchMock.post("*", ArcGISOnlineAuthError);
|
117
|
+
|
118
|
+
const retryHandlerSpy = spyOn(MockAuth, "retryHandler").and.callThrough();
|
119
|
+
|
120
|
+
error.retry(MockAuth.retryHandler).catch((e: any) => {
|
121
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
122
|
+
expect(url).toEqual(
|
123
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem"
|
124
|
+
);
|
125
|
+
expect(options.method).toEqual("POST");
|
126
|
+
expect(retryHandlerSpy).toHaveBeenCalledTimes(3);
|
127
|
+
expect(options.body).toContain("token=token");
|
128
|
+
expect(options.body).toContain("tags=foo");
|
129
|
+
expect(options.body).toContain("f=json");
|
130
|
+
expect(e.name).toBe(ErrorTypes.ArcGISAuthError);
|
131
|
+
expect(e.message).toBe("498: Invalid token.");
|
132
|
+
done();
|
133
|
+
});
|
134
|
+
});
|
135
|
+
|
136
|
+
it("should throw an error if retrying throws a non-auth error", done => {
|
137
|
+
const requestUrl =
|
138
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem";
|
139
|
+
const error = new ArcGISAuthError(
|
140
|
+
"Invalid token.",
|
141
|
+
498,
|
142
|
+
ArcGISAuthError,
|
143
|
+
requestUrl,
|
144
|
+
{
|
145
|
+
httpMethod: "POST",
|
146
|
+
params: {
|
147
|
+
type: "Web Map",
|
148
|
+
f: "json"
|
149
|
+
}
|
150
|
+
}
|
151
|
+
);
|
152
|
+
|
153
|
+
fetchMock.post("*", ArcGISOnlineError);
|
154
|
+
|
155
|
+
const retryHandlerSpy = spyOn(MockAuth, "retryHandler").and.callThrough();
|
156
|
+
|
157
|
+
error.retry(MockAuth.retryHandler).catch((e: any) => {
|
158
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
159
|
+
expect(url).toEqual(requestUrl);
|
160
|
+
expect(options.method).toEqual("POST");
|
161
|
+
expect(retryHandlerSpy).toHaveBeenCalledTimes(1);
|
162
|
+
expect(options.body).toContain("token=token");
|
163
|
+
expect(options.body).toContain("f=json");
|
164
|
+
expect(e.name).toBe(ErrorTypes.ArcGISRequestError);
|
165
|
+
expect(e.message).toBe("400: 'type' and 'title' property required.");
|
166
|
+
done();
|
167
|
+
});
|
168
|
+
});
|
169
|
+
});
|
170
|
+
});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { ArcGISRequestError } from "../../src/index";
|
5
|
+
import { ArcGISOnlineError } from "./../mocks/errors";
|
6
|
+
|
7
|
+
describe("ArcGISRequestError", () => {
|
8
|
+
it("should be an instanceof Error", () => {
|
9
|
+
expect(new ArcGISRequestError() instanceof Error).toBe(true);
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should expose basic error properties", () => {
|
13
|
+
const error = new ArcGISRequestError(
|
14
|
+
ArcGISOnlineError.error.message,
|
15
|
+
ArcGISOnlineError.error.code,
|
16
|
+
ArcGISOnlineError,
|
17
|
+
"https://example.com",
|
18
|
+
{
|
19
|
+
params: {
|
20
|
+
f: "json"
|
21
|
+
},
|
22
|
+
httpMethod: "POST"
|
23
|
+
}
|
24
|
+
);
|
25
|
+
|
26
|
+
expect(error.name).toBe("ArcGISRequestError");
|
27
|
+
expect(error.message).toBe("400: 'type' and 'title' property required.");
|
28
|
+
expect(error.code).toBe(400);
|
29
|
+
expect(error.originalMessage).toBe("'type' and 'title' property required.");
|
30
|
+
expect(error.response).toEqual(ArcGISOnlineError);
|
31
|
+
expect(error.url).toBe("https://example.com");
|
32
|
+
expect(error.options.params).toEqual({ f: "json" });
|
33
|
+
expect(error.options.httpMethod).toEqual("POST");
|
34
|
+
});
|
35
|
+
|
36
|
+
it("should still format without a message, code or response", () => {
|
37
|
+
const error = new ArcGISRequestError();
|
38
|
+
expect(error.message).toBe("UNKNOWN_ERROR");
|
39
|
+
expect(error.code).toEqual("UNKNOWN_ERROR_CODE");
|
40
|
+
expect(error.originalMessage).toBe("UNKNOWN_ERROR");
|
41
|
+
expect(error.response).toEqual(undefined);
|
42
|
+
});
|
43
|
+
|
44
|
+
it("should still format with a null or empty string message or code", () => {
|
45
|
+
const error = new ArcGISRequestError(null, "");
|
46
|
+
expect(error.message).toBe("UNKNOWN_ERROR");
|
47
|
+
expect(error.code).toEqual("UNKNOWN_ERROR_CODE");
|
48
|
+
expect(error.originalMessage).toBe("UNKNOWN_ERROR");
|
49
|
+
expect(error.response).toEqual(undefined);
|
50
|
+
});
|
51
|
+
});
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import {
|
5
|
+
checkForErrors,
|
6
|
+
warn,
|
7
|
+
ArcGISRequestError,
|
8
|
+
ArcGISAuthError
|
9
|
+
} from "../../src/index";
|
10
|
+
import { SharingRestInfo } from "./../mocks/sharing-rest-info";
|
11
|
+
import {
|
12
|
+
ArcGISOnlineError,
|
13
|
+
BillingError,
|
14
|
+
TaskErrorWithJSON,
|
15
|
+
TaskError,
|
16
|
+
ArcGISOnlineErrorNoMessageCode,
|
17
|
+
ArcGISOnlineErrorNoCode,
|
18
|
+
ArcGISServerTokenRequired,
|
19
|
+
ArcGISOnlineAuthError,
|
20
|
+
BillingErrorWithCode200
|
21
|
+
} from "./../mocks/errors";
|
22
|
+
|
23
|
+
describe("checkForErrors", () => {
|
24
|
+
it("should pass if an error is not found", () => {
|
25
|
+
expect(checkForErrors(SharingRestInfo)).toBe(SharingRestInfo);
|
26
|
+
});
|
27
|
+
|
28
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS REST API", () => {
|
29
|
+
expect(() => {
|
30
|
+
checkForErrors(ArcGISOnlineError);
|
31
|
+
}).toThrowError(
|
32
|
+
ArcGISRequestError,
|
33
|
+
"400: 'type' and 'title' property required."
|
34
|
+
);
|
35
|
+
});
|
36
|
+
|
37
|
+
it("should throw an ArcGISOnlineAuthError for an error from the ArcGIS REST API", () => {
|
38
|
+
expect(() => {
|
39
|
+
checkForErrors(ArcGISOnlineAuthError);
|
40
|
+
}).toThrowError(ArcGISAuthError, "498: Invalid token.");
|
41
|
+
});
|
42
|
+
|
43
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS REST API that has no messageCode", () => {
|
44
|
+
expect(() => {
|
45
|
+
checkForErrors(ArcGISOnlineErrorNoMessageCode);
|
46
|
+
}).toThrowError(
|
47
|
+
ArcGISRequestError,
|
48
|
+
"403: You do not have permissions to access this resource or perform this operation."
|
49
|
+
);
|
50
|
+
});
|
51
|
+
|
52
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS REST API that has no code", () => {
|
53
|
+
expect(() => {
|
54
|
+
checkForErrors(ArcGISOnlineErrorNoCode);
|
55
|
+
}).toThrowError(
|
56
|
+
ArcGISRequestError,
|
57
|
+
"You do not have permissions to access this resource or perform this operation."
|
58
|
+
);
|
59
|
+
});
|
60
|
+
|
61
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS Online Billing Backend", () => {
|
62
|
+
expect(() => {
|
63
|
+
checkForErrors(BillingError);
|
64
|
+
}).toThrowError(ArcGISRequestError, "500: Error getting subscription info");
|
65
|
+
});
|
66
|
+
|
67
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS Online Billing Backend with a failure status", () => {
|
68
|
+
expect(() => {
|
69
|
+
checkForErrors(BillingErrorWithCode200);
|
70
|
+
}).toThrowError(ArcGISRequestError, "UNKNOWN_ERROR");
|
71
|
+
});
|
72
|
+
|
73
|
+
it("should throw an ArcGISRequestError for an error when checking long running tasks in ArcGIS REST API", () => {
|
74
|
+
expect(() => {
|
75
|
+
checkForErrors(TaskErrorWithJSON);
|
76
|
+
}).toThrowError(
|
77
|
+
ArcGISRequestError,
|
78
|
+
"400: Index was outside the bounds of the array."
|
79
|
+
);
|
80
|
+
});
|
81
|
+
|
82
|
+
it("should throw an ArcGISRequestError for an error when checking long running tasks in ArcGIS REST API without a JSON statusMessage", () => {
|
83
|
+
expect(() => {
|
84
|
+
checkForErrors(TaskError);
|
85
|
+
}).toThrowError(ArcGISRequestError, "failed");
|
86
|
+
});
|
87
|
+
|
88
|
+
it("should throw an ArcGISAuthError instead of ArcGISRequestError for messageCode=GWM_0003", () => {
|
89
|
+
expect(() => {
|
90
|
+
checkForErrors(ArcGISServerTokenRequired);
|
91
|
+
}).toThrowError(ArcGISAuthError, "GWM_0003: Token Required");
|
92
|
+
});
|
93
|
+
});
|
94
|
+
|
95
|
+
describe("warn", () => {
|
96
|
+
it("should bubble up deprecation warnings", () => {
|
97
|
+
console.warn = jasmine.createSpy("warning");
|
98
|
+
warn("Danger Will Robinson!");
|
99
|
+
expect(console.warn).toHaveBeenCalledWith("Danger Will Robinson!");
|
100
|
+
});
|
101
|
+
});
|
102
|
+
|
103
|
+
describe("warn", () => {
|
104
|
+
it("should carry on gracefully when no console is available", () => {
|
105
|
+
const realConsoleWarn = console.warn;
|
106
|
+
console.warn = undefined;
|
107
|
+
warn("Danger Will Robinson!");
|
108
|
+
expect(console.warn).toBe(undefined);
|
109
|
+
console.warn = realConsoleWarn;
|
110
|
+
});
|
111
|
+
});
|