DC-005: Fix all 138 broken test paths after src/ refactor

After the DC-005 module reorganization (41 files moved into src/ subdirs),
138 test suites failed because the refactor script's path-rewrite logic
missed three categories:

1. Files inside src/ doing 'require("./src/...")' — should be 'require("../...")'
2. Files in src/X/Y/ doing 'require("../../../src/...")' — should be 'require("../../...")'
3. Test files in __tests__/ with leftover 'require("../../../src/...")' paths

Root cause: the original refactor script ran before all files were moved,
so it computed relative paths against stale filesystem state.

Result:
- 30/30 test suites pass
- 879/879 tests pass (was: 18/30 suites, 614/687 tests)

Also fixed:
- routes/apps/restore.js: wrong responses import path
- routes/*/*.js: '../../src/utilities/X' → '../src/utilities/X' (depth 2 routes)
This commit is contained in:
Hermes
2026-06-13 12:16:56 -07:00
parent 9468dfc0eb
commit 7bc2a207f3
129 changed files with 591 additions and 310 deletions
@@ -9,27 +9,27 @@ function asyncHandler(fn) {
}
// Mock modules that services.js requires at top-level
jest.mock('../../constants', () => ({
jest.mock('../../src/utilities/constants', () => ({
APP: { USER_AGENTS: { PROBE: 'DashCaddy/1.0' } },
REGEX: { SUBDOMAIN: /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/ },
TIMEOUTS: { DEFAULT: 10000 },
HTTP_STATUS: { OK: 200, CREATED: 201, NO_CONTENT: 204, BAD_REQUEST: 400, UNAUTHORIZED: 401, FORBIDDEN: 403, NOT_FOUND: 404, CONFLICT: 409, INTERNAL_ERROR: 500 }
}));
jest.mock('../../input-validator', () => ({
jest.mock('../../src/security/input-validator', () => ({
validateServiceConfig: jest.fn(),
isValidPort: jest.fn(p => p >= 1 && p <= 65535),
}));
jest.mock('../../fs-helpers', () => ({
jest.mock('../../src/utilities/fs-helpers', () => ({
exists: jest.fn().mockResolvedValue(true),
}));
jest.mock('../../url-resolver', () => ({
jest.mock('../../src/utilities/url-resolver', () => ({
resolveServiceUrl: jest.fn((id) => `https://${id}.test`),
}));
jest.mock('../../pagination', () => ({
jest.mock('../../src/utilities/pagination', () => ({
paginate: jest.fn((data, params) => ({ data, pagination: null })),
parsePaginationParams: jest.fn(() => null),
}));
@@ -45,8 +45,8 @@ jest.mock('../../src/utils/responses', () => ({
// errors module NOT mocked — used for real ValidationError/NotFoundError/ConflictError
const { exists } = require('../../fs-helpers');
const { validateServiceConfig } = require('../../input-validator');
const { exists } = require('../../src/utilities/fs-helpers');
const { validateServiceConfig } = require('../../src/security/input-validator');
function createApp(depsOverride = {}) {
const defaultDeps = {
@@ -450,7 +450,7 @@ describe('Services Routes', () => {
});
it('rejects invalid port', async () => {
const { isValidPort } = require('../../input-validator');
const { isValidPort } = require('../../src/security/input-validator');
isValidPort.mockReturnValue(false);
const { app } = createApp();
const res = await request(app)