feat: add opportunity workflows, delete routes, company sites, algorithms, and expanded test coverage

This commit is contained in:
2026-03-09 02:56:08 -05:00
parent c0a4d4f919
commit f53b390e18
50 changed files with 8837 additions and 63 deletions
+107
View File
@@ -17,6 +17,45 @@ const { privateKey: _testPrivateKey, publicKey: _testPublicKey } =
publicKeyEncoding: { type: "spki", format: "pem" },
});
// ---------------------------------------------------------------------------
// Mock the globalEvents module — many source files import `events` from here.
// We provide both `events` and `setupEventDebugger` so that no test
// encounters "export not found" when another test's mock.module is stale.
// ---------------------------------------------------------------------------
mock.module("../src/modules/globalEvents", () => ({
events: {
emit: mock(),
on: mock(),
off: mock(),
once: mock(),
removeAllListeners: mock(),
},
setupEventDebugger: mock(),
}));
// ---------------------------------------------------------------------------
// Mock modules that are commonly mocked by test files at top-level.
// Having them in the preload ensures that even when per-test mock.module
// calls persist globally, the baseline mock is complete.
// ---------------------------------------------------------------------------
mock.module("../src/modules/fetchMicrosoftUser", () => ({
fetchMicrosoftUser: mock(() => Promise.resolve({})),
}));
mock.module("../src/managers/sessions", () => ({
sessions: {
create: mock(() =>
Promise.resolve({
accessToken: "mock-access",
refreshToken: "mock-refresh",
}),
),
fetch: mock(() => Promise.resolve(null)),
},
}));
// ---------------------------------------------------------------------------
// Mock the constants module — almost every source file imports from here.
// We provide safe defaults so modules can be imported without side-effects.
@@ -60,6 +99,74 @@ mock.module("../src/constants", () => ({
// Helpers
// ---------------------------------------------------------------------------
/**
* Build a complete mock constants object for use with `mock.module()`.
*
* Pass `overrides` to replace specific exports (e.g. a custom prisma mock).
* All keys from the preload mock are included so that downstream modules
* importing named exports (secureValuesPublicKey, connectWiseApi, etc.)
* never encounter "export not found" errors.
*/
export function buildMockConstants(
overrides: Record<string, any> = {},
): Record<string, any> {
return {
prisma: createMockPrisma(),
PORT: "3333",
API_BASE_URL: "http://localhost:3333",
sessionDuration: 30 * 24 * 60 * 60_000,
accessTokenDuration: "10min",
refreshTokenDuration: "30d",
accessTokenPrivateKey: _testPrivateKey,
refreshTokenPrivateKey: _testPrivateKey,
permissionsPrivateKey: _testPrivateKey,
secureValuesPrivateKey: _testPrivateKey,
secureValuesPublicKey: _testPublicKey,
msalClient: { acquireTokenByCode: mock(() => Promise.resolve({})) },
connectWiseApi: {
get: mock(() => Promise.resolve({ data: {} })),
post: mock(() => Promise.resolve({ data: {} })),
put: mock(() => Promise.resolve({ data: {} })),
patch: mock(() => Promise.resolve({ data: {} })),
delete: mock(() => Promise.resolve({ data: {} })),
},
redis: {
get: mock(() => Promise.resolve(null)),
set: mock(() => Promise.resolve("OK")),
del: mock(() => Promise.resolve(1)),
},
unifi: createMockUnifi(),
unifiControllerBaseUrl: "https://unifi.test.local",
unifiSite: "default",
unifiUsername: "admin",
unifiPassword: "test-pass",
io: { of: mock(() => ({ on: mock() })) },
engine: {},
...overrides,
};
}
/**
* Build a complete mock globalEvents object for use with `mock.module()`.
* Includes both `events` and `setupEventDebugger` so downstream modules
* never encounter "export not found" errors.
*/
export function buildMockGlobalEvents(
overrides: Record<string, any> = {},
): Record<string, any> {
return {
events: {
emit: mock(),
on: mock(),
off: mock(),
once: mock(),
removeAllListeners: mock(),
},
setupEventDebugger: mock(),
...overrides,
};
}
export function createMockPrisma() {
const createModelProxy = () =>
new Proxy(