diff --git a/apps/dokploy/__test__/drop/drop.test.test.ts b/apps/dokploy/__test__/drop/drop.test.test.ts index c5960fce..23d6eace 100644 --- a/apps/dokploy/__test__/drop/drop.test.test.ts +++ b/apps/dokploy/__test__/drop/drop.test.test.ts @@ -81,14 +81,17 @@ const baseApp: ApplicationNested = { username: null, dockerContextPath: null, }; -// -vi.mock("@/server/constants", () => ({ - paths: () => ({ - APPLICATIONS_PATH: "./__test__/drop/zips/output", - }), - // APPLICATIONS_PATH: "./__test__/drop/zips/output", -})); +vi.mock("@dokploy/builders", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + unzipDrop: actual.unzipDrop, // Asegura que unzipDrop esté presente en el mock + paths: () => ({ + APPLICATIONS_PATH: "./__test__/drop/zips/output", + }), + }; +}); describe("unzipDrop using real zip files", () => { // const { APPLICATIONS_PATH } = paths(); beforeAll(async () => { @@ -102,15 +105,19 @@ describe("unzipDrop using real zip files", () => { it("should correctly extract a zip with a single root folder", async () => { baseApp.appName = "single-file"; // const appName = "single-file"; - const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code"); - const zip = new AdmZip("./__test__/drop/zips/single-file.zip"); - - const zipBuffer = zip.toBuffer(); - const file = new File([zipBuffer], "single.zip"); - await unzipDrop(file, baseApp); - - const files = await fs.readdir(outputPath, { withFileTypes: true }); - expect(files.some((f) => f.name === "test.txt")).toBe(true); + try { + const outputPath = path.join(APPLICATIONS_PATH, baseApp.appName, "code"); + const zip = new AdmZip("./__test__/drop/zips/single-file.zip"); + console.log(`Output Path: ${outputPath}`); + const zipBuffer = zip.toBuffer(); + const file = new File([zipBuffer], "single.zip"); + await unzipDrop(file, baseApp); + const files = await fs.readdir(outputPath, { withFileTypes: true }); + expect(files.some((f) => f.name === "test.txt")).toBe(true); + } catch (err) { + console.log(err); + } finally { + } }); it("should correctly extract a zip with a single root folder and a subfolder", async () => { diff --git a/apps/dokploy/__test__/vitest.config.ts b/apps/dokploy/__test__/vitest.config.ts index 71749b6c..c11f6cef 100644 --- a/apps/dokploy/__test__/vitest.config.ts +++ b/apps/dokploy/__test__/vitest.config.ts @@ -13,4 +13,9 @@ export default defineConfig({ exclude: ["**/node_modules/**", "**/dist/**", "**/.docker/**"], pool: "forks", }, + define: { + "process.env": { + NODE: "test", + }, + }, }); diff --git a/packages/builders/src/db/index.ts b/packages/builders/src/db/index.ts index 7c5f79bd..c8153144 100644 --- a/packages/builders/src/db/index.ts +++ b/packages/builders/src/db/index.ts @@ -1,15 +1,7 @@ import { type PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js"; import postgres from "postgres"; -// import { sc } from "@dokploy/schema"; import * as schema from "./schema"; -// schema -// import * as schema from "@dokploy/schema"; - -// type Schema = typeof schema; - -// type Schema = typeof schema; declare global { - // eslint-disable-next-line no-var -- only var works here var db: PostgresJsDatabase | undefined; } diff --git a/packages/builders/src/db/migration.ts b/packages/builders/src/db/migration.ts index d38d3943..75a79b34 100644 --- a/packages/builders/src/db/migration.ts +++ b/packages/builders/src/db/migration.ts @@ -1,21 +1,21 @@ -import { drizzle } from "drizzle-orm/postgres-js"; -import { migrate } from "drizzle-orm/postgres-js/migrator"; -import postgres from "postgres"; +// import { drizzle } from "drizzle-orm/postgres-js"; +// import { migrate } from "drizzle-orm/postgres-js/migrator"; +// import postgres from "postgres"; -const connectionString = process.env.DATABASE_URL || ""; +// const connectionString = process.env.DATABASE_URL || ""; -const sql = postgres(connectionString, { max: 1 }); -const db = drizzle(sql); +// const sql = postgres(connectionString, { max: 1 }); +// const db = drizzle(sql); -export const migration = async () => - await migrate(db, { migrationsFolder: "drizzle" }) - .then(() => { - console.log("Migration complete"); - sql.end(); - }) - .catch((error) => { - console.log("Migration failed", error); - }) - .finally(() => { - sql.end(); - }); +// export const migration = async () => +// await migrate(db, { migrationsFolder: "drizzle" }) +// .then(() => { +// console.log("Migration complete"); +// sql.end(); +// }) +// .catch((error) => { +// console.log("Migration failed", error); +// }) +// .finally(() => { +// sql.end(); +// }); diff --git a/packages/builders/src/db/reset.ts b/packages/builders/src/db/reset.ts index 4a4dbecb..d280e0f2 100644 --- a/packages/builders/src/db/reset.ts +++ b/packages/builders/src/db/reset.ts @@ -1,23 +1,23 @@ -import { sql } from "drizzle-orm"; -// Credits to Louistiti from Drizzle Discord: https://discord.com/channels/1043890932593987624/1130802621750448160/1143083373535973406 -import { drizzle } from "drizzle-orm/postgres-js"; -import postgres from "postgres"; +// import { sql } from "drizzle-orm"; +// // Credits to Louistiti from Drizzle Discord: https://discord.com/channels/1043890932593987624/1130802621750448160/1143083373535973406 +// import { drizzle } from "drizzle-orm/postgres-js"; +// import postgres from "postgres"; -const connectionString = process.env.DATABASE_URL || ""; +// const connectionString = process.env.DATABASE_URL || ""; -const pg = postgres(connectionString, { max: 1 }); -const db = drizzle(pg); +// const pg = postgres(connectionString, { max: 1 }); +// const db = drizzle(pg); -const clearDb = async (): Promise => { - try { - const tablesQuery = sql`DROP SCHEMA public CASCADE; CREATE SCHEMA public; DROP schema drizzle CASCADE;`; - const tables = await db.execute(tablesQuery); - console.log(tables); - await pg.end(); - } catch (error) { - console.error("Error to clean database", error); - } finally { - } -}; +// const clearDb = async (): Promise => { +// try { +// const tablesQuery = sql`DROP SCHEMA public CASCADE; CREATE SCHEMA public; DROP schema drizzle CASCADE;`; +// const tables = await db.execute(tablesQuery); +// console.log(tables); +// await pg.end(); +// } catch (error) { +// console.error("Error to clean database", error); +// } finally { +// } +// }; -clearDb(); +// clearDb(); diff --git a/packages/builders/src/db/seed.ts b/packages/builders/src/db/seed.ts index bbb3c3f2..9e19cb0f 100644 --- a/packages/builders/src/db/seed.ts +++ b/packages/builders/src/db/seed.ts @@ -1,35 +1,35 @@ -import bc from "bcrypt"; -import { drizzle } from "drizzle-orm/postgres-js"; -import postgres from "postgres"; -import { users } from "./schema"; +// import bc from "bcrypt"; +// import { drizzle } from "drizzle-orm/postgres-js"; +// import postgres from "postgres"; +// import { users } from "./schema"; -const connectionString = process.env.DATABASE_URL || ""; +// const connectionString = process.env.DATABASE_URL || ""; -const pg = postgres(connectionString, { max: 1 }); -const db = drizzle(pg); +// const pg = postgres(connectionString, { max: 1 }); +// const db = drizzle(pg); -function password(txt: string) { - return bc.hashSync(txt, 10); -} +// function password(txt: string) { +// return bc.hashSync(txt, 10); +// } -async function seed() { - console.log("> Seed:", process.env.DATABASE_PATH, "\n"); +// async function seed() { +// console.log("> Seed:", process.env.DATABASE_PATH, "\n"); - // const authenticationR = await db - // .insert(users) - // .values([ - // { - // email: "user1@hotmail.com", - // password: password("12345671"), - // }, - // ]) - // .onConflictDoNothing() - // .returning(); +// // const authenticationR = await db +// // .insert(users) +// // .values([ +// // { +// // email: "user1@hotmail.com", +// // password: password("12345671"), +// // }, +// // ]) +// // .onConflictDoNothing() +// // .returning(); - // console.log("\nSemillas Update:", authenticationR.length); -} +// // console.log("\nSemillas Update:", authenticationR.length); +// } -seed().catch((e) => { - console.error(e); - process.exit(1); -}); +// seed().catch((e) => { +// console.error(e); +// process.exit(1); +// });