mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-21 13:23:14 +01:00
Fix failing tests (#1009)
* chore: ignore all .data directories * fix: date locale for unit tests * test: disable parallelism to prevent database locks * chore: fix lint errors * chore: remove unused function --------- Co-authored-by: zebrapurring <> Co-authored-by: Tonya <tonya@tokia.dev>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -60,7 +60,7 @@ backend/app/api/static/public/*
|
|||||||
backend/api
|
backend/api
|
||||||
|
|
||||||
docs/.vitepress/cache/
|
docs/.vitepress/cache/
|
||||||
/.data/
|
.data/
|
||||||
|
|
||||||
# Playwright
|
# Playwright
|
||||||
frontend/test-results/
|
frontend/test-results/
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ function clampDecimals(currency: string, decimals: number): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Type guard to validate currency response shape with strict validation
|
// Type guard to validate currency response shape with strict validation
|
||||||
function isValidCurrencyItem(item: CurrenciesCurrency) {
|
function isValidCurrencyItem(item: CurrenciesCurrency): boolean {
|
||||||
if (
|
if (
|
||||||
typeof item !== "object" ||
|
typeof item !== "object" ||
|
||||||
item === null ||
|
item === null ||
|
||||||
|
|||||||
@@ -1,20 +1,9 @@
|
|||||||
import { describe, expect, test } from "vitest";
|
import { describe, expect, test } from "vitest";
|
||||||
import { factorRange, format, parse, zeroTime } from "./datelib";
|
import { factorRange, parse, zeroTime } from "./datelib";
|
||||||
|
|
||||||
describe("format", () => {
|
|
||||||
test("should format a date as a string", () => {
|
|
||||||
const date = new Date(2020, 1, 1);
|
|
||||||
expect(format(date)).toBe("2020-02-01");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("should return the string if a string is passed in", () => {
|
|
||||||
expect(format("2020-02-01")).toBe("2020-02-01");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("zeroTime", () => {
|
describe("zeroTime", () => {
|
||||||
test("should zero out the time", () => {
|
test("should zero out the time", () => {
|
||||||
const date = new Date(2020, 1, 1, 12, 30, 30);
|
const date = new Date(Date.UTC(2020, 1, 1, 12, 30, 30));
|
||||||
const zeroed = zeroTime(date);
|
const zeroed = zeroTime(date);
|
||||||
expect(zeroed.getHours()).toBe(0);
|
expect(zeroed.getHours()).toBe(0);
|
||||||
expect(zeroed.getMinutes()).toBe(0);
|
expect(zeroed.getMinutes()).toBe(0);
|
||||||
|
|||||||
@@ -1,19 +1,9 @@
|
|||||||
import { addDays } from "date-fns";
|
import { addDays } from "date-fns";
|
||||||
|
|
||||||
/*
|
|
||||||
* Formats a date as a string
|
|
||||||
* */
|
|
||||||
export function format(date: Date | string): string {
|
|
||||||
if (typeof date === "string") {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
return date.toISOString().split("T")[0]!;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function zeroTime(date: Date): Date {
|
export function zeroTime(date: Date): Date {
|
||||||
return new Date(
|
const result = new Date(date.getTime());
|
||||||
new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - date.getTimezoneOffset() * 60000
|
result.setHours(0, 0, 0, 0);
|
||||||
);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function factorRange(offset: number = 7): [Date, Date] {
|
export function factorRange(offset: number = 7): [Date, Date] {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"lint:fix": "eslint --ext \".ts,.js,.vue\" --ignore-pattern \"components/ui\" . --fix",
|
"lint:fix": "eslint --ext \".ts,.js,.vue\" --ignore-pattern \"components/ui\" . --fix",
|
||||||
"lint:ci": "eslint --ext \".ts,.js,.vue\" --ignore-pattern \"components/ui\" . --max-warnings 1",
|
"lint:ci": "eslint --ext \".ts,.js,.vue\" --ignore-pattern \"components/ui\" . --max-warnings 1",
|
||||||
"typecheck": "pnpm nuxi typecheck --noEmit",
|
"typecheck": "pnpm nuxi typecheck --noEmit",
|
||||||
"test:ci": "TEST_SHUTDOWN_API_SERVER=true vitest --run --config ./test/vitest.config.ts",
|
"test:ci": "TEST_SHUTDOWN_API_SERVER=true vitest --run --config ./test/vitest.config.ts --no-file-parallelism",
|
||||||
"test:local": "TEST_SHUTDOWN_API_SERVER=false && vitest --run --config ./test/vitest.config.ts",
|
"test:local": "TEST_SHUTDOWN_API_SERVER=false && vitest --run --config ./test/vitest.config.ts",
|
||||||
"test:watch": " TEST_SHUTDOWN_API_SERVER=false vitest --config ./test/vitest.config.ts"
|
"test:watch": " TEST_SHUTDOWN_API_SERVER=false vitest --config ./test/vitest.config.ts"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user