-
Notifications
You must be signed in to change notification settings - Fork 1
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
e83ba61
commit 8a4935e
Showing
11 changed files
with
628 additions
and
84 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,37 @@ | ||
import getTrailingTwelveMonths from "@/utils/getTrailingTwelveMonths"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("getTrailingTwelveMonths", () => { | ||
// Basic functionality tests | ||
describe("Standard date inputs", () => { | ||
it("should return correct trailing 12 months start date for mid-year input", () => { | ||
expect(getTrailingTwelveMonths("2023-07")).toBe("2022-08"); | ||
}); | ||
|
||
it("should return correct trailing 12 months start date for year-end", () => { | ||
expect(getTrailingTwelveMonths("2023-12")).toBe("2023-01"); | ||
}); | ||
|
||
it("should return correct trailing 12 months start date for year-start", () => { | ||
expect(getTrailingTwelveMonths("2023-01")).toBe("2022-02"); | ||
}); | ||
}); | ||
|
||
// Edge case tests | ||
describe("Edge cases", () => { | ||
it("should handle single-digit month inputs", () => { | ||
expect(getTrailingTwelveMonths("2023-03")).toBe("2022-04"); | ||
}); | ||
|
||
it("should handle year transitions correctly", () => { | ||
expect(getTrailingTwelveMonths("2024-01")).toBe("2023-02"); | ||
}); | ||
}); | ||
|
||
// Leap year considerations | ||
describe("Leap year handling", () => { | ||
it("should work correctly across leap year boundaries", () => { | ||
expect(getTrailingTwelveMonths("2024-02")).toBe("2023-03"); | ||
}); | ||
}); | ||
}); |
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,8 @@ | ||
import { format, subMonths } from "date-fns"; | ||
|
||
const getTrailingTwelveMonths = (dateString: string) => { | ||
const targetDate = new Date(`${dateString}-01`); | ||
return format(subMonths(targetDate, 11), "yyyy-MM"); | ||
}; | ||
|
||
export default getTrailingTwelveMonths; |
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
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,21 @@ | ||
import { resolve } from "node:path"; | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: "node", | ||
coverage: { | ||
provider: "v8", | ||
reporter: ["text", "json", "html"], | ||
include: ["src/**/*.{js,ts}"], | ||
exclude: ["**/node_modules/**", "**/*.d.ts"], | ||
}, | ||
include: ["src/**/*.{test,spec}.{js,ts}"], | ||
}, | ||
resolve: { | ||
alias: { | ||
"@": resolve(__dirname, "./src"), | ||
}, | ||
}, | ||
}); |