stellar-plus
Version:
beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain
44 lines (43 loc) • 2.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const errors_1 = require("../../stellar-plus/horizon/errors");
const index_1 = require("../../stellar-plus/horizon/index");
const network_1 = require("../../stellar-plus/network");
// jest.mock('@stellar/stellar-sdk', () => ({
// Horizon: jest.fn(),
// }))
// const MOCKED_HORIZON = Horizon as unknown as jest.Mock
const NETWORK_CONFIG = (0, network_1.TestNet)();
describe('Default Horizon Handler', () => {
describe('Constructor', () => {
it('should throw an error if the network c]onfiguration is missing the Horizon URL', () => {
const netWorkConfigWithoutHorizonUrl = (0, network_1.CustomNet)(Object.assign(Object.assign({}, NETWORK_CONFIG), { horizonUrl: undefined }));
expect(() => new index_1.HorizonHandlerClient(netWorkConfigWithoutHorizonUrl)).toThrow(errors_1.DHHError.missingHorizonUrl());
});
it('should create a new Horizon server instance', () => {
const horizonHandler = new index_1.HorizonHandlerClient(NETWORK_CONFIG);
expect(horizonHandler).toBeDefined();
expect(horizonHandler.server).toBeDefined();
});
it('should create a new Horizon server instance with allowHttp option when enabled in the network', () => {
const networkConfigWithHttp = (0, network_1.CustomNet)(Object.assign(Object.assign({}, NETWORK_CONFIG), { allowHttp: true }));
const horizonHandler = new index_1.HorizonHandlerClient(networkConfigWithHttp);
expect(horizonHandler).toBeDefined();
expect(horizonHandler.server).toBeDefined();
});
});
describe('loadAccount', () => {
it('should throw an error if the account fails to load', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const horizonHandler = new index_1.HorizonHandlerClient(NETWORK_CONFIG);
horizonHandler.server.loadAccount = jest.fn().mockRejectedValue(new Error('Failed to load account'));
yield expect(horizonHandler.loadAccount('mock_account')).rejects.toThrow(errors_1.DHHError.failedToLoadAccount());
}));
it('should return the account response from horizon', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const horizonHandler = new index_1.HorizonHandlerClient(NETWORK_CONFIG);
horizonHandler.server.loadAccount = jest.fn().mockResolvedValue({ id: 'mock_account' });
const response = yield horizonHandler.loadAccount('mock_account');
expect(response).toEqual({ id: 'mock_account' });
}));
});
});