Skip to content
Extraits de code Groupes Projets
Valider ce72760a rédigé par Will Hunt's avatar Will Hunt
Parcourir les fichiers

Add tests for config and log

parent 94f8e233
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
import * as Chai from "chai";
import * as ChaiAsPromised from "chai-as-promised";
import { DiscordBridgeConfig } from "../src/config";
Chai.use(ChaiAsPromised);
const expect = Chai.expect;
describe("DiscordBridgeConfig.ApplyConfig", () => {
it("should merge configs correctly", () => {
const config = new DiscordBridgeConfig();
config.ApplyConfig({
bridge: {
homeserverUrl: "blah",
disableTypingNotifications: true,
disableDiscordMentions: false,
disableDeletionForwarding: true,
enableSelfServiceBridging: false
},
logging: {
console: "warn",
}
});
expect(config.bridge.homeserverUrl, "blah");
expect(config.bridge.disableTypingNotifications).to.be.true;
expect(config.bridge.disableDiscordMentions).to.be.false;
expect(config.bridge.disableDeletionForwarding).to.be.true;
expect(config.bridge.enableSelfServiceBridging).to.be.false;
expect(config.logging.console, "warn");
});
it("should merge logging.files correctly", () => {
const config = new DiscordBridgeConfig();
config.ApplyConfig({
logging: {
console: "silent",
files: [
{
file: "./bacon.log",
}
]
}
});
expect(config.logging.files[0].file, "./bacon.log");
});
})
\ No newline at end of file
import * as Chai from "chai";
import * as ChaiAsPromised from "chai-as-promised";
import * as Proxyquire from "proxyquire";
import * as RealLog from "../src/log";
Chai.use(ChaiAsPromised);
const expect = Chai.expect;
let created_logger = null;
let logger_closed = false;
let logged_messages = [];
const WinstonMock = {
createLogger: (format, transports) => {
return created_logger = {
format,
transports,
close: () => {
logger_closed = true;
},
silent: false,
log: (type, ...msg) => {
logged_messages = logged_messages.concat(msg);
}
};
},
};
const Log = (Proxyquire("../src/log", {
"winston": WinstonMock,
}).Log);
describe("Log", () => {
beforeEach(() => {
logger_closed = false;
logged_messages = [];
})
describe("ConfigureBridge", () => {
it("should pass if config is empty", () => {
Log.ConfigureBridge({});
});
it("should set basic log options", () => {
Log.ConfigureBridge({
console: "warn",
lineDateFormat: "HH:mm:ss"
});
expect(Log.config.console).to.equal("warn");
expect(Log.config.lineDateFormat).to.equal("HH:mm:ss");
expect(Log.config.files).to.be.empty;
});
it("should setup file logging", () => {
Log.ConfigureBridge({
files: [
{
file: "./logfile.log"
}
]
});
expect(Log.config.files).to.not.be.empty;
expect(Log.config.files[0].file).to.equal("./logfile.log");
});
});
describe("ForceSilent", () => {
it("should be silent", () => {
Log.ForceSilent();
expect(created_logger.silent).to.be.true;
expect(logged_messages).to.contain("Log set to silent");
});
});
describe("instance", () => {
it("should log without configuring", () => {
new Log("test").info("hi");
expect(logged_messages).to.contain("hi");
});
});
})
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter