Skip to content

Commit

Permalink
fix(null): dont stringify values in item calls
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-items

add tests

simpler

more
  • Loading branch information
jgravois committed Mar 27, 2019
1 parent 34e6e4f commit c0f48fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
16 changes: 11 additions & 5 deletions packages/arcgis-rest-items/src/add.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { request, getPortalUrl, appendCustomParams } from "@esri/arcgis-rest-request";
import {
request,
getPortalUrl,
appendCustomParams
} from "@esri/arcgis-rest-request";

import {
IItemIdRequestOptions,
Expand Down Expand Up @@ -56,7 +60,7 @@ export function addItemJsonData(
// a `text` form field. It can also be sent with the `.create` call by sending
// a `.data` property.
requestOptions.params = {
text: JSON.stringify(requestOptions.data),
text: requestOptions.data,
...requestOptions.params
};

Expand Down Expand Up @@ -117,11 +121,13 @@ export function addItemData(
*/
export function addItemRelationship(
requestOptions: IManageItemRelationshipRequestOptions
): Promise<{ "success": boolean }> {
): Promise<{ success: boolean }> {
const owner = determineOwner(requestOptions);
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/addRelationship`;
const url = `${getPortalUrl(
requestOptions
)}/content/users/${owner}/addRelationship`;

const options = { params: {}, ...requestOptions }
const options = { params: {}, ...requestOptions };
appendCustomParams(requestOptions, options);

return request(url, options);
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-items/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function serializeItem(item: IItemAdd | IItemUpdate | IItem): any {

// convert .data to .text
if (clone.data) {
clone.text = JSON.stringify(clone.data);
clone.text = clone.data;
delete clone.data;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/arcgis-rest-items/test/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as fetchMock from "fetch-mock";

import { attachmentFile } from "../../arcgis-rest-feature-service/test/attachments.test";

import {
import {
addItemJsonData,
addItemData,
addItemResource,
Expand All @@ -16,7 +16,7 @@ import { ItemSuccessResponse } from "./mocks/item";

import { UserSession } from "@esri/arcgis-rest-auth";
import { TOMORROW } from "@esri/arcgis-rest-auth/test/utils";
import { encodeParam, appendCustomParams } from "@esri/arcgis-rest-request";
import { encodeParam } from "@esri/arcgis-rest-request";

describe("search", () => {
afterEach(fetchMock.restore);
Expand Down Expand Up @@ -183,7 +183,7 @@ describe("search", () => {

it("should add a relationship to an item", done => {
fetchMock.once("*", { success: true });

addItemRelationship({
originItemId: "3ef",
destinationItemId: "ae7",
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-items/test/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("search", () => {
}
};
updateItem({ item: fakeItem, ...MOCK_USER_REQOPTS })
.then(response => {
.then(() => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
Expand Down

0 comments on commit c0f48fc

Please sign in to comment.