postchain-client
Version:
Client library for accessing a Postchain node through REST.
62 lines • 3.31 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { HttpResponse, http } from "msw";
import { toString } from "../../../src/formatter";
import { server } from "../../../mocks/servers";
import { LOCAL_POOL, mockBufferBlockchainRid, mockStringBlockchainRid } from "../../common/mocks";
import { getTestsClient } from "../../common/setups";
const tx = "A581B83081B5A56B3069A12204200398A1E7B0F87709AFD14CD1821EAAAFB41931A8097FFA2D83E5FE10DA7E4DD5A51A3018A5163014A20E0C0C6D795F6F7065726174696F6EA5023000A5273025A1230421032BF0FCF83A287FB5EC71E4DAEA5DE892804A5BBBED6130DBCDDB871015C34EA0A5463044A14204404B425779BF8BD5ED503837337BBE102B7013F791F3BCFB812726EA93E076A3267656EC773AA10617E1ABDB25E97AB1CF2992CDB3E059D668C90BDA6BB91FE836";
let client;
describe("retry feature in blockchain client", () => {
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
server.listen();
const attemptsPerEndpoint = 3;
client = yield getTestsClient({
failOverConfig: {
attemptsPerEndpoint,
},
});
}));
afterEach(() => {
server.resetHandlers();
});
afterAll(() => {
server.close();
});
it("move to next node if current node returns unknown error status code", () => __awaiter(void 0, void 0, void 0, function* () {
server.use(http.get(`http://localhost1/tx/*`, () => {
return new HttpResponse("Unpredicted error", { status: 555 });
}), http.get(`${LOCAL_POOL}/tx/*`, () => {
return HttpResponse.json({
tx,
});
}), http.get(`http://localhost1/brid/iid_0`, () => {
return new HttpResponse(mockStringBlockchainRid);
}));
const res = yield client.getTransaction(mockBufferBlockchainRid);
expect(toString(res)).toBe(tx);
}));
it("returns error when all nodes are failed with request", () => __awaiter(void 0, void 0, void 0, function* () {
server.use(http.get(`http://localhost1/tx/*`, () => {
return new HttpResponse("Unpredicted error", { status: 550 });
}), http.get(`${LOCAL_POOL}/tx/*`, () => {
return new HttpResponse("Unpredicted error", { status: 550 });
}), http.get(`http://localhost1/brid/iid_0`, () => {
return new HttpResponse(mockStringBlockchainRid);
}));
try {
yield client.getTransaction(mockBufferBlockchainRid);
}
catch (error) {
expect(error.message).toBe("Unexpected status code from server. Code: 550. Message: Unpredicted error.");
}
}));
});
//# sourceMappingURL=clientCustomStatusCodes.test.js.map