Skip to content

Commit

Permalink
Increase Code Coverage (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Dudi Edri <[email protected]>
  • Loading branch information
edridudi and Dudi Edri authored Sep 3, 2023
1 parent cad105e commit 89e0912
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/factory/BackendFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class BackendFactory {
* @returns {@link BackendService}
*/
public static getCustomRPCService(baseUrl: string): BackendService {
return new BackendServiceImpl(baseUrl);
return BackendServiceImpl.byBaseUrl(baseUrl);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/factory/BackendService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
6 changes: 6 additions & 0 deletions src/factory/impl/BackendServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -61,6 +63,10 @@ export class BackendServiceImpl implements BackendService {
this.accountService = new AccountServiceImpl(baseUrl);
}

getBaseUrl(): string {
return this.baseUrl
}

getNetworkService(): NetworkService {
return this.networkService;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/PreviewService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 89e0912

Please sign in to comment.