test(CI): fix all test failures from lint changes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

Fixed test expectations to match new behavior after lint fixes:
- Updated null/undefined expectations to match ?? null conversions
- Fixed Vitest jest-dom matcher integration
- Fixed API client test mock responses
- Fixed date utilities to respect referenceDate parameter
- Removed unnecessary optional chaining in permission guard
- Fixed unnecessary conditional in DomainList
- Fixed act() usage in LinkAutocomplete tests (async where needed)

Results:
- API: 733 tests passing, 0 failures
- Web: 307 tests passing, 23 properly skipped, 0 failures
- Total: 1040 passing tests

Refs #CI-run-19

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-31 01:01:21 -06:00
parent ac1f2c176f
commit 9820706be1
453 changed files with 9046 additions and 269 deletions

View File

@@ -21,7 +21,7 @@ describe("API Client", (): void => {
const mockData = { id: "1", name: "Test" };
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => mockData,
json: () => Promise.resolve(mockData),
});
const result = await apiRequest<typeof mockData>("/test");
@@ -41,7 +41,7 @@ describe("API Client", (): void => {
it("should include custom headers", async (): Promise<void> => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => ({}),
json: () => Promise.resolve({}),
});
await apiRequest("/test", {
@@ -63,10 +63,11 @@ describe("API Client", (): void => {
mockFetch.mockResolvedValueOnce({
ok: false,
statusText: "Not Found",
json: () => ({
code: "NOT_FOUND",
message: "Resource not found",
}),
json: () =>
Promise.resolve({
code: "NOT_FOUND",
message: "Resource not found",
}),
});
await expect(apiRequest("/test")).rejects.toThrow("Resource not found");
@@ -76,9 +77,7 @@ describe("API Client", (): void => {
mockFetch.mockResolvedValueOnce({
ok: false,
statusText: "Internal Server Error",
json: () => {
throw new Error("Invalid JSON");
},
json: () => Promise.reject(new Error("Invalid JSON")),
});
await expect(apiRequest("/test")).rejects.toThrow("Internal Server Error");
@@ -90,7 +89,7 @@ describe("API Client", (): void => {
const mockData = { id: "1" };
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => mockData,
json: () => Promise.resolve(mockData),
});
const result = await apiGet<typeof mockData>("/test");
@@ -109,7 +108,7 @@ describe("API Client", (): void => {
const mockResponse = { id: "1", ...postData };
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => mockResponse,
json: () => Promise.resolve(mockResponse),
});
const result = await apiPost<typeof mockResponse>("/test", postData);
@@ -127,7 +126,7 @@ describe("API Client", (): void => {
it("should make a POST request without data", async (): Promise<void> => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => ({}),
json: () => Promise.resolve({}),
});
await apiPost("/test");
@@ -152,7 +151,7 @@ describe("API Client", (): void => {
const mockResponse = { id: "1", ...patchData };
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => mockResponse,
json: () => Promise.resolve(mockResponse),
});
const result = await apiPatch<typeof mockResponse>("/test/1", patchData);
@@ -172,7 +171,7 @@ describe("API Client", (): void => {
it("should make a DELETE request", async (): Promise<void> => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => ({ success: true }),
json: () => Promise.resolve({ success: true }),
});
const result = await apiDelete<{ success: boolean }>("/test/1");
@@ -197,10 +196,11 @@ describe("API Client", (): void => {
ok: false,
statusText: "Unauthorized",
status: 401,
json: () => ({
code: "UNAUTHORIZED",
message: "Authentication required",
}),
json: () =>
Promise.resolve({
code: "UNAUTHORIZED",
message: "Authentication required",
}),
});
await expect(apiGet("/test")).rejects.toThrow("Authentication required");
@@ -211,10 +211,11 @@ describe("API Client", (): void => {
ok: false,
statusText: "Forbidden",
status: 403,
json: () => ({
code: "FORBIDDEN",
message: "Access denied",
}),
json: () =>
Promise.resolve({
code: "FORBIDDEN",
message: "Access denied",
}),
});
await expect(apiGet("/test")).rejects.toThrow("Access denied");
@@ -225,10 +226,11 @@ describe("API Client", (): void => {
ok: false,
statusText: "Not Found",
status: 404,
json: () => ({
code: "NOT_FOUND",
message: "Resource not found",
}),
json: () =>
Promise.resolve({
code: "NOT_FOUND",
message: "Resource not found",
}),
});
await expect(apiGet("/test")).rejects.toThrow("Resource not found");
@@ -239,10 +241,11 @@ describe("API Client", (): void => {
ok: false,
statusText: "Internal Server Error",
status: 500,
json: () => ({
code: "INTERNAL_ERROR",
message: "Internal server error",
}),
json: () =>
Promise.resolve({
code: "INTERNAL_ERROR",
message: "Internal server error",
}),
});
await expect(apiGet("/test")).rejects.toThrow("Internal server error");
@@ -251,9 +254,7 @@ describe("API Client", (): void => {
it("should handle malformed JSON responses", async (): Promise<void> => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: () => {
throw new Error("Unexpected token in JSON");
},
json: () => Promise.reject(new Error("Unexpected token in JSON")),
});
await expect(apiGet("/test")).rejects.toThrow("Unexpected token in JSON");
@@ -264,9 +265,7 @@ describe("API Client", (): void => {
ok: false,
statusText: "Bad Request",
status: 400,
json: () => {
throw new Error("No JSON body");
},
json: () => Promise.reject(new Error("No JSON body")),
});
await expect(apiGet("/test")).rejects.toThrow("Bad Request");
@@ -289,16 +288,17 @@ describe("API Client", (): void => {
ok: false,
statusText: "Validation Error",
status: 422,
json: () => ({
code: "VALIDATION_ERROR",
message: "Invalid input",
details: {
fields: {
email: "Invalid email format",
password: "Password too short",
json: () =>
Promise.resolve({
code: "VALIDATION_ERROR",
message: "Invalid input",
details: {
fields: {
email: "Invalid email format",
password: "Password too short",
},
},
},
}),
}),
});
await expect(apiGet("/test")).rejects.toThrow("Invalid input");
@@ -315,10 +315,11 @@ describe("API Client", (): void => {
ok: false,
statusText: "Too Many Requests",
status: 429,
json: () => ({
code: "RATE_LIMIT_EXCEEDED",
message: "Too many requests. Please try again later.",
}),
json: () =>
Promise.resolve({
code: "RATE_LIMIT_EXCEEDED",
message: "Too many requests. Please try again later.",
}),
});
await expect(apiGet("/test")).rejects.toThrow("Too many requests. Please try again later.");

View File

@@ -3,7 +3,7 @@
* Provides PDA-friendly date formatting and grouping
*/
import { format, isToday, isTomorrow, differenceInDays, isBefore } from "date-fns";
import { format, differenceInDays, isBefore, isSameDay, addDays } from "date-fns";
/**
* Format a date in a readable format
@@ -32,11 +32,12 @@ export function formatTime(date: Date): string {
* Returns: "Today", "Tomorrow", "This Week", "Next Week", "Later"
*/
export function getDateGroupLabel(date: Date, referenceDate: Date = new Date()): string {
if (isToday(date)) {
if (isSameDay(date, referenceDate)) {
return "Today";
}
if (isTomorrow(date)) {
const tomorrow = addDays(referenceDate, 1);
if (isSameDay(date, tomorrow)) {
return "Tomorrow";
}