-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wrangler-d1): Teach wrangler d1 insights about more timePeriods (#…
…5307) * feat(wrangler-d1): Teach wrangler d1 insights about more timePeriods * Change to patch Co-authored-by: Max Rozen <[email protected]> * Update changeset description Co-authored-by: Max Rozen <[email protected]> * Address review comments * chore: add tests for d1 insights --------- Co-authored-by: Max Rozen <[email protected]>
- Loading branch information
Showing
3 changed files
with
91 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: add more timePeriods to `wrangler d1 insights` | ||
|
||
This PR updates `wrangler d1 insights` to accept arbitrary timePeriod values up to 31 days. |
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,42 @@ | ||
import { vi } from "vitest"; | ||
import { getDurationDates } from "../../d1/insights"; | ||
|
||
describe("getDurationDates()", () => { | ||
beforeAll(() => { | ||
vi.useFakeTimers(); | ||
//lock time to 2023-08-01 UTC | ||
vi.setSystemTime(new Date(2023, 7, 1)); | ||
}); | ||
|
||
afterAll(() => { | ||
vi.useRealTimers(); | ||
}); | ||
|
||
it("should throw an error if duration is greater than 31 days (in days)", () => { | ||
expect(() => getDurationDates("32d")).toThrowError( | ||
"Duration cannot be greater than 31 days" | ||
); | ||
}); | ||
it("should throw an error if duration is greater than 31 days (in minutes)", () => { | ||
expect(() => getDurationDates("44641m")).toThrowError( | ||
"Duration cannot be greater than 44640 minutes (31 days)" | ||
); | ||
}); | ||
|
||
it("should throw an error if duration is greater than 31 days (in hours)", () => { | ||
expect(() => getDurationDates("745h")).toThrowError( | ||
"Duration cannot be greater than 744 hours (31 days)" | ||
); | ||
}); | ||
|
||
it("should throw an error if duration unit is invalid", () => { | ||
expect(() => getDurationDates("1y")).toThrowError("Invalid duration unit"); | ||
}); | ||
|
||
it("should return the correct start and end dates", () => { | ||
const [startDate, endDate] = getDurationDates("5d"); | ||
|
||
expect(+new Date(startDate)).toBe(+new Date(2023, 6, 27)); | ||
expect(+new Date(endDate)).toBe(+new Date(2023, 7, 1)); | ||
}); | ||
}); |
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