Skip to content

Commit

Permalink
Merge pull request #313 from Esri/chore/lint
Browse files Browse the repository at this point in the history
chore(lint): make sure *all* the code is linted each commit
  • Loading branch information
jgravois authored Sep 11, 2018
2 parents 6a17fe5 + ffbeeac commit 0dc4531
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 210 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"lint-staged": {
"*.ts": [
"prettier --write --parser typescript --tab-width 2 --use-tabs false",
"tslint",
"tslint --project tsconfig.json",
"git add"
]
},
Expand All @@ -82,7 +82,7 @@
"test:firefox": "karma start --single-run --browsers=Firefox",
"test:node": "jasmine --config=jasmine.json",
"test:node:debug": "inspect jasmine --config=jasmine.json",
"test:ci": "npm run test:node && npm run test:chrome:ci && npm run test:firefox",
"test:ci": "npm run lint && npm run test:node && npm run test:chrome:ci && npm run test:firefox",
"test:all": "npm run test:node && npm run test:firefox && npm run test:chrome",
"docs:build": "rimraf docs/build && npm run docs:typedoc && npm run docs:build:acetate && npm run docs:build:sass && npm run docs:build:images",
"docs:build:acetate": "ENV=prod acetate build --config docs/acetate.config.js",
Expand All @@ -98,8 +98,8 @@
"predocs:dev:sass": "npm run docs:build:sass",
"docs:dev:sass": "node-sass --watch --recursive --output docs/build/css --source-map true --source-map-contents docs/src/sass",
"docs:dev:js": "cpx \"docs/src/**/{api-search,nav-toggle}.js\" docs/build -w",
"lint": "tslint --project tsconfig.json --type-check",
"lint:fix": "tslint --project tsconfig.json --type-check --fix",
"lint": "tslint --project tsconfig.json",
"lint:fix": "tslint --project tsconfig.json --fix",
"precommit": "lint-staged",
"bootstrap": "lerna bootstrap",
"postinstall": "npm run bootstrap",
Expand Down
7 changes: 0 additions & 7 deletions packages/arcgis-rest-auth/src/ApplicationSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ export interface IApplicationSessionOptions {
* Expiration date for the `token`
*/
expires?: Date;

/**
* Duration of requested tokens in minutes. Used when requesting tokens with `username` and `password` for when validating the identities of unknown servers. Defaults to 2 weeks.
*/
duration?: number;
}

export class ApplicationSession implements IAuthenticationManager {
Expand All @@ -44,7 +39,6 @@ export class ApplicationSession implements IAuthenticationManager {
private clientSecret: string;
private token: string;
private expires: Date;
private duration: number;

/**
* Internal object to keep track of pending token requests. Used to prevent
Expand All @@ -58,7 +52,6 @@ export class ApplicationSession implements IAuthenticationManager {
this.token = options.token;
this.expires = options.expires;
this.portal = "https://www.arcgis.com/sharing/rest";
this.duration = options.duration || 20160;
}

// url isnt actually read or passed through.
Expand Down
9 changes: 1 addition & 8 deletions packages/arcgis-rest-auth/src/UserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,9 @@ export class UserSession implements IAuthenticationManager {
options: IOauth2Options,
authorizationCode: string
): Promise<UserSession> {
const {
portal,
clientId,
duration,
redirectUri,
refreshTokenTTL
}: IOauth2Options = {
const { portal, clientId, redirectUri, refreshTokenTTL }: IOauth2Options = {
...{
portal: "https://www.arcgis.com/sharing/rest",
duration: 20160,
refreshTokenTTL: 1440
},
...options
Expand Down
51 changes: 37 additions & 14 deletions packages/arcgis-rest-auth/test/UserSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ describe("UserSession", () => {
.then(token => {
expect(token).toBe("token");
done();
})
.catch(e => {
fail(e);
});
});

Expand Down Expand Up @@ -184,6 +187,9 @@ describe("UserSession", () => {
.then(token => {
expect(token).toBe("serverToken");
done();
})
.catch(e => {
fail(e);
});
});

Expand Down Expand Up @@ -224,6 +230,9 @@ describe("UserSession", () => {
.then(token => {
expect(token).toBe("serverToken");
done();
})
.catch(e => {
fail(e);
});
});

Expand Down Expand Up @@ -278,14 +287,18 @@ describe("UserSession", () => {
session.getToken(
"https://gisservices.city.gov/public/rest/services/trees/FeatureServer/0/query"
)
]).then(([token1, token2]) => {
expect(token1).toBe("serverToken");
expect(token2).toBe("serverToken");
expect(
fetchMock.calls("https://gis.city.gov/sharing/generateToken").length
).toBe(1);
done();
});
])
.then(([token1, token2]) => {
expect(token1).toBe("serverToken");
expect(token2).toBe("serverToken");
expect(
fetchMock.calls("https://gis.city.gov/sharing/generateToken").length
).toBe(1);
done();
})
.catch(e => {
fail(e);
});
});

it("should throw an ArcGISAuthError when the owning system doesn't match", done => {
Expand Down Expand Up @@ -835,13 +848,23 @@ describe("UserSession", () => {
password: "123456"
});

session.getUser().then(response => {
expect(response.role).toEqual("org_publisher");
session.getUser().then(cachedResponse => {
expect(cachedResponse.fullName).toEqual("John Smith");
done();
session
.getUser()
.then(response => {
expect(response.role).toEqual("org_publisher");
session
.getUser()
.then(cachedResponse => {
expect(cachedResponse.fullName).toEqual("John Smith");
done();
})
.catch(e => {
fail(e);
});
})
.catch(e => {
fail(e);
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

import { IEditFeatureResult, appendCustomParams } from "./helpers";
import { IEditFeatureResult } from "./helpers";

/**
* Request options to for updating a related attachment to a feature by id. See [Update Attachment](https://developers.arcgis.com/rest/services-reference/update-attachment.htm) for more information.
Expand Down
145 changes: 83 additions & 62 deletions packages/arcgis-rest-feature-service/test/attachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,23 @@ describe("attachment methods", () => {
httpMethod: "GET"
} as IGetAttachmentsOptions;
fetchMock.once("*", getAttachmentsResponse);
getAttachments(requestOptions).then(response => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${
requestOptions.featureId
}/attachments?f=json&gdbVersion=SDE.DEFAULT`
);
expect(options.method).toBe("GET");
expect(getAttachmentsResponse.attachmentInfos.length).toEqual(2);
expect(getAttachmentsResponse.attachmentInfos[0].id).toEqual(409);
done();
});
getAttachments(requestOptions)
.then(() => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${
requestOptions.featureId
}/attachments?f=json&gdbVersion=SDE.DEFAULT`
);
expect(options.method).toBe("GET");
expect(getAttachmentsResponse.attachmentInfos.length).toEqual(2);
expect(getAttachmentsResponse.attachmentInfos[0].id).toEqual(409);
done();
})
.catch(e => {
fail(e);
});
});

it("should return objectId of the added attachment and a truthy success", done => {
Expand All @@ -74,22 +78,31 @@ describe("attachment methods", () => {
}
} as IAddAttachmentOptions;
fetchMock.once("*", addAttachmentResponse);
addAttachment(requestOptions).then(response => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${requestOptions.featureId}/addAttachment`
);
expect(options.method).toBe("POST");
expect(options.body instanceof FormData).toBeTruthy();
const params = options.body as FormData;
// we could introspect FormData in Chrome this way, but not Node.js
// more info: https://github.com/form-data/form-data/issues/124
// expect(params.get("returnEditMoment")).toEqual("true");
expect(addAttachmentResponse.addAttachmentResult.objectId).toEqual(1001);
expect(addAttachmentResponse.addAttachmentResult.success).toEqual(true);
done();
});
addAttachment(requestOptions)
.then(() => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${requestOptions.featureId}/addAttachment`
);
expect(options.method).toBe("POST");

const params = options.body as FormData;
expect(params instanceof FormData).toBeTruthy();
// we can introspect FormData in Chrome this way, but not Node.js
// more info: https://github.com/form-data/form-data/issues/124
if (params.get) {
expect(params.get("returnEditMoment")).toEqual("true");
}
expect(addAttachmentResponse.addAttachmentResult.objectId).toEqual(
1001
);
expect(addAttachmentResponse.addAttachmentResult.success).toEqual(true);
done();
})
.catch(e => {
fail(e);
});
});

it("should return an error for a service/feature which does not have attachments", done => {
Expand All @@ -104,7 +117,7 @@ describe("attachment methods", () => {
} as IAddAttachmentOptions;
fetchMock.once("*", genericInvalidResponse);
addAttachment(requestOptions)
.then(response => {
.then(() => {
// nothing to test here forcing error
fail();
})
Expand Down Expand Up @@ -134,21 +147,25 @@ describe("attachment methods", () => {
}
} as IUpdateAttachmentOptions;
fetchMock.once("*", updateAttachmentResponse);
updateAttachment(requestOptions).then(response => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${requestOptions.featureId}/updateAttachment`
);
expect(options.method).toBe("POST");
expect(updateAttachmentResponse.updateAttachmentResult.objectId).toEqual(
1001
);
expect(updateAttachmentResponse.updateAttachmentResult.success).toEqual(
true
);
done();
});
updateAttachment(requestOptions)
.then(() => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${requestOptions.featureId}/updateAttachment`
);
expect(options.method).toBe("POST");
expect(
updateAttachmentResponse.updateAttachmentResult.objectId
).toEqual(1001);
expect(updateAttachmentResponse.updateAttachmentResult.success).toEqual(
true
);
done();
})
.catch(e => {
fail(e);
});
});

it("should return objectId of the deleted attachment and a truthy success", done => {
Expand All @@ -161,22 +178,26 @@ describe("attachment methods", () => {
}
} as IDeleteAttachmentsOptions;
fetchMock.once("*", deleteAttachmentsResponse);
deleteAttachments(requestOptions).then(response => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${requestOptions.featureId}/deleteAttachments`
);
expect(options.body).toContain("attachmentIds=1001");
expect(options.body).toContain("returnEditMoment=true");
expect(options.method).toBe("POST");
expect(
deleteAttachmentsResponse.deleteAttachmentResults[0].objectId
).toEqual(1001);
expect(
deleteAttachmentsResponse.deleteAttachmentResults[0].success
).toEqual(true);
done();
});
deleteAttachments(requestOptions)
.then(() => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${requestOptions.featureId}/deleteAttachments`
);
expect(options.body).toContain("attachmentIds=1001");
expect(options.body).toContain("returnEditMoment=true");
expect(options.method).toBe("POST");
expect(
deleteAttachmentsResponse.deleteAttachmentResults[0].objectId
).toEqual(1001);
expect(
deleteAttachmentsResponse.deleteAttachmentResults[0].success
).toEqual(true);
done();
})
.catch(e => {
fail(e);
});
});
});
Loading

0 comments on commit 0dc4531

Please sign in to comment.