Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature add logger tests #1725

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/integration/AccountBalanceIntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ describe("AccountBalanceQuery", function () {
env = await IntegrationTestEnv.new({ throwaway: true });
});

it("can query balance of node 0.0.3", async function () {
this.timeout(50000);

const balance = await new AccountBalanceQuery()
.setAccountId("0.0.3")
.execute(clientTestnet);
expect(balance.hbars.toTinybars().compare(0)).to.be.equal(1);
});

it("can connect to previewnet with TLS", async function () {
this.timeout(30000);
if (skipTestDueToNodeJsVersion(16)) {
Expand Down
15 changes: 0 additions & 15 deletions test/unit/AccountBalanceQuery.js

This file was deleted.

File renamed without changes.
71 changes: 71 additions & 0 deletions test/unit/LoggerTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Logger, LogLevel, Transaction } from "../../src/exports.js";
import { Client } from "../../src/index.js";

describe("Logger", function () {
this.timeout(50000);

it("set and get log level correctly inside the `Client` object", async function () {
const client = Client.forPreviewnet({
scheduleNetworkUpdate: false,
});

//during initialization of the `Client`, there is no logger set
expect(client.logger).to.be.null;

//set logger with info level of logging to the `Client`
let infoLogger = new Logger(LogLevel.Info);
client.setLogger(infoLogger);

//check if the log level is in fact `info`
expect(client.logger.level).to.be.equal(LogLevel.Info);

//change the level of the logger to `warn` and check
//if it is the same when extracted from the `Client`
infoLogger.setLevel(LogLevel.Warn);
expect(client.logger.level).to.be.equal(LogLevel.Warn);

//silence the logger and check if it changed inside the `Client`
infoLogger.setSilent(true);
expect(client.logger.level).to.be.equal(LogLevel.Silent);
});

it("set and get log level correctly inside the `Transaction` object", async function () {
const transaction = new Transaction();

//during initialization of the `Transaction`, there is no logger set
expect(transaction.logger).to.be.null;

//set logger with info level of logging to the `Transaction`
let infoLogger = new Logger(LogLevel.Info);
transaction.setLogger(infoLogger);

//check if the log level is in fact `info`
expect(transaction.logger.level).to.be.equal(LogLevel.Info);

//change the level of the logger to `warn` and check
//if it is the same when extracted from the `Transaction`
infoLogger.setLevel(LogLevel.Warn);
expect(transaction.logger.level).to.be.equal(LogLevel.Warn);

//silence the logger and check if it changed inside the `Transaction`
infoLogger.setSilent(true);
expect(transaction.logger.level).to.be.equal(LogLevel.Silent);
});

it("check the possible log levels on the logger", async function () {
const transaction = new Transaction();
//during initialization of the `Transaction`, there is no logger set
expect(transaction.logger).to.be.null;

//set logger with info level of logging to the `Transaction`
const infoLogger = new Logger(LogLevel.Info);
const levels = Object.values(infoLogger.levels);

expect(levels).to.include("trace");
expect(levels).to.include("debug");
expect(levels).to.include("info");
expect(levels).to.include("warn");
expect(levels).to.include("error");
expect(levels).to.include("fatal");
});
});