diff --git a/src/factory/BackendFactory.ts b/src/factory/BackendFactory.ts index a41d714..9e0c51d 100644 --- a/src/factory/BackendFactory.ts +++ b/src/factory/BackendFactory.ts @@ -67,7 +67,7 @@ export class BackendFactory { * @returns {@link BackendService} */ public static getCustomRPCService(baseUrl: string): BackendService { - return new BackendServiceImpl(baseUrl); + return BackendServiceImpl.byBaseUrl(baseUrl); } } diff --git a/src/factory/BackendService.ts b/src/factory/BackendService.ts index 4625a96..3ef5156 100644 --- a/src/factory/BackendService.ts +++ b/src/factory/BackendService.ts @@ -12,6 +12,13 @@ import { AccountService } from '../api/account/AccountService'; * Backend Service */ export interface BackendService { + + /** + * Get Base URL + * @return string - base url + */ + getBaseUrl(): string; + /** * Get Network Service * diff --git a/src/factory/impl/BackendServiceImpl.ts b/src/factory/impl/BackendServiceImpl.ts index 41bf914..29eaded 100644 --- a/src/factory/impl/BackendServiceImpl.ts +++ b/src/factory/impl/BackendServiceImpl.ts @@ -26,6 +26,7 @@ import { OperationType } from "@app/factory/OperationType"; */ export class BackendServiceImpl implements BackendService { + private readonly baseUrl: string; private readonly networkService: NetworkService; private readonly epochService: EpochService; private readonly blockService: BlockService; @@ -50,6 +51,7 @@ export class BackendServiceImpl implements BackendService { */ constructor(baseUrl: string) { console.log(`Koios URL: ${baseUrl}`); + this.baseUrl = baseUrl; this.networkService = new NetworkServiceImpl(baseUrl); this.epochService = new EpochServiceImpl(baseUrl); this.blockService = new BlockServiceImpl(baseUrl); @@ -61,6 +63,10 @@ export class BackendServiceImpl implements BackendService { this.accountService = new AccountServiceImpl(baseUrl); } + getBaseUrl(): string { + return this.baseUrl + } + getNetworkService(): NetworkService { return this.networkService; } diff --git a/tests/PreviewService.test.ts b/tests/PreviewService.test.ts index 1780d6e..7eb46ad 100644 --- a/tests/PreviewService.test.ts +++ b/tests/PreviewService.test.ts @@ -31,6 +31,10 @@ describe("koiosBeckendService", () => { const koiosMainnetService = BackendFactory.getKoiosMainnetService() expect(koiosMainnetService).toBeInstanceOf(BackendServiceImpl) }) + test("koiosCustomRPCService", () => { + const koiosCustomRPCService = BackendFactory.getCustomRPCService("https://preview.koios.rest/api/v0/") + expect(koiosPreviewService.getBaseUrl()).toBe(koiosCustomRPCService.getBaseUrl()) + }) test("koiosMainnetServiceByApiVersion", () => { const koiosMainnetService = BackendFactory.getKoiosMainnetService(ApiVersion.VERSION_0) expect(koiosMainnetService).toBeInstanceOf(BackendServiceImpl) @@ -181,8 +185,10 @@ describe("koiosTransactionsService", () => { const result = await koiosTransactionsService.submitTransaction(new Uint8Array([0])) console.log(result) expect(result).toBeInstanceOf(KoiosHttpError) - expect(result.statusCode).toBe(400) - expect(result.statusText).toBe('Bad Request') + const koiosHttpError: KoiosHttpError = result + expect(koiosHttpError.getStatusCode()).toBe(400) + expect(koiosHttpError.getStatusText()).toBe('Bad Request') + expect(koiosHttpError.getUrl()).not.toBeNull() }); test("getTransactionStatus", async () => { const txHashes = [