mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-15 20:25:23 +02:00
feat(tests): add mock database setup for Vitest testing environment
- Introduced a new mock database setup file to simulate database interactions during tests. - Updated Vitest configuration to include the mock setup file, enhancing test reliability and isolation.
This commit is contained in:
56
apps/dokploy/__test__/setup/mock-db.ts
Normal file
56
apps/dokploy/__test__/setup/mock-db.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
// Mock postgres to prevent actual database connections
|
||||
vi.mock("postgres", () => {
|
||||
return {
|
||||
default: vi.fn(() => ({
|
||||
end: vi.fn(),
|
||||
unsafe: vi.fn(),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
// Mock the db export from @dokploy/server/db
|
||||
vi.mock("@dokploy/server/db", () => {
|
||||
const createChainableMock = (): any => {
|
||||
const chain: any = {
|
||||
set: vi.fn(() => chain),
|
||||
where: vi.fn(() => chain),
|
||||
returning: vi.fn().mockResolvedValue([{}]),
|
||||
execute: vi.fn().mockResolvedValue([{}]),
|
||||
};
|
||||
return chain;
|
||||
};
|
||||
|
||||
return {
|
||||
db: {
|
||||
select: vi.fn(() => createChainableMock()),
|
||||
insert: vi.fn(() => createChainableMock()),
|
||||
update: vi.fn(() => createChainableMock()),
|
||||
delete: vi.fn(() => createChainableMock()),
|
||||
query: {
|
||||
applications: {
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
deployments: {
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
servers: {
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
users: {
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
organizations: {
|
||||
findFirst: vi.fn(),
|
||||
findMany: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
dbUrl: "postgres://mock:mock@localhost:5432/mock",
|
||||
};
|
||||
});
|
||||
@@ -7,6 +7,7 @@ export default defineConfig({
|
||||
include: ["__test__/**/*.test.ts"], // Incluir solo los archivos de test en el directorio __test__
|
||||
exclude: ["**/node_modules/**", "**/dist/**", "**/.docker/**"],
|
||||
pool: "forks",
|
||||
setupFiles: ["./__test__/setup/mock-db.ts"],
|
||||
},
|
||||
define: {
|
||||
"process.env": {
|
||||
|
||||
Reference in New Issue
Block a user