diff --git a/dlt-connector/src/client/IotaClientSingleton.test.ts b/dlt-connector/src/client/IotaClientSingleton.test.ts index d416cea69..a3436b92d 100644 --- a/dlt-connector/src/client/IotaClientSingleton.test.ts +++ b/dlt-connector/src/client/IotaClientSingleton.test.ts @@ -1,6 +1,29 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { IotaClientSingleton } from '@/client/IotaClientSingleton' import CONFIG from '@/config' +import { logger } from '@/server/logger' + +describe('apis/IotaClientSingleton/disabled', () => { + beforeEach(() => { + CONFIG.IOTA = false + }) + it('getInstance return undefined if iota is disabled', () => { + const spyLog = jest.spyOn(logger, 'info') + expect(IotaClientSingleton.getInstance()).toBeUndefined() + expect(spyLog).toHaveBeenCalledWith('Iota are disabled via config...') + }) +}) + +describe('apis/IotaClientSingleton/invalidIotaUrl', () => { + beforeEach(() => { + CONFIG.IOTA = true + CONFIG.IOTA_API_URL = 'invalidUrl' + }) + it('throw exception on invalid iota url', () => { + // eslint-disable-next-line jest/unbound-method + expect(IotaClientSingleton.getInstance).toThrow() + }) +}) describe('apis/IotaClientSingleton/enabled', () => { describe('Hello World', () => { diff --git a/dlt-connector/src/client/IotaClientSingleton.ts b/dlt-connector/src/client/IotaClientSingleton.ts index c65616fa1..e47254638 100644 --- a/dlt-connector/src/client/IotaClientSingleton.ts +++ b/dlt-connector/src/client/IotaClientSingleton.ts @@ -34,8 +34,9 @@ class IotaClientSingleton { return } if (!IotaClientSingleton.instance) { + const client = new ClientBuilder().node(CONFIG.IOTA_API_URL).build() IotaClientSingleton.instance = new IotaClientSingleton() - IotaClientSingleton.instance.client = new ClientBuilder().node(CONFIG.IOTA_API_URL).build() + IotaClientSingleton.instance.client = client } return IotaClientSingleton.instance diff --git a/dlt-connector/src/client/IotaClientSingleton_disabled.test.ts b/dlt-connector/src/client/IotaClientSingleton_disabled.test.ts deleted file mode 100644 index c6b3704af..000000000 --- a/dlt-connector/src/client/IotaClientSingleton_disabled.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { IotaClientSingleton } from '@/client/IotaClientSingleton' -import CONFIG from '@/config' -import { logger } from '@/server/logger' - -describe('apis/IotaClientSingleton/disabled', () => { - beforeEach(() => { - CONFIG.IOTA = false - }) - it('getInstance return undefined if iota is disabled', () => { - const spyLog = jest.spyOn(logger, 'info') - expect(IotaClientSingleton.getInstance()).toBeUndefined() - expect(spyLog).toHaveBeenCalledWith('Iota are disabled via config...') - }) -}) - -describe('apis/IotaClientSingleton/invalidIotaUrl', () => { - beforeEach(() => { - CONFIG.IOTA = true - CONFIG.IOTA_API_URL = 'invalidUrl' - }) - it('throw exception on invalid iota url', () => { - // eslint-disable-next-line jest/unbound-method - expect(IotaClientSingleton.getInstance).toThrow() - }) -})