-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c351ae0
commit 97723e6
Showing
5 changed files
with
58 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters