Skip to content

Commit

Permalink
Added some tests that cover some exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaro-mota-funttastic committed Oct 24, 2023
1 parent 49ac103 commit da4b091
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
4 changes: 2 additions & 2 deletions test-bronze/connectors/kujira/fixtures/patches/data.ts

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions test-bronze/connectors/kujira/fixtures/patches/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ export const createPatches = (
);

patches.setIn(
['kujira', 'kujiraGetTendermint34Client'],
['kujira', 'kujiraGetTendermint37Client'],
async (testTitle: string) => {
if (!usePatches) return;

patch(kujira, 'kujiraGetTendermint34Client', async (...any: any[]) => {
patch(kujira, 'kujiraGetTendermint37Client', async (...any: any[]) => {
const inputArguments = any;

if (!ordinalMap.has(testTitle)) {
Expand All @@ -191,7 +191,7 @@ export const createPatches = (

const dataKey = [
'kujira',
'kujiraGetTendermint34Client',
'kujiraGetTendermint37Client',
testTitle,
ordinal,
];
Expand All @@ -202,7 +202,7 @@ export const createPatches = (
return await inputOutputWrapper<any>(
dataKey,
kujira,
'kujiraGetTendermint34Client',
'kujiraGetTendermint37Client',
inputArguments
);
}
Expand Down
58 changes: 54 additions & 4 deletions test-bronze/connectors/kujira/kujira.controllers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
Market,
MarketId,
MarketName,
MarketNotFoundError,
MarketsWithdrawsFundsResponse,
MarketsWithdrawsRequest,
MarketWithdrawRequest,
Expand Down Expand Up @@ -142,11 +143,11 @@ import express from 'express';
import { Express } from 'express-serve-static-core';
import data from './fixtures/patches/data';

enablePatches();
// disablePatches();
// enablePatches();
disablePatches();

// enableInputOutputWrapper();
disableInputOutputWrapper();
// disableInputOutputWrapper();

// const requestStrategy = RequestStrategy.RESTful;
const requestStrategy = RequestStrategy.Controller;
Expand Down Expand Up @@ -290,7 +291,7 @@ beforeAll(async () => {
// await getPatch(['global', 'fetch'])('beforeAll');
await getPatch(['kujira', 'getFastestRpc'])('beforeAll');
await getPatch(['kujira', 'kujiraGetHttpBatchClient'])('beforeAll');
await getPatch(['kujira', 'kujiraGetTendermint34Client'])('beforeAll');
await getPatch(['kujira', 'kujiraGetTendermint37Client'])('beforeAll');
await getPatch(['kujira', 'kujiraGetKujiraQueryClient'])('beforeAll');
await getPatch(['kujira', 'kujiraGetStargateClient'])('beforeAll');
await getPatch(['kujira', 'kujiraGetBasicMarkets'])('beforeAll');
Expand Down Expand Up @@ -4819,4 +4820,53 @@ describe('Kujira', () => {
}
});
});

describe('Exceptions', () => {
it('Generate Exception TokenNotFound', async () => {
const requestBody = {
name: 'KUJ',
} as GetTokenRequest;

const request = {
...commonRequestBody,
...requestBody,
};

logRequest(request);

try {
sendRequest<GetTokenResponse>({
RESTMethod: RESTfulMethod.GET,
RESTRoute: '/token',
RESTRequest: request,
controllerFunction: KujiraController.getToken,
});
} catch (e) {
expect(true).toBeTrue();
}
});

it('Generate MarketNotFoundError Exception', async () => {
const requestBody = {
ownerAddress: ownerAddress,
} as MarketsWithdrawsRequest;

const request = {
...commonRequestBody,
...requestBody,
};

logRequest(request);
try {
await sendRequest<MarketsWithdrawsFundsResponse>({
RESTMethod: RESTfulMethod.POST,
RESTRoute: '/market/withdraws',
RESTRequest: request,
controllerFunction: KujiraController.withdrawFromMarkets,
});
} catch (e) {
expect(e).toEqual(new MarketNotFoundError('No market informed.'));
}
});
});
});

0 comments on commit da4b091

Please sign in to comment.