// SPDX-License-Identifier: Apache-2.0
import { container } from "tsyringe";
import NetworkService from "./NetworkService"; // Adjust path as needed
describe("NetworkService", () => {
    let networkService;
    let mockProps;
    beforeEach(() => {
        jest.clearAllMocks();
        container.clearInstances();
        mockProps = {
            environment: {},
            mirrorNode: {},
            rpcNode: {},
            consensusNodes: "consensus-node-1,consensus-node-2",
            configuration: {},
        };
        container.register("NetworkProps", { useValue: mockProps });
        networkService = container.resolve(NetworkService);
    });
    describe("constructor", () => {
        it("should initialize with provided NetworkProps", () => {
            expect(networkService.environment).toBe(mockProps.environment);
            expect(networkService.mirrorNode).toBe(mockProps.mirrorNode);
            expect(networkService.rpcNode).toBe(mockProps.rpcNode);
            expect(networkService.consensusNodes).toBe(mockProps.consensusNodes);
            expect(networkService.configuration).toBe(mockProps.configuration);
        });
        it("should initialize with undefined props if none provided", () => {
            container.clearInstances();
            container.register("NetworkProps", {
                useValue: {
                    environment: undefined,
                    mirrorNode: undefined,
                    rpcNode: undefined,
                    consensusNodes: undefined,
                    configuration: undefined,
                },
            });
            const service = container.resolve(NetworkService);
            expect(service.environment).toBeUndefined();
            expect(service.mirrorNode).toBeUndefined();
            expect(service.rpcNode).toBeUndefined();
            expect(service.consensusNodes).toBeUndefined();
            expect(service.configuration).toBeUndefined();
        });
        it("should be a singleton", () => {
            const service1 = container.resolve(NetworkService);
            const service2 = container.resolve(NetworkService);
            expect(service1).toBe(service2);
        });
    });
    describe("environment getter and setter", () => {
        it("should get and set environment", () => {
            const newEnvironment = {};
            networkService.environment = newEnvironment;
            const result = networkService.environment;
            expect(result).toBe(newEnvironment);
        });
    });
    describe("mirrorNode getter and setter", () => {
        it("should get and set mirrorNode", () => {
            const newMirrorNode = {};
            networkService.mirrorNode = newMirrorNode;
            const result = networkService.mirrorNode;
            expect(result).toBe(newMirrorNode);
        });
    });
    describe("rpcNode getter and setter", () => {
        it("should get and set rpcNode", () => {
            const newRpcNode = {};
            networkService.rpcNode = newRpcNode;
            const result = networkService.rpcNode;
            expect(result).toBe(newRpcNode);
        });
    });
    describe("consensusNodes getter and setter", () => {
        it("should get and set consensusNodes", () => {
            const newConsensusNodes = "new-consensus-node";
            networkService.consensusNodes = newConsensusNodes;
            const result = networkService.consensusNodes;
            expect(result).toBe(newConsensusNodes);
        });
        it("should handle undefined consensusNodes", () => {
            networkService.consensusNodes = undefined;
            const result = networkService.consensusNodes;
            expect(result).toBeUndefined();
        });
    });
    describe("configuration getter and setter", () => {
        it("should get and set configuration", () => {
            const newConfiguration = {};
            networkService.configuration = newConfiguration;
            const result = networkService.configuration;
            expect(result).toBe(newConfiguration);
        });
    });
});
