etincidunt 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 +29 -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 +172 -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 +14 -0
- package/demos/batch-geocoder-node/batch-geocode.js +112 -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 +37 -0
- package/demos/express/README.md +10 -0
- package/demos/express/config.json.template +3 -0
- package/demos/express/package-lock.json +388 -0
- package/demos/express/package.json +18 -0
- package/demos/express/server.js +28 -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 +163 -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 +8 -0
- package/demos/jsapi-integration/config.js +6 -0
- package/demos/jsapi-integration/index.html +79 -0
- package/demos/jsapi-integration/package-lock.json +184 -0
- package/demos/jsapi-integration/package.json +19 -0
- package/demos/oauth2-browser/README.md +12 -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/vue/.babelrc +6 -0
- package/demos/vue/.env.example +8 -0
- package/demos/vue/README.md +17 -0
- package/demos/vue/index.html +21 -0
- package/demos/vue/package-lock.json +7236 -0
- package/demos/vue/package.json +39 -0
- package/demos/vue/src/assets/logo.svg +29 -0
- package/demos/vue/src/components/App.vue +302 -0
- package/demos/vue/src/components/Authenticate.vue +68 -0
- package/demos/vue/src/components/Loader.vue +216 -0
- package/demos/vue/src/main.js +75 -0
- package/demos/vue/webpack.config.js +84 -0
- package/docs/FAQ.md +28 -0
- package/docs/HISTORY.md +62 -0
- package/docs/acetate.config.js +214 -0
- package/docs/build-typedoc.js +301 -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 +9 -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 +30 -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 +113 -0
- package/docs/src/js/index.js +1 -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 +91 -0
- package/packages/arcgis-rest-auth/README.md +64 -0
- package/packages/arcgis-rest-auth/package-lock.json +11 -0
- package/packages/arcgis-rest-auth/package.json +51 -0
- package/packages/arcgis-rest-auth/src/ApplicationSession.ts +91 -0
- package/packages/arcgis-rest-auth/src/UserSession.ts +829 -0
- package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +21 -0
- package/packages/arcgis-rest-auth/src/fetch-token.ts +55 -0
- package/packages/arcgis-rest-auth/src/generate-token.ts +36 -0
- package/packages/arcgis-rest-auth/src/index.ts +5 -0
- package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +121 -0
- package/packages/arcgis-rest-auth/test/UserSession.test.ts +883 -0
- package/packages/arcgis-rest-auth/test/fetchToken.test.ts +76 -0
- package/packages/arcgis-rest-auth/test/generateToken.test.ts +36 -0
- package/packages/arcgis-rest-auth/test/utils.ts +11 -0
- package/packages/arcgis-rest-auth/tsconfig.json +6 -0
- package/packages/arcgis-rest-common-types/README.md +61 -0
- package/packages/arcgis-rest-common-types/package.json +38 -0
- package/packages/arcgis-rest-common-types/src/group.ts +51 -0
- package/packages/arcgis-rest-common-types/src/index.ts +467 -0
- package/packages/arcgis-rest-common-types/src/item.ts +45 -0
- package/packages/arcgis-rest-common-types/src/webmap.ts +1225 -0
- package/packages/arcgis-rest-common-types/tsconfig.json +11 -0
- package/packages/arcgis-rest-feature-service/README.md +70 -0
- package/packages/arcgis-rest-feature-service/package-lock.json +11 -0
- package/packages/arcgis-rest-feature-service/package.json +50 -0
- package/packages/arcgis-rest-feature-service/src/add.ts +82 -0
- package/packages/arcgis-rest-feature-service/src/addAttachment.ts +65 -0
- package/packages/arcgis-rest-feature-service/src/delete.ts +85 -0
- package/packages/arcgis-rest-feature-service/src/deleteAttachments.ts +68 -0
- package/packages/arcgis-rest-feature-service/src/getAttachments.ts +64 -0
- package/packages/arcgis-rest-feature-service/src/helpers.ts +77 -0
- package/packages/arcgis-rest-feature-service/src/index.ts +8 -0
- package/packages/arcgis-rest-feature-service/src/query.ts +174 -0
- package/packages/arcgis-rest-feature-service/src/update.ts +81 -0
- package/packages/arcgis-rest-feature-service/src/updateAttachment.ts +74 -0
- package/packages/arcgis-rest-feature-service/test/attachments.test.ts +179 -0
- package/packages/arcgis-rest-feature-service/test/features.test.ts +172 -0
- package/packages/arcgis-rest-feature-service/test/mocks/feature.ts +220 -0
- package/packages/arcgis-rest-feature-service/test/mocks/foo.txt +1 -0
- package/packages/arcgis-rest-feature-service/tsconfig.json +6 -0
- package/packages/arcgis-rest-geocoder/README.md +73 -0
- package/packages/arcgis-rest-geocoder/package-lock.json +11 -0
- package/packages/arcgis-rest-geocoder/package.json +52 -0
- package/packages/arcgis-rest-geocoder/src/bulk.ts +102 -0
- package/packages/arcgis-rest-geocoder/src/geocode.ts +117 -0
- package/packages/arcgis-rest-geocoder/src/helpers.ts +81 -0
- package/packages/arcgis-rest-geocoder/src/index.ts +4 -0
- package/packages/arcgis-rest-geocoder/src/reverse.ts +84 -0
- package/packages/arcgis-rest-geocoder/src/suggest.ts +72 -0
- package/packages/arcgis-rest-geocoder/test/geocoder.test.ts +510 -0
- package/packages/arcgis-rest-geocoder/test/mocks/responses.ts +588 -0
- package/packages/arcgis-rest-geocoder/tsconfig.json +6 -0
- package/packages/arcgis-rest-groups/README.md +64 -0
- package/packages/arcgis-rest-groups/package-lock.json +11 -0
- package/packages/arcgis-rest-groups/package.json +52 -0
- package/packages/arcgis-rest-groups/src/groups.ts +272 -0
- package/packages/arcgis-rest-groups/src/index.ts +1 -0
- package/packages/arcgis-rest-groups/test/groups.test.ts +280 -0
- package/packages/arcgis-rest-groups/test/mocks/responses.ts +137 -0
- package/packages/arcgis-rest-groups/tsconfig.json +6 -0
- package/packages/arcgis-rest-items/README.md +66 -0
- package/packages/arcgis-rest-items/package-lock.json +11 -0
- package/packages/arcgis-rest-items/package.json +52 -0
- package/packages/arcgis-rest-items/src/index.ts +1 -0
- package/packages/arcgis-rest-items/src/items.ts +498 -0
- package/packages/arcgis-rest-items/test/items.test.ts +1153 -0
- package/packages/arcgis-rest-items/test/mocks/foo.zip +0 -0
- package/packages/arcgis-rest-items/test/mocks/item.ts +30 -0
- package/packages/arcgis-rest-items/test/mocks/resources.ts +28 -0
- package/packages/arcgis-rest-items/test/mocks/search.ts +60 -0
- package/packages/arcgis-rest-items/tsconfig.json +6 -0
- package/packages/arcgis-rest-request/README.md +65 -0
- package/packages/arcgis-rest-request/package-lock.json +11 -0
- package/packages/arcgis-rest-request/package.json +42 -0
- package/packages/arcgis-rest-request/src/index.ts +10 -0
- package/packages/arcgis-rest-request/src/request.ts +259 -0
- package/packages/arcgis-rest-request/src/utils/ArcGISAuthError.ts +67 -0
- package/packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts +73 -0
- package/packages/arcgis-rest-request/src/utils/ErrorTypes.ts +29 -0
- package/packages/arcgis-rest-request/src/utils/check-for-errors.ts +65 -0
- package/packages/arcgis-rest-request/src/utils/encode-form-data.ts +29 -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/process-params.ts +99 -0
- package/packages/arcgis-rest-request/test/mocks/errors.ts +59 -0
- package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +10 -0
- package/packages/arcgis-rest-request/test/mocks/portal.ts +109 -0
- package/packages/arcgis-rest-request/test/mocks/sharing-rest-info.ts +38 -0
- package/packages/arcgis-rest-request/test/mocks/webmap.ts +38 -0
- package/packages/arcgis-rest-request/test/request.test.ts +296 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +167 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISRequestError.test.ts +40 -0
- package/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +101 -0
- package/packages/arcgis-rest-request/test/utils/encode-form-data.test.ts +112 -0
- package/packages/arcgis-rest-request/test/utils/get-portal-url.test.ts +34 -0
- package/packages/arcgis-rest-request/test/utils/portal.test.ts +94 -0
- package/packages/arcgis-rest-request/test/utils/process-params.test.ts +190 -0
- package/packages/arcgis-rest-request/tsconfig.json +6 -0
- package/packages/arcgis-rest-sharing/README.md +67 -0
- package/packages/arcgis-rest-sharing/package-lock.json +11 -0
- package/packages/arcgis-rest-sharing/package.json +55 -0
- package/packages/arcgis-rest-sharing/src/access.ts +91 -0
- package/packages/arcgis-rest-sharing/src/group-sharing.ts +212 -0
- package/packages/arcgis-rest-sharing/src/helpers.ts +92 -0
- package/packages/arcgis-rest-sharing/src/index.ts +2 -0
- package/packages/arcgis-rest-sharing/test/access.test.ts +153 -0
- package/packages/arcgis-rest-sharing/test/group-sharing.test.ts +436 -0
- package/packages/arcgis-rest-sharing/test/mocks/sharing.ts +15 -0
- package/packages/arcgis-rest-sharing/tsconfig.json +6 -0
- package/packages/arcgis-rest-users/README.md +71 -0
- package/packages/arcgis-rest-users/package-lock.json +11 -0
- package/packages/arcgis-rest-users/package.json +51 -0
- package/packages/arcgis-rest-users/src/index.ts +1 -0
- package/packages/arcgis-rest-users/src/users.ts +70 -0
- package/packages/arcgis-rest-users/test/mocks/responses.ts +170 -0
- package/packages/arcgis-rest-users/test/users.test.ts +97 -0
- package/packages/arcgis-rest-users/tsconfig.json +6 -0
- package/support/FormData.d.ts +1 -0
- package/support/changelog.js +388 -0
- package/support/commit-template.txt +19 -0
- package/support/deploy-doc-site.js +16 -0
- package/support/publish.sh +40 -0
- package/support/test-helpers.js +8 -0
- package/tsconfig.json +69 -0
- package/tslint.json +14 -0
- package/umd-base-profile.js +82 -0
- package/umd-production-profile.js +13 -0
@@ -0,0 +1,1153 @@
|
|
1
|
+
import * as fetchMock from "fetch-mock";
|
2
|
+
|
3
|
+
import { attachmentFile } from "../../arcgis-rest-feature-service/test/attachments.test";
|
4
|
+
|
5
|
+
import {
|
6
|
+
searchItems,
|
7
|
+
getItem,
|
8
|
+
getItemData,
|
9
|
+
removeItem,
|
10
|
+
createItem,
|
11
|
+
createItemInFolder,
|
12
|
+
updateItem,
|
13
|
+
addItemJsonData,
|
14
|
+
addItemData,
|
15
|
+
protectItem,
|
16
|
+
unprotectItem,
|
17
|
+
getItemResources,
|
18
|
+
updateItemResource,
|
19
|
+
removeItemResource,
|
20
|
+
ISearchRequestOptions
|
21
|
+
} from "../src/index";
|
22
|
+
|
23
|
+
import {
|
24
|
+
ItemSuccessResponse,
|
25
|
+
ItemResponse,
|
26
|
+
ItemDataResponse
|
27
|
+
} from "./mocks/item";
|
28
|
+
|
29
|
+
import {
|
30
|
+
GetItemResourcesResponse,
|
31
|
+
UpdateItemResourceResponse,
|
32
|
+
RemoveItemResourceResponse
|
33
|
+
} from "./mocks/resources";
|
34
|
+
|
35
|
+
import { SearchResponse } from "./mocks/search";
|
36
|
+
import { UserSession } from "@esri/arcgis-rest-auth";
|
37
|
+
import { TOMORROW } from "@esri/arcgis-rest-auth/test/utils";
|
38
|
+
import { encodeParam } from "@esri/arcgis-rest-request";
|
39
|
+
|
40
|
+
describe("search", () => {
|
41
|
+
afterEach(fetchMock.restore);
|
42
|
+
|
43
|
+
it("should make a simple, single search request", done => {
|
44
|
+
fetchMock.once("*", SearchResponse);
|
45
|
+
|
46
|
+
searchItems("DC AND typekeywords:hubSiteApplication")
|
47
|
+
.then(response => {
|
48
|
+
expect(fetchMock.called()).toEqual(true);
|
49
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
50
|
+
expect(url).toEqual(
|
51
|
+
"https://www.arcgis.com/sharing/rest/search?f=json&q=DC%20AND%20typekeywords%3AhubSiteApplication"
|
52
|
+
);
|
53
|
+
expect(options.method).toBe("GET");
|
54
|
+
done();
|
55
|
+
})
|
56
|
+
.catch(e => {
|
57
|
+
fail(e);
|
58
|
+
});
|
59
|
+
});
|
60
|
+
|
61
|
+
it("should take num, start, sortField, sortDir and construct the request", done => {
|
62
|
+
fetchMock.once("*", SearchResponse);
|
63
|
+
|
64
|
+
searchItems({
|
65
|
+
searchForm: {
|
66
|
+
q: "DC AND typekeywords:hubSiteApplication",
|
67
|
+
num: 12,
|
68
|
+
start: 22,
|
69
|
+
sortField: "title",
|
70
|
+
sortDir: "desc"
|
71
|
+
}
|
72
|
+
})
|
73
|
+
.then(response => {
|
74
|
+
expect(fetchMock.called()).toEqual(true);
|
75
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
76
|
+
expect(url).toEqual(
|
77
|
+
"https://www.arcgis.com/sharing/rest/search?f=json&q=DC%20AND%20typekeywords%3AhubSiteApplication&num=12&start=22&sortField=title&sortDir=desc"
|
78
|
+
);
|
79
|
+
expect(options.method).toBe("GET");
|
80
|
+
done();
|
81
|
+
})
|
82
|
+
.catch(e => {
|
83
|
+
fail(e);
|
84
|
+
});
|
85
|
+
});
|
86
|
+
|
87
|
+
it("should pass through other requestOptions at the same time", done => {
|
88
|
+
fetchMock.once("*", SearchResponse);
|
89
|
+
|
90
|
+
searchItems({
|
91
|
+
searchForm: {
|
92
|
+
q: "DC AND typekeywords:hubSiteApplication",
|
93
|
+
num: 12,
|
94
|
+
start: 22,
|
95
|
+
sortField: "title",
|
96
|
+
sortDir: "desc"
|
97
|
+
},
|
98
|
+
httpMethod: "POST"
|
99
|
+
})
|
100
|
+
.then(response => {
|
101
|
+
expect(fetchMock.called()).toEqual(true);
|
102
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
103
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/search");
|
104
|
+
expect(options.body).toContain(
|
105
|
+
"q=DC%20AND%20typekeywords%3AhubSiteApplication&num=12&start=22&sortField=title&sortDir=desc"
|
106
|
+
);
|
107
|
+
expect(options.method).toBe("POST");
|
108
|
+
done();
|
109
|
+
})
|
110
|
+
.catch(e => {
|
111
|
+
fail(e);
|
112
|
+
});
|
113
|
+
});
|
114
|
+
|
115
|
+
it("should return an item by id", done => {
|
116
|
+
fetchMock.once("*", ItemResponse);
|
117
|
+
|
118
|
+
getItem("3ef")
|
119
|
+
.then(response => {
|
120
|
+
expect(fetchMock.called()).toEqual(true);
|
121
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
122
|
+
expect(url).toEqual(
|
123
|
+
"https://www.arcgis.com/sharing/rest/content/items/3ef?f=json"
|
124
|
+
);
|
125
|
+
expect(options.method).toBe("GET");
|
126
|
+
done();
|
127
|
+
})
|
128
|
+
.catch(e => {
|
129
|
+
fail(e);
|
130
|
+
});
|
131
|
+
});
|
132
|
+
|
133
|
+
it("should return an item data by id", done => {
|
134
|
+
fetchMock.once("*", ItemDataResponse);
|
135
|
+
|
136
|
+
getItemData("3ef")
|
137
|
+
.then(response => {
|
138
|
+
expect(fetchMock.called()).toEqual(true);
|
139
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
140
|
+
expect(url).toEqual(
|
141
|
+
"https://www.arcgis.com/sharing/rest/content/items/3ef/data?f=json"
|
142
|
+
);
|
143
|
+
expect(options.method).toBe("GET");
|
144
|
+
done();
|
145
|
+
})
|
146
|
+
.catch(e => {
|
147
|
+
fail(e);
|
148
|
+
});
|
149
|
+
});
|
150
|
+
|
151
|
+
it("should return binary item data by id", done => {
|
152
|
+
// Blob() is only available in the browser
|
153
|
+
if (typeof window !== "undefined") {
|
154
|
+
fetchMock.once("*", {
|
155
|
+
sendAsJson: false,
|
156
|
+
headers: { "Content-Type": "application/zip" },
|
157
|
+
body: new Blob()
|
158
|
+
});
|
159
|
+
|
160
|
+
getItemData("3ef", { file: true })
|
161
|
+
.then(response => {
|
162
|
+
expect(fetchMock.called()).toEqual(true);
|
163
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
164
|
+
expect(url).toEqual(
|
165
|
+
"https://www.arcgis.com/sharing/rest/content/items/3ef/data"
|
166
|
+
);
|
167
|
+
expect(options.method).toBe("GET");
|
168
|
+
expect(response instanceof Blob).toBeTruthy();
|
169
|
+
done();
|
170
|
+
})
|
171
|
+
.catch(e => {
|
172
|
+
fail(e);
|
173
|
+
});
|
174
|
+
} else {
|
175
|
+
done();
|
176
|
+
}
|
177
|
+
});
|
178
|
+
|
179
|
+
describe("Authenticated methods", () => {
|
180
|
+
// setup a UserSession to use in all these tests
|
181
|
+
const MOCK_USER_SESSION = new UserSession({
|
182
|
+
clientId: "clientId",
|
183
|
+
redirectUri: "https://example-app.com/redirect-uri",
|
184
|
+
token: "fake-token",
|
185
|
+
tokenExpires: TOMORROW,
|
186
|
+
refreshToken: "refreshToken",
|
187
|
+
refreshTokenExpires: TOMORROW,
|
188
|
+
refreshTokenTTL: 1440,
|
189
|
+
username: "casey",
|
190
|
+
password: "123456",
|
191
|
+
portal: "https://myorg.maps.arcgis.com/sharing/rest"
|
192
|
+
});
|
193
|
+
|
194
|
+
const MOCK_USER_REQOPTS = {
|
195
|
+
authentication: MOCK_USER_SESSION
|
196
|
+
};
|
197
|
+
|
198
|
+
it("search should use the portal and token from Auth Manager", done => {
|
199
|
+
fetchMock.once("*", SearchResponse);
|
200
|
+
|
201
|
+
const MOCK_USER_REQOPTS_SEARCH = MOCK_USER_REQOPTS as ISearchRequestOptions;
|
202
|
+
|
203
|
+
MOCK_USER_REQOPTS_SEARCH.searchForm = {
|
204
|
+
q: "DC AND typekeywords:hubSiteApplication"
|
205
|
+
};
|
206
|
+
|
207
|
+
searchItems(MOCK_USER_REQOPTS_SEARCH)
|
208
|
+
.then(response => {
|
209
|
+
expect(fetchMock.called()).toEqual(true);
|
210
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
211
|
+
expect(url).toEqual(
|
212
|
+
"https://myorg.maps.arcgis.com/sharing/rest/search?f=json&q=DC%20AND%20typekeywords%3AhubSiteApplication&token=fake-token"
|
213
|
+
);
|
214
|
+
expect(options.method).toBe("GET");
|
215
|
+
done();
|
216
|
+
})
|
217
|
+
.catch(e => {
|
218
|
+
fail(e);
|
219
|
+
});
|
220
|
+
});
|
221
|
+
|
222
|
+
it("should return an item by id using a token", done => {
|
223
|
+
fetchMock.once("*", ItemResponse);
|
224
|
+
|
225
|
+
getItem("3ef", MOCK_USER_REQOPTS)
|
226
|
+
.then(response => {
|
227
|
+
expect(fetchMock.called()).toEqual(true);
|
228
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
229
|
+
expect(url).toEqual(
|
230
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/items/3ef?f=json&token=fake-token"
|
231
|
+
);
|
232
|
+
expect(options.method).toBe("GET");
|
233
|
+
done();
|
234
|
+
})
|
235
|
+
.catch(e => {
|
236
|
+
fail(e);
|
237
|
+
});
|
238
|
+
});
|
239
|
+
it("should return an item data by id using a token", done => {
|
240
|
+
fetchMock.once("*", ItemDataResponse);
|
241
|
+
|
242
|
+
getItemData("3ef", MOCK_USER_REQOPTS)
|
243
|
+
.then(response => {
|
244
|
+
expect(fetchMock.called()).toEqual(true);
|
245
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
246
|
+
expect(url).toEqual(
|
247
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/items/3ef/data?f=json&token=fake-token"
|
248
|
+
);
|
249
|
+
expect(options.method).toBe("GET");
|
250
|
+
done();
|
251
|
+
})
|
252
|
+
.catch(e => {
|
253
|
+
fail(e);
|
254
|
+
});
|
255
|
+
});
|
256
|
+
|
257
|
+
it("should create an item with data", done => {
|
258
|
+
fetchMock.once("*", ItemSuccessResponse);
|
259
|
+
const fakeItem = {
|
260
|
+
owner: "dbouwman",
|
261
|
+
title: "my fake item",
|
262
|
+
description: "yep its fake",
|
263
|
+
snipped: "so very fake",
|
264
|
+
type: "Web Mapping Application",
|
265
|
+
typeKeywords: ["fake", "kwds"],
|
266
|
+
tags: ["fakey", "mcfakepants"],
|
267
|
+
properties: {
|
268
|
+
key: "somevalue"
|
269
|
+
},
|
270
|
+
data: {
|
271
|
+
values: {
|
272
|
+
key: "value"
|
273
|
+
}
|
274
|
+
}
|
275
|
+
};
|
276
|
+
createItem({
|
277
|
+
item: fakeItem,
|
278
|
+
owner: "dbouwman",
|
279
|
+
...MOCK_USER_REQOPTS
|
280
|
+
})
|
281
|
+
.then(response => {
|
282
|
+
expect(fetchMock.called()).toEqual(true);
|
283
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
284
|
+
expect(url).toEqual(
|
285
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/addItem"
|
286
|
+
);
|
287
|
+
expect(options.method).toBe("POST");
|
288
|
+
expect(options.body).toContain("f=json");
|
289
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
290
|
+
expect(options.body).toContain("owner=dbouwman");
|
291
|
+
// ensure the array props are serialized into strings
|
292
|
+
expect(options.body).toContain(
|
293
|
+
encodeParam("typeKeywords", "fake, kwds")
|
294
|
+
);
|
295
|
+
expect(options.body).toContain(
|
296
|
+
encodeParam("tags", "fakey, mcfakepants")
|
297
|
+
);
|
298
|
+
expect(options.body).toContain(
|
299
|
+
encodeParam("properties", JSON.stringify(fakeItem.properties))
|
300
|
+
);
|
301
|
+
|
302
|
+
done();
|
303
|
+
})
|
304
|
+
.catch(e => {
|
305
|
+
fail(e);
|
306
|
+
});
|
307
|
+
});
|
308
|
+
|
309
|
+
it("should create an item without an explicit owner", done => {
|
310
|
+
fetchMock.once("*", ItemSuccessResponse);
|
311
|
+
const fakeItem = {
|
312
|
+
title: "my fake item",
|
313
|
+
owner: "dbouwman",
|
314
|
+
description: "yep its fake",
|
315
|
+
snipped: "so very fake",
|
316
|
+
type: "Web Mapping Application",
|
317
|
+
typeKeywords: ["fake", "kwds"],
|
318
|
+
tags: ["fakey", "mcfakepants"],
|
319
|
+
properties: {
|
320
|
+
key: "somevalue"
|
321
|
+
}
|
322
|
+
};
|
323
|
+
createItem({
|
324
|
+
item: fakeItem,
|
325
|
+
...MOCK_USER_REQOPTS
|
326
|
+
})
|
327
|
+
.then(response => {
|
328
|
+
expect(fetchMock.called()).toEqual(true);
|
329
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
330
|
+
expect(url).toEqual(
|
331
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/addItem"
|
332
|
+
);
|
333
|
+
expect(options.method).toBe("POST");
|
334
|
+
expect(options.body).toContain("f=json");
|
335
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
336
|
+
expect(options.body).toContain("owner=dbouwman");
|
337
|
+
// ensure the array props are serialized into strings
|
338
|
+
expect(options.body).toContain(
|
339
|
+
encodeParam("typeKeywords", "fake, kwds")
|
340
|
+
);
|
341
|
+
expect(options.body).toContain(
|
342
|
+
encodeParam("tags", "fakey, mcfakepants")
|
343
|
+
);
|
344
|
+
expect(options.body).toContain(
|
345
|
+
encodeParam("properties", JSON.stringify(fakeItem.properties))
|
346
|
+
);
|
347
|
+
|
348
|
+
done();
|
349
|
+
})
|
350
|
+
.catch(e => {
|
351
|
+
fail(e);
|
352
|
+
});
|
353
|
+
});
|
354
|
+
|
355
|
+
it("should create an item with only a username from auth", done => {
|
356
|
+
fetchMock.once("*", ItemSuccessResponse);
|
357
|
+
const fakeItem = {
|
358
|
+
title: "my fake item",
|
359
|
+
description: "yep its fake",
|
360
|
+
snipped: "so very fake",
|
361
|
+
type: "Web Mapping Application",
|
362
|
+
typeKeywords: ["fake", "kwds"],
|
363
|
+
tags: ["fakey", "mcfakepants"],
|
364
|
+
properties: {
|
365
|
+
key: "somevalue"
|
366
|
+
}
|
367
|
+
};
|
368
|
+
// why not just use item.owner??
|
369
|
+
createItem({
|
370
|
+
item: fakeItem,
|
371
|
+
...MOCK_USER_REQOPTS
|
372
|
+
})
|
373
|
+
.then(response => {
|
374
|
+
expect(fetchMock.called()).toEqual(true);
|
375
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
376
|
+
expect(url).toEqual(
|
377
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/addItem"
|
378
|
+
);
|
379
|
+
expect(options.method).toBe("POST");
|
380
|
+
expect(options.body).toContain("f=json");
|
381
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
382
|
+
// expect(options.body).toContain("owner=casey");
|
383
|
+
// ensure the array props are serialized into strings
|
384
|
+
expect(options.body).toContain(
|
385
|
+
encodeParam("typeKeywords", "fake, kwds")
|
386
|
+
);
|
387
|
+
expect(options.body).toContain(
|
388
|
+
encodeParam("tags", "fakey, mcfakepants")
|
389
|
+
);
|
390
|
+
expect(options.body).toContain(
|
391
|
+
encodeParam("properties", JSON.stringify(fakeItem.properties))
|
392
|
+
);
|
393
|
+
|
394
|
+
done();
|
395
|
+
})
|
396
|
+
.catch(e => {
|
397
|
+
fail(e);
|
398
|
+
});
|
399
|
+
});
|
400
|
+
|
401
|
+
it("should create an item with no tags or typeKeywords", done => {
|
402
|
+
fetchMock.once("*", ItemSuccessResponse);
|
403
|
+
const fakeItem = {
|
404
|
+
title: "my fake item",
|
405
|
+
description: "yep its fake",
|
406
|
+
snipped: "so very fake",
|
407
|
+
type: "Web Mapping Application",
|
408
|
+
properties: {
|
409
|
+
key: "somevalue"
|
410
|
+
}
|
411
|
+
};
|
412
|
+
createItem({
|
413
|
+
item: fakeItem,
|
414
|
+
...MOCK_USER_REQOPTS
|
415
|
+
})
|
416
|
+
.then(response => {
|
417
|
+
expect(fetchMock.called()).toEqual(true);
|
418
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
419
|
+
expect(url).toEqual(
|
420
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/addItem"
|
421
|
+
);
|
422
|
+
expect(options.method).toBe("POST");
|
423
|
+
expect(options.body).toContain("f=json");
|
424
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
425
|
+
expect(options.body).toContain(
|
426
|
+
encodeParam("type", "Web Mapping Application")
|
427
|
+
);
|
428
|
+
// ensure the array props are serialized into strings
|
429
|
+
expect(options.body).toContain(
|
430
|
+
encodeParam("properties", JSON.stringify(fakeItem.properties))
|
431
|
+
);
|
432
|
+
|
433
|
+
done();
|
434
|
+
})
|
435
|
+
.catch(e => {
|
436
|
+
fail(e);
|
437
|
+
});
|
438
|
+
});
|
439
|
+
|
440
|
+
it("should create an item in a folder", done => {
|
441
|
+
fetchMock.once("*", ItemSuccessResponse);
|
442
|
+
const fakeItem = {
|
443
|
+
owner: "dbouwman",
|
444
|
+
title: "my fake item",
|
445
|
+
description: "yep its fake",
|
446
|
+
snipped: "so very fake",
|
447
|
+
type: "Web Mapping Application",
|
448
|
+
typeKeywords: ["fake", "kwds"],
|
449
|
+
tags: ["fakey", "mcfakepants"]
|
450
|
+
};
|
451
|
+
createItemInFolder({
|
452
|
+
owner: "dbouwman",
|
453
|
+
item: fakeItem,
|
454
|
+
folder: "someFolder",
|
455
|
+
...MOCK_USER_REQOPTS
|
456
|
+
})
|
457
|
+
.then(response => {
|
458
|
+
expect(fetchMock.called()).toEqual(true);
|
459
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
460
|
+
expect(url).toEqual(
|
461
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/someFolder/addItem"
|
462
|
+
);
|
463
|
+
expect(options.method).toBe("POST");
|
464
|
+
expect(options.body).toContain("f=json");
|
465
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
466
|
+
expect(options.body).toContain("owner=dbouwman");
|
467
|
+
// ensure the array props are serialized into strings
|
468
|
+
expect(options.body).toContain(
|
469
|
+
encodeParam("typeKeywords", "fake, kwds")
|
470
|
+
);
|
471
|
+
expect(options.body).toContain(
|
472
|
+
encodeParam("tags", "fakey, mcfakepants")
|
473
|
+
);
|
474
|
+
done();
|
475
|
+
})
|
476
|
+
.catch(e => {
|
477
|
+
fail(e);
|
478
|
+
});
|
479
|
+
});
|
480
|
+
|
481
|
+
it("should create an item in a folder and pass through arbitrary params", done => {
|
482
|
+
fetchMock.once("*", ItemSuccessResponse);
|
483
|
+
const fakeItem = {
|
484
|
+
owner: "dbouwman",
|
485
|
+
title: "my fake item",
|
486
|
+
description: "yep its fake",
|
487
|
+
snipped: "so very fake",
|
488
|
+
type: "Web Mapping Application",
|
489
|
+
typeKeywords: ["fake", "kwds"],
|
490
|
+
tags: ["fakey", "mcfakepants"]
|
491
|
+
};
|
492
|
+
createItemInFolder({
|
493
|
+
owner: "dbouwman",
|
494
|
+
item: fakeItem,
|
495
|
+
folder: "someFolder",
|
496
|
+
params: {
|
497
|
+
foo: "bar"
|
498
|
+
},
|
499
|
+
...MOCK_USER_REQOPTS
|
500
|
+
})
|
501
|
+
.then(response => {
|
502
|
+
expect(fetchMock.called()).toEqual(true);
|
503
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
504
|
+
expect(url).toEqual(
|
505
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/someFolder/addItem"
|
506
|
+
);
|
507
|
+
expect(options.method).toBe("POST");
|
508
|
+
expect(options.body).toContain("f=json");
|
509
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
510
|
+
expect(options.body).toContain("owner=dbouwman");
|
511
|
+
expect(options.body).toContain("foo=bar");
|
512
|
+
// ensure the array props are serialized into strings
|
513
|
+
expect(options.body).toContain(
|
514
|
+
encodeParam("typeKeywords", "fake, kwds")
|
515
|
+
);
|
516
|
+
expect(options.body).toContain(
|
517
|
+
encodeParam("tags", "fakey, mcfakepants")
|
518
|
+
);
|
519
|
+
done();
|
520
|
+
})
|
521
|
+
.catch(e => {
|
522
|
+
fail(e);
|
523
|
+
});
|
524
|
+
});
|
525
|
+
|
526
|
+
it("should create an item in a folder when no owner is passed", done => {
|
527
|
+
fetchMock.once("*", ItemSuccessResponse);
|
528
|
+
const fakeItem = {
|
529
|
+
owner: "casey",
|
530
|
+
title: "my fake item",
|
531
|
+
description: "yep its fake",
|
532
|
+
snipped: "so very fake",
|
533
|
+
type: "Web Mapping Application",
|
534
|
+
typeKeywords: ["fake", "kwds"],
|
535
|
+
tags: ["fakey", "mcfakepants"]
|
536
|
+
};
|
537
|
+
createItemInFolder({
|
538
|
+
item: fakeItem,
|
539
|
+
...MOCK_USER_REQOPTS
|
540
|
+
})
|
541
|
+
.then(response => {
|
542
|
+
expect(fetchMock.called()).toEqual(true);
|
543
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
544
|
+
expect(url).toEqual(
|
545
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/addItem"
|
546
|
+
);
|
547
|
+
expect(options.method).toBe("POST");
|
548
|
+
expect(options.body).toContain("f=json");
|
549
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
550
|
+
expect(options.body).toContain("owner=casey");
|
551
|
+
// ensure the array props are serialized into strings
|
552
|
+
expect(options.body).toContain(
|
553
|
+
encodeParam("typeKeywords", "fake, kwds")
|
554
|
+
);
|
555
|
+
expect(options.body).toContain(
|
556
|
+
encodeParam("tags", "fakey, mcfakepants")
|
557
|
+
);
|
558
|
+
done();
|
559
|
+
})
|
560
|
+
.catch(e => {
|
561
|
+
fail(e);
|
562
|
+
});
|
563
|
+
});
|
564
|
+
it("should add data to an item", done => {
|
565
|
+
fetchMock.once("*", ItemSuccessResponse);
|
566
|
+
const fakeData = {
|
567
|
+
values: {
|
568
|
+
key: "someValue"
|
569
|
+
}
|
570
|
+
};
|
571
|
+
// addItemJsonData("3ef", "dbouwman", fakeData, MOCK_REQOPTS)
|
572
|
+
addItemJsonData({
|
573
|
+
id: "3ef",
|
574
|
+
owner: "dbouwman",
|
575
|
+
data: fakeData,
|
576
|
+
...MOCK_USER_REQOPTS
|
577
|
+
})
|
578
|
+
.then(response => {
|
579
|
+
expect(fetchMock.called()).toEqual(true);
|
580
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
581
|
+
expect(url).toEqual(
|
582
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/3ef/update"
|
583
|
+
);
|
584
|
+
expect(options.method).toBe("POST");
|
585
|
+
|
586
|
+
expect(options.body).toContain("f=json");
|
587
|
+
expect(options.body).toContain("token=fake-token");
|
588
|
+
expect(options.body).toContain(
|
589
|
+
encodeParam("text", JSON.stringify(fakeData))
|
590
|
+
);
|
591
|
+
|
592
|
+
done();
|
593
|
+
})
|
594
|
+
.catch(e => {
|
595
|
+
fail(e);
|
596
|
+
});
|
597
|
+
});
|
598
|
+
|
599
|
+
it("should add data to an item, no owner passed", done => {
|
600
|
+
fetchMock.once("*", ItemSuccessResponse);
|
601
|
+
const fakeData = {
|
602
|
+
values: {
|
603
|
+
key: "someValue"
|
604
|
+
}
|
605
|
+
};
|
606
|
+
// addItemJsonData("3ef", "dbouwman", fakeData, MOCK_REQOPTS)
|
607
|
+
addItemJsonData({
|
608
|
+
id: "3ef",
|
609
|
+
data: fakeData,
|
610
|
+
...MOCK_USER_REQOPTS
|
611
|
+
})
|
612
|
+
.then(response => {
|
613
|
+
expect(fetchMock.called()).toEqual(true);
|
614
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
615
|
+
expect(url).toEqual(
|
616
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/update"
|
617
|
+
);
|
618
|
+
expect(options.method).toBe("POST");
|
619
|
+
|
620
|
+
expect(options.body).toContain("f=json");
|
621
|
+
expect(options.body).toContain("token=fake-token");
|
622
|
+
expect(options.body).toContain(
|
623
|
+
encodeParam("text", JSON.stringify(fakeData))
|
624
|
+
);
|
625
|
+
|
626
|
+
done();
|
627
|
+
})
|
628
|
+
.catch(e => {
|
629
|
+
fail(e);
|
630
|
+
});
|
631
|
+
});
|
632
|
+
|
633
|
+
it("should add data to an item, extra parameters", done => {
|
634
|
+
fetchMock.once("*", ItemSuccessResponse);
|
635
|
+
const fakeData = {
|
636
|
+
values: {
|
637
|
+
key: "someValue"
|
638
|
+
}
|
639
|
+
};
|
640
|
+
// addItemJsonData("3ef", "dbouwman", fakeData, MOCK_REQOPTS)
|
641
|
+
addItemJsonData({
|
642
|
+
id: "3ef",
|
643
|
+
data: fakeData,
|
644
|
+
...MOCK_USER_REQOPTS,
|
645
|
+
params: {
|
646
|
+
relationshipType: "WMA2Code"
|
647
|
+
}
|
648
|
+
})
|
649
|
+
.then(response => {
|
650
|
+
expect(fetchMock.called()).toEqual(true);
|
651
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
652
|
+
expect(url).toEqual(
|
653
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/update"
|
654
|
+
);
|
655
|
+
expect(options.method).toBe("POST");
|
656
|
+
expect(options.body).toContain("relationshipType=WMA2Code");
|
657
|
+
expect(options.body).toContain("f=json");
|
658
|
+
expect(options.body).toContain("token=fake-token");
|
659
|
+
expect(options.body).toContain(
|
660
|
+
encodeParam("text", JSON.stringify(fakeData))
|
661
|
+
);
|
662
|
+
|
663
|
+
done();
|
664
|
+
})
|
665
|
+
.catch(e => {
|
666
|
+
fail(e);
|
667
|
+
});
|
668
|
+
});
|
669
|
+
|
670
|
+
it("should add binary item data by id", done => {
|
671
|
+
fetchMock.once("*", {
|
672
|
+
success: true
|
673
|
+
});
|
674
|
+
|
675
|
+
addItemData({
|
676
|
+
id: "3ef",
|
677
|
+
// File() is only available in the browser
|
678
|
+
data: attachmentFile(),
|
679
|
+
...MOCK_USER_REQOPTS
|
680
|
+
})
|
681
|
+
.then(() => {
|
682
|
+
expect(fetchMock.called()).toEqual(true);
|
683
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
684
|
+
expect(url).toEqual(
|
685
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/update"
|
686
|
+
);
|
687
|
+
expect(options.method).toBe("POST");
|
688
|
+
expect(options.body instanceof FormData).toBeTruthy();
|
689
|
+
const params = options.body as FormData;
|
690
|
+
// need to figure out how to introspect FormData from Node.js
|
691
|
+
// expect(params.get("token")).toEqual("fake-token");
|
692
|
+
// expect(params.get("f")).toEqual("json");
|
693
|
+
// expect(params.get("filename")).toEqual("foo.txt");
|
694
|
+
done();
|
695
|
+
})
|
696
|
+
.catch(e => {
|
697
|
+
fail(e);
|
698
|
+
});
|
699
|
+
});
|
700
|
+
|
701
|
+
it("should update an item, including data", done => {
|
702
|
+
fetchMock.once("*", ItemSuccessResponse);
|
703
|
+
const fakeItem = {
|
704
|
+
id: "5bc",
|
705
|
+
owner: "dbouwman",
|
706
|
+
title: "my fake item",
|
707
|
+
description: "yep its fake",
|
708
|
+
snipped: "so very fake",
|
709
|
+
type: "Web Mapping Application",
|
710
|
+
typeKeywords: ["fake", "kwds"],
|
711
|
+
tags: ["fakey", "mcfakepants"],
|
712
|
+
properties: {
|
713
|
+
key: "somevalue"
|
714
|
+
},
|
715
|
+
data: {
|
716
|
+
values: {
|
717
|
+
key: "value"
|
718
|
+
}
|
719
|
+
}
|
720
|
+
};
|
721
|
+
updateItem({ item: fakeItem, ...MOCK_USER_REQOPTS })
|
722
|
+
.then(response => {
|
723
|
+
expect(fetchMock.called()).toEqual(true);
|
724
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
725
|
+
expect(url).toEqual(
|
726
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/5bc/update"
|
727
|
+
);
|
728
|
+
expect(options.method).toBe("POST");
|
729
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
730
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
731
|
+
expect(options.body).toContain(encodeParam("owner", "dbouwman"));
|
732
|
+
// ensure the array props are serialized into strings
|
733
|
+
expect(options.body).toContain(
|
734
|
+
encodeParam("typeKeywords", "fake, kwds")
|
735
|
+
);
|
736
|
+
expect(options.body).toContain(
|
737
|
+
encodeParam("tags", "fakey, mcfakepants")
|
738
|
+
);
|
739
|
+
expect(options.body).toContain(
|
740
|
+
encodeParam("text", JSON.stringify(fakeItem.data))
|
741
|
+
);
|
742
|
+
done();
|
743
|
+
})
|
744
|
+
.catch(e => {
|
745
|
+
fail(e);
|
746
|
+
});
|
747
|
+
});
|
748
|
+
|
749
|
+
it("should update an item, including data and service proxy params", done => {
|
750
|
+
fetchMock.once("*", ItemSuccessResponse);
|
751
|
+
const fakeItem = {
|
752
|
+
id: "5bc",
|
753
|
+
owner: "dbouwman",
|
754
|
+
title: "my fake item",
|
755
|
+
description: "yep its fake",
|
756
|
+
snipped: "so very fake",
|
757
|
+
type: "Web Mapping Application",
|
758
|
+
typeKeywords: ["fake", "kwds"],
|
759
|
+
tags: ["fakey", "mcfakepants"],
|
760
|
+
properties: {
|
761
|
+
key: "somevalue"
|
762
|
+
},
|
763
|
+
serviceProxyParams: {
|
764
|
+
hitsPerInterval: 2,
|
765
|
+
intervalSeconds: 60,
|
766
|
+
referrers: ["http://<servername>"]
|
767
|
+
},
|
768
|
+
data: {
|
769
|
+
values: {
|
770
|
+
key: "value"
|
771
|
+
}
|
772
|
+
}
|
773
|
+
};
|
774
|
+
|
775
|
+
updateItem({
|
776
|
+
item: fakeItem,
|
777
|
+
params: { foo: "bar" },
|
778
|
+
...MOCK_USER_REQOPTS
|
779
|
+
})
|
780
|
+
.then(response => {
|
781
|
+
expect(fetchMock.called()).toEqual(true);
|
782
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
783
|
+
expect(url).toEqual(
|
784
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/5bc/update"
|
785
|
+
);
|
786
|
+
expect(options.method).toBe("POST");
|
787
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
788
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
789
|
+
expect(options.body).toContain(encodeParam("owner", "dbouwman"));
|
790
|
+
expect(options.body).toContain(encodeParam("foo", "bar"));
|
791
|
+
expect(options.body).toContain(
|
792
|
+
encodeParam(
|
793
|
+
"serviceProxyParams",
|
794
|
+
'{"hitsPerInterval":2,"intervalSeconds":60,"referrers":["http://<servername>"]}'
|
795
|
+
)
|
796
|
+
);
|
797
|
+
// ensure the array props are serialized into strings
|
798
|
+
expect(options.body).toContain(
|
799
|
+
encodeParam("typeKeywords", "fake, kwds")
|
800
|
+
);
|
801
|
+
expect(options.body).toContain(
|
802
|
+
encodeParam("tags", "fakey, mcfakepants")
|
803
|
+
);
|
804
|
+
expect(options.body).toContain(
|
805
|
+
encodeParam("text", JSON.stringify(fakeItem.data))
|
806
|
+
);
|
807
|
+
done();
|
808
|
+
})
|
809
|
+
.catch(e => {
|
810
|
+
fail(e);
|
811
|
+
});
|
812
|
+
});
|
813
|
+
|
814
|
+
it("should remove an item", done => {
|
815
|
+
fetchMock.once("*", ItemSuccessResponse);
|
816
|
+
removeItem({
|
817
|
+
id: "3ef",
|
818
|
+
owner: "dbouwman",
|
819
|
+
...MOCK_USER_REQOPTS
|
820
|
+
})
|
821
|
+
.then(response => {
|
822
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
823
|
+
expect(url).toEqual(
|
824
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/3ef/delete"
|
825
|
+
);
|
826
|
+
expect(options.method).toBe("POST");
|
827
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
828
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
829
|
+
done();
|
830
|
+
})
|
831
|
+
.catch(e => {
|
832
|
+
fail(e);
|
833
|
+
});
|
834
|
+
});
|
835
|
+
|
836
|
+
it("should remove an item, no owner passed", done => {
|
837
|
+
fetchMock.once("*", ItemSuccessResponse);
|
838
|
+
removeItem({
|
839
|
+
id: "3ef",
|
840
|
+
...MOCK_USER_REQOPTS
|
841
|
+
})
|
842
|
+
.then(response => {
|
843
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
844
|
+
expect(url).toEqual(
|
845
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/delete"
|
846
|
+
);
|
847
|
+
expect(options.method).toBe("POST");
|
848
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
849
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
850
|
+
done();
|
851
|
+
})
|
852
|
+
.catch(e => {
|
853
|
+
fail(e);
|
854
|
+
});
|
855
|
+
});
|
856
|
+
|
857
|
+
it("should protect an item", done => {
|
858
|
+
fetchMock.once("*", ItemSuccessResponse);
|
859
|
+
protectItem({
|
860
|
+
id: "3ef",
|
861
|
+
owner: "dbouwman",
|
862
|
+
...MOCK_USER_REQOPTS
|
863
|
+
})
|
864
|
+
.then(response => {
|
865
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
866
|
+
expect(url).toEqual(
|
867
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/3ef/protect"
|
868
|
+
);
|
869
|
+
expect(options.method).toBe("POST");
|
870
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
871
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
872
|
+
done();
|
873
|
+
})
|
874
|
+
.catch(e => {
|
875
|
+
fail(e);
|
876
|
+
});
|
877
|
+
});
|
878
|
+
|
879
|
+
it("should protect an item, no owner passed", done => {
|
880
|
+
fetchMock.once("*", ItemSuccessResponse);
|
881
|
+
protectItem({
|
882
|
+
id: "3ef",
|
883
|
+
...MOCK_USER_REQOPTS
|
884
|
+
})
|
885
|
+
.then(response => {
|
886
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
887
|
+
expect(url).toEqual(
|
888
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/protect"
|
889
|
+
);
|
890
|
+
expect(options.method).toBe("POST");
|
891
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
892
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
893
|
+
done();
|
894
|
+
})
|
895
|
+
.catch(e => {
|
896
|
+
fail(e);
|
897
|
+
});
|
898
|
+
});
|
899
|
+
|
900
|
+
it("should unprotect an item", done => {
|
901
|
+
fetchMock.once("*", ItemSuccessResponse);
|
902
|
+
unprotectItem({
|
903
|
+
id: "3ef",
|
904
|
+
owner: "dbouwman",
|
905
|
+
...MOCK_USER_REQOPTS
|
906
|
+
})
|
907
|
+
.then(response => {
|
908
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
909
|
+
expect(url).toEqual(
|
910
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/3ef/unprotect"
|
911
|
+
);
|
912
|
+
expect(options.method).toBe("POST");
|
913
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
914
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
915
|
+
done();
|
916
|
+
})
|
917
|
+
.catch(e => {
|
918
|
+
fail(e);
|
919
|
+
});
|
920
|
+
});
|
921
|
+
|
922
|
+
it("should unprotect an item, no owner passed", done => {
|
923
|
+
fetchMock.once("*", ItemSuccessResponse);
|
924
|
+
unprotectItem({
|
925
|
+
id: "3ef",
|
926
|
+
...MOCK_USER_REQOPTS
|
927
|
+
})
|
928
|
+
.then(response => {
|
929
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
930
|
+
expect(url).toEqual(
|
931
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/unprotect"
|
932
|
+
);
|
933
|
+
expect(options.method).toBe("POST");
|
934
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
935
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
936
|
+
done();
|
937
|
+
})
|
938
|
+
.catch(e => {
|
939
|
+
fail(e);
|
940
|
+
});
|
941
|
+
});
|
942
|
+
|
943
|
+
it("get item resources", done => {
|
944
|
+
fetchMock.once("*", GetItemResourcesResponse);
|
945
|
+
getItemResources({
|
946
|
+
id: "3ef",
|
947
|
+
...MOCK_USER_REQOPTS
|
948
|
+
})
|
949
|
+
.then(response => {
|
950
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
951
|
+
expect(url).toEqual(
|
952
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/items/3ef/resources"
|
953
|
+
);
|
954
|
+
expect(options.method).toBe("POST");
|
955
|
+
expect(options.body).toContain("f=json");
|
956
|
+
done();
|
957
|
+
})
|
958
|
+
.catch(e => {
|
959
|
+
fail(e);
|
960
|
+
});
|
961
|
+
});
|
962
|
+
|
963
|
+
it("get item resources with extra parameters", done => {
|
964
|
+
fetchMock.once("*", GetItemResourcesResponse);
|
965
|
+
getItemResources({
|
966
|
+
id: "3ef",
|
967
|
+
...MOCK_USER_REQOPTS,
|
968
|
+
params: {
|
969
|
+
resourcesPrefix: "foolder"
|
970
|
+
}
|
971
|
+
})
|
972
|
+
.then(response => {
|
973
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
974
|
+
expect(url).toEqual(
|
975
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/items/3ef/resources"
|
976
|
+
);
|
977
|
+
expect(options.method).toBe("POST");
|
978
|
+
expect(options.body).toContain("f=json");
|
979
|
+
expect(options.body).toContain("resourcesPrefix=foolder");
|
980
|
+
done();
|
981
|
+
})
|
982
|
+
.catch(e => {
|
983
|
+
fail(e);
|
984
|
+
});
|
985
|
+
});
|
986
|
+
|
987
|
+
it("update an item resource", done => {
|
988
|
+
fetchMock.once("*", UpdateItemResourceResponse);
|
989
|
+
updateItemResource({
|
990
|
+
id: "3ef",
|
991
|
+
owner: "dbouwman",
|
992
|
+
name: "image/banner.png",
|
993
|
+
content: "jumbotron",
|
994
|
+
...MOCK_USER_REQOPTS
|
995
|
+
})
|
996
|
+
.then(response => {
|
997
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
998
|
+
expect(url).toEqual(
|
999
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/3ef/updateResources"
|
1000
|
+
);
|
1001
|
+
expect(options.method).toBe("POST");
|
1002
|
+
expect(options.body).toContain("f=json");
|
1003
|
+
expect(options.body).toContain(
|
1004
|
+
encodeParam("fileName", "image/banner.png")
|
1005
|
+
);
|
1006
|
+
expect(options.body).toContain(encodeParam("text", "jumbotron"));
|
1007
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
1008
|
+
done();
|
1009
|
+
})
|
1010
|
+
.catch(e => {
|
1011
|
+
fail(e);
|
1012
|
+
});
|
1013
|
+
});
|
1014
|
+
|
1015
|
+
it("update an item resource, no owner passed", done => {
|
1016
|
+
fetchMock.once("*", UpdateItemResourceResponse);
|
1017
|
+
updateItemResource({
|
1018
|
+
id: "3ef",
|
1019
|
+
name: "image/banner.png",
|
1020
|
+
content: "jumbotron",
|
1021
|
+
...MOCK_USER_REQOPTS
|
1022
|
+
})
|
1023
|
+
.then(response => {
|
1024
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
1025
|
+
expect(url).toEqual(
|
1026
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/updateResources"
|
1027
|
+
);
|
1028
|
+
expect(options.method).toBe("POST");
|
1029
|
+
expect(options.body).toContain("f=json");
|
1030
|
+
expect(options.body).toContain(
|
1031
|
+
encodeParam("fileName", "image/banner.png")
|
1032
|
+
);
|
1033
|
+
expect(options.body).toContain(encodeParam("text", "jumbotron"));
|
1034
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
1035
|
+
done();
|
1036
|
+
})
|
1037
|
+
.catch(e => {
|
1038
|
+
fail(e);
|
1039
|
+
});
|
1040
|
+
});
|
1041
|
+
|
1042
|
+
it("update an item resource with extra params", done => {
|
1043
|
+
fetchMock.once("*", UpdateItemResourceResponse);
|
1044
|
+
updateItemResource({
|
1045
|
+
id: "3ef",
|
1046
|
+
name: "image/banner.png",
|
1047
|
+
content: "jumbotron",
|
1048
|
+
...MOCK_USER_REQOPTS,
|
1049
|
+
params: {
|
1050
|
+
resourcesPrefix: "foolder"
|
1051
|
+
}
|
1052
|
+
})
|
1053
|
+
.then(response => {
|
1054
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
1055
|
+
expect(url).toEqual(
|
1056
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/updateResources"
|
1057
|
+
);
|
1058
|
+
expect(options.method).toBe("POST");
|
1059
|
+
expect(options.body).toContain("f=json");
|
1060
|
+
expect(options.body).toContain(
|
1061
|
+
encodeParam("fileName", "image/banner.png")
|
1062
|
+
);
|
1063
|
+
expect(options.body).toContain("resourcesPrefix=foolder");
|
1064
|
+
expect(options.body).toContain(encodeParam("text", "jumbotron"));
|
1065
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
1066
|
+
done();
|
1067
|
+
})
|
1068
|
+
.catch(e => {
|
1069
|
+
fail(e);
|
1070
|
+
});
|
1071
|
+
});
|
1072
|
+
|
1073
|
+
it("should remove a resource", done => {
|
1074
|
+
fetchMock.once("*", RemoveItemResourceResponse);
|
1075
|
+
removeItemResource({
|
1076
|
+
id: "3ef",
|
1077
|
+
owner: "dbouwman",
|
1078
|
+
resource: "image/banner.png",
|
1079
|
+
...MOCK_USER_REQOPTS
|
1080
|
+
})
|
1081
|
+
.then(response => {
|
1082
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
1083
|
+
expect(url).toEqual(
|
1084
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/3ef/removeResources"
|
1085
|
+
);
|
1086
|
+
expect(options.method).toBe("POST");
|
1087
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
1088
|
+
expect(options.body).toContain(
|
1089
|
+
encodeParam("resource", "image/banner.png")
|
1090
|
+
);
|
1091
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
1092
|
+
done();
|
1093
|
+
})
|
1094
|
+
.catch(e => {
|
1095
|
+
fail(e);
|
1096
|
+
});
|
1097
|
+
});
|
1098
|
+
|
1099
|
+
it("should remove a resource, no owner passed", done => {
|
1100
|
+
fetchMock.once("*", RemoveItemResourceResponse);
|
1101
|
+
removeItemResource({
|
1102
|
+
id: "3ef",
|
1103
|
+
resource: "image/banner.png",
|
1104
|
+
...MOCK_USER_REQOPTS
|
1105
|
+
})
|
1106
|
+
.then(response => {
|
1107
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
1108
|
+
expect(url).toEqual(
|
1109
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/removeResources"
|
1110
|
+
);
|
1111
|
+
expect(options.method).toBe("POST");
|
1112
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
1113
|
+
expect(options.body).toContain(
|
1114
|
+
encodeParam("resource", "image/banner.png")
|
1115
|
+
);
|
1116
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
1117
|
+
done();
|
1118
|
+
})
|
1119
|
+
.catch(e => {
|
1120
|
+
fail(e);
|
1121
|
+
});
|
1122
|
+
});
|
1123
|
+
|
1124
|
+
it("should remove a resource with extra params", done => {
|
1125
|
+
fetchMock.once("*", RemoveItemResourceResponse);
|
1126
|
+
removeItemResource({
|
1127
|
+
id: "3ef",
|
1128
|
+
resource: "image/banner.png",
|
1129
|
+
...MOCK_USER_REQOPTS,
|
1130
|
+
params: {
|
1131
|
+
deleteAll: true
|
1132
|
+
}
|
1133
|
+
})
|
1134
|
+
.then(response => {
|
1135
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
1136
|
+
expect(url).toEqual(
|
1137
|
+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/3ef/removeResources"
|
1138
|
+
);
|
1139
|
+
expect(options.method).toBe("POST");
|
1140
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
1141
|
+
expect(options.body).toContain(encodeParam("deleteAll", "true"));
|
1142
|
+
expect(options.body).toContain(
|
1143
|
+
encodeParam("resource", "image/banner.png")
|
1144
|
+
);
|
1145
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
1146
|
+
done();
|
1147
|
+
})
|
1148
|
+
.catch(e => {
|
1149
|
+
fail(e);
|
1150
|
+
});
|
1151
|
+
});
|
1152
|
+
}); // auth requests
|
1153
|
+
});
|