Skip to content

Commit

Permalink
fix(:couple:): make it possible to update a service using a layer def…
Browse files Browse the repository at this point in the history
…inition

AFFECTS PACKAGES:
@esri/arcgis-rest-common-types
@esri/arcgis-rest-feature-service-admin
  • Loading branch information
jgravois committed Oct 9, 2018
1 parent dc62e37 commit 462af65
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/arcgis-rest-common-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export interface IField {
length?: number;
/** A Boolean defining whether this field can have a null value. */
nullable?: boolean;
/** The value written in for new records by default. */
defaultValue?: any;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/arcgis-rest-common-types/src/webmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ export interface ILayerDefinition extends IHasZM {
/** Boolean value indicating whether the validateSQL operation is supported across a feature service layer. */
supportsValidateSql?: boolean;
/** A property of the layer definition when there are no types defined; otherwise, templates are defined as properties of the types. */
templates?: ITemplate;
templates?: ITemplate[];
/** The time info metadata of the layer. May be set for feature layers inside a feature collection item. */
timeInfo?: any;
/** Indicates whether the layerDefinition applies to a Feature Layer or a Table. */
Expand All @@ -900,6 +900,7 @@ export interface ILayerDefinition extends IHasZM {
* The field's values are 0 = do not display, 1 = display.
*/
visibilityField?: string;
relationships?: any[];
}

export interface ITypeInfoDomain {
Expand Down
8 changes: 6 additions & 2 deletions packages/arcgis-rest-feature-service-admin/src/addTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

import { request } from "@esri/arcgis-rest-request";
import { IUserRequestOptions } from "@esri/arcgis-rest-auth";
import { ILayer, ITable } from "@esri/arcgis-rest-common-types";
import {
ILayer,
ILayerDefinition,
ITable
} from "@esri/arcgis-rest-common-types";

export interface IAddToServiceDefinitionRequestOptions
extends IUserRequestOptions {
/**
* Layers to add
*/
layers?: ILayer[];
layers?: ILayer[] | ILayerDefinition[];
/**
* Tables to add
*/
Expand Down
43 changes: 43 additions & 0 deletions packages/arcgis-rest-feature-service-admin/test/addTo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
AddToFeatureServiceError
} from "./mocks/service";

import { layerDefinitionSid } from "./mocks/layerDefinition";

import { UserSession } from "@esri/arcgis-rest-auth";
import { TOMORROW } from "@esri/arcgis-rest-auth/test/utils";
import { encodeParam, ErrorTypes } from "@esri/arcgis-rest-request";
Expand Down Expand Up @@ -224,6 +226,47 @@ describe("add to feature service", () => {
});
});

it("should add a layer definition", done => {
fetchMock.once("*", AddToFeatureServiceSuccessResponseCydAndGene);

addToServiceDefinition(
"https://services1.arcgis.com/ORG/arcgis/rest/services/FEATURE_SERVICE/FeatureServer",
{
layers: [layerDefinitionSid],
...MOCK_USER_REQOPTS
}
)
.then(response => {
// Check service call
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");

expect(url).toEqual(
"https://services1.arcgis.com/ORG/arcgis/rest/admin/services/FEATURE_SERVICE/FeatureServer/addToDefinition"
);
expect(options.method).toBe("POST");
expect(options.body).toContain("f=json");
expect(options.body).toContain(encodeParam("token", "fake-token"));
expect(options.body).toContain(
encodeParam(
"addToDefinition",
JSON.stringify({
layers: [layerDefinitionSid]
})
)
);

// Check response
expect(response).toEqual(
AddToFeatureServiceSuccessResponseCydAndGene
);
done();
})
.catch(e => {
fail(e);
});
});

it("should fail to add a bad layer", done => {
fetchMock.once("*", AddToFeatureServiceError);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { ILayerDefinition, IExtent } from "@esri/arcgis-rest-common-types";

const defaultExtent: IExtent = {
xmin: -180,
ymin: -90,
xmax: 180,
ymax: 90,
spatialReference: {
wkid: 4326,
latestWkid: 4326
}
};

export const layerDefinitionSid: ILayerDefinition = {
allowGeometryUpdates: true,
capabilities: "Create,Delete,Query,Update,Editing",
copyrightText: "",
defaultVisibility: true,
description: "",
drawingInfo: {
transparency: 0,
labelingInfo: null,
renderer: {
type: "simple",
symbol: {
color: [20, 158, 206, 70],
outline: {
color: [255, 255, 255, 229],
width: 2.25,
type: "esriSLS",
style: "esriSLSSolid"
},
type: "esriSFS",
style: "esriSFSSolid"
}
}
},
extent: defaultExtent,
fields: [
{
name: "OBJECTID",
type: "esriFieldTypeOID",
alias: "OBJECTID",
nullable: false,
editable: false,
domain: null
},
{
name: "author",
type: "esriFieldTypeString",
alias: "author",
length: 256,
nullable: false,
editable: true,
domain: null,
defaultValue: null
}
],
geometryType: "esriGeometryPolygon",
hasAttachments: true,
hasZ: false,
hasStaticData: false,
htmlPopupType: "esriServerHTMLPopupTypeNone",
isDataVersioned: false,
maxRecordCount: 2000,
name: "hub_annotations",
objectIdField: "OBJECTID",
relationships: [],
supportsAdvancedQueries: true,
supportsRollbackOnFailureParameter: true,
supportsStatistics: true,
type: "Feature Layer",
typeIdField: "",
types: [],
timeInfo: {}
};

0 comments on commit 462af65

Please sign in to comment.