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,203 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import * as fetchMock from "fetch-mock";
|
5
|
+
|
6
|
+
import {
|
7
|
+
getAttachments,
|
8
|
+
IGetAttachmentsOptions,
|
9
|
+
addAttachment,
|
10
|
+
IAddAttachmentOptions,
|
11
|
+
updateAttachment,
|
12
|
+
IUpdateAttachmentOptions,
|
13
|
+
deleteAttachments,
|
14
|
+
IDeleteAttachmentsOptions
|
15
|
+
} from "../src/index";
|
16
|
+
|
17
|
+
import {
|
18
|
+
getAttachmentsResponse,
|
19
|
+
addAttachmentResponse,
|
20
|
+
updateAttachmentResponse,
|
21
|
+
deleteAttachmentsResponse,
|
22
|
+
genericInvalidResponse
|
23
|
+
} from "./mocks/feature";
|
24
|
+
|
25
|
+
export function attachmentFile() {
|
26
|
+
if (typeof File !== "undefined" && File) {
|
27
|
+
return new File(["foo"], "foo.txt", { type: "text/plain" });
|
28
|
+
} else {
|
29
|
+
const fs = require("fs");
|
30
|
+
return fs.createReadStream(
|
31
|
+
"./packages/arcgis-rest-feature-service/test/mocks/foo.txt"
|
32
|
+
);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
const serviceUrl =
|
37
|
+
"https://services.arcgis.com/f8b/arcgis/rest/services/Custom/FeatureServer/0";
|
38
|
+
|
39
|
+
describe("attachment methods", () => {
|
40
|
+
afterEach(fetchMock.restore);
|
41
|
+
|
42
|
+
it("should return an array of attachmentInfos for a feature by id", done => {
|
43
|
+
const requestOptions = {
|
44
|
+
url: serviceUrl,
|
45
|
+
featureId: 42,
|
46
|
+
params: {
|
47
|
+
gdbVersion: "SDE.DEFAULT"
|
48
|
+
},
|
49
|
+
httpMethod: "GET"
|
50
|
+
} as IGetAttachmentsOptions;
|
51
|
+
fetchMock.once("*", getAttachmentsResponse);
|
52
|
+
getAttachments(requestOptions)
|
53
|
+
.then(() => {
|
54
|
+
expect(fetchMock.called()).toBeTruthy();
|
55
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
56
|
+
expect(url).toEqual(
|
57
|
+
`${requestOptions.url}/${
|
58
|
+
requestOptions.featureId
|
59
|
+
}/attachments?f=json&gdbVersion=SDE.DEFAULT`
|
60
|
+
);
|
61
|
+
expect(options.method).toBe("GET");
|
62
|
+
expect(getAttachmentsResponse.attachmentInfos.length).toEqual(2);
|
63
|
+
expect(getAttachmentsResponse.attachmentInfos[0].id).toEqual(409);
|
64
|
+
done();
|
65
|
+
})
|
66
|
+
.catch(e => {
|
67
|
+
fail(e);
|
68
|
+
});
|
69
|
+
});
|
70
|
+
|
71
|
+
it("should return objectId of the added attachment and a truthy success", done => {
|
72
|
+
const requestOptions = {
|
73
|
+
url: serviceUrl,
|
74
|
+
featureId: 42,
|
75
|
+
attachment: attachmentFile(),
|
76
|
+
params: {
|
77
|
+
returnEditMoment: true
|
78
|
+
}
|
79
|
+
} as IAddAttachmentOptions;
|
80
|
+
fetchMock.once("*", addAttachmentResponse);
|
81
|
+
addAttachment(requestOptions)
|
82
|
+
.then(() => {
|
83
|
+
expect(fetchMock.called()).toBeTruthy();
|
84
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
85
|
+
expect(url).toEqual(
|
86
|
+
`${requestOptions.url}/${requestOptions.featureId}/addAttachment`
|
87
|
+
);
|
88
|
+
expect(options.method).toBe("POST");
|
89
|
+
|
90
|
+
const params = options.body as FormData;
|
91
|
+
expect(params instanceof FormData).toBeTruthy();
|
92
|
+
// we can introspect FormData in Chrome this way, but not Node.js
|
93
|
+
// more info: https://github.com/form-data/form-data/issues/124
|
94
|
+
if (params.get) {
|
95
|
+
expect(params.get("returnEditMoment")).toEqual("true");
|
96
|
+
}
|
97
|
+
expect(addAttachmentResponse.addAttachmentResult.objectId).toEqual(
|
98
|
+
1001
|
99
|
+
);
|
100
|
+
expect(addAttachmentResponse.addAttachmentResult.success).toEqual(true);
|
101
|
+
done();
|
102
|
+
})
|
103
|
+
.catch(e => {
|
104
|
+
fail(e);
|
105
|
+
});
|
106
|
+
});
|
107
|
+
|
108
|
+
it("should return an error for a service/feature which does not have attachments", done => {
|
109
|
+
const requestOptions = {
|
110
|
+
url:
|
111
|
+
"https://services.arcgis.com/f8b/arcgis/rest/services/NoAttachments/FeatureServer/0",
|
112
|
+
featureId: 654,
|
113
|
+
attachment: attachmentFile(),
|
114
|
+
params: {
|
115
|
+
returnEditMoment: true
|
116
|
+
}
|
117
|
+
} as IAddAttachmentOptions;
|
118
|
+
fetchMock.once("*", genericInvalidResponse);
|
119
|
+
addAttachment(requestOptions)
|
120
|
+
.then(() => {
|
121
|
+
// nothing to test here forcing error
|
122
|
+
fail();
|
123
|
+
})
|
124
|
+
.catch(error => {
|
125
|
+
expect(fetchMock.called()).toBeTruthy();
|
126
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
127
|
+
expect(url).toEqual(
|
128
|
+
`${requestOptions.url}/${requestOptions.featureId}/addAttachment`
|
129
|
+
);
|
130
|
+
expect(options.method).toBe("POST");
|
131
|
+
expect(error.response.error.code).toEqual(400);
|
132
|
+
expect(error.response.error.message).toEqual(
|
133
|
+
"Invalid or missing input parameters."
|
134
|
+
);
|
135
|
+
done();
|
136
|
+
});
|
137
|
+
});
|
138
|
+
|
139
|
+
it("should return objectId of the updated attachment and a truthy success", done => {
|
140
|
+
const requestOptions = {
|
141
|
+
url: serviceUrl,
|
142
|
+
featureId: 42,
|
143
|
+
attachmentId: 1001,
|
144
|
+
attachment: attachmentFile(),
|
145
|
+
params: {
|
146
|
+
returnEditMoment: true
|
147
|
+
}
|
148
|
+
} as IUpdateAttachmentOptions;
|
149
|
+
fetchMock.once("*", updateAttachmentResponse);
|
150
|
+
updateAttachment(requestOptions)
|
151
|
+
.then(() => {
|
152
|
+
expect(fetchMock.called()).toBeTruthy();
|
153
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
154
|
+
expect(url).toEqual(
|
155
|
+
`${requestOptions.url}/${requestOptions.featureId}/updateAttachment`
|
156
|
+
);
|
157
|
+
expect(options.method).toBe("POST");
|
158
|
+
expect(
|
159
|
+
updateAttachmentResponse.updateAttachmentResult.objectId
|
160
|
+
).toEqual(1001);
|
161
|
+
expect(updateAttachmentResponse.updateAttachmentResult.success).toEqual(
|
162
|
+
true
|
163
|
+
);
|
164
|
+
done();
|
165
|
+
})
|
166
|
+
.catch(e => {
|
167
|
+
fail(e);
|
168
|
+
});
|
169
|
+
});
|
170
|
+
|
171
|
+
it("should return objectId of the deleted attachment and a truthy success", done => {
|
172
|
+
const requestOptions = {
|
173
|
+
url: serviceUrl,
|
174
|
+
featureId: 42,
|
175
|
+
attachmentIds: [1001],
|
176
|
+
params: {
|
177
|
+
returnEditMoment: true
|
178
|
+
}
|
179
|
+
} as IDeleteAttachmentsOptions;
|
180
|
+
fetchMock.once("*", deleteAttachmentsResponse);
|
181
|
+
deleteAttachments(requestOptions)
|
182
|
+
.then(() => {
|
183
|
+
expect(fetchMock.called()).toBeTruthy();
|
184
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
185
|
+
expect(url).toEqual(
|
186
|
+
`${requestOptions.url}/${requestOptions.featureId}/deleteAttachments`
|
187
|
+
);
|
188
|
+
expect(options.body).toContain("attachmentIds=1001");
|
189
|
+
expect(options.body).toContain("returnEditMoment=true");
|
190
|
+
expect(options.method).toBe("POST");
|
191
|
+
expect(
|
192
|
+
deleteAttachmentsResponse.deleteAttachmentResults[0].objectId
|
193
|
+
).toEqual(1001);
|
194
|
+
expect(
|
195
|
+
deleteAttachmentsResponse.deleteAttachmentResults[0].success
|
196
|
+
).toEqual(true);
|
197
|
+
done();
|
198
|
+
})
|
199
|
+
.catch(e => {
|
200
|
+
fail(e);
|
201
|
+
});
|
202
|
+
});
|
203
|
+
});
|
@@ -0,0 +1,263 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import {
|
5
|
+
addFeatures,
|
6
|
+
updateFeatures,
|
7
|
+
deleteFeatures,
|
8
|
+
IDeleteFeaturesRequestOptions,
|
9
|
+
IUpdateFeaturesRequestOptions
|
10
|
+
} from "../src/index";
|
11
|
+
|
12
|
+
import * as fetchMock from "fetch-mock";
|
13
|
+
|
14
|
+
import {
|
15
|
+
addFeaturesResponse,
|
16
|
+
updateFeaturesResponse,
|
17
|
+
deleteFeaturesResponse
|
18
|
+
} from "./mocks/feature";
|
19
|
+
|
20
|
+
const serviceUrl =
|
21
|
+
"https://services.arcgis.com/f8b/arcgis/rest/services/Custom/FeatureServer/0";
|
22
|
+
|
23
|
+
describe("feature", () => {
|
24
|
+
afterEach(fetchMock.restore);
|
25
|
+
|
26
|
+
it("should return objectId of the added feature and a truthy success", done => {
|
27
|
+
const requestOptions = {
|
28
|
+
url: serviceUrl,
|
29
|
+
features: [
|
30
|
+
{
|
31
|
+
geometry: {
|
32
|
+
x: -9177311.62541634,
|
33
|
+
y: 4247151.205222242,
|
34
|
+
spatialReference: {
|
35
|
+
wkid: 102100,
|
36
|
+
latestWkid: 3857
|
37
|
+
}
|
38
|
+
},
|
39
|
+
attributes: {
|
40
|
+
Tree_ID: 102,
|
41
|
+
Collected: 1349395200000,
|
42
|
+
Crew: "Linden+ Forrest+ Johnny"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
]
|
46
|
+
};
|
47
|
+
fetchMock.once("*", addFeaturesResponse);
|
48
|
+
addFeatures(requestOptions)
|
49
|
+
.then(response => {
|
50
|
+
expect(fetchMock.called()).toBeTruthy();
|
51
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
52
|
+
expect(url).toEqual(`${requestOptions.url}/addFeatures`);
|
53
|
+
expect(options.body).toContain(
|
54
|
+
"features=" +
|
55
|
+
encodeURIComponent(
|
56
|
+
'[{"geometry":{"x":-9177311.62541634,"y":4247151.205222242,"spatialReference":{"wkid":102100,"latestWkid":3857}},"attributes":{"Tree_ID":102,"Collected":1349395200000,"Crew":"Linden+ Forrest+ Johnny"}}]'
|
57
|
+
)
|
58
|
+
);
|
59
|
+
expect(options.method).toBe("POST");
|
60
|
+
expect(response.addResults[0].objectId).toEqual(1001);
|
61
|
+
expect(response.addResults[0].success).toEqual(true);
|
62
|
+
done();
|
63
|
+
})
|
64
|
+
.catch(e => {
|
65
|
+
fail(e);
|
66
|
+
});
|
67
|
+
});
|
68
|
+
|
69
|
+
it("should return objectId of the updated feature and a truthy success", done => {
|
70
|
+
const requestOptions = {
|
71
|
+
url: serviceUrl,
|
72
|
+
features: [
|
73
|
+
{
|
74
|
+
attributes: {
|
75
|
+
OBJECTID: 1001,
|
76
|
+
Street: "NO",
|
77
|
+
Native: "YES"
|
78
|
+
}
|
79
|
+
}
|
80
|
+
],
|
81
|
+
rollbackOnFailure: false
|
82
|
+
} as IUpdateFeaturesRequestOptions;
|
83
|
+
fetchMock.once("*", updateFeaturesResponse);
|
84
|
+
updateFeatures(requestOptions)
|
85
|
+
.then(response => {
|
86
|
+
expect(fetchMock.called()).toBeTruthy();
|
87
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
88
|
+
expect(url).toEqual(`${requestOptions.url}/updateFeatures`);
|
89
|
+
expect(options.method).toBe("POST");
|
90
|
+
expect(options.body).toContain(
|
91
|
+
"features=" +
|
92
|
+
encodeURIComponent(
|
93
|
+
'[{"attributes":{"OBJECTID":1001,"Street":"NO","Native":"YES"}}]'
|
94
|
+
)
|
95
|
+
);
|
96
|
+
expect(options.body).toContain("rollbackOnFailure=false");
|
97
|
+
expect(response.updateResults[0].success).toEqual(true);
|
98
|
+
done();
|
99
|
+
})
|
100
|
+
.catch(e => {
|
101
|
+
fail(e);
|
102
|
+
});
|
103
|
+
});
|
104
|
+
|
105
|
+
it("should return objectId of the deleted feature and a truthy success", done => {
|
106
|
+
const requestOptions = {
|
107
|
+
url: serviceUrl,
|
108
|
+
objectIds: [1001],
|
109
|
+
where: "1=1"
|
110
|
+
} as IDeleteFeaturesRequestOptions;
|
111
|
+
fetchMock.once("*", deleteFeaturesResponse);
|
112
|
+
deleteFeatures(requestOptions)
|
113
|
+
.then(response => {
|
114
|
+
expect(fetchMock.called()).toBeTruthy();
|
115
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
116
|
+
expect(url).toEqual(`${requestOptions.url}/deleteFeatures`);
|
117
|
+
expect(options.body).toContain("objectIds=1001");
|
118
|
+
expect(options.body).toContain("where=1%3D1");
|
119
|
+
expect(options.method).toBe("POST");
|
120
|
+
expect(response.deleteResults[0].objectId).toEqual(
|
121
|
+
requestOptions.objectIds[0]
|
122
|
+
);
|
123
|
+
expect(response.deleteResults[0].success).toEqual(true);
|
124
|
+
done();
|
125
|
+
})
|
126
|
+
.catch(e => {
|
127
|
+
fail(e);
|
128
|
+
});
|
129
|
+
});
|
130
|
+
|
131
|
+
// tests for depreciated params
|
132
|
+
// remove when `adds`, `updates` and `deletes` params removed
|
133
|
+
it("should return objectId of the added feature and a truthy success", done => {
|
134
|
+
const requestOptions = {
|
135
|
+
url: serviceUrl,
|
136
|
+
features: [
|
137
|
+
{
|
138
|
+
geometry: {
|
139
|
+
x: -9177311.62541634,
|
140
|
+
y: 4247151.205222242,
|
141
|
+
spatialReference: {
|
142
|
+
wkid: 102100,
|
143
|
+
latestWkid: 3857
|
144
|
+
}
|
145
|
+
},
|
146
|
+
attributes: {
|
147
|
+
Tree_ID: 102,
|
148
|
+
Collected: 1349395200000,
|
149
|
+
Crew: "Linden+ Forrest+ Johnny"
|
150
|
+
}
|
151
|
+
}
|
152
|
+
], // for linting
|
153
|
+
adds: [
|
154
|
+
{
|
155
|
+
geometry: {
|
156
|
+
x: -9177311.62541634,
|
157
|
+
y: 4247151.205222242,
|
158
|
+
spatialReference: {
|
159
|
+
wkid: 102100,
|
160
|
+
latestWkid: 3857
|
161
|
+
}
|
162
|
+
},
|
163
|
+
attributes: {
|
164
|
+
Tree_ID: 102,
|
165
|
+
Collected: 1349395200000,
|
166
|
+
Crew: "Linden+ Forrest+ Johnny"
|
167
|
+
}
|
168
|
+
}
|
169
|
+
]
|
170
|
+
};
|
171
|
+
fetchMock.once("*", addFeaturesResponse);
|
172
|
+
addFeatures(requestOptions)
|
173
|
+
.then(response => {
|
174
|
+
expect(fetchMock.called()).toBeTruthy();
|
175
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
176
|
+
expect(url).toEqual(`${requestOptions.url}/addFeatures`);
|
177
|
+
expect(options.body).toContain(
|
178
|
+
"features=" +
|
179
|
+
encodeURIComponent(
|
180
|
+
'[{"geometry":{"x":-9177311.62541634,"y":4247151.205222242,"spatialReference":{"wkid":102100,"latestWkid":3857}},"attributes":{"Tree_ID":102,"Collected":1349395200000,"Crew":"Linden+ Forrest+ Johnny"}}]'
|
181
|
+
)
|
182
|
+
);
|
183
|
+
expect(options.method).toBe("POST");
|
184
|
+
expect(response.addResults[0].objectId).toEqual(1001);
|
185
|
+
expect(response.addResults[0].success).toEqual(true);
|
186
|
+
done();
|
187
|
+
})
|
188
|
+
.catch(e => {
|
189
|
+
fail(e);
|
190
|
+
});
|
191
|
+
});
|
192
|
+
|
193
|
+
it("should return objectId of the updated feature and a truthy success", done => {
|
194
|
+
const requestOptions = {
|
195
|
+
url: serviceUrl,
|
196
|
+
features: [
|
197
|
+
{
|
198
|
+
attributes: {
|
199
|
+
OBJECTID: 1001,
|
200
|
+
Street: "NO",
|
201
|
+
Native: "YES"
|
202
|
+
}
|
203
|
+
}
|
204
|
+
], // for linting
|
205
|
+
updates: [
|
206
|
+
{
|
207
|
+
attributes: {
|
208
|
+
OBJECTID: 1001,
|
209
|
+
Street: "NO",
|
210
|
+
Native: "YES"
|
211
|
+
}
|
212
|
+
}
|
213
|
+
],
|
214
|
+
rollbackOnFailure: false
|
215
|
+
} as IUpdateFeaturesRequestOptions;
|
216
|
+
fetchMock.once("*", updateFeaturesResponse);
|
217
|
+
updateFeatures(requestOptions)
|
218
|
+
.then(response => {
|
219
|
+
expect(fetchMock.called()).toBeTruthy();
|
220
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
221
|
+
expect(url).toEqual(`${requestOptions.url}/updateFeatures`);
|
222
|
+
expect(options.method).toBe("POST");
|
223
|
+
expect(options.body).toContain(
|
224
|
+
"features=" +
|
225
|
+
encodeURIComponent(
|
226
|
+
'[{"attributes":{"OBJECTID":1001,"Street":"NO","Native":"YES"}}]'
|
227
|
+
)
|
228
|
+
);
|
229
|
+
expect(options.body).toContain("rollbackOnFailure=false");
|
230
|
+
expect(response.updateResults[0].success).toEqual(true);
|
231
|
+
done();
|
232
|
+
})
|
233
|
+
.catch(e => {
|
234
|
+
fail(e);
|
235
|
+
});
|
236
|
+
});
|
237
|
+
|
238
|
+
it("should return objectId of the deleted feature and a truthy success", done => {
|
239
|
+
const requestOptions = {
|
240
|
+
url: serviceUrl,
|
241
|
+
deletes: [1001],
|
242
|
+
where: "1=1"
|
243
|
+
} as IDeleteFeaturesRequestOptions;
|
244
|
+
fetchMock.once("*", deleteFeaturesResponse);
|
245
|
+
deleteFeatures(requestOptions)
|
246
|
+
.then(response => {
|
247
|
+
expect(fetchMock.called()).toBeTruthy();
|
248
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
249
|
+
expect(url).toEqual(`${requestOptions.url}/deleteFeatures`);
|
250
|
+
expect(options.body).toContain("objectIds=1001");
|
251
|
+
expect(options.body).toContain("where=1%3D1");
|
252
|
+
expect(options.method).toBe("POST");
|
253
|
+
expect(response.deleteResults[0].objectId).toEqual(
|
254
|
+
requestOptions.deletes[0]
|
255
|
+
);
|
256
|
+
expect(response.deleteResults[0].success).toEqual(true);
|
257
|
+
done();
|
258
|
+
})
|
259
|
+
.catch(e => {
|
260
|
+
fail(e);
|
261
|
+
});
|
262
|
+
});
|
263
|
+
});
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { decodeValues } from "../src/decodeValues";
|
5
|
+
|
6
|
+
import * as fetchMock from "fetch-mock";
|
7
|
+
|
8
|
+
import {
|
9
|
+
cvdQueryResponse,
|
10
|
+
cvdFeaturesFormatted
|
11
|
+
} from "./mocks/cvdQueryResponse";
|
12
|
+
import { cvdServiceFields, serviceFields } from "./mocks/fields";
|
13
|
+
import { getFeatureServiceResponse } from "./mocks/service";
|
14
|
+
import { queryResponse } from "./mocks/feature";
|
15
|
+
|
16
|
+
const serviceUrl =
|
17
|
+
"https://services.arcgis.com/f8b/arcgis/rest/services/Custom/FeatureServer/0";
|
18
|
+
|
19
|
+
describe("formatCodedValues()", () => {
|
20
|
+
afterEach(fetchMock.restore);
|
21
|
+
|
22
|
+
it("should format the cvd codes in a raw response", done => {
|
23
|
+
decodeValues({
|
24
|
+
url: serviceUrl,
|
25
|
+
fields: cvdServiceFields,
|
26
|
+
queryResponse: cvdQueryResponse
|
27
|
+
})
|
28
|
+
.then(response => {
|
29
|
+
expect(response.features[0]).toEqual(cvdFeaturesFormatted[0]);
|
30
|
+
done();
|
31
|
+
})
|
32
|
+
.catch(e => {
|
33
|
+
fail(e);
|
34
|
+
});
|
35
|
+
});
|
36
|
+
|
37
|
+
it("should return the original response if there are no coded value domains", done => {
|
38
|
+
decodeValues({
|
39
|
+
url: serviceUrl,
|
40
|
+
fields: serviceFields,
|
41
|
+
queryResponse
|
42
|
+
})
|
43
|
+
.then(response => {
|
44
|
+
expect(response).toEqual(queryResponse);
|
45
|
+
done();
|
46
|
+
})
|
47
|
+
.catch(e => {
|
48
|
+
fail(e);
|
49
|
+
});
|
50
|
+
});
|
51
|
+
|
52
|
+
it("should fetch metadata and then format cvd codes in a raw response", done => {
|
53
|
+
fetchMock.once("*", getFeatureServiceResponse);
|
54
|
+
|
55
|
+
decodeValues({
|
56
|
+
url: serviceUrl,
|
57
|
+
queryResponse: cvdQueryResponse
|
58
|
+
})
|
59
|
+
.then(response => {
|
60
|
+
expect(response.features[0]).toEqual(cvdFeaturesFormatted[0]);
|
61
|
+
done();
|
62
|
+
})
|
63
|
+
.catch(e => {
|
64
|
+
fail(e);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { getLayer } from "../src/getLayer";
|
5
|
+
|
6
|
+
import * as fetchMock from "fetch-mock";
|
7
|
+
|
8
|
+
import { getFeatureServiceResponse } from "./mocks/service";
|
9
|
+
|
10
|
+
const layerUrl =
|
11
|
+
"https://services.arcgis.com/f8b/arcgis/rest/services/Custom/FeatureServer/0";
|
12
|
+
|
13
|
+
describe("feature", () => {
|
14
|
+
afterEach(fetchMock.restore);
|
15
|
+
|
16
|
+
it("should fetch service metadata", done => {
|
17
|
+
fetchMock.once("*", getFeatureServiceResponse);
|
18
|
+
getLayer(layerUrl)
|
19
|
+
.then(response => {
|
20
|
+
expect(fetchMock.called()).toBeTruthy();
|
21
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
22
|
+
expect(url).toEqual(layerUrl);
|
23
|
+
expect(options.method).toBe("POST");
|
24
|
+
expect(response).toEqual(getFeatureServiceResponse);
|
25
|
+
done();
|
26
|
+
})
|
27
|
+
.catch(e => {
|
28
|
+
fail(e);
|
29
|
+
});
|
30
|
+
});
|
31
|
+
});
|