From 43b7db00f93db5715a469996589c03a1d3444713 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 19 Jan 2025 01:21:03 -0600 Subject: [PATCH] refactor: add missing values to test --- .../server/update-server-config.test.ts | 109 +++++++++--------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/apps/dokploy/__test__/traefik/server/update-server-config.test.ts b/apps/dokploy/__test__/traefik/server/update-server-config.test.ts index c966748a..9c5beb40 100644 --- a/apps/dokploy/__test__/traefik/server/update-server-config.test.ts +++ b/apps/dokploy/__test__/traefik/server/update-server-config.test.ts @@ -1,95 +1,98 @@ import { fs, vol } from "memfs"; vi.mock("node:fs", () => ({ - ...fs, - default: fs, + ...fs, + default: fs, })); import type { Admin, FileConfig } from "@dokploy/server"; import { - createDefaultServerTraefikConfig, - loadOrCreateConfig, - updateServerTraefik, + createDefaultServerTraefikConfig, + loadOrCreateConfig, + updateServerTraefik, } from "@dokploy/server"; import { beforeEach, expect, test, vi } from "vitest"; const baseAdmin: Admin = { - createdAt: "", - authId: "", - adminId: "string", - serverIp: null, - certificateType: "none", - host: null, - letsEncryptEmail: null, - sshPrivateKey: null, - enableDockerCleanup: false, - enableLogRotation: false, - serversQuantity: 0, - stripeCustomerId: "", - stripeSubscriptionId: "", + cleanupCacheApplications: false, + cleanupCacheOnCompose: false, + cleanupCacheOnPreviews: false, + createdAt: "", + authId: "", + adminId: "string", + serverIp: null, + certificateType: "none", + host: null, + letsEncryptEmail: null, + sshPrivateKey: null, + enableDockerCleanup: false, + enableLogRotation: false, + serversQuantity: 0, + stripeCustomerId: "", + stripeSubscriptionId: "", }; beforeEach(() => { - vol.reset(); - createDefaultServerTraefikConfig(); + vol.reset(); + createDefaultServerTraefikConfig(); }); test("Should read the configuration file", () => { - const config: FileConfig = loadOrCreateConfig("dokploy"); + const config: FileConfig = loadOrCreateConfig("dokploy"); - expect(config.http?.routers?.["dokploy-router-app"]?.service).toBe( - "dokploy-service-app", - ); + expect(config.http?.routers?.["dokploy-router-app"]?.service).toBe( + "dokploy-service-app" + ); }); test("Should apply redirect-to-https", () => { - updateServerTraefik( - { - ...baseAdmin, - certificateType: "letsencrypt", - }, - "example.com", - ); + updateServerTraefik( + { + ...baseAdmin, + certificateType: "letsencrypt", + }, + "example.com" + ); - const config: FileConfig = loadOrCreateConfig("dokploy"); + const config: FileConfig = loadOrCreateConfig("dokploy"); - expect(config.http?.routers?.["dokploy-router-app"]?.middlewares).toContain( - "redirect-to-https", - ); + expect(config.http?.routers?.["dokploy-router-app"]?.middlewares).toContain( + "redirect-to-https" + ); }); test("Should change only host when no certificate", () => { - updateServerTraefik(baseAdmin, "example.com"); + updateServerTraefik(baseAdmin, "example.com"); - const config: FileConfig = loadOrCreateConfig("dokploy"); + const config: FileConfig = loadOrCreateConfig("dokploy"); - expect(config.http?.routers?.["dokploy-router-app-secure"]).toBeUndefined(); + expect(config.http?.routers?.["dokploy-router-app-secure"]).toBeUndefined(); }); test("Should not touch config without host", () => { - const originalConfig: FileConfig = loadOrCreateConfig("dokploy"); + const originalConfig: FileConfig = loadOrCreateConfig("dokploy"); - updateServerTraefik(baseAdmin, null); + updateServerTraefik(baseAdmin, null); - const config: FileConfig = loadOrCreateConfig("dokploy"); + const config: FileConfig = loadOrCreateConfig("dokploy"); - expect(originalConfig).toEqual(config); + expect(originalConfig).toEqual(config); }); test("Should remove websecure if https rollback to http", () => { - const originalConfig: FileConfig = loadOrCreateConfig("dokploy"); + const originalConfig: FileConfig = loadOrCreateConfig("dokploy"); - updateServerTraefik( - { ...baseAdmin, certificateType: "letsencrypt" }, - "example.com", - ); + updateServerTraefik( + { ...baseAdmin, certificateType: "letsencrypt" }, + "example.com" + ); - updateServerTraefik({ ...baseAdmin, certificateType: "none" }, "example.com"); + updateServerTraefik({ ...baseAdmin, certificateType: "none" }, "example.com"); - const config: FileConfig = loadOrCreateConfig("dokploy"); + const config: FileConfig = loadOrCreateConfig("dokploy"); - expect(config.http?.routers?.["dokploy-router-app-secure"]).toBeUndefined(); - expect( - config.http?.routers?.["dokploy-router-app"]?.middlewares, - ).not.toContain("redirect-to-https"); + expect(config.http?.routers?.["dokploy-router-app-secure"]).toBeUndefined(); + expect( + config.http?.routers?.["dokploy-router-app"]?.middlewares + ).not.toContain("redirect-to-https"); });