Skip to content

Commit

Permalink
f/165476 moved function
Browse files Browse the repository at this point in the history
  • Loading branch information
drspacemanphd committed Jan 26, 2021
1 parent c351ae0 commit 97723e6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
ILayerDefinition
} from "@esri/arcgis-rest-feature-layer";
import { DownloadFormat, DownloadFormats } from "../download-format";
import { urlBuilder, composeDownloadId, isRecentlyUpdated } from "../utils";
import { urlBuilder, composeDownloadId } from "../utils";
import { DownloadTarget } from "../download-target";
import { DownloadStatus } from "../download-status";
import { isRecentlyUpdated } from "./utils";

enum ItemTypes {
FeatureService = "Feature Service",
Expand Down
17 changes: 17 additions & 0 deletions packages/downloads/src/portal/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DownloadTarget } from "../download-target";

const DOWNLOADS_LOCK_MS = 10 * 60 * 1000;

/**
* @private
*/
export function isRecentlyUpdated(
target: DownloadTarget,
lastEditDate: number
): boolean {
return (
target === "portal" &&
lastEditDate &&
new Date().getTime() - lastEditDate <= DOWNLOADS_LOCK_MS
);
}
18 changes: 0 additions & 18 deletions packages/downloads/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { DownloadTarget } from "./download-target";

const DOWNLOADS_LOCK_MS = 10 * 60 * 1000;

interface IQueryParams {
[key: string]: string;
}
Expand Down Expand Up @@ -53,17 +49,3 @@ export function composeDownloadId(params: IDownloadIdParams): string {
const { datasetId, format, spatialRefId, geometry, where } = params;
return `${datasetId}:${format}:${spatialRefId}:${geometry}:${where}`;
}

/**
* @private
*/
export function isRecentlyUpdated(
target: DownloadTarget,
lastEditDate: number
): boolean {
return (
target === "portal" &&
lastEditDate &&
new Date().getTime() - lastEditDate <= DOWNLOADS_LOCK_MS
);
}
38 changes: 38 additions & 0 deletions packages/downloads/test/portal/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { DownloadTarget } from "../../src/download-target";
import { isRecentlyUpdated } from "../../src/portal/utils";

describe("isRecentlyUpdated", () => {
it('should return false if target is not "portal", even if data was recently updated', done => {
const targetOne: DownloadTarget = undefined;
const targetTwo: DownloadTarget = "hub";
const targetThree: DownloadTarget = "enterprise";
const lastEditDate: number = new Date().getTime();

expect(isRecentlyUpdated(targetOne, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetTwo, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetThree, lastEditDate)).toBeFalsy();
done();
});

it("should return false for any target if data was recently updated", done => {
const targetOne: DownloadTarget = undefined;
const targetTwo: DownloadTarget = "hub";
const targetThree: DownloadTarget = "enterprise";
const targetFour: DownloadTarget = "portal";
const lastEditDate: number = 1000;

expect(isRecentlyUpdated(targetOne, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetTwo, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetThree, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetFour, lastEditDate)).toBeFalsy();
done();
});

it('should return true only if target is "portal" and if data was recently updated', done => {
const target: DownloadTarget = "portal";
const lastEditDate: number = new Date().getTime();

expect(isRecentlyUpdated(target, lastEditDate)).toBeTruthy();
done();
});
});
39 changes: 1 addition & 38 deletions packages/downloads/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DownloadTarget } from "../src/download-target";
import { urlBuilder, composeDownloadId, isRecentlyUpdated } from "../src/utils";
import { urlBuilder, composeDownloadId } from "../src/utils";

describe("utils", () => {
describe("urlBuilder", () => {
Expand Down Expand Up @@ -54,40 +53,4 @@ describe("utils", () => {
done();
});
});

describe("isRecentlyUpdated", () => {
it('should return false if target is not "portal", even if data was recently updated', done => {
const targetOne: DownloadTarget = undefined;
const targetTwo: DownloadTarget = "hub";
const targetThree: DownloadTarget = "enterprise";
const lastEditDate: number = new Date().getTime();

expect(isRecentlyUpdated(targetOne, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetTwo, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetThree, lastEditDate)).toBeFalsy();
done();
});

it("should return false for any target if data was recently updated", done => {
const targetOne: DownloadTarget = undefined;
const targetTwo: DownloadTarget = "hub";
const targetThree: DownloadTarget = "enterprise";
const targetFour: DownloadTarget = "portal";
const lastEditDate: number = 1000;

expect(isRecentlyUpdated(targetOne, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetTwo, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetThree, lastEditDate)).toBeFalsy();
expect(isRecentlyUpdated(targetFour, lastEditDate)).toBeFalsy();
done();
});

it('should return true only if target is "portal" and if data was recently updated', done => {
const target: DownloadTarget = "portal";
const lastEditDate: number = new Date().getTime();

expect(isRecentlyUpdated(target, lastEditDate)).toBeTruthy();
done();
});
});
});

0 comments on commit 97723e6

Please sign in to comment.