mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-01 01:32:16 +00:00
refactor(network-service): enhance network addition logic to include default network
- Updated the addDokployNetworkToService function to automatically include the "default" network when adding new networks. - Modified test cases to reflect the new behavior, ensuring no duplicates of the default network are added. - Improved handling of network addition for both arrays and objects.
This commit is contained in:
@@ -4,21 +4,30 @@ import { describe, expect, it } from "vitest";
|
|||||||
describe("addDokployNetworkToService", () => {
|
describe("addDokployNetworkToService", () => {
|
||||||
it("should add network to an empty array", () => {
|
it("should add network to an empty array", () => {
|
||||||
const result = addDokployNetworkToService([]);
|
const result = addDokployNetworkToService([]);
|
||||||
expect(result).toEqual(["dokploy-network"]);
|
expect(result).toEqual(["dokploy-network", "default"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not add duplicate network to an array", () => {
|
it("should not add duplicate network to an array", () => {
|
||||||
const result = addDokployNetworkToService(["dokploy-network"]);
|
const result = addDokployNetworkToService(["dokploy-network"]);
|
||||||
expect(result).toEqual(["dokploy-network"]);
|
expect(result).toEqual(["dokploy-network", "default"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add network to an existing array with other networks", () => {
|
it("should add network to an existing array with other networks", () => {
|
||||||
const result = addDokployNetworkToService(["other-network"]);
|
const result = addDokployNetworkToService(["other-network"]);
|
||||||
expect(result).toEqual(["other-network", "dokploy-network"]);
|
expect(result).toEqual(["other-network", "dokploy-network", "default"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should add network to an object if networks is an object", () => {
|
it("should add network to an object if networks is an object", () => {
|
||||||
const result = addDokployNetworkToService({ "other-network": {} });
|
const result = addDokployNetworkToService({ "other-network": {} });
|
||||||
expect(result).toEqual({ "other-network": {}, "dokploy-network": {} });
|
expect(result).toEqual({
|
||||||
|
"other-network": {},
|
||||||
|
"dokploy-network": {},
|
||||||
|
default: {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not duplicate default network when already present", () => {
|
||||||
|
const result = addDokployNetworkToService(["default", "dokploy-network"]);
|
||||||
|
expect(result).toEqual(["default", "dokploy-network"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -330,6 +330,7 @@ export const addDokployNetworkToService = (
|
|||||||
) => {
|
) => {
|
||||||
let networks = networkService;
|
let networks = networkService;
|
||||||
const network = "dokploy-network";
|
const network = "dokploy-network";
|
||||||
|
const defaultNetwork = "default";
|
||||||
if (!networks) {
|
if (!networks) {
|
||||||
networks = [];
|
networks = [];
|
||||||
}
|
}
|
||||||
@@ -338,10 +339,16 @@ export const addDokployNetworkToService = (
|
|||||||
if (!networks.includes(network)) {
|
if (!networks.includes(network)) {
|
||||||
networks.push(network);
|
networks.push(network);
|
||||||
}
|
}
|
||||||
|
if (!networks.includes(defaultNetwork)) {
|
||||||
|
networks.push(defaultNetwork);
|
||||||
|
}
|
||||||
} else if (networks && typeof networks === "object") {
|
} else if (networks && typeof networks === "object") {
|
||||||
if (!(network in networks)) {
|
if (!(network in networks)) {
|
||||||
networks[network] = {};
|
networks[network] = {};
|
||||||
}
|
}
|
||||||
|
if (!(defaultNetwork in networks)) {
|
||||||
|
networks[defaultNetwork] = {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return networks;
|
return networks;
|
||||||
|
|||||||
Reference in New Issue
Block a user